blob: b86421c6b9a03043bec305a10be3080204605c8e [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 Qianccbaf742021-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 Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -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;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700189import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800192import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000193import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800194import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700195import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800197import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800198import com.android.phone.callcomposer.CallComposerPictureManager;
199import com.android.phone.callcomposer.CallComposerPictureTransfer;
200import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700201import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800203import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700205import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800206import com.android.services.telephony.TelecomAccountRegistry;
207import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800208import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800209
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700211import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.IOException;
213import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700214import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800217import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800218import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800219import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100220import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700222import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800226import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800227import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229/**
230 * Implementation of the ITelephony interface.
231 */
Santos Cordon117fee72014-05-16 17:56:12 -0700232public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 private static final String LOG_TAG = "PhoneInterfaceManager";
234 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
235 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238 // Message codes used with mMainThreadHandler
239 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700240 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
241 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242 private static final int CMD_OPEN_CHANNEL = 9;
243 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
244 private static final int CMD_CLOSE_CHANNEL = 11;
245 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800246 private static final int CMD_NV_READ_ITEM = 13;
247 private static final int EVENT_NV_READ_ITEM_DONE = 14;
248 private static final int CMD_NV_WRITE_ITEM = 15;
249 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
250 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
251 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700252 private static final int CMD_RESET_MODEM_CONFIG = 19;
253 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800254 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
255 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800256 private static final int CMD_SEND_ENVELOPE = 25;
257 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000258 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
259 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700260 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
261 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
262 private static final int CMD_EXCHANGE_SIM_IO = 31;
263 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
265 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700266 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
267 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700268 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
269 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700270 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
271 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
272 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
273 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700274 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
275 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
276 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
277 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700278 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800279 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
280 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000281 private static final int CMD_SWITCH_SLOTS = 50;
282 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700283 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
284 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
285 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
286 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
287 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
288 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
289 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
290 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700291 private static final int CMD_GET_ALL_CELL_INFO = 60;
292 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
293 private static final int CMD_GET_CELL_LOCATION = 62;
294 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700295 private static final int CMD_MODEM_REBOOT = 64;
296 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700297 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
298 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800299 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
300 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700301 private static final int CMD_GET_MODEM_STATUS = 70;
302 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700303 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
304 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700305 private static final int CMD_ERASE_MODEM_CONFIG = 74;
306 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800307 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
308 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
309 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
310 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800311 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
312 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800314 private static final int CMD_GET_CALL_FORWARDING = 83;
315 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
316 private static final int CMD_SET_CALL_FORWARDING = 85;
317 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
318 private static final int CMD_GET_CALL_WAITING = 87;
319 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
320 private static final int CMD_SET_CALL_WAITING = 89;
321 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700322 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
323 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
324 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
325 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700326 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
327 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800328 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
329 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800330 private static final int CMD_SET_DATA_THROTTLING = 99;
331 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800332 private static final int CMD_SET_SIM_POWER = 101;
333 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800334 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
335 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
336 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
337 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800338 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
339 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000340 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800341 private static final int CMD_GET_SLICING_CONFIG = 110;
342 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800343 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800345 // Parameters of select command.
346 private static final int SELECT_COMMAND = 0xA4;
347 private static final int SELECT_P1 = 0x04;
348 private static final int SELECT_P2 = 0;
349 private static final int SELECT_P3 = 0x10;
350
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 /** The singleton instance. */
352 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800353 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
Wink Saville3ab207e2014-11-20 13:07:20 -0800355 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800356 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800357 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700358 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700360 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800362 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700364 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800365 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
Peter Wangdafb9ac2020-01-15 14:13:38 -0800367 /** User Activity */
368 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800369 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
370
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700371 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
372
Derek Tan97ebb422014-09-05 16:55:38 -0700373 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
374 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800375 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800376 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700377
Michelecea4cf22018-12-21 15:00:11 -0800378 // String to store multi SIM allowed
379 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
380
Derek Tan740e1672017-06-27 14:56:27 -0700381 // The AID of ISD-R.
382 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
383
yinxub1bed742017-04-17 11:45:04 -0700384 private NetworkScanRequestTracker mNetworkScanRequestTracker;
385
David Kelly5e06a7f2018-03-12 14:10:59 +0000386 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
387 private static final int MANUFACTURER_CODE_LENGTH = 8;
388
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800389 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800390 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800391
Derek Tan89e89d42014-07-08 17:00:10 -0700392 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700393 * Experiment flag to enable erase modem config on reset network, default value is false
394 */
395 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
396 "reset_network_erase_modem_config_enabled";
397
Rambo Wang0f050d82021-02-12 11:43:36 -0800398 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
399
Naina Nallurid63128d2019-09-17 14:10:30 -0700400 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700401 * A request object to use for transmitting data to an ICC.
402 */
403 private static final class IccAPDUArgument {
404 public int channel, cla, command, p1, p2, p3;
405 public String data;
406
407 public IccAPDUArgument(int channel, int cla, int command,
408 int p1, int p2, int p3, String data) {
409 this.channel = channel;
410 this.cla = cla;
411 this.command = command;
412 this.p1 = p1;
413 this.p2 = p2;
414 this.p3 = p3;
415 this.data = data;
416 }
417 }
418
419 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700420 * A request object to use for transmitting data to an ICC.
421 */
422 private static final class ManualNetworkSelectionArgument {
423 public OperatorInfo operatorInfo;
424 public boolean persistSelection;
425
426 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
427 this.operatorInfo = operatorInfo;
428 this.persistSelection = persistSelection;
429 }
430 }
431
432 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
434 * request after sending. The main thread will notify the request when it is complete.
435 */
436 private static final class MainThreadRequest {
437 /** The argument to use for the request */
438 public Object argument;
439 /** The result of the request that is run on the main thread */
440 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800441 // The subscriber id that this request applies to. Defaults to
442 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
443 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Nathan Harold92bed182018-10-12 18:16:49 -0700445 // In cases where subId is unavailable, the caller needs to specify the phone.
446 public Phone phone;
447
vagdeviaf9a5b92018-08-15 16:01:53 -0700448 public WorkSource workSource;
449
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 public MainThreadRequest(Object argument) {
451 this.argument = argument;
452 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800453
Nathan Harold92bed182018-10-12 18:16:49 -0700454 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
455 this.argument = argument;
456 if (phone != null) {
457 this.phone = phone;
458 }
459 this.workSource = workSource;
460 }
461
vagdeviaf9a5b92018-08-15 16:01:53 -0700462 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800463 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800464 if (subId != null) {
465 this.subId = subId;
466 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700467 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 }
470
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800471 private static final class IncomingThirdPartyCallArgs {
472 public final ComponentName component;
473 public final String callId;
474 public final String callerDisplayName;
475
476 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
477 String callerDisplayName) {
478 this.component = component;
479 this.callId = callId;
480 this.callerDisplayName = callerDisplayName;
481 }
482 }
483
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 /**
485 * A handler that processes messages on the main thread in the phone process. Since many
486 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
487 * inbound binder threads to the main thread in the phone process. The Binder thread
488 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
489 * on, which will be notified when the operation completes and will contain the result of the
490 * request.
491 *
492 * <p>If a MainThreadRequest object is provided in the msg.obj field,
493 * note that request.result must be set to something non-null for the calling thread to
494 * unblock.
495 */
496 private final class MainThreadHandler extends Handler {
497 @Override
498 public void handleMessage(Message msg) {
499 MainThreadRequest request;
500 Message onCompleted;
501 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800504 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505
506 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 case CMD_HANDLE_USSD_REQUEST: {
508 request = (MainThreadRequest) msg.obj;
509 final Phone phone = getPhoneFromRequest(request);
510 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
511 String ussdRequest = ussdObject.first;
512 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700513
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 if (!isUssdApiAllowed(request.subId)) {
515 // Carrier does not support use of this API, return failure.
516 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
517 UssdResponse response = new UssdResponse(ussdRequest, null);
518 Bundle returnData = new Bundle();
519 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
520 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700521
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 request.result = true;
523 notifyRequester(request);
524 return;
525 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700526
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 try {
528 request.result = phone != null
529 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
530 } catch (CallStateException cse) {
531 request.result = false;
532 }
533 // Wake up the requesting thread
534 notifyRequester(request);
535 break;
pkanwar32d516d2016-10-14 19:37:38 -0700536 }
537
Yorke Lee716f67e2015-06-17 15:39:16 -0700538 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700540 final Phone phone = getPhoneFromRequest(request);
541 request.result = phone != null ?
542 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
543 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccTransmitApduLogicalChannel: No UICC");
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
559 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 iccArgument.channel, iccArgument.cla, iccArgument.command,
562 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
572 } else {
573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
574 if (ar.result == null) {
575 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800576 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800578 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 } else {
580 loge("iccTransmitApduLogicalChannel: Unknown exception");
581 }
582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 break;
585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
587 request = (MainThreadRequest) msg.obj;
588 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 if (uiccCard == null) {
591 loge("iccTransmitApduBasicChannel: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
596 request);
597 uiccCard.iccTransmitApduBasicChannel(
598 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
599 iccArgument.p3, iccArgument.data, onCompleted);
600 }
601 break;
602
603 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("iccTransmitApduBasicChannel: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("iccTransmitApduBasicChannel: CommandException: " +
614 ar.exception);
615 } else {
616 loge("iccTransmitApduBasicChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 break;
621
622 case CMD_EXCHANGE_SIM_IO:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 if (uiccCard == null) {
627 loge("iccExchangeSimIO: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
632 request);
633 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
634 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
635 iccArgument.data, onCompleted);
636 }
637 break;
638
639 case EVENT_EXCHANGE_SIM_IO_DONE:
640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result;
644 } else {
645 request.result = new IccIoResult(0x6f, 0, (byte[])null);
646 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 break;
649
Derek Tan4d5e5c12014-02-04 11:54:58 -0800650 case CMD_SEND_ENVELOPE:
651 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800652 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 if (uiccCard == null) {
654 loge("sendEnvelopeWithStatus: No UICC");
655 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
659 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
660 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800661 break;
662
663 case EVENT_SEND_ENVELOPE_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800668 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700669 request.result = new IccIoResult(0x6F, 0, (byte[])null);
670 if (ar.result == null) {
671 loge("sendEnvelopeWithStatus: Empty response");
672 } else if (ar.exception instanceof CommandException) {
673 loge("sendEnvelopeWithStatus: CommandException: " +
674 ar.exception);
675 } else {
676 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
677 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800680 break;
681
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 case CMD_OPEN_CHANNEL:
683 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800684 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800685 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 if (uiccCard == null) {
687 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800688 request.result = new IccOpenLogicalChannelResponse(-1,
689 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 } else {
692 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800693 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
694 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
698 case EVENT_OPEN_CHANNEL_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 int[] result = (int[]) ar.result;
704 int channelId = result[0];
705 byte[] selectResponse = null;
706 if (result.length > 1) {
707 selectResponse = new byte[result.length - 1];
708 for (int i = 1; i < result.length; ++i) {
709 selectResponse[i - 1] = (byte) result[i];
710 }
711 }
712 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700713 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 if (ar.result == null) {
716 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 if (ar.exception != null) {
719 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
720 }
721
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700722 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700723 if (ar.exception instanceof CommandException) {
724 CommandException.Error error =
725 ((CommandException) (ar.exception)).getCommandError();
726 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700728 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700729 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700730 }
731 }
732 openChannelResp = new IccOpenLogicalChannelResponse(
733 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700735 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 break;
738
739 case CMD_CLOSE_CHANNEL:
740 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800741 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 if (uiccCard == null) {
743 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900744 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 } else {
747 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
748 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
749 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 break;
751
752 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800753 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
754 break;
755
756 case CMD_NV_READ_ITEM:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800759 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
760 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800761 break;
762
763 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 ar = (AsyncResult) msg.obj;
765 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800766 if (ar.exception == null && ar.result != null) {
767 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800769 request.result = "";
770 if (ar.result == null) {
771 loge("nvReadItem: Empty response");
772 } else if (ar.exception instanceof CommandException) {
773 loge("nvReadItem: CommandException: " +
774 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800776 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700777 }
778 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700779 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 break;
781
Jake Hambye994d462014-02-03 13:10:13 -0800782 case CMD_NV_WRITE_ITEM:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
785 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800786 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700787 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
790 case EVENT_NV_WRITE_ITEM_DONE:
791 handleNullReturnEvent(msg, "nvWriteItem");
792 break;
793
794 case CMD_NV_WRITE_CDMA_PRL:
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800797 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800798 break;
799
800 case EVENT_NV_WRITE_CDMA_PRL_DONE:
801 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
802 break;
803
chen xu6dac5ab2018-10-26 17:39:23 -0700804 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800805 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700806 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800807 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800808 break;
809
chen xu6dac5ab2018-10-26 17:39:23 -0700810 case EVENT_RESET_MODEM_CONFIG_DONE:
811 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
Sooraj Sasindran37444802020-08-11 10:40:43 -0700814 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
817 request);
818 Phone phone = getPhoneFromRequest(request);
819 if (phone != null) {
820 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
821 } else {
822 loge("isNRDualConnectivityEnabled: No phone object");
823 request.result = false;
824 notifyRequester(request);
825 }
826 break;
827 }
828
829 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null && ar.result != null) {
833 request.result = ar.result;
834 } else {
835 // request.result must be set to something non-null
836 // for the calling thread to unblock
837 if (request.result != null) {
838 request.result = ar.result;
839 } else {
840 request.result = false;
841 }
842 if (ar.result == null) {
843 loge("isNRDualConnectivityEnabled: Empty response");
844 } else if (ar.exception instanceof CommandException) {
845 loge("isNRDualConnectivityEnabled: CommandException: "
846 + ar.exception);
847 } else {
848 loge("isNRDualConnectivityEnabled: Unknown exception");
849 }
850 }
851 notifyRequester(request);
852 break;
853
854 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
855 request = (MainThreadRequest) msg.obj;
856 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
857 Phone phone = getPhoneFromRequest(request);
858 if (phone != null) {
859 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
860 request.workSource);
861 } else {
862 loge("enableNrDualConnectivity: No phone object");
863 request.result =
864 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
865 notifyRequester(request);
866 }
867 break;
868 }
869
870 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null) {
874 request.result =
875 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
876 } else {
877 request.result =
878 TelephonyManager
879 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
880 if (ar.exception instanceof CommandException) {
881 CommandException.Error error =
882 ((CommandException) (ar.exception)).getCommandError();
883 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
884 request.result =
885 TelephonyManager
886 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000887 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
888 request.result =
889 TelephonyManager
890 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700891 }
892 loge("enableNrDualConnectivity" + ": CommandException: "
893 + ar.exception);
894 } else {
895 loge("enableNrDualConnectivity" + ": Unknown exception");
896 }
897 }
898 notifyRequester(request);
899 break;
900 }
901
SongFerngWang3ef3e072020-12-21 16:41:52 +0800902 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800904 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
905 request);
906 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 break;
908
SongFerngWang3ef3e072020-12-21 16:41:52 +0800909 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result; // Integer
914 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530915 // request.result must be set to something non-null
916 // for the calling thread to unblock
917 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800919 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800921 loge("getAllowedNetworkTypesBitmask: CommandException: "
922 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800924 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800925 }
926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700927 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800928 break;
929
SongFerngWang3ef3e072020-12-21 16:41:52 +0800930 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800931 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800932 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
933 request);
934 Pair<Integer, Long> reasonWithNetworkTypes =
935 (Pair<Integer, Long>) request.argument;
936 getPhoneFromRequest(request).setAllowedNetworkTypes(
937 reasonWithNetworkTypes.first,
938 reasonWithNetworkTypes.second,
939 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800940 break;
941
SongFerngWang3ef3e072020-12-21 16:41:52 +0800942 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
943 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800944 break;
945
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000946 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
947 request = (MainThreadRequest)msg.obj;
948 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800949 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000950 break;
951
952 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
953 ar = (AsyncResult)msg.obj;
954 request = (MainThreadRequest)ar.userObj;
955 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000957 break;
958
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800959 case CMD_SET_VOICEMAIL_NUMBER:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
962 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800963 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
964 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800965 break;
966
967 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
968 handleNullReturnEvent(msg, "setVoicemailNumber");
969 break;
970
Stuart Scott54788802015-03-30 13:18:01 -0700971 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
974 request);
975 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
976 break;
977
978 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
979 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
980 break;
981
Shishir Agrawal302c8692015-06-19 13:49:39 -0700982 case CMD_PERFORM_NETWORK_SCAN:
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
985 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
986 break;
987
Hall Liu27d24262020-09-18 19:04:59 -0700988 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700991 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
992 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
993 request.argument;
994 int callForwardingReason = args.first;
995 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800996 break;
Hall Liu27d24262020-09-18 19:04:59 -0700997 }
998 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001001 TelephonyManager.CallForwardingInfoCallback callback =
1002 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1003 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001004 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001005 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001006 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1007 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1008 // Service Class is a bit mask per 3gpp 27.007. Search for
1009 // any service for voice call.
1010 if ((callForwardInfo.serviceClass
1011 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001012 callForwardingInfo = new CallForwardingInfo(
1013 callForwardInfo.status
1014 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001015 callForwardInfo.reason,
1016 callForwardInfo.number,
1017 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001018 break;
1019 }
1020 }
1021 // Didn't find a call forward info for voice call.
1022 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001023 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1024 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001025 }
Hall Liu27d24262020-09-18 19:04:59 -07001026 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001027 } else {
1028 if (ar.result == null) {
1029 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1030 }
1031 if (ar.exception != null) {
1032 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1033 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001034 int errorCode = TelephonyManager
1035 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001036 if (ar.exception instanceof CommandException) {
1037 CommandException.Error error =
1038 ((CommandException) (ar.exception)).getCommandError();
1039 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001040 errorCode = TelephonyManager
1041 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001042 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001043 errorCode = TelephonyManager
1044 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001045 }
1046 }
Hall Liu27d24262020-09-18 19:04:59 -07001047 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001048 }
Shuo Qian4a594052020-01-23 11:59:30 -08001049 break;
Hall Liu27d24262020-09-18 19:04:59 -07001050 }
Shuo Qian4a594052020-01-23 11:59:30 -08001051
Hall Liu27d24262020-09-18 19:04:59 -07001052 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001053 request = (MainThreadRequest) msg.obj;
1054 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001055 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001056 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001057 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1058 request.argument).first;
1059 request.phone.setCallForwardingOption(
1060 callForwardingInfoToSet.isEnabled()
1061 ? CommandsInterface.CF_ACTION_ENABLE
1062 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001063 callForwardingInfoToSet.getReason(),
1064 callForwardingInfoToSet.getNumber(),
1065 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1066 break;
Hall Liu27d24262020-09-18 19:04:59 -07001067 }
Shuo Qian4a594052020-01-23 11:59:30 -08001068
Hall Liu27d24262020-09-18 19:04:59 -07001069 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001072 Consumer<Integer> callback =
1073 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1074 request.argument).second;
1075 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001076 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001077 int errorCode = TelephonyManager.CallForwardingInfoCallback
1078 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001079 if (ar.exception instanceof CommandException) {
1080 CommandException.Error error =
1081 ((CommandException) (ar.exception)).getCommandError();
1082 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001083 errorCode = TelephonyManager.CallForwardingInfoCallback
1084 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001085 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001086 errorCode = TelephonyManager.CallForwardingInfoCallback
1087 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001088 }
1089 }
1090 callback.accept(errorCode);
1091 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001092 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001093 }
Shuo Qian4a594052020-01-23 11:59:30 -08001094 break;
Hall Liu27d24262020-09-18 19:04:59 -07001095 }
Shuo Qian4a594052020-01-23 11:59:30 -08001096
Hall Liu27d24262020-09-18 19:04:59 -07001097 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001098 request = (MainThreadRequest) msg.obj;
1099 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1100 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1101 break;
Hall Liu27d24262020-09-18 19:04:59 -07001102 }
Shuo Qian4a594052020-01-23 11:59:30 -08001103
Hall Liu27d24262020-09-18 19:04:59 -07001104 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001107 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001108 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1109 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001110 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001111 // Service Class is a bit mask per 3gpp 27.007.
1112 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001113 if (callForwardResults.length > 1
1114 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001115 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001116 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001117 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1118 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001119 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001120 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001121 }
1122 } else {
1123 if (ar.result == null) {
1124 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1125 }
1126 if (ar.exception != null) {
1127 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1128 }
1129 if (ar.exception instanceof CommandException) {
1130 CommandException.Error error =
1131 ((CommandException) (ar.exception)).getCommandError();
1132 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1133 callForwardingStatus =
1134 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1135 }
1136 }
1137 }
Hall Liu27d24262020-09-18 19:04:59 -07001138 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001139 break;
Hall Liu27d24262020-09-18 19:04:59 -07001140 }
Shuo Qian4a594052020-01-23 11:59:30 -08001141
Hall Liu27d24262020-09-18 19:04:59 -07001142 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001145 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1146 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001147 break;
Hall Liu27d24262020-09-18 19:04:59 -07001148 }
Shuo Qian4a594052020-01-23 11:59:30 -08001149
Hall Liu27d24262020-09-18 19:04:59 -07001150 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001151 ar = (AsyncResult) msg.obj;
1152 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001153 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1154 Consumer<Integer> callback =
1155 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1156 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001157 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001158 if (ar.exception instanceof CommandException) {
1159 CommandException.Error error =
1160 ((CommandException) (ar.exception)).getCommandError();
1161 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1162 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1163 } else {
1164 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1165 }
1166 } else {
1167 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1168 }
1169 } else {
1170 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1171 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001172 }
Shuo Qian4a594052020-01-23 11:59:30 -08001173 break;
Hall Liu27d24262020-09-18 19:04:59 -07001174 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001175 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1176 ar = (AsyncResult) msg.obj;
1177 request = (MainThreadRequest) ar.userObj;
1178 CellNetworkScanResult cellScanResult;
1179 if (ar.exception == null && ar.result != null) {
1180 cellScanResult = new CellNetworkScanResult(
1181 CellNetworkScanResult.STATUS_SUCCESS,
1182 (List<OperatorInfo>) ar.result);
1183 } else {
1184 if (ar.result == null) {
1185 loge("getCellNetworkScanResults: Empty response");
1186 }
1187 if (ar.exception != null) {
1188 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1189 }
1190 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1191 if (ar.exception instanceof CommandException) {
1192 CommandException.Error error =
1193 ((CommandException) (ar.exception)).getCommandError();
1194 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1195 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1196 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1197 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1198 }
1199 }
1200 cellScanResult = new CellNetworkScanResult(errorCode, null);
1201 }
1202 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001203 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001204 break;
1205
1206 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1207 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001208 ManualNetworkSelectionArgument selArg =
1209 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001210 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1211 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001212 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1213 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001214 break;
1215
1216 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001217 ar = (AsyncResult) msg.obj;
1218 request = (MainThreadRequest) ar.userObj;
1219 if (ar.exception == null) {
1220 request.result = true;
1221 } else {
1222 request.result = false;
1223 loge("setNetworkSelectionModeManual " + ar.exception);
1224 }
1225 notifyRequester(request);
1226 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001227 break;
1228
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001229 case CMD_GET_MODEM_ACTIVITY_INFO:
1230 request = (MainThreadRequest) msg.obj;
1231 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001232 if (defaultPhone != null) {
1233 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001234 } else {
1235 ResultReceiver result = (ResultReceiver) request.argument;
1236 Bundle bundle = new Bundle();
1237 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001238 new ModemActivityInfo(0, 0, 0,
1239 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001240 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001241 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001242 break;
1243
Hall Liud0f208c2020-10-14 16:54:44 -07001244 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001245 ar = (AsyncResult) msg.obj;
1246 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001247 ResultReceiver result = (ResultReceiver) request.argument;
1248
Hall Liud0f208c2020-10-14 16:54:44 -07001249 ModemActivityInfo ret = null;
1250 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001251 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001252 // Update the last modem activity info and the result of the request.
1253 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1254 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001255 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001256 int[] txTimeMs = info.getTransmitTimeMillis();
1257 int[] lastModemTxTimeMs = mLastModemActivityInfo
1258 .getTransmitTimeMillis();
1259 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1260 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1261 }
Hall Liu49656c02020-10-09 19:00:11 -07001262 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001263 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1264 + mLastModemActivityInfo.getSleepTimeMillis());
1265 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1266 + mLastModemActivityInfo.getIdleTimeMillis());
1267 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1268 mLastModemActivityInfo.setReceiveTimeMillis(
1269 info.getReceiveTimeMillis()
1270 + mLastModemActivityInfo.getReceiveTimeMillis());
1271 }
Hall Liu49656c02020-10-09 19:00:11 -07001272 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001273 mLastModemActivityInfo.getSleepTimeMillis(),
1274 mLastModemActivityInfo.getIdleTimeMillis(),
1275 mLastModemActivityInfo.getTransmitTimeMillis(),
1276 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001277 } else {
1278 if (ar.result == null) {
1279 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001280 error = TelephonyManager.ModemActivityInfoException
1281 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001282 } else if (ar.exception instanceof CommandException) {
1283 loge("queryModemActivityInfo: CommandException: " +
1284 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001285 error = TelephonyManager.ModemActivityInfoException
1286 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001287 } else {
1288 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001289 error = TelephonyManager.ModemActivityInfoException
1290 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001291 }
1292 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001293 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001294 if (ret != null) {
1295 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1296 } else {
1297 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1298 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001299 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001300 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001301 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001302 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001303
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 case CMD_SET_ALLOWED_CARRIERS:
1305 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001306 CarrierRestrictionRules argument =
1307 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001308 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001309 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001310 break;
1311
1312 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1313 ar = (AsyncResult) msg.obj;
1314 request = (MainThreadRequest) ar.userObj;
1315 if (ar.exception == null && ar.result != null) {
1316 request.result = ar.result;
1317 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001318 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1319 if (ar.exception instanceof CommandException) {
1320 loge("setAllowedCarriers: CommandException: " + ar.exception);
1321 CommandException.Error error =
1322 ((CommandException) (ar.exception)).getCommandError();
1323 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1324 request.result =
1325 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1326 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001327 } else {
1328 loge("setAllowedCarriers: Unknown exception");
1329 }
1330 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001331 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001332 break;
1333
1334 case CMD_GET_ALLOWED_CARRIERS:
1335 request = (MainThreadRequest) msg.obj;
1336 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001337 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001338 break;
1339
1340 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 if (ar.exception == null && ar.result != null) {
1344 request.result = ar.result;
1345 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001346 request.result = new IllegalStateException(
1347 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001348 if (ar.result == null) {
1349 loge("getAllowedCarriers: Empty response");
1350 } else if (ar.exception instanceof CommandException) {
1351 loge("getAllowedCarriers: CommandException: " +
1352 ar.exception);
1353 } else {
1354 loge("getAllowedCarriers: Unknown exception");
1355 }
1356 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001357 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001358 break;
1359
Nathan Haroldb3014052017-01-25 15:57:32 -08001360 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1361 ar = (AsyncResult) msg.obj;
1362 request = (MainThreadRequest) ar.userObj;
1363 if (ar.exception == null && ar.result != null) {
1364 request.result = ar.result;
1365 } else {
1366 request.result = new IllegalArgumentException(
1367 "Failed to retrieve Forbidden Plmns");
1368 if (ar.result == null) {
1369 loge("getForbiddenPlmns: Empty response");
1370 } else {
1371 loge("getForbiddenPlmns: Unknown exception");
1372 }
1373 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001374 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001375 break;
1376
1377 case CMD_GET_FORBIDDEN_PLMNS:
1378 request = (MainThreadRequest) msg.obj;
1379 uiccCard = getUiccCardFromRequest(request);
1380 if (uiccCard == null) {
1381 loge("getForbiddenPlmns() UiccCard is null");
1382 request.result = new IllegalArgumentException(
1383 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001384 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001385 break;
1386 }
1387 Integer appType = (Integer) request.argument;
1388 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1389 if (uiccApp == null) {
1390 loge("getForbiddenPlmns() no app with specified type -- "
1391 + appType);
1392 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001393 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001394 break;
1395 } else {
1396 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1397 + " specified type -- " + appType);
1398 }
1399 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1400 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1401 onCompleted);
1402 break;
1403
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001404 case CMD_SWITCH_SLOTS:
1405 request = (MainThreadRequest) msg.obj;
1406 int[] physicalSlots = (int[]) request.argument;
1407 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1408 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1409 break;
1410
1411 case EVENT_SWITCH_SLOTS_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001415 notifyRequester(request);
1416 break;
1417 case CMD_GET_NETWORK_SELECTION_MODE:
1418 request = (MainThreadRequest) msg.obj;
1419 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1420 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1421 break;
1422
1423 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
1426 if (ar.exception != null) {
1427 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1428 } else {
1429 int mode = ((int[]) ar.result)[0];
1430 if (mode == 0) {
1431 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1432 } else {
1433 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1434 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001435 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001436 notifyRequester(request);
1437 break;
1438 case CMD_GET_CDMA_ROAMING_MODE:
1439 request = (MainThreadRequest) msg.obj;
1440 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1441 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1442 break;
1443 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1444 ar = (AsyncResult) msg.obj;
1445 request = (MainThreadRequest) ar.userObj;
1446 if (ar.exception != null) {
1447 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1448 } else {
1449 request.result = ((int[]) ar.result)[0];
1450 }
1451 notifyRequester(request);
1452 break;
1453 case CMD_SET_CDMA_ROAMING_MODE:
1454 request = (MainThreadRequest) msg.obj;
1455 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1456 int mode = (int) request.argument;
1457 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1458 break;
1459 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 request.result = ar.exception == null;
1463 notifyRequester(request);
1464 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001465 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1466 request = (MainThreadRequest) msg.obj;
1467 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1468 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1469 break;
1470 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1471 ar = (AsyncResult) msg.obj;
1472 request = (MainThreadRequest) ar.userObj;
1473 if (ar.exception != null) {
1474 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1475 } else {
1476 request.result = ((int[]) ar.result)[0];
1477 }
1478 notifyRequester(request);
1479 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1481 request = (MainThreadRequest) msg.obj;
1482 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1483 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001484 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1485 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001486 break;
1487 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1488 ar = (AsyncResult) msg.obj;
1489 request = (MainThreadRequest) ar.userObj;
1490 request.result = ar.exception == null;
1491 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001492 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 case CMD_GET_ALL_CELL_INFO:
1494 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001496 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001497 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001498 case EVENT_GET_ALL_CELL_INFO_DONE:
1499 ar = (AsyncResult) msg.obj;
1500 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001501 // If a timeout occurs, the response will be null
1502 request.result = (ar.exception == null && ar.result != null)
1503 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001504 synchronized (request) {
1505 request.notifyAll();
1506 }
1507 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001508 case CMD_REQUEST_CELL_INFO_UPDATE:
1509 request = (MainThreadRequest) msg.obj;
1510 request.phone.requestCellInfoUpdate(request.workSource,
1511 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1512 break;
1513 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1514 ar = (AsyncResult) msg.obj;
1515 request = (MainThreadRequest) ar.userObj;
1516 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1517 try {
1518 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001519 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001520 cb.onError(
1521 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1522 ar.exception.getClass().getName(),
1523 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001524 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001525 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001526 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001527 } else {
1528 // use the result as returned
1529 cb.onCellInfo((List<CellInfo>) ar.result);
1530 }
1531 } catch (RemoteException re) {
1532 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1533 }
1534 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001535 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001536 request = (MainThreadRequest) msg.obj;
1537 WorkSource ws = (WorkSource) request.argument;
1538 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001539 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001540 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001541 }
1542 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001543 ar = (AsyncResult) msg.obj;
1544 request = (MainThreadRequest) ar.userObj;
1545 if (ar.exception == null) {
1546 request.result = ar.result;
1547 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001548 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001549 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001550 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001551 }
1552
1553 synchronized (request) {
1554 request.notifyAll();
1555 }
1556 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001557 }
chen xu6dac5ab2018-10-26 17:39:23 -07001558 case CMD_MODEM_REBOOT:
1559 request = (MainThreadRequest) msg.obj;
1560 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001561 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001562 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001563 case EVENT_CMD_MODEM_REBOOT_DONE:
1564 handleNullReturnEvent(msg, "rebootModem");
1565 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001566 case CMD_REQUEST_ENABLE_MODEM:
1567 request = (MainThreadRequest) msg.obj;
1568 boolean enable = (boolean) request.argument;
1569 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001570 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001571 PhoneConfigurationManager.getInstance()
1572 .enablePhone(request.phone, enable, onCompleted);
1573 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001574 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001575 ar = (AsyncResult) msg.obj;
1576 request = (MainThreadRequest) ar.userObj;
1577 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001578 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001579 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001580 if ((boolean) request.result) {
1581 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1582 updateModemStateMetrics();
1583 } else {
1584 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1585 + ar.exception);
1586 }
1587 notifyRequester(request);
1588 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001589 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001590 case CMD_GET_MODEM_STATUS:
1591 request = (MainThreadRequest) msg.obj;
1592 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1593 PhoneConfigurationManager.getInstance()
1594 .getPhoneStatusFromModem(request.phone, onCompleted);
1595 break;
1596 case EVENT_GET_MODEM_STATUS_DONE:
1597 ar = (AsyncResult) msg.obj;
1598 request = (MainThreadRequest) ar.userObj;
1599 int id = request.phone.getPhoneId();
1600 if (ar.exception == null && ar.result != null) {
1601 request.result = ar.result;
1602 //update the cache as modem status has changed
1603 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1604 (boolean) request.result);
1605 } else {
1606 // Return true if modem status cannot be retrieved. For most cases,
1607 // modem status is on. And for older version modems, GET_MODEM_STATUS
1608 // and disable modem are not supported. Modem is always on.
1609 // TODO: this should be fixed in R to support a third
1610 // status UNKNOWN b/131631629
1611 request.result = true;
1612 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1613 + ar.exception);
1614 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001615 notifyRequester(request);
1616 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001617 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1618 request = (MainThreadRequest) msg.obj;
1619 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1620 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1621 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1622 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1623 break;
1624 }
1625 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1626 ar = (AsyncResult) msg.obj;
1627 request = (MainThreadRequest) ar.userObj;
1628 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1629 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1630 args.second.accept(ar.exception == null);
1631 notifyRequester(request);
1632 break;
1633 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001634 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1635 request = (MainThreadRequest) msg.obj;
1636 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1637 Phone phone = getPhoneFromRequest(request);
1638 if (phone != null) {
1639 phone.getSystemSelectionChannels(onCompleted);
1640 } else {
1641 loge("getSystemSelectionChannels: No phone object");
1642 request.result = new ArrayList<RadioAccessSpecifier>();
1643 notifyRequester(request);
1644 }
1645 break;
1646 }
1647 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1648 ar = (AsyncResult) msg.obj;
1649 request = (MainThreadRequest) ar.userObj;
1650 if (ar.exception == null && ar.result != null) {
1651 request.result = ar.result;
1652 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001653 request.result = new IllegalStateException(
1654 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001655 if (ar.result == null) {
1656 loge("getSystemSelectionChannels: Empty response");
1657 } else {
1658 loge("getSystemSelectionChannels: Unknown exception");
1659 }
1660 }
1661 notifyRequester(request);
1662 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001663 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
1666 if (ar.exception == null && ar.result != null) {
1667 request.result = ar.result;
1668 } else {
1669 request.result = -1;
1670 loge("Failed to set Forbidden Plmns");
1671 if (ar.result == null) {
1672 loge("setForbidenPlmns: Empty response");
1673 } else if (ar.exception != null) {
1674 loge("setForbiddenPlmns: Exception: " + ar.exception);
1675 request.result = -1;
1676 } else {
1677 loge("setForbiddenPlmns: Unknown exception");
1678 }
1679 }
1680 notifyRequester(request);
1681 break;
1682 case CMD_SET_FORBIDDEN_PLMNS:
1683 request = (MainThreadRequest) msg.obj;
1684 uiccCard = getUiccCardFromRequest(request);
1685 if (uiccCard == null) {
1686 loge("setForbiddenPlmns: UiccCard is null");
1687 request.result = -1;
1688 notifyRequester(request);
1689 break;
1690 }
1691 Pair<Integer, List<String>> setFplmnsArgs =
1692 (Pair<Integer, List<String>>) request.argument;
1693 appType = setFplmnsArgs.first;
1694 List<String> fplmns = setFplmnsArgs.second;
1695 uiccApp = uiccCard.getApplicationByType(appType);
1696 if (uiccApp == null) {
1697 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1698 request.result = -1;
1699 loge("Failed to get UICC App");
1700 notifyRequester(request);
1701 } else {
1702 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1703 ((SIMRecords) uiccApp.getIccRecords())
1704 .setForbiddenPlmns(onCompleted, fplmns);
1705 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001706 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001707 case CMD_ERASE_MODEM_CONFIG:
1708 request = (MainThreadRequest) msg.obj;
1709 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1710 defaultPhone.eraseModemConfig(onCompleted);
1711 break;
1712 case EVENT_ERASE_MODEM_CONFIG_DONE:
1713 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001714 break;
zoey chene02881a2019-12-30 16:11:23 +08001715
Kai Shif70f46f2021-03-03 13:59:46 -08001716 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1717 request = (MainThreadRequest) msg.obj;
1718 request.result = defaultPhone.eraseDataInSharedPreferences();
1719 notifyRequester(request);
1720 break;
1721
zoey chene02881a2019-12-30 16:11:23 +08001722 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1723 request = (MainThreadRequest) msg.obj;
1724 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1725 Pair<String, String> changed = (Pair<String, String>) request.argument;
1726 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1727 changed.first, changed.second, onCompleted);
1728 break;
1729 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1730 ar = (AsyncResult) msg.obj;
1731 request = (MainThreadRequest) ar.userObj;
1732 if (ar.exception == null) {
1733 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001734 // If the operation is successful, update the PIN storage
1735 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1736 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001737 UiccController.getInstance().getPinStorage()
1738 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001739 } else {
1740 request.result = msg.arg1;
1741 }
1742 notifyRequester(request);
1743 break;
1744
Michele Berionne5e411512020-11-13 02:36:59 +00001745 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001746 request = (MainThreadRequest) msg.obj;
1747 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1748 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1749 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1750 enabled.first, enabled.second, onCompleted);
1751 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001752 }
zoey chene02881a2019-12-30 16:11:23 +08001753 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1754 ar = (AsyncResult) msg.obj;
1755 request = (MainThreadRequest) ar.userObj;
1756 if (ar.exception == null) {
1757 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001758 // If the operation is successful, update the PIN storage
1759 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1760 int phoneId = getPhoneFromRequest(request).getPhoneId();
1761 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001762 UiccController.getInstance().getPinStorage()
1763 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001764 } else {
1765 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1766 }
zoey chene02881a2019-12-30 16:11:23 +08001767 } else {
1768 request.result = msg.arg1;
1769 }
Michele Berionne5e411512020-11-13 02:36:59 +00001770
1771
zoey chene02881a2019-12-30 16:11:23 +08001772 notifyRequester(request);
1773 break;
1774
Peter Wangdafb9ac2020-01-15 14:13:38 -08001775 case MSG_NOTIFY_USER_ACTIVITY:
1776 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001777 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001778 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1779 getDefaultPhone().getContext().sendBroadcastAsUser(
1780 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1781 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001782
1783 case CMD_SET_DATA_THROTTLING: {
1784 request = (MainThreadRequest) msg.obj;
1785 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1786 DataThrottlingRequest dataThrottlingRequest =
1787 (DataThrottlingRequest) request.argument;
1788 Phone phone = getPhoneFromRequest(request);
1789 if (phone != null) {
1790 phone.setDataThrottling(onCompleted,
1791 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1792 dataThrottlingRequest.getCompletionDurationMillis());
1793 } else {
1794 loge("setDataThrottling: No phone object");
1795 request.result =
1796 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1797 notifyRequester(request);
1798 }
1799
1800 break;
1801 }
1802 case EVENT_SET_DATA_THROTTLING_DONE:
1803 ar = (AsyncResult) msg.obj;
1804 request = (MainThreadRequest) ar.userObj;
1805
1806 if (ar.exception == null) {
1807 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1808 } else if (ar.exception instanceof CommandException) {
1809 loge("setDataThrottling: CommandException: " + ar.exception);
1810 CommandException.Error error =
1811 ((CommandException) (ar.exception)).getCommandError();
1812
1813 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1814 request.result = TelephonyManager
1815 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1816 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1817 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001818 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1819 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001820 } else {
1821 request.result =
1822 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1823 }
1824 } else {
1825 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1826 }
1827 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1828 notifyRequester(request);
1829 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001830
1831 case CMD_SET_SIM_POWER: {
1832 request = (MainThreadRequest) msg.obj;
1833 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1834 request = (MainThreadRequest) msg.obj;
1835 int stateToSet =
1836 ((Pair<Integer, IIntegerConsumer>)
1837 request.argument).first;
1838 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1839 break;
1840 }
1841 case EVENT_SET_SIM_POWER_DONE: {
1842 ar = (AsyncResult) msg.obj;
1843 request = (MainThreadRequest) ar.userObj;
1844 IIntegerConsumer callback =
1845 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1846 if (ar.exception != null) {
1847 loge("setSimPower exception: " + ar.exception);
1848 int errorCode = TelephonyManager.CallForwardingInfoCallback
1849 .RESULT_ERROR_UNKNOWN;
1850 if (ar.exception instanceof CommandException) {
1851 CommandException.Error error =
1852 ((CommandException) (ar.exception)).getCommandError();
1853 if (error == CommandException.Error.SIM_ERR) {
1854 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1855 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1856 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1857 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1858 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1859 } else {
1860 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1861 }
1862 }
1863 try {
1864 callback.accept(errorCode);
1865 } catch (RemoteException e) {
1866 // Ignore if the remote process is no longer available to call back.
1867 Log.w(LOG_TAG, "setSimPower: callback not available.");
1868 }
1869 } else {
1870 try {
1871 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1872 } catch (RemoteException e) {
1873 // Ignore if the remote process is no longer available to call back.
1874 Log.w(LOG_TAG, "setSimPower: callback not available.");
1875 }
1876 }
1877 break;
1878 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001879 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1880 request = (MainThreadRequest) msg.obj;
1881
1882 final Phone phone = getPhoneFromRequest(request);
1883 if (phone == null || phone.getServiceStateTracker() == null) {
1884 request.result = new IllegalStateException("Phone or SST is null");
1885 notifyRequester(request);
1886 break;
1887 }
1888
1889 Pair<Integer, SignalStrengthUpdateRequest> pair =
1890 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1891 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1892 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001893 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001894 request.subId, pair.first /*callingUid*/,
1895 pair.second /*request*/, onCompleted);
1896 break;
1897 }
1898 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1899 ar = (AsyncResult) msg.obj;
1900 request = (MainThreadRequest) ar.userObj;
1901 // request.result will be the exception of ar if present, true otherwise.
1902 // Be cautious not to leave result null which will wait() forever
1903 request.result = ar.exception != null ? ar.exception : true;
1904 notifyRequester(request);
1905 break;
1906 }
1907 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1908 request = (MainThreadRequest) msg.obj;
1909
1910 Phone phone = getPhoneFromRequest(request);
1911 if (phone == null || phone.getServiceStateTracker() == null) {
1912 request.result = new IllegalStateException("Phone or SST is null");
1913 notifyRequester(request);
1914 break;
1915 }
1916
1917 Pair<Integer, SignalStrengthUpdateRequest> pair =
1918 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1919 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1920 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001921 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001922 request.subId, pair.first /*callingUid*/,
1923 pair.second /*request*/, onCompleted);
1924 break;
1925 }
1926 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 request.result = ar.exception != null ? ar.exception : true;
1930 notifyRequester(request);
1931 break;
1932 }
Jordan Liu109698e2020-11-24 14:50:34 -08001933
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001934 case CMD_GET_SLICING_CONFIG: {
1935 request = (MainThreadRequest) msg.obj;
1936 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1937 request.phone.getSlicingConfig(onCompleted);
1938 break;
1939 }
1940 case EVENT_GET_SLICING_CONFIG_DONE: {
1941 ar = (AsyncResult) msg.obj;
1942 request = (MainThreadRequest) ar.userObj;
1943 ResultReceiver result = (ResultReceiver) request.argument;
1944
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001945 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001946 Bundle bundle = new Bundle();
1947 int resultCode = 0;
1948 if (ar.exception != null) {
1949 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1950 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001951 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001952 } else if (ar.result == null) {
1953 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001954 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001955 } else {
1956 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001957 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1958 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001959 }
1960
1961 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001962 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001963 }
1964 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1965 result.send(resultCode, bundle);
1966 notifyRequester(request);
1967 break;
1968 }
1969
Michele Berionne5e411512020-11-13 02:36:59 +00001970 case CMD_PREPARE_UNATTENDED_REBOOT:
1971 request = (MainThreadRequest) msg.obj;
1972 request.result =
1973 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1974 notifyRequester(request);
1975 break;
1976
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 default:
1978 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1979 break;
1980 }
1981 }
Jake Hambye994d462014-02-03 13:10:13 -08001982
Pengquan Menga1bb6272018-09-06 09:59:22 -07001983 private void notifyRequester(MainThreadRequest request) {
1984 synchronized (request) {
1985 request.notifyAll();
1986 }
1987 }
1988
Jake Hambye994d462014-02-03 13:10:13 -08001989 private void handleNullReturnEvent(Message msg, String command) {
1990 AsyncResult ar = (AsyncResult) msg.obj;
1991 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1992 if (ar.exception == null) {
1993 request.result = true;
1994 } else {
1995 request.result = false;
1996 if (ar.exception instanceof CommandException) {
1997 loge(command + ": CommandException: " + ar.exception);
1998 } else {
1999 loge(command + ": Unknown exception");
2000 }
2001 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002002 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 }
2005
2006 /**
2007 * Posts the specified command to be executed on the main thread,
2008 * waits for the request to complete, and returns the result.
2009 * @see #sendRequestAsync
2010 */
2011 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002012 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2013 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002014 }
2015
2016 /**
2017 * Posts the specified command to be executed on the main thread,
2018 * waits for the request to complete, and returns the result.
2019 * @see #sendRequestAsync
2020 */
2021 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2022 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002023 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002024 }
2025
2026 /**
2027 * Posts the specified command to be executed on the main thread,
2028 * waits for the request to complete, and returns the result.
2029 * @see #sendRequestAsync
2030 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002031 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002032 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2033 }
2034
2035 /**
2036 * Posts the specified command to be executed on the main thread,
2037 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2038 * if not timeout or null otherwise.
2039 * @see #sendRequestAsync
2040 */
2041 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2042 long timeoutInMs) {
2043 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002044 }
2045
2046 /**
2047 * Posts the specified command to be executed on the main thread,
2048 * waits for the request to complete, and returns the result.
2049 * @see #sendRequestAsync
2050 */
Nathan Harold92bed182018-10-12 18:16:49 -07002051 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002052 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002053 }
2054
2055 /**
2056 * Posts the specified command to be executed on the main thread,
2057 * waits for the request to complete, and returns the result.
2058 * @see #sendRequestAsync
2059 */
2060 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002061 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2062 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002063 }
2064
2065 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002066 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2067 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2068 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002069 * @see #sendRequestAsync
2070 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002071 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2072 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2074 throw new RuntimeException("This method will deadlock if called from the main thread.");
2075 }
2076
Nathan Harold92bed182018-10-12 18:16:49 -07002077 MainThreadRequest request = null;
2078 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2079 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2080 } else if (phone != null) {
2081 request = new MainThreadRequest(argument, phone, workSource);
2082 } else {
2083 request = new MainThreadRequest(argument, subId, workSource);
2084 }
2085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 Message msg = mMainThreadHandler.obtainMessage(command, request);
2087 msg.sendToTarget();
2088
Rambo Wang0f050d82021-02-12 11:43:36 -08002089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002091 if (timeoutInMs >= 0) {
2092 // Wait for at least timeoutInMs before returning null request result
2093 long now = SystemClock.elapsedRealtime();
2094 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002095 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002096 try {
2097 request.wait(deadline - now);
2098 } catch (InterruptedException e) {
2099 // Do nothing, go back and check if request is completed or timeout
2100 } finally {
2101 now = SystemClock.elapsedRealtime();
2102 }
2103 }
2104 } else {
2105 // Wait for the request to complete
2106 while (request.result == null) {
2107 try {
2108 request.wait();
2109 } catch (InterruptedException e) {
2110 // Do nothing, go back and wait until the request is complete
2111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113 }
2114 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002115 if (request.result == null) {
2116 Log.wtf(LOG_TAG,
2117 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 return request.result;
2120 }
2121
2122 /**
2123 * Asynchronous ("fire and forget") version of sendRequest():
2124 * Posts the specified command to be executed on the main thread, and
2125 * returns immediately.
2126 * @see #sendRequest
2127 */
2128 private void sendRequestAsync(int command) {
2129 mMainThreadHandler.sendEmptyMessage(command);
2130 }
2131
2132 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002133 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002134 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002135 */
2136 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002137 sendRequestAsync(command, argument, null, null);
2138 }
2139
2140 /**
2141 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2142 * @see {@link #sendRequest(int,Object)}
2143 */
2144 private void sendRequestAsync(
2145 int command, Object argument, Phone phone, WorkSource workSource) {
2146 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002147 Message msg = mMainThreadHandler.obtainMessage(command, request);
2148 msg.sendToTarget();
2149 }
2150
2151 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 * Initialize the singleton PhoneInterfaceManager instance.
2153 * This is only done once, at startup, from PhoneApp.onCreate().
2154 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002155 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 synchronized (PhoneInterfaceManager.class) {
2157 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002158 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 } else {
2160 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2161 }
2162 return sInstance;
2163 }
2164 }
2165
2166 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002167 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002170 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002171 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002173 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002175 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002176 mTelephonySharedPreferences =
2177 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002178 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002179 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002180 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002181 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002182
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 publish();
2184 }
2185
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002186 private Phone getDefaultPhone() {
2187 Phone thePhone = getPhone(getDefaultSubscription());
2188 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2189 }
2190
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 private void publish() {
2192 if (DBG) log("publish: " + this);
2193
Peter Wangc035ce42020-01-08 21:00:22 -08002194 TelephonyFrameworkInitializer
2195 .getTelephonyServiceManager()
2196 .getTelephonyServiceRegisterer()
2197 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 }
2199
Stuart Scott584921c2015-01-15 17:10:34 -08002200 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002201 if (request.phone != null) {
2202 return request.phone;
2203 } else {
2204 return getPhoneFromSubId(request.subId);
2205 }
2206 }
2207
2208 private Phone getPhoneFromSubId(int subId) {
2209 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2210 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002211 }
2212
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002213 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2214 Phone phone = getPhoneFromRequest(request);
2215 return phone == null ? null :
2216 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2217 }
2218
Wink Saville36469e72014-06-11 15:17:00 -07002219 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002220 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002221 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223
Kai Shif70f46f2021-03-03 13:59:46 -08002224 private void sendEraseModemConfig(@NonNull Phone phone) {
2225 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2226 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2227 }
2228
2229 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2230 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2231 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002232 }
2233
Peter Wang44b186e2020-01-13 23:33:09 -08002234 private boolean isImsAvailableOnDevice() {
2235 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2236 if (pm == null) {
2237 // For some reason package manger is not available.. This will fail internally anyway,
2238 // so do not throw error and allow.
2239 return true;
2240 }
2241 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2242 }
2243
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002245 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002246 }
2247
Wink Savilleb564aae2014-10-23 10:18:09 -07002248 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 if (DBG) log("dial: " + number);
2250 // No permission check needed here: This is just a wrapper around the
2251 // ACTION_DIAL intent, which is available to any app since it puts up
2252 // the UI before it does anything.
2253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254 final long identity = Binder.clearCallingIdentity();
2255 try {
2256 String url = createTelUrl(number);
2257 if (url == null) {
2258 return;
2259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 // PENDING: should we just silently fail if phone is offhook or ringing?
2262 PhoneConstants.State state = mCM.getState(subId);
2263 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2264 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2265 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2266 mApp.startActivity(intent);
2267 }
2268 } finally {
2269 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 }
2271 }
2272
2273 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002274 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002275 }
2276
Wink Savilleb564aae2014-10-23 10:18:09 -07002277 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 if (DBG) log("call: " + number);
2279
2280 // This is just a wrapper around the ACTION_CALL intent, but we still
2281 // need to do a permission check since we're calling startActivity()
2282 // from the context of the phone app.
2283 enforceCallPermission();
2284
Jordan Liu1617b712019-07-10 15:06:26 -07002285 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 != AppOpsManager.MODE_ALLOWED) {
2287 return;
2288 }
2289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 String url = createTelUrl(number);
2293 if (url == null) {
2294 return;
2295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297 boolean isValid = false;
2298 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2299 if (slist != null) {
2300 for (SubscriptionInfo subInfoRecord : slist) {
2301 if (subInfoRecord.getSubscriptionId() == subId) {
2302 isValid = true;
2303 break;
2304 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002305 }
Wink Saville08874612014-08-31 19:19:58 -07002306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002307 if (!isValid) {
2308 return;
2309 }
Wink Saville08874612014-08-31 19:19:58 -07002310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2312 intent.putExtra(SUBSCRIPTION_KEY, subId);
2313 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2314 mApp.startActivity(intent);
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002318 }
2319
Wink Savilleb564aae2014-10-23 10:18:09 -07002320 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002321 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002322 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2323 }
2324
Wink Savilleb564aae2014-10-23 10:18:09 -07002325 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002326 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002327 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2328 }
2329
Wink Savilleb564aae2014-10-23 10:18:09 -07002330 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002332
2333 final long identity = Binder.clearCallingIdentity();
2334 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002335 Phone phone = getPhone(subId);
2336 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337 checkSimPin.start();
2338 return checkSimPin.unlockSim(null, pin);
2339 } finally {
2340 Binder.restoreCallingIdentity(identity);
2341 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
2343
Wink Savilleb564aae2014-10-23 10:18:09 -07002344 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346
2347 final long identity = Binder.clearCallingIdentity();
2348 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002349 Phone phone = getPhone(subId);
2350 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002351 checkSimPuk.start();
2352 return checkSimPuk.unlockSim(puk, pin);
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
2355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 }
2357
2358 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002359 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 * a synchronous one.
2361 */
2362 private static class UnlockSim extends Thread {
2363
2364 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002365 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366
2367 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002368 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2369 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370
2371 // For replies from SimCard interface
2372 private Handler mHandler;
2373
2374 // For async handler to identify request type
2375 private static final int SUPPLY_PIN_COMPLETE = 100;
2376
Michele Berionne5e411512020-11-13 02:36:59 +00002377 UnlockSim(int phoneId, IccCard simCard) {
2378 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 mSimCard = simCard;
2380 }
2381
2382 @Override
2383 public void run() {
2384 Looper.prepare();
2385 synchronized (UnlockSim.this) {
2386 mHandler = new Handler() {
2387 @Override
2388 public void handleMessage(Message msg) {
2389 AsyncResult ar = (AsyncResult) msg.obj;
2390 switch (msg.what) {
2391 case SUPPLY_PIN_COMPLETE:
2392 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2393 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002394 mRetryCount = msg.arg1;
2395 if (ar.exception != null) {
2396 if (ar.exception instanceof CommandException &&
2397 ((CommandException)(ar.exception)).getCommandError()
2398 == CommandException.Error.PASSWORD_INCORRECT) {
2399 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002400 } //When UiccCardApp dispose,handle message and return exception
2401 else if (ar.exception instanceof CommandException &&
2402 ((CommandException) (ar.exception)).getCommandError()
2403 == CommandException.Error.ABORTED) {
2404 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002405 } else {
2406 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2407 }
2408 } else {
2409 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2410 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 mDone = true;
2412 UnlockSim.this.notifyAll();
2413 }
2414 break;
2415 }
2416 }
2417 };
2418 UnlockSim.this.notifyAll();
2419 }
2420 Looper.loop();
2421 }
2422
2423 /*
2424 * Use PIN or PUK to unlock SIM card
2425 *
2426 * If PUK is null, unlock SIM card with PIN
2427 *
2428 * If PUK is not null, unlock SIM card with PUK and set PIN code
2429 */
Wink Saville9de0f752013-10-22 19:04:03 -07002430 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431
2432 while (mHandler == null) {
2433 try {
2434 wait();
2435 } catch (InterruptedException e) {
2436 Thread.currentThread().interrupt();
2437 }
2438 }
2439 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2440
2441 if (puk == null) {
2442 mSimCard.supplyPin(pin, callback);
2443 } else {
2444 mSimCard.supplyPuk(puk, pin, callback);
2445 }
2446
2447 while (!mDone) {
2448 try {
2449 Log.d(LOG_TAG, "wait for done");
2450 wait();
2451 } catch (InterruptedException e) {
2452 // Restore the interrupted status
2453 Thread.currentThread().interrupt();
2454 }
2455 }
2456 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002457 int[] resultArray = new int[2];
2458 resultArray[0] = mResult;
2459 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002460
2461 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002462 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002463 }
2464
Wink Saville9de0f752013-10-22 19:04:03 -07002465 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002466 }
2467 }
2468
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002469 /**
2470 * This method has been removed due to privacy and stability concerns.
2471 */
2472 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002474 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2475 return;
Wink Saville36469e72014-06-11 15:17:00 -07002476 }
2477
Nathan Harold1f889d82020-06-04 17:05:26 -07002478 @Override
2479 public void updateServiceLocationWithPackageName(String callingPackage) {
2480 mApp.getSystemService(AppOpsManager.class)
2481 .checkPackage(Binder.getCallingUid(), callingPackage);
2482
Nathan Haroldf096d982020-11-18 17:18:06 -08002483 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002484 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2485 // Callers targeting S have no business invoking this method.
2486 return;
2487 }
2488
2489 LocationAccessPolicy.LocationPermissionResult locationResult =
2490 LocationAccessPolicy.checkLocationPermission(mApp,
2491 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2492 .setCallingPackage(callingPackage)
2493 .setCallingFeatureId(null)
2494 .setCallingPid(Binder.getCallingPid())
2495 .setCallingUid(Binder.getCallingUid())
2496 .setMethod("updateServiceLocation")
2497 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2498 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2499 .build());
2500 // Apps that lack location permission have no business calling this method;
2501 // however, because no permission was declared in the public API, denials must
2502 // all be "soft".
2503 switch (locationResult) {
2504 case DENIED_HARD: /* fall through */
2505 case DENIED_SOFT:
2506 return;
2507 }
2508
2509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 final long identity = Binder.clearCallingIdentity();
2511 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002512 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002514 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002521 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 @Override
2523 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002524 return isRadioOnWithFeature(callingPackage, null);
2525 }
2526
2527
2528 @Override
2529 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2530 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2531 callingFeatureId);
2532 }
2533
2534 @Deprecated
2535 @Override
2536 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2537 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002538 }
2539
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002540 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002541 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2542 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002544 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002545 return false;
2546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 return isRadioOnForSubscriber(subId);
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
2553 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002554 }
2555
2556 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 final Phone phone = getPhone(subId);
2560 if (phone != null) {
2561 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2562 } else {
2563 return false;
2564 }
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
2570 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002571 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 }
Wink Saville36469e72014-06-11 15:17:00 -07002573
Wink Savilleb564aae2014-10-23 10:18:09 -07002574 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002576
2577 final long identity = Binder.clearCallingIdentity();
2578 try {
2579 final Phone phone = getPhone(subId);
2580 if (phone != null) {
2581 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 }
Wink Saville36469e72014-06-11 15:17:00 -07002586 }
2587
2588 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002589 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002590 }
2591
Wink Savilleb564aae2014-10-23 10:18:09 -07002592 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002593 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 final Phone phone = getPhone(subId);
2598 if (phone == null) {
2599 return false;
2600 }
2601 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2602 toggleRadioOnOffForSubscriber(subId);
2603 }
2604 return true;
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
Wink Saville36469e72014-06-11 15:17:00 -07002609
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002610 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002611 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002612 /*
2613 * If any of the Radios are available, it will need to be
2614 * shutdown. So return true if any Radio is available.
2615 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2619 Phone phone = PhoneFactory.getPhone(i);
2620 if (phone != null && phone.isRadioAvailable()) return true;
2621 }
2622 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2623 return false;
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002626 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002627 }
2628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002630 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 enforceModifyPermission();
2632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2636 logv("Shutting down Phone " + i);
2637 shutdownRadioUsingPhoneId(i);
2638 }
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002641 }
2642 }
2643
2644 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002645 Phone phone = PhoneFactory.getPhone(phoneId);
2646 if (phone != null && phone.isRadioAvailable()) {
2647 phone.shutdownRadio();
2648 }
2649 }
2650
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002652 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2657 if (defaultPhone != null) {
2658 defaultPhone.setRadioPower(turnOn);
2659 return true;
2660 } else {
2661 loge("There's no default phone.");
2662 return false;
2663 }
2664 } finally {
2665 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002666 }
Wink Saville36469e72014-06-11 15:17:00 -07002667 }
2668
Wink Savilleb564aae2014-10-23 10:18:09 -07002669 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002670 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671
2672 final long identity = Binder.clearCallingIdentity();
2673 try {
2674 final Phone phone = getPhone(subId);
2675 if (phone != null) {
2676 phone.setRadioPower(turnOn);
2677 return true;
2678 } else {
2679 return false;
2680 }
2681 } finally {
2682 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 }
2685
Wink Saville36469e72014-06-11 15:17:00 -07002686 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002687 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002688 public boolean enableDataConnectivity() {
2689 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690
2691 final long identity = Binder.clearCallingIdentity();
2692 try {
2693 int subId = mSubscriptionController.getDefaultDataSubId();
2694 final Phone phone = getPhone(subId);
2695 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002696 phone.getDataEnabledSettings().setDataEnabled(
2697 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 return true;
2699 } else {
2700 return false;
2701 }
2702 } finally {
2703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 }
2706
Wink Saville36469e72014-06-11 15:17:00 -07002707 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002708 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 public boolean disableDataConnectivity() {
2710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711
2712 final long identity = Binder.clearCallingIdentity();
2713 try {
2714 int subId = mSubscriptionController.getDefaultDataSubId();
2715 final Phone phone = getPhone(subId);
2716 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002717 phone.getDataEnabledSettings().setDataEnabled(
2718 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 return true;
2720 } 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
Sanket Padawe356d7632015-06-22 14:03:32 -07002728 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002729 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 final Phone phone = getPhone(subId);
2733 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002734 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 } else {
2736 return false;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 }
2742
2743 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002744 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002745 }
2746
pkanwarae03a6b2016-11-06 20:37:09 -08002747 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002748 enforceCallPermission();
2749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2753 return;
2754 }
2755 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2756 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2757 } finally {
2758 Binder.restoreCallingIdentity(identity);
2759 }
pkanwar32d516d2016-10-14 19:37:38 -07002760 };
2761
Wink Savilleb564aae2014-10-23 10:18:09 -07002762 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2768 return false;
2769 }
2770 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
2775
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002776 /**
2777 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2778 * tag on getCallState Binder call.
2779 */
2780 @Deprecated
2781 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002782 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002783 if (CompatChanges.isChangeEnabled(
2784 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2785 Binder.getCallingUid())) {
2786 // Do not allow this API to be called on API version 31+, it should only be
2787 // called on old apps using this Binder call directly.
2788 throw new SecurityException("This method can only be used for applications "
2789 + "targeting API version 30 or less.");
2790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002793 Phone phone = getPhone(getDefaultSubscription());
2794 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2795 PhoneConstantConversions.convertCallState(phone.getState());
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
2798 }
2799 }
2800
2801 @Override
2802 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2803 if (CompatChanges.isChangeEnabled(
2804 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2805 Binder.getCallingUid())) {
2806 // Check READ_PHONE_STATE for API version 31+
2807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2808 featureId, "getCallStateForSubscription")) {
2809 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2810 + "targeting API level 31+.");
2811 }
2812 }
2813 final long identity = Binder.clearCallingIdentity();
2814 try {
2815 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2817 PhoneConstantConversions.convertCallState(phone.getState());
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
2820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 }
2822
Sanket Padawe356d7632015-06-22 14:03:32 -07002823 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002824 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002825 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2826 }
2827
2828 @Override
2829 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 final long identity = Binder.clearCallingIdentity();
2831 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002832 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 if (phone != null) {
2834 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2835 } else {
2836 return PhoneConstantConversions.convertDataState(
2837 PhoneConstants.DataState.DISCONNECTED);
2838 }
2839 } finally {
2840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 }
2843
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002845 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002846 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2847 }
2848
2849 @Override
2850 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 final long identity = Binder.clearCallingIdentity();
2852 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002853 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 if (phone != null) {
2855 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2856 } else {
2857 return TelephonyManager.DATA_ACTIVITY_NONE;
2858 }
2859 } finally {
2860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
2864 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002865 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002866 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002867 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002868
2869 LocationAccessPolicy.LocationPermissionResult locationResult =
2870 LocationAccessPolicy.checkLocationPermission(mApp,
2871 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2872 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002873 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002874 .setCallingPid(Binder.getCallingPid())
2875 .setCallingUid(Binder.getCallingUid())
2876 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002877 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2879 .build());
2880 switch (locationResult) {
2881 case DENIED_HARD:
2882 throw new SecurityException("Not allowed to access cell location");
2883 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002884 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2885 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 }
2887
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 final long identity = Binder.clearCallingIdentity();
2890 try {
2891 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002892 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002893 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002894 } finally {
2895 Binder.restoreCallingIdentity(identity);
2896 }
Svetoslav64fad262015-04-14 14:35:21 -07002897 }
2898
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002899 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002900 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002901 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2902 // registered cell info, so return a NULL country instead.
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002905 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2906 // Get default phone in this case.
2907 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2908 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002909 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002911 if (phone == null) return "";
2912 ServiceStateTracker sst = phone.getServiceStateTracker();
2913 if (sst == null) return "";
2914 LocaleTracker lt = sst.getLocaleTracker();
2915 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002916 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002917 } finally {
2918 Binder.restoreCallingIdentity(identity);
2919 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002920 }
2921
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002922 /**
2923 * This method was removed due to potential issues caused by performing partial
2924 * updates of service state, and lack of a credible use case.
2925 *
2926 * This has the ability to break the telephony implementation by disabling notification of
2927 * changes in device connectivity. DO NOT USE THIS!
2928 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002929 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 public void enableLocationUpdates() {
2931 mApp.enforceCallingOrSelfPermission(
2932 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002935 /**
2936 * This method was removed due to potential issues caused by performing partial
2937 * updates of service state, and lack of a credible use case.
2938 *
2939 * This has the ability to break the telephony implementation by disabling notification of
2940 * changes in device connectivity. DO NOT USE THIS!
2941 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 @Override
2943 public void disableLocationUpdates() {
2944 mApp.enforceCallingOrSelfPermission(
2945 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 }
2947
2948 @Override
2949 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002950 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2951 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002952 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002953 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2954 throw new SecurityException(
2955 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2956 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002957
Jordan Liu1617b712019-07-10 15:06:26 -07002958 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002959 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2960 return null;
2961 }
Svetoslav64fad262015-04-14 14:35:21 -07002962
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002963 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002965 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002966 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002967
Nathan Haroldf180aac2018-06-01 18:43:55 -07002968 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2969 for (CellInfo ci : info) {
2970 if (ci instanceof CellInfoGsm) {
2971 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2972 } else if (ci instanceof CellInfoWcdma) {
2973 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002976 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 }
2978
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002979 private List<CellInfo> getCachedCellInfo() {
2980 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2981 for (Phone phone : PhoneFactory.getPhones()) {
2982 List<CellInfo> info = phone.getAllCellInfo();
2983 if (info != null) cellInfos.addAll(info);
2984 }
2985 return cellInfos;
2986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002987
2988 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002989 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002991 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002992
2993 LocationAccessPolicy.LocationPermissionResult locationResult =
2994 LocationAccessPolicy.checkLocationPermission(mApp,
2995 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2996 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002997 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002998 .setCallingPid(Binder.getCallingPid())
2999 .setCallingUid(Binder.getCallingUid())
3000 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003001 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003002 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3003 .build());
3004 switch (locationResult) {
3005 case DENIED_HARD:
3006 throw new SecurityException("Not allowed to access cell info");
3007 case DENIED_SOFT:
3008 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003009 }
3010
Nathan Haroldf096d982020-11-18 17:18:06 -08003011 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003012 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3013 return getCachedCellInfo();
3014 }
3015
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003016 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003017 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018 final long identity = Binder.clearCallingIdentity();
3019 try {
3020 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3021 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003022 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003023 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003024 if (info != null) cellInfos.addAll(info);
3025 }
3026 return cellInfos;
3027 } finally {
3028 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 }
3030 }
3031
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003032 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003033 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3034 String callingFeatureId) {
3035 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3036 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003037 }
3038
3039 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003040 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3041 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003042 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003043 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003044 }
3045
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003046 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3047 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003048 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003049 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003050
3051 LocationAccessPolicy.LocationPermissionResult locationResult =
3052 LocationAccessPolicy.checkLocationPermission(mApp,
3053 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3054 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003055 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003056 .setCallingPid(Binder.getCallingPid())
3057 .setCallingUid(Binder.getCallingUid())
3058 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003059 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3060 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003061 .build());
3062 switch (locationResult) {
3063 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003064 if (TelephonyPermissions
3065 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003066 // Safetynet logging for b/154934934
3067 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3068 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003069 throw new SecurityException("Not allowed to access cell info");
3070 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003071 if (TelephonyPermissions
3072 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003073 // Safetynet logging for b/154934934
3074 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3075 }
Nathan Harold5320c422019-05-09 10:26:08 -07003076 try {
3077 cb.onCellInfo(new ArrayList<CellInfo>());
3078 } catch (RemoteException re) {
3079 // Drop without consequences
3080 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003081 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003082 }
3083
Nathan Harolda939a962019-05-09 10:13:47 -07003084
3085 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003086 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3087
3088 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3089 }
3090
3091 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003092 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003093 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003094 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003098 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099 } finally {
3100 Binder.restoreCallingIdentity(identity);
3101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 }
3103
Shishir Agrawala9f32182016-04-12 12:00:16 -07003104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003105 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003106 Phone phone = PhoneFactory.getPhone(slotIndex);
3107 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003108 return null;
3109 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003110 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003111 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003112 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003113 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003114 return null;
3115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116
3117 final long identity = Binder.clearCallingIdentity();
3118 try {
3119 return phone.getImei();
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003123 }
3124
3125 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003126 public String getTypeAllocationCodeForSlot(int slotIndex) {
3127 Phone phone = PhoneFactory.getPhone(slotIndex);
3128 String tac = null;
3129 if (phone != null) {
3130 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003131 try {
3132 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3133 } catch (IndexOutOfBoundsException e) {
3134 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3135 return null;
3136 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003137 }
3138 return tac;
3139 }
3140
3141 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003143 Phone phone = PhoneFactory.getPhone(slotIndex);
3144 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003145 return null;
3146 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003147
Jeff Davidson913390f2018-02-23 17:11:49 -08003148 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003149 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003150 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003151 return null;
3152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 return phone.getMeid();
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
Jack Yu2af8d712017-03-15 17:14:14 -07003160 }
3161
3162 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003163 public String getManufacturerCodeForSlot(int slotIndex) {
3164 Phone phone = PhoneFactory.getPhone(slotIndex);
3165 String manufacturerCode = null;
3166 if (phone != null) {
3167 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003168 try {
3169 manufacturerCode =
3170 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3171 } catch (IndexOutOfBoundsException e) {
3172 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3173 return null;
3174 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003175 }
3176 return manufacturerCode;
3177 }
3178
3179 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003180 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3181 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003182 Phone phone = PhoneFactory.getPhone(slotIndex);
3183 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003184 return null;
3185 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003186 int subId = phone.getSubId();
3187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003188 mApp, subId, callingPackage, callingFeatureId,
3189 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003190 return null;
3191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192
3193 final long identity = Binder.clearCallingIdentity();
3194 try {
3195 return phone.getDeviceSvn();
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003199 }
3200
fionaxu43304da2017-11-27 22:51:16 -08003201 @Override
3202 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 final Phone phone = getPhone(subId);
3206 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
fionaxu43304da2017-11-27 22:51:16 -08003210 }
3211
3212 @Override
3213 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 final Phone phone = getPhone(subId);
3217 return phone == null ? null : phone.getCarrierName();
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
fionaxu43304da2017-11-27 22:51:16 -08003221 }
3222
calvinpanffe225e2018-11-01 19:43:06 +08003223 @Override
chen xu0026ca62019-03-06 15:28:50 -08003224 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 final Phone phone = getPhone(subId);
3228 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003229 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003230 } finally {
3231 Binder.restoreCallingIdentity(identity);
3232 }
3233 }
3234
3235 @Override
chen xu0026ca62019-03-06 15:28:50 -08003236 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003240 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 }
3245
chen xu651eec72018-11-11 19:03:44 -08003246 @Override
chen xu864e11c2018-12-06 22:10:03 -08003247 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3248 if (!isSubscriptionMccMnc) {
3249 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3250 }
chen xu651eec72018-11-11 19:03:44 -08003251 final Phone phone = PhoneFactory.getPhone(slotIndex);
3252 if (phone == null) {
3253 return TelephonyManager.UNKNOWN_CARRIER_ID;
3254 }
3255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
3261 }
3262
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 //
3264 // Internal helper methods.
3265 //
3266
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003267 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003268 * Make sure the caller is the calling package itself
3269 *
3270 * @throws SecurityException if the caller is not the calling package
3271 */
3272 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3273 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003274 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3275 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003276 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003277 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003278 } catch (PackageManager.NameNotFoundException e) {
3279 // packageUid is -1
3280 }
3281 if (packageUid != callingUid) {
3282 throw new SecurityException(message + ": Package " + callingPackage
3283 + " does not belong to " + callingUid);
3284 }
3285 }
3286
3287 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003288 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3289 *
3290 * @throws SecurityException if the caller does not have the required permission
3291 */
3292 private void enforceModifyPermission() {
3293 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3294 }
3295
Shuo Qian3b6ee772019-11-13 17:43:31 -08003296 private void enforceActiveEmergencySessionPermission() {
3297 mApp.enforceCallingOrSelfPermission(
3298 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3299 }
3300
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 /**
3302 * Make sure the caller has the CALL_PHONE permission.
3303 *
3304 * @throws SecurityException if the caller does not have the required permission
3305 */
3306 private void enforceCallPermission() {
3307 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3308 }
3309
paulhu5a773602019-08-23 19:17:33 +08003310 private void enforceSettingsPermission() {
3311 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003312 }
3313
Michele Berionne5e411512020-11-13 02:36:59 +00003314 private void enforceRebootPermission() {
3315 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3316 }
3317
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003318 private String createTelUrl(String number) {
3319 if (TextUtils.isEmpty(number)) {
3320 return null;
3321 }
3322
Jake Hambye994d462014-02-03 13:10:13 -08003323 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324 }
3325
Ihab Awadf9e92732013-12-05 18:02:52 -08003326 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003327 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3328 }
3329
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003330 private static void logv(String msg) {
3331 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3332 }
3333
Ihab Awadf9e92732013-12-05 18:02:52 -08003334 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003335 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3336 }
3337
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003338 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003339 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003340 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003341 }
3342
Sanket Padawe356d7632015-06-22 14:03:32 -07003343 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003344 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 final Phone phone = PhoneFactory.getPhone(slotIndex);
3348 if (phone == null) {
3349 return PhoneConstants.PHONE_TYPE_NONE;
3350 } else {
3351 return phone.getPhoneType();
3352 }
3353 } finally {
3354 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003356 }
3357
3358 /**
3359 * Returns the CDMA ERI icon index to display
3360 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003362 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3363 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3364 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003365 }
3366
Sanket Padawe356d7632015-06-22 14:03:32 -07003367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003368 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3369 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003371 mApp, subId, callingPackage, callingFeatureId,
3372 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003373 return -1;
3374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 final Phone phone = getPhone(subId);
3379 if (phone != null) {
3380 return phone.getCdmaEriIconIndex();
3381 } else {
3382 return -1;
3383 }
3384 } finally {
3385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387 }
3388
3389 /**
3390 * Returns the CDMA ERI icon mode,
3391 * 0 - ON
3392 * 1 - FLASHING
3393 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003394 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003395 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3396 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3397 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003398 }
3399
Sanket Padawe356d7632015-06-22 14:03:32 -07003400 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003401 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3402 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003404 mApp, subId, callingPackage, callingFeatureId,
3405 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003406 return -1;
3407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003408
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 final Phone phone = getPhone(subId);
3412 if (phone != null) {
3413 return phone.getCdmaEriIconMode();
3414 } else {
3415 return -1;
3416 }
3417 } finally {
3418 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003419 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003420 }
3421
3422 /**
3423 * Returns the CDMA ERI text,
3424 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003425 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003426 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3427 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3428 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003429 }
3430
Sanket Padawe356d7632015-06-22 14:03:32 -07003431 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003432 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3433 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003435 mApp, subId, callingPackage, callingFeatureId,
3436 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003437 return null;
3438 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 final Phone phone = getPhone(subId);
3443 if (phone != null) {
3444 return phone.getCdmaEriText();
3445 } else {
3446 return null;
3447 }
3448 } finally {
3449 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 }
3452
3453 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003454 * Returns the CDMA MDN.
3455 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003456 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003457 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3459 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 return phone.getLine1Number();
3466 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003467 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003468 return null;
3469 }
3470 } finally {
3471 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003472 }
3473 }
3474
3475 /**
3476 * Returns the CDMA MIN.
3477 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003478 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003479 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3481 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003482
3483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 final Phone phone = getPhone(subId);
3486 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3487 return phone.getCdmaMin();
3488 } else {
3489 return null;
3490 }
3491 } finally {
3492 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003493 }
3494 }
3495
Hall Liud892bec2018-11-30 14:51:45 -08003496 @Override
3497 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3498 INumberVerificationCallback callback, String callingPackage) {
3499 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3500 != PERMISSION_GRANTED) {
3501 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3502 }
3503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3504
3505 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3506 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003507 throw new SecurityException("Calling package must be configured in the device config: "
3508 + "calling package: " + callingPackage
3509 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003510 }
3511
3512 if (range == null) {
3513 throw new NullPointerException("Range must be non-null");
3514 }
3515
3516 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003517 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003518
3519 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3520 }
3521
Junda Liuca05d5d2014-08-14 22:36:34 -07003522 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003523 * Returns true if CDMA provisioning needs to run.
3524 */
3525 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003526 final long identity = Binder.clearCallingIdentity();
3527 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003528 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 }
3533
3534 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003535 * Sets the voice mail number of a given subId.
3536 */
3537 @Override
3538 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003539 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3540 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541
3542 final long identity = Binder.clearCallingIdentity();
3543 try {
3544 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3545 new Pair<String, String>(alphaTag, number), new Integer(subId));
3546 return success;
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
3549 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003550 }
3551
Ta-wei Yen87c49842016-05-13 21:19:52 -07003552 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003553 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3554 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003555 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3556 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003557 if (!TextUtils.equals(callingPackage, systemDialer)) {
3558 throw new SecurityException("caller must be system dialer");
3559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3564 if (phoneAccountHandle == null) {
3565 return null;
3566 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003567 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 } finally {
3569 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003570 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003571 }
3572
3573 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003574 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3575 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003576 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003578 mApp, subId, callingPackage, callingFeatureId,
3579 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003580 return null;
3581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003583 final long identity = Binder.clearCallingIdentity();
3584 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003589 }
3590
3591 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003592 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3593 VisualVoicemailSmsFilterSettings settings) {
3594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
3596 final long identity = Binder.clearCallingIdentity();
3597 try {
3598 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003599 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003603 }
3604
3605 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003606 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003608
3609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003612 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003613 } finally {
3614 Binder.restoreCallingIdentity(identity);
3615 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003616 }
3617
3618 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003619 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3620 String callingPackage, int subId) {
3621 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622
3623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003626 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003627 } finally {
3628 Binder.restoreCallingIdentity(identity);
3629 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003630 }
3631
3632 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003633 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003634 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635
3636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003643 }
3644
3645 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003646 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3647 String callingAttributionTag, int subId, String number, int port, String text,
3648 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003649 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003650 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003651 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003652 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003653 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3654 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003655 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003656
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003657 /**
fionaxu0152e512016-11-14 13:36:14 -08003658 * Sets the voice activation state of a given subId.
3659 */
3660 @Override
3661 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3663 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 final Phone phone = getPhone(subId);
3668 if (phone != null) {
3669 phone.setVoiceActivationState(activationState);
3670 } else {
3671 loge("setVoiceActivationState fails with invalid subId: " + subId);
3672 }
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003675 }
3676 }
3677
3678 /**
3679 * Sets the data activation state of a given subId.
3680 */
3681 @Override
3682 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3684 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 final Phone phone = getPhone(subId);
3689 if (phone != null) {
3690 phone.setDataActivationState(activationState);
3691 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003692 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693 }
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003696 }
3697 }
3698
3699 /**
3700 * Returns the voice activation state of a given subId.
3701 */
3702 @Override
3703 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705
fionaxu0152e512016-11-14 13:36:14 -08003706 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 if (phone != null) {
3710 return phone.getVoiceActivationState();
3711 } else {
3712 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3713 }
3714 } finally {
3715 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003716 }
3717 }
3718
3719 /**
3720 * Returns the data activation state of a given subId.
3721 */
3722 @Override
3723 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725
fionaxu0152e512016-11-14 13:36:14 -08003726 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727 final long identity = Binder.clearCallingIdentity();
3728 try {
3729 if (phone != null) {
3730 return phone.getDataActivationState();
3731 } else {
3732 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3733 }
3734 } finally {
3735 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003736 }
3737 }
3738
3739 /**
Wink Saville36469e72014-06-11 15:17:00 -07003740 * Returns the unread count of voicemails for a subId
3741 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003742 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003743 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3744 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003746 mApp, subId, callingPackage, callingFeatureId,
3747 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003748 return 0;
3749 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 final Phone phone = getPhone(subId);
3753 if (phone != null) {
3754 return phone.getVoiceMessageCount();
3755 } else {
3756 return 0;
3757 }
3758 } finally {
3759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003761 }
3762
3763 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003764 * returns true, if the device is in a state where both voice and data
3765 * are supported simultaneously. This can change based on location or network condition.
3766 */
3767 @Override
3768 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 final Phone phone = getPhone(subId);
3772 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3773 } finally {
3774 Binder.restoreCallingIdentity(identity);
3775 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003776 }
3777
3778 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003779 * Send the dialer code if called from the current default dialer or the caller has
3780 * carrier privilege.
3781 * @param inputCode The dialer code to send
3782 */
3783 @Override
3784 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003785 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003786 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003787 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3788 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003789 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003790 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003791 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003793
3794 final long identity = Binder.clearCallingIdentity();
3795 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003796 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
fionaxu235cc5e2017-03-06 22:25:57 -08003800 }
3801
Pengquan Menga1bb6272018-09-06 09:59:22 -07003802 @Override
3803 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003804 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003805 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003806 mApp, subId, "getNetworkSelectionMode");
3807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 if (!isActiveSubscription(subId)) {
3810 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3811 }
3812 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3813 } finally {
3814 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003815 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003816 }
3817
Brad Ebinger35c841c2018-10-01 10:40:55 -07003818 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003819 public boolean isInEmergencySmsMode() {
3820 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3821 final long identity = Binder.clearCallingIdentity();
3822 try {
3823 for (Phone phone : PhoneFactory.getPhones()) {
3824 if (phone.isInEmergencySmsMode()) {
3825 return true;
3826 }
3827 }
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
3830 }
3831 return false;
3832 }
3833
shilu366312e2019-12-17 09:28:10 -08003834 /**
3835 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3836 * @param subId The subscription to use to check the configuration.
3837 * @param c The callback that will be used to send the result.
3838 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003839 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003840 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3841 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003842 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003843 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003844
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003845 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3846 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3847 "IMS not available on device.");
3848 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 final long token = Binder.clearCallingIdentity();
3850 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003851 int slotId = getSlotIndexOrException(subId);
3852 verifyImsMmTelConfiguredOrThrow(slotId);
3853 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003854 } catch (ImsException e) {
3855 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003856 } finally {
3857 Binder.restoreCallingIdentity(token);
3858 }
3859 }
3860
shilu366312e2019-12-17 09:28:10 -08003861 /**
3862 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3863 * @param subId The subscription to use to check the configuration.
3864 * @param c The callback that will be used to send the result.
3865 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003866 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003867 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003868 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003869 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003870 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3871 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3872 }
Meng Wangafbc5852019-09-19 17:37:13 -07003873 final long token = Binder.clearCallingIdentity();
3874 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003875 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3876 .removeRegistrationCallbackForSubscription(c, subId);
3877 } catch (ImsException e) {
3878 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3879 + "is inactive, ignoring unregister.");
3880 // If the subscription is no longer active, just return, since the callback
3881 // will already have been removed internally.
3882 } finally {
3883 Binder.restoreCallingIdentity(token);
3884 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 }
3886
Brad Ebingera34a6c22019-10-22 17:36:18 -07003887 /**
3888 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3889 */
3890 @Override
3891 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3892 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3893 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3894 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3895 "IMS not available on device.");
3896 }
3897 final long token = Binder.clearCallingIdentity();
3898 try {
3899 Phone phone = getPhone(subId);
3900 if (phone == null) {
3901 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3902 + subId + "'");
3903 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3904 }
3905 phone.getImsRegistrationState(regState -> {
3906 try {
3907 consumer.accept((regState == null)
3908 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3909 } catch (RemoteException e) {
3910 // Ignore if the remote process is no longer available to call back.
3911 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3912 }
3913 });
3914 } finally {
3915 Binder.restoreCallingIdentity(token);
3916 }
3917 }
3918
3919 /**
3920 * Get the transport type for the IMS service registration state.
3921 */
3922 @Override
3923 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003924 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003925 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003926 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3927 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3928 "IMS not available on device.");
3929 }
3930 final long token = Binder.clearCallingIdentity();
3931 try {
3932 Phone phone = getPhone(subId);
3933 if (phone == null) {
3934 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3935 + subId + "'");
3936 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3937 }
3938 phone.getImsRegistrationTech(regTech -> {
3939 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3940 int regTechConverted = (regTech == null)
3941 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3942 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3943 regTechConverted);
3944 try {
3945 consumer.accept(regTechConverted);
3946 } catch (RemoteException e) {
3947 // Ignore if the remote process is no longer available to call back.
3948 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3949 }
3950 });
3951 } finally {
3952 Binder.restoreCallingIdentity(token);
3953 }
3954 }
3955
shilu366312e2019-12-17 09:28:10 -08003956 /**
3957 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3958 * @param subId The subscription to use to check the configuration.
3959 * @param c The callback that will be used to send the result.
3960 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003962 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3963 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003964 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003965 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003966 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3967 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3968 "IMS not available on device.");
3969 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 final long token = Binder.clearCallingIdentity();
3971 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003972 int slotId = getSlotIndexOrException(subId);
3973 verifyImsMmTelConfiguredOrThrow(slotId);
3974 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003975 } catch (ImsException e) {
3976 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 } finally {
3978 Binder.restoreCallingIdentity(token);
3979 }
3980 }
3981
shilu366312e2019-12-17 09:28:10 -08003982 /**
3983 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3984 * @param subId The subscription to use to check the configuration.
3985 * @param c The callback that will be used to send the result.
3986 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003987 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003988 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003989 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003990 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003991 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3992 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3993 }
Meng Wangafbc5852019-09-19 17:37:13 -07003994
3995 final long token = Binder.clearCallingIdentity();
3996 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003997 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003998 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003999 } catch (ImsException e) {
4000 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4001 + "is inactive, ignoring unregister.");
4002 // If the subscription is no longer active, just return, since the callback
4003 // will already have been removed internally.
4004 } finally {
4005 Binder.restoreCallingIdentity(token);
4006 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 }
4008
4009 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004010 public boolean isCapable(int subId, int capability, int regTech) {
4011 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 final long token = Binder.clearCallingIdentity();
4013 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004014 int slotId = getSlotIndexOrException(subId);
4015 verifyImsMmTelConfiguredOrThrow(slotId);
4016 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004017 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004018 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4019 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004020 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004021 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4022 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 } finally {
4024 Binder.restoreCallingIdentity(token);
4025 }
4026 }
4027
4028 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004029 public boolean isAvailable(int subId, int capability, int regTech) {
4030 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 final long token = Binder.clearCallingIdentity();
4032 try {
4033 Phone phone = getPhone(subId);
4034 if (phone == null) return false;
4035 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004036 } catch (com.android.ims.ImsException e) {
4037 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4038 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 } finally {
4040 Binder.restoreCallingIdentity(token);
4041 }
4042 }
4043
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004044 /**
4045 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4046 * subscription.
4047 * @param subId The subscription to use to check the configuration.
4048 * @param callback The callback that will be used to send the result.
4049 * @param capability The MmTelFeature capability that will be used to send the result.
4050 * @param transportType The transport type of the MmTelFeature capability.
4051 */
4052 @Override
4053 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4054 int transportType) {
4055 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4056 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4057 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4058 "IMS not available on device.");
4059 }
4060 final long token = Binder.clearCallingIdentity();
4061 try {
4062 int slotId = getSlotIndex(subId);
4063 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4064 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4065 + subId + "'");
4066 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4067 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004068 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004069 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4070 transportType, aBoolean -> {
4071 try {
4072 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4073 } catch (RemoteException e) {
4074 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4075 + "running. Ignore");
4076 }
4077 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004078 } catch (ImsException e) {
4079 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004080 } finally {
4081 Binder.restoreCallingIdentity(token);
4082 }
4083 }
4084
shilu366312e2019-12-17 09:28:10 -08004085 /**
4086 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4087 * @param subId The subscription to use to check the configuration.
4088 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 @Override
4090 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004091 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004092 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004093
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 final long token = Binder.clearCallingIdentity();
4095 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004096 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004097 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004098 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 } finally {
4102 Binder.restoreCallingIdentity(token);
4103 }
4104 }
4105
4106 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004107 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004109 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 final long identity = Binder.clearCallingIdentity();
4111 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004112 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004113 // This setting doesn't require an active ImsService connection, so do not verify. The
4114 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004115 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004116 } catch (ImsException e) {
4117 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 } finally {
4119 Binder.restoreCallingIdentity(identity);
4120 }
4121 }
4122
shilu366312e2019-12-17 09:28:10 -08004123 /**
4124 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4125 * @param subId The subscription to use to check the configuration.
4126 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004128 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004129 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004130 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004131 final long identity = Binder.clearCallingIdentity();
4132 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004133 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004134 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004135 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004136 } catch (ImsException e) {
4137 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
4141 }
4142
4143 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004144 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004146 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 final long identity = Binder.clearCallingIdentity();
4148 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004149 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004150 // This setting doesn't require an active ImsService connection, so do not verify. The
4151 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004152 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004153 } catch (ImsException e) {
4154 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 } finally {
4156 Binder.restoreCallingIdentity(identity);
4157 }
4158 }
4159
shilu366312e2019-12-17 09:28:10 -08004160 /**
4161 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4162 * @param subId The subscription to use to check the configuration.
4163 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 @Override
4165 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004166 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004167 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 final long identity = Binder.clearCallingIdentity();
4169 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004170 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004171 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004172 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004173 } catch (ImsException e) {
4174 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
4178 }
4179
4180 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004181 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004183 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 final long identity = Binder.clearCallingIdentity();
4185 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004186 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004187 // This setting doesn't require an active ImsService connection, so do not verify. The
4188 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004189 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004190 } catch (ImsException e) {
4191 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 } finally {
4193 Binder.restoreCallingIdentity(identity);
4194 }
4195 }
4196
shilu366312e2019-12-17 09:28:10 -08004197 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004198 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4199 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4200 * @param subId The subscription to use to check the configuration.
4201 */
4202 @Override
4203 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004204 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004205 mApp, subId, "isCrossSimCallingEnabledByUser");
4206 final long identity = Binder.clearCallingIdentity();
4207 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004208 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004209 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004210 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004211 } catch (ImsException e) {
4212 throw new ServiceSpecificException(e.getCode());
4213 } finally {
4214 Binder.restoreCallingIdentity(identity);
4215 }
4216 }
4217
4218 /**
4219 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4220 * Requires MODIFY_PHONE_STATE permission.
4221 * @param subId The subscription to use to check the configuration.
4222 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4223 * false otherwise
4224 */
4225 @Override
4226 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4228 "setCrossSimCallingEnabled");
4229 final long identity = Binder.clearCallingIdentity();
4230 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004231 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004232 // This setting doesn't require an active ImsService connection, so do not verify. The
4233 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004234 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004235 } catch (ImsException e) {
4236 throw new ServiceSpecificException(e.getCode());
4237 } finally {
4238 Binder.restoreCallingIdentity(identity);
4239 }
4240 }
4241
4242 /**
shilu366312e2019-12-17 09:28:10 -08004243 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4244 * @param subId The subscription to use to check the configuration.
4245 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004246 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004247
Brad Ebinger35c841c2018-10-01 10:40:55 -07004248 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004249 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004250 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 final long identity = Binder.clearCallingIdentity();
4252 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004253 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004254 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004255 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004256 } catch (ImsException e) {
4257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
4260 }
4261 }
4262
4263 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004264 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004266 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 final long identity = Binder.clearCallingIdentity();
4268 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004269 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004270 // This setting doesn't require an active ImsService connection, so do not verify. The
4271 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004272 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004273 } catch (ImsException e) {
4274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
4278 }
4279
4280 @Override
4281 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4283 "setVoWiFiNonPersistent");
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004286 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004287 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 } catch (ImsException e) {
4290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
4294 }
4295
shilu366312e2019-12-17 09:28:10 -08004296 /**
4297 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4298 * @param subId The subscription to use to check the configuration.
4299 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 @Override
4301 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004302 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004303 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 final long identity = Binder.clearCallingIdentity();
4305 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004306 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004307 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004308 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004309 } catch (ImsException e) {
4310 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
4314 }
4315
4316 @Override
4317 public void setVoWiFiModeSetting(int subId, int mode) {
4318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4319 "setVoWiFiModeSetting");
4320 final long identity = Binder.clearCallingIdentity();
4321 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004323 // This setting doesn't require an active ImsService connection, so do not verify. The
4324 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004325 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004326 } catch (ImsException e) {
4327 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332
4333 @Override
4334 public int getVoWiFiRoamingModeSetting(int subId) {
4335 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4336 final long identity = Binder.clearCallingIdentity();
4337 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004338 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004339 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004340 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004341 } catch (ImsException e) {
4342 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
4346 }
4347
4348 @Override
4349 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4351 "setVoWiFiRoamingModeSetting");
4352 final long identity = Binder.clearCallingIdentity();
4353 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004354 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004355 // This setting doesn't require an active ImsService connection, so do not verify. The
4356 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004357 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004358 } catch (ImsException e) {
4359 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
4363 }
4364
4365 @Override
4366 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4368 "setRttCapabilityEnabled");
4369 final long identity = Binder.clearCallingIdentity();
4370 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004371 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004372 // This setting doesn't require an active ImsService connection, so do not verify. The
4373 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004375 } catch (ImsException e) {
4376 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
4380 }
4381
shilu366312e2019-12-17 09:28:10 -08004382 /**
4383 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4384 * @param subId The subscription to use to check the configuration.
4385 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 @Override
4387 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004388 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004389 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004390 final long identity = Binder.clearCallingIdentity();
4391 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004392 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004393 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004394 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004395 } catch (ImsException e) {
4396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004402 @Override
4403 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4404 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4405 final long identity = Binder.clearCallingIdentity();
4406 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004407 if (!isImsAvailableOnDevice()) {
4408 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4409 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004410 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 int slotId = getSlotIndexOrException(subId);
4412 verifyImsMmTelConfiguredOrThrow(slotId);
4413 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004414 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004415 } catch (ImsException e) {
4416 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
4420 }
4421
4422 @Override
4423 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4424 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4425 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004426 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4427 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4428 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004429 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004430 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004431 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004432 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004433 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4434 + "is inactive, ignoring unregister.");
4435 // If the subscription is no longer active, just return, since the callback will already
4436 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
4440 }
4441
allenwtsu99c623b2020-01-03 18:24:23 +08004442
4443 private void checkModifyPhoneStatePermission(int subId, String message) {
4444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4445 message);
4446 }
4447
4448 private boolean isImsProvisioningRequired(int subId, int capability,
4449 boolean isMmtelCapability) {
4450 Phone phone = getPhone(subId);
4451 if (phone == null) {
4452 loge("phone instance null for subid " + subId);
4453 return false;
4454 }
4455 if (isMmtelCapability) {
4456 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4457 return false;
4458 }
4459 } else {
4460 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4461 return false;
4462 }
4463 }
4464 return true;
4465 }
4466
4467 @Override
4468 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4469 boolean isProvisioned) {
4470 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4471
4472 final long identity = Binder.clearCallingIdentity();
4473 try {
4474 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4475 if (!isImsProvisioningRequired(subId, capability, false)) {
4476 return;
4477 }
4478
4479 // this capability requires provisioning, route to the correct API.
4480 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4481 switch (capability) {
4482 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4483 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4484 ims.setEabProvisioned(isProvisioned);
4485 break;
4486 default: {
4487 throw new IllegalArgumentException("Tried to set provisioning for "
4488 + "rcs capability '" + capability + "', which does not require "
4489 + "provisioning.");
4490 }
4491 }
4492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
4495
4496 }
4497
4498
4499 @Override
4500 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4501 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4502 final long identity = Binder.clearCallingIdentity();
4503 try {
4504 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4505 if (!isImsProvisioningRequired(subId, capability, false)) {
4506 return true;
4507 }
4508
4509 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4510 switch (capability) {
4511 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4512 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4513 return ims.isEabProvisionedOnDevice();
4514
4515 default: {
4516 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4517 + "capability '" + capability + "', which does not require "
4518 + "provisioning.");
4519 }
4520 }
4521
4522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
4525 }
4526
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004527 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004528 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4529 boolean isProvisioned) {
4530 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004531 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4532 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4533 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004534 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4535 }
allenwtsu99c623b2020-01-03 18:24:23 +08004536 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004537 final long identity = Binder.clearCallingIdentity();
4538 try {
4539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004540 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004541 return;
4542 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004543 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4544 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4545 loge("setImsProvisioningStatusForCapability: called for technology that does "
4546 + "not support provisioning - " + tech);
4547 return;
4548 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004549
4550 // this capability requires provisioning, route to the correct API.
4551 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4552 switch (capability) {
4553 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4554 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4555 ims.setVolteProvisioned(isProvisioned);
4556 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4557 ims.setWfcProvisioned(isProvisioned);
4558 }
4559 break;
4560 }
4561 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4562 // There is currently no difference in VT provisioning type.
4563 ims.setVtProvisioned(isProvisioned);
4564 break;
4565 }
4566 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4567 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4568 // change the capability of the feature instead if needed.
4569 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4570 == isProvisioned) {
4571 // No change in provisioning.
4572 return;
4573 }
4574 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4575 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004576 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004577 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004578 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4579 + ", Exception" + e.getMessage());
4580 }
4581 break;
4582 }
4583 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004584 throw new IllegalArgumentException("Tried to set provisioning for "
4585 + "MmTel capability '" + capability + "', which does not require "
4586 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004587 }
4588 }
4589
4590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
4593 }
4594
4595 @Override
4596 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4597 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004598 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4599 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4600 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004601 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4602 }
4603 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004607 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004608 return true;
4609 }
4610
Brad Ebinger0d79c572021-04-17 15:20:49 -07004611 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4612 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4613 loge("getImsProvisioningStatusForCapability: called for technology that does "
4614 + "not support provisioning - " + tech);
4615 return true;
4616 }
4617
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004618 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4619 switch (capability) {
4620 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4621 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4622 return ims.isVolteProvisionedOnDevice();
4623 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4624 return ims.isWfcProvisionedOnDevice();
4625 }
4626 // This should never happen, since we are checking tech above to make sure it
4627 // is either LTE or IWLAN.
4628 throw new IllegalArgumentException("Invalid radio technology for voice "
4629 + "capability.");
4630 }
4631 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4632 // There is currently no difference in VT provisioning type.
4633 return ims.isVtProvisionedOnDevice();
4634 }
4635 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4636 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4637 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4638 }
4639 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004640 throw new IllegalArgumentException(
4641 "Tried to get provisioning for MmTel capability '" + capability
4642 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004643 }
4644 }
4645
4646 } finally {
4647 Binder.restoreCallingIdentity(identity);
4648 }
4649 }
4650
4651 @Override
4652 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4653 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4654 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4655 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4656 }
4657 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4658 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4659 return (provisionedBits & capability) > 0;
4660 }
4661
4662 @Override
4663 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4664 boolean isProvisioned) {
4665 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4666 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4667 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4668 }
4669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4670 "setProvisioningStatusForCapability");
4671 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4672 // If the current provisioning status for capability already matches isProvisioned,
4673 // do nothing.
4674 if (((provisionedBits & capability) > 0) == isProvisioned) {
4675 return;
4676 }
4677 if (isProvisioned) {
4678 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4679 } else {
4680 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4681 }
4682 }
4683
4684 /**
4685 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4686 * technology. The bitfield should mirror the bitfield defined by
4687 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4688 */
4689 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4690 String key = getMmTelProvisioningKey(subId, tech);
4691 // Default is no capabilities are provisioned.
4692 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4693 }
4694
4695 /**
4696 * Sets the MmTel capability provisioning bitfield (defined by
4697 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4698 * technology specified.
4699 *
4700 * Note: This is a synchronous command and should not be called on UI thread.
4701 */
4702 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4703 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4704 String key = getMmTelProvisioningKey(subId, tech);
4705 editor.putInt(key, newField);
4706 editor.commit();
4707 }
4708
4709 private static String getMmTelProvisioningKey(int subId, int tech) {
4710 // resulting key is provision_ims_mmtel_{subId}_{tech}
4711 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4712 }
4713
4714 /**
4715 * Query CarrierConfig to see if the specified capability requires provisioning for the
4716 * carrier associated with the subscription id.
4717 */
4718 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4719 int capability) {
4720 CarrierConfigManager configManager = new CarrierConfigManager(context);
4721 PersistableBundle c = configManager.getConfigForSubId(subId);
4722 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004723 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4725 false);
4726 boolean requireVoiceVtProvisioning = c.getBoolean(
4727 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4728
4729 // First check to make sure that the capability requires provisioning.
4730 switch (capability) {
4731 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4732 // intentional fallthrough
4733 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4734 if (requireVoiceVtProvisioning) {
4735 // Voice and Video requires provisioning
4736 return true;
4737 }
4738 break;
4739 }
4740 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4741 if (requireUtProvisioning) {
4742 // UT requires provisioning
4743 return true;
4744 }
4745 break;
4746 }
4747 }
4748 return false;
4749 }
4750
allenwtsu99c623b2020-01-03 18:24:23 +08004751 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4752 int capability) {
4753 CarrierConfigManager configManager = new CarrierConfigManager(context);
4754 PersistableBundle c = configManager.getConfigForSubId(subId);
4755
4756 boolean requireRcsProvisioning = c.getBoolean(
4757 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4758
4759 // First check to make sure that the capability requires provisioning.
4760 switch (capability) {
4761 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4762 // intentional fallthrough
4763 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4764 if (requireRcsProvisioning) {
4765 // OPTION or PRESENCE requires provisioning
4766 return true;
4767 }
4768 break;
4769 }
4770 }
4771 return false;
4772 }
4773
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004774 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004775 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004776 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4777 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4778 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 enforceReadPrivilegedPermission("getImsProvisioningInt");
4780 final long identity = Binder.clearCallingIdentity();
4781 try {
4782 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004783 int slotId = getSlotIndex(subId);
4784 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4785 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4786 + subId + "' for key:" + key);
4787 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4788 }
calvinpanb5a34062021-02-08 19:59:36 +08004789 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004790 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004791 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4792 + subId + "' for key:" + key);
4793 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004794 } finally {
4795 Binder.restoreCallingIdentity(identity);
4796 }
4797 }
4798
4799 @Override
4800 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004801 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4802 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4803 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004804 enforceReadPrivilegedPermission("getImsProvisioningString");
4805 final long identity = Binder.clearCallingIdentity();
4806 try {
4807 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004808 int slotId = getSlotIndex(subId);
4809 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4810 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4811 + subId + "' for key:" + key);
4812 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4813 }
calvinpanb5a34062021-02-08 19:59:36 +08004814 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004815 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004816 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4817 + subId + "' for key:" + key);
4818 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004819 } finally {
4820 Binder.restoreCallingIdentity(identity);
4821 }
4822 }
4823
4824 @Override
4825 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004826 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4827 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4828 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4830 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004834 int slotId = getSlotIndex(subId);
4835 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4836 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4837 + subId + "' for key:" + key);
4838 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4839 }
calvinpanb5a34062021-02-08 19:59:36 +08004840 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4841 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004842 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004843 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004844 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
4848 }
4849
4850 @Override
4851 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004852 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4853 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4854 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4856 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004857 final long identity = Binder.clearCallingIdentity();
4858 try {
4859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004860 int slotId = getSlotIndex(subId);
4861 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4862 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4863 + subId + "' for key:" + key);
4864 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4865 }
calvinpanb5a34062021-02-08 19:59:36 +08004866 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4867 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004868 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004869 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004870 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004871 } finally {
4872 Binder.restoreCallingIdentity(identity);
4873 }
4874 }
4875
Brad Ebinger919631e2021-06-02 17:46:35 -07004876 /**
4877 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4878 * for the given slot ID or no ImsResolver instance has been created.
4879 * @param slotId The slot ID that the IMS service is created for.
4880 * @throws ImsException If there is no ImsService configured for this slot.
4881 */
4882 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4883 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4884 ImsFeature.FEATURE_MMTEL)) {
4885 throw new ImsException("This subscription does not support MMTEL over IMS",
4886 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4887 }
4888 }
4889
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004890 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004891 int slotId = SubscriptionManager.getSlotIndex(subId);
4892 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004893 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4894 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004895 }
4896 return slotId;
4897 }
4898
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 private int getSlotIndex(int subId) {
4900 int slotId = SubscriptionManager.getSlotIndex(subId);
4901 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4902 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4903 }
4904 return slotId;
4905 }
4906
Wink Saville36469e72014-06-11 15:17:00 -07004907 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004908 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004909 */
4910 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004911 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4912 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004913 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004914 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004915 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004916 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004917 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004918 mApp, subId, callingPackage, callingFeatureId,
4919 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004920 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4921 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004923 final long identity = Binder.clearCallingIdentity();
4924 try {
4925 final Phone phone = getPhone(subId);
4926 if (phone != null) {
4927 return phone.getServiceState().getDataNetworkType();
4928 } else {
4929 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4930 }
4931 } finally {
4932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004934 }
4935
4936 /**
4937 * Returns the data network type
4938 */
4939 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004940 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004941 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4942 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004943 }
4944
4945 /**
4946 * Returns the data network type for a subId
4947 */
4948 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004949 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4950 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004952 mApp, subId, callingPackage, callingFeatureId,
4953 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004954 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4955 }
4956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957 final long identity = Binder.clearCallingIdentity();
4958 try {
4959 final Phone phone = getPhone(subId);
4960 if (phone != null) {
4961 return phone.getServiceState().getDataNetworkType();
4962 } else {
4963 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4964 }
4965 } finally {
4966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004968 }
4969
4970 /**
Wink Saville36469e72014-06-11 15:17:00 -07004971 * Returns the Voice network type for a subId
4972 */
4973 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004974 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4975 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004977 mApp, subId, callingPackage, callingFeatureId,
4978 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004979 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4980 }
4981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 final long identity = Binder.clearCallingIdentity();
4983 try {
4984 final Phone phone = getPhone(subId);
4985 if (phone != null) {
4986 return phone.getServiceState().getVoiceNetworkType();
4987 } else {
4988 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4989 }
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004993 }
4994
4995 /**
4996 * @return true if a ICC card is present
4997 */
4998 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004999 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005000 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5001 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005002 }
5003
5004 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005005 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005006 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005007 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005008 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 final Phone phone = PhoneFactory.getPhone(slotIndex);
5012 if (phone != null) {
5013 return phone.getIccCard().hasIccCard();
5014 } else {
5015 return false;
5016 }
5017 } finally {
5018 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005019 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005020 }
5021
5022 /**
5023 * Return if the current radio is LTE on CDMA. This
5024 * is a tri-state return value as for a period of time
5025 * the mode may be unknown.
5026 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005027 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005028 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005029 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005030 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005031 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005032 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5033 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5034 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005035 }
5036
Sanket Padawe356d7632015-06-22 14:03:32 -07005037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5039 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005040 try {
5041 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5042 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005043 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5044 }
5045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 final Phone phone = getPhone(subId);
5049 if (phone == null) {
5050 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5051 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005052 return TelephonyProperties.lte_on_cdma_device()
5053 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 }
5055 } finally {
5056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005057 }
Wink Saville36469e72014-06-11 15:17:00 -07005058 }
5059
Wink Saville36469e72014-06-11 15:17:00 -07005060 /**
5061 * {@hide}
5062 * Returns Default subId, 0 in the case of single standby.
5063 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005064 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005065 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005066 }
5067
Shishir Agrawala9f32182016-04-12 12:00:16 -07005068 private int getSlotForDefaultSubscription() {
5069 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5070 }
5071
Wink Savilleb564aae2014-10-23 10:18:09 -07005072 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005073 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005074 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005075
Pengquan Menge92a50d2018-09-21 15:54:48 -07005076 private boolean isActiveSubscription(int subId) {
5077 return mSubscriptionController.isActiveSubId(subId);
5078 }
5079
Ihab Awadf2177b72013-11-25 13:33:23 -08005080 /**
5081 * @see android.telephony.TelephonyManager.WifiCallingChoices
5082 */
5083 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084 final long identity = Binder.clearCallingIdentity();
5085 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005086 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5088 getWhenToMakeWifiCallsDefaultPreference());
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005092 }
5093
5094 /**
5095 * @see android.telephony.TelephonyManager.WifiCallingChoices
5096 */
5097 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 final long identity = Binder.clearCallingIdentity();
5099 try {
5100 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005101 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5103 } finally {
5104 Binder.restoreCallingIdentity(identity);
5105 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005106 }
5107
Sailesh Nepald1e68152013-12-12 19:08:02 -08005108 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005109 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005110 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005111 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005112
Jordan Liu4c733742019-02-28 12:03:40 -08005113 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5114 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5115 if (phoneId == -1) {
5116 throw new IllegalArgumentException("Given slot index: " + slotIndex
5117 + " does not correspond to an active phone");
5118 }
5119 return PhoneFactory.getPhone(phoneId);
5120 }
5121
Shishir Agrawal566b7612013-10-28 14:41:00 -07005122 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005123 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5124 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5126 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005127 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005128 if (DBG) {
5129 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5130 }
5131 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5132 p2);
5133 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005134
Jordan Liu4c733742019-02-28 12:03:40 -08005135
5136 @Override
5137 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5138 int slotIndex, String callingPackage, String aid, int p2) {
5139 enforceModifyPermission();
5140 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5141 if (DBG) {
5142 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5143 }
5144 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5145 callingPackage, aid, p2);
5146 }
5147
5148 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5149 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 if (TextUtils.equals(ISDR_AID, aid)) {
5153 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005154 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5155 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 if (bestComponent == null
5157 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5158 loge("The calling package is not allowed to access ISD-R.");
5159 throw new SecurityException(
5160 "The calling package is not allowed to access ISD-R.");
5161 }
Derek Tan740e1672017-06-27 14:56:27 -07005162 }
Derek Tan740e1672017-06-27 14:56:27 -07005163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005165 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5166 null /* workSource */);
5167 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 return response;
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
5171 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005172 }
5173
5174 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005175 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5177 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005178 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5179 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5180 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005181
Jordan Liu4c733742019-02-28 12:03:40 -08005182 @Override
5183 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5184 enforceModifyPermission();
5185 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5186 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5187 channel);
5188 }
5189
5190 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 final long identity = Binder.clearCallingIdentity();
5192 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 if (channel < 0) {
5194 return false;
5195 }
Jordan Liu4c733742019-02-28 12:03:40 -08005196 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5197 null /* workSource */);
5198 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 return success;
5200 } finally {
5201 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005202 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005203 }
5204
5205 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005206 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005207 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5209 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005210 if (DBG) {
5211 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5212 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5213 + p3 + " data=" + data);
5214 }
5215 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5216 command, p1, p2, p3, data);
5217 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005218
Jordan Liu4c733742019-02-28 12:03:40 -08005219 @Override
5220 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5221 int command, int p1, int p2, int p3, String data) {
5222 enforceModifyPermission();
5223 if (DBG) {
5224 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5225 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5226 + p3 + " data=" + data);
5227 }
5228 return iccTransmitApduLogicalChannelWithPermission(
5229 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5230 data);
5231 }
5232
5233 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5234 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 final long identity = Binder.clearCallingIdentity();
5236 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005237 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 return "";
5239 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005242 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5243 null /* workSource */);
5244 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 // Append the returned status code to the end of the response payload.
5247 String s = Integer.toHexString(
5248 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5249 if (response.payload != null) {
5250 s = IccUtils.bytesToHexString(response.payload) + s;
5251 }
5252 return s;
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005255 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005256 }
Jake Hambye994d462014-02-03 13:10:13 -08005257
Evan Charltonc66da362014-05-16 14:06:40 -07005258 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005259 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5260 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5262 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005264 if (DBG) {
5265 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5266 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5267 }
5268 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5269 cla, command, p1, p2, p3, data);
5270 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005271
Jordan Liu4c733742019-02-28 12:03:40 -08005272 @Override
5273 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5274 int command, int p1, int p2, int p3, String data) {
5275 enforceModifyPermission();
5276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5277 if (DBG) {
5278 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5279 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5280 + " data=" + data);
5281 }
5282
5283 return iccTransmitApduBasicChannelWithPermission(
5284 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5285 p2, p3, data);
5286 }
5287
5288 // open APDU basic channel assuming the caller has sufficient permissions
5289 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5290 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 final long identity = Binder.clearCallingIdentity();
5292 try {
5293 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5294 && TextUtils.equals(ISDR_AID, data)) {
5295 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005296 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5297 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 if (bestComponent == null
5299 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5300 loge("The calling package is not allowed to select ISD-R.");
5301 throw new SecurityException(
5302 "The calling package is not allowed to select ISD-R.");
5303 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005304 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005307 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5308 null /* workSource */);
5309 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 // Append the returned status code to the end of the response payload.
5312 String s = Integer.toHexString(
5313 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5314 if (response.payload != null) {
5315 s = IccUtils.bytesToHexString(response.payload) + s;
5316 }
5317 return s;
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005320 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005321 }
5322
5323 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005324 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005325 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5327 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 final long identity = Binder.clearCallingIdentity();
5330 try {
5331 if (DBG) {
5332 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5333 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5334 }
5335
5336 IccIoResult response =
5337 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5338 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5339 subId);
5340
5341 if (DBG) {
5342 log("Exchange SIM_IO [R]" + response);
5343 }
5344
5345 byte[] result = null;
5346 int length = 2;
5347 if (response.payload != null) {
5348 length = 2 + response.payload.length;
5349 result = new byte[length];
5350 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5351 } else {
5352 result = new byte[length];
5353 }
5354
5355 result[length - 1] = (byte) response.sw2;
5356 result[length - 2] = (byte) response.sw1;
5357 return result;
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005360 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005361 }
5362
Nathan Haroldb3014052017-01-25 15:57:32 -08005363 /**
5364 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5365 * on a particular subscription
5366 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005367 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5368 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005370 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005371 return null;
5372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373
5374 final long identity = Binder.clearCallingIdentity();
5375 try {
5376 if (appType != TelephonyManager.APPTYPE_USIM
5377 && appType != TelephonyManager.APPTYPE_SIM) {
5378 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5379 return null;
5380 }
5381 Object response = sendRequest(
5382 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5383 if (response instanceof String[]) {
5384 return (String[]) response;
5385 }
yincheng zhao2737e882019-09-06 17:06:54 -07005386 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005388 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 } finally {
5390 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005391 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005392 }
5393
yincheng zhao2737e882019-09-06 17:06:54 -07005394 /**
5395 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5396 * subscription.
5397 *
5398 * @param subId the id of the subscription.
5399 * @param appType the uicc app type, must be USIM or SIM.
5400 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5401 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005402 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005403 * @return number of fplmns that is successfully written to the SIM.
5404 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005405 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5406 String callingFeatureId) {
5407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5408 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005409 if (DBG) logv("no permissions for setForbiddenplmns");
5410 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5411 }
5412 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5413 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5414 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5415 }
5416 if (fplmns == null) {
5417 throw new IllegalArgumentException("Fplmn List provided is null");
5418 }
5419 for (String fplmn : fplmns) {
5420 if (!CellIdentity.isValidPlmn(fplmn)) {
5421 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5422 }
5423 }
5424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 Object response = sendRequest(
5427 CMD_SET_FORBIDDEN_PLMNS,
5428 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5429 subId);
5430 return (int) response;
5431 } finally {
5432 Binder.restoreCallingIdentity(identity);
5433 }
5434 }
5435
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005436 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005437 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5439 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5444 if (response.payload == null) {
5445 return "";
5446 }
Evan Charltonc66da362014-05-16 14:06:40 -07005447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 // Append the returned status code to the end of the response payload.
5449 String s = Integer.toHexString(
5450 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5451 s = IccUtils.bytesToHexString(response.payload) + s;
5452 return s;
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
5455 }
Evan Charltonc66da362014-05-16 14:06:40 -07005456 }
5457
Jake Hambye994d462014-02-03 13:10:13 -08005458 /**
5459 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5460 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5461 *
5462 * @param itemID the ID of the item to read
5463 * @return the NV item as a String, or null on error.
5464 */
5465 @Override
5466 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5469 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005470
5471 final long identity = Binder.clearCallingIdentity();
5472 try {
5473 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005474 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5476 return value;
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
5479 }
Jake Hambye994d462014-02-03 13:10:13 -08005480 }
5481
5482 /**
5483 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5484 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5485 *
5486 * @param itemID the ID of the item to read
5487 * @param itemValue the value to write, as a String
5488 * @return true on success; false on any failure
5489 */
5490 @Override
5491 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005492 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005493 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5494 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495
5496 final long identity = Binder.clearCallingIdentity();
5497 try {
5498 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5499 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005500 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5502 return success;
5503 } finally {
5504 Binder.restoreCallingIdentity(identity);
5505 }
Jake Hambye994d462014-02-03 13:10:13 -08005506 }
5507
5508 /**
5509 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5510 * Used for device configuration by some CDMA operators.
5511 *
5512 * @param preferredRoamingList byte array containing the new PRL
5513 * @return true on success; false on any failure
5514 */
5515 @Override
5516 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5518 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5523 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5524 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5525 return success;
5526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
Jake Hambye994d462014-02-03 13:10:13 -08005529 }
5530
5531 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005532 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005533 * Used for device configuration by some CDMA operators.
5534 *
chen xu6dac5ab2018-10-26 17:39:23 -07005535 * @param slotIndex - device slot.
5536 *
Jake Hambye994d462014-02-03 13:10:13 -08005537 * @return true on success; false on any failure
5538 */
5539 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005540 public boolean resetModemConfig(int slotIndex) {
5541 Phone phone = PhoneFactory.getPhone(slotIndex);
5542 if (phone != null) {
5543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5544 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545
chen xu6dac5ab2018-10-26 17:39:23 -07005546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5549 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5550 return success;
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 }
chen xu6dac5ab2018-10-26 17:39:23 -07005555 return false;
5556 }
5557
5558 /**
5559 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5560 *
5561 * @param slotIndex - device slot.
5562 *
5563 * @return true on success; false on any failure
5564 */
5565 @Override
5566 public boolean rebootModem(int slotIndex) {
5567 Phone phone = PhoneFactory.getPhone(slotIndex);
5568 if (phone != null) {
5569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5570 mApp, phone.getSubId(), "rebootModem");
5571
5572 final long identity = Binder.clearCallingIdentity();
5573 try {
5574 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5575 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5576 return success;
5577 } finally {
5578 Binder.restoreCallingIdentity(identity);
5579 }
5580 }
5581 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005582 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005583
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005584 public String[] getPcscfAddress(String apnType, String callingPackage,
5585 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005586 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5588 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005589 return new String[0];
5590 }
5591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 final long identity = Binder.clearCallingIdentity();
5593 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005594 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
Wink Saville36469e72014-06-11 15:17:00 -07005598 }
5599
Brad Ebinger51f743a2017-01-23 13:50:20 -08005600 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005601 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5602 * {@link #disableIms(int)}.
5603 * @param slotIndex device slot.
5604 */
5605 public void resetIms(int slotIndex) {
5606 enforceModifyPermission();
5607
5608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 if (mImsResolver == null) {
5611 // may happen if the does not support IMS.
5612 return;
5613 }
5614 mImsResolver.disableIms(slotIndex);
5615 mImsResolver.enableIms(slotIndex);
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
5618 }
5619 }
5620
5621 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005622 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5623 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005624 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005625 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005626 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005630 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005631 // may happen if the device does not support IMS.
5632 return;
5633 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005634 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005638 }
5639
5640 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005641 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5642 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005643 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005644 public void disableIms(int slotId) {
5645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646
5647 final long identity = Binder.clearCallingIdentity();
5648 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005649 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005650 // may happen if the device does not support IMS.
5651 return;
5652 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005653 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005657 }
5658
5659 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005660 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5661 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005662 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005663 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005664 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005669 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005670 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5671 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005672 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005673 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005677 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005678 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005679 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5680 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005681 @Override
5682 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005683 enforceModifyPermission();
5684
5685 final long identity = Binder.clearCallingIdentity();
5686 try {
5687 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005688 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691 }
5692 }
5693
5694 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005695 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005696 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005697 */
5698 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5699 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700
5701 final long identity = Binder.clearCallingIdentity();
5702 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005703 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005704 // may happen if the device does not support IMS.
5705 return null;
5706 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005707 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005711 }
5712
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005713 /**
5714 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005715 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005716 */
5717 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5718 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719
5720 final long identity = Binder.clearCallingIdentity();
5721 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005722 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005723 // may happen if the device does not support IMS.
5724 return null;
5725 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005726 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005730 }
5731
Brad Ebinger884c07b2018-02-15 16:17:40 -08005732 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005733 * Sets the ImsService Package Name that Telephony will bind to.
5734 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005735 * @param slotIndex the slot ID that the ImsService should bind for.
5736 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005737 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 * @param featureTypes An integer array of feature types associated with a packageName.
5739 * @param packageName The name of the package that the current configuration will be replaced
5740 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005741 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005742 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005743 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5744 int[] featureTypes, String packageName) {
5745 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5746 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5748 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005749 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 final long identity = Binder.clearCallingIdentity();
5752 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005753 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005754 // may happen if the device does not support IMS.
5755 return false;
5756 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005757 Map<Integer, String> featureConfig = new HashMap<>();
5758 for (int featureType : featureTypes) {
5759 featureConfig.put(featureType, packageName);
5760 }
5761 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5762 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005766 }
5767
5768 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005769 * Clears any carrier ImsService overrides for the slot index specified that were previously
5770 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5771 *
5772 * This should only be used for testing.
5773 *
5774 * @param slotIndex the slot ID that the ImsService should bind for.
5775 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5776 */
5777 @Override
5778 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5779 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5781 "clearCarrierImsServiceOverride");
5782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5783 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5784 "clearCarrierImsServiceOverride");
5785
5786 final long identity = Binder.clearCallingIdentity();
5787 try {
5788 if (mImsResolver == null) {
5789 // may happen if the device does not support IMS.
5790 return false;
5791 }
5792 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
5796 }
5797
5798 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005799 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005800 *
5801 * @param slotId The slot that the ImsService is associated with.
5802 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5803 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005804 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005805 * @return the package name of the ImsService configuration.
5806 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005807 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5808 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005809 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005810 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005811 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005812 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5813 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 final long identity = Binder.clearCallingIdentity();
5816 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005817 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005818 // may happen if the device does not support IMS.
5819 return "";
5820 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005821 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5823 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005827 }
5828
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005829 /**
5830 * Get the MmTelFeature state associated with the requested subscription id.
5831 * @param subId The subscription that the MmTelFeature is associated with.
5832 * @param callback A callback with an integer containing the
5833 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5834 */
5835 @Override
5836 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5837 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5838 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5839 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5840 "IMS not available on device.");
5841 }
5842 final long token = Binder.clearCallingIdentity();
5843 try {
5844 int slotId = getSlotIndex(subId);
5845 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5846 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5847 + subId + "'");
5848 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5849 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005850 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005851 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5852 try {
5853 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5854 } catch (RemoteException e) {
5855 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5856 + "Ignore");
5857 }
5858 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005859 } catch (ImsException e) {
5860 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005861 } finally {
5862 Binder.restoreCallingIdentity(token);
5863 }
5864 }
5865
Daniel Brightbb5840b2021-01-12 15:48:18 -08005866 /**
5867 * Sets the ims registration state on all valid {@link Phone}s.
5868 */
5869 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871
5872 final long identity = Binder.clearCallingIdentity();
5873 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005874 // NOTE: Before S, this method only set the default phone.
5875 for (final Phone phone : PhoneFactory.getPhones()) {
5876 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5877 phone.setImsRegistrationState(registered);
5878 }
5879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 } finally {
5881 Binder.restoreCallingIdentity(identity);
5882 }
Wink Saville36469e72014-06-11 15:17:00 -07005883 }
5884
5885 /**
Stuart Scott54788802015-03-30 13:18:01 -07005886 * Set the network selection mode to automatic.
5887 *
5888 */
5889 @Override
5890 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5892 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893
5894 final long identity = Binder.clearCallingIdentity();
5895 try {
shilufc958392020-01-20 11:36:01 -08005896 if (!isActiveSubscription(subId)) {
5897 return;
5898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005900 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5901 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 } finally {
5903 Binder.restoreCallingIdentity(identity);
5904 }
Stuart Scott54788802015-03-30 13:18:01 -07005905 }
5906
Jack Yud10cdd42020-09-28 20:28:01 -07005907 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005908 * Ask the radio to connect to the input network and change selection mode to manual.
5909 *
5910 * @param subId the id of the subscription.
5911 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5912 * the operator to attach to.
5913 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5914 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5915 * normal network selection next time.
5916 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005917 */
5918 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005919 public boolean setNetworkSelectionModeManual(
5920 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5922 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005923
5924 if (!isActiveSubscription(subId)) {
5925 return false;
5926 }
5927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 final long identity = Binder.clearCallingIdentity();
5929 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005930 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005932 if (DBG) {
5933 log("setNetworkSelectionModeManual: subId: " + subId
5934 + " operator: " + operatorInfo);
5935 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
5939 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005940 }
shilu84f6e8b2019-12-19 13:58:01 -08005941 /**
5942 * Get the manual network selection
5943 *
5944 * @param subId the id of the subscription.
5945 *
5946 * @return the previously saved user selected PLMN
5947 */
5948 @Override
5949 public String getManualNetworkSelectionPlmn(int subId) {
5950 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005951 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005952 mApp, subId, "getManualNetworkSelectionPlmn");
5953
5954 final long identity = Binder.clearCallingIdentity();
5955 try {
5956 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005957 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005958 }
5959
5960 final Phone phone = getPhone(subId);
5961 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005962 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005963 }
5964 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5965 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5966 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
5970 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005971
5972 /**
5973 * Scans for available networks.
5974 */
5975 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005976 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5977 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5979 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005980 LocationAccessPolicy.LocationPermissionResult locationResult =
5981 LocationAccessPolicy.checkLocationPermission(mApp,
5982 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5983 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005984 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005985 .setCallingPid(Binder.getCallingPid())
5986 .setCallingUid(Binder.getCallingUid())
5987 .setMethod("getCellNetworkScanResults")
5988 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005989 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5990 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005991 .build());
5992 switch (locationResult) {
5993 case DENIED_HARD:
5994 throw new SecurityException("Not allowed to access scan results -- location");
5995 case DENIED_SOFT:
5996 return null;
5997 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998
Pengquan Menga1bb6272018-09-06 09:59:22 -07005999 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 try {
6001 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006002 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 } finally {
6005 Binder.restoreCallingIdentity(identity);
6006 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006007 }
6008
6009 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006010 * Get the call forwarding info, given the call forwarding reason.
6011 */
6012 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006013 public void getCallForwarding(int subId, int callForwardingReason,
6014 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006015 enforceReadPrivilegedPermission("getCallForwarding");
6016 long identity = Binder.clearCallingIdentity();
6017 try {
6018 if (DBG) {
6019 log("getCallForwarding: subId " + subId
6020 + " callForwardingReason" + callForwardingReason);
6021 }
Hall Liu27d24262020-09-18 19:04:59 -07006022
6023 Phone phone = getPhone(subId);
6024 if (phone == null) {
6025 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006026 callback.onError(
6027 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006028 } catch (RemoteException e) {
6029 // ignore
6030 }
6031 return;
6032 }
6033
6034 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6035 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6036 @Override
6037 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6038 try {
6039 callback.onCallForwardingInfoAvailable(info);
6040 } catch (RemoteException e) {
6041 // ignore
6042 }
6043 }
6044
6045 @Override
6046 public void onError(int error) {
6047 try {
6048 callback.onError(error);
6049 } catch (RemoteException e) {
6050 // ignore
6051 }
6052 }
6053 });
6054 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006055 } finally {
6056 Binder.restoreCallingIdentity(identity);
6057 }
6058 }
6059
6060 /**
6061 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6062 * reason, the number to forward, and the timeout before the forwarding is attempted.
6063 */
6064 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006065 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6066 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006067 enforceModifyPermission();
6068 long identity = Binder.clearCallingIdentity();
6069 try {
6070 if (DBG) {
6071 log("setCallForwarding: subId " + subId
6072 + " callForwardingInfo" + callForwardingInfo);
6073 }
Hall Liu27d24262020-09-18 19:04:59 -07006074
6075 Phone phone = getPhone(subId);
6076 if (phone == null) {
6077 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006078 callback.accept(
6079 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006080 } catch (RemoteException e) {
6081 // ignore
6082 }
6083 return;
6084 }
6085
6086 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6087 FunctionalUtils.ignoreRemoteException(callback::accept));
6088
6089 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
6093 }
6094
6095 /**
Hall Liu27d24262020-09-18 19:04:59 -07006096 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006097 */
6098 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006099 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006100 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006101 long identity = Binder.clearCallingIdentity();
6102 try {
Hall Liu27d24262020-09-18 19:04:59 -07006103 Phone phone = getPhone(subId);
6104 if (phone == null) {
6105 try {
6106 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6107 } catch (RemoteException e) {
6108 // ignore
6109 }
6110 return;
6111 }
SongFerngWang0e767992021-03-31 22:08:45 +08006112 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6113 PersistableBundle c = configManager.getConfigForSubId(subId);
6114 boolean requireUssd = c.getBoolean(
6115 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006116
Shuo Qian4a594052020-01-23 11:59:30 -08006117 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006118 if (requireUssd) {
6119 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6120 getSubscriptionCarrierId(subId));
6121 String newUssdCommand = "";
6122 try {
6123 newUssdCommand = carrierXmlParser.getFeature(
6124 CarrierXmlParser.FEATURE_CALL_WAITING)
6125 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6126 } catch (NullPointerException e) {
6127 loge("Failed to generate USSD number" + e);
6128 }
6129 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6130 mMainThreadHandler, callback, carrierXmlParser,
6131 CarrierXmlParser.SsEntry.SSAction.QUERY);
6132 final String ussdCommand = newUssdCommand;
6133 Executors.newSingleThreadExecutor().execute(() -> {
6134 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6135 });
6136 } else {
6137 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6138 callback::accept);
6139 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6140 }
Shuo Qian4a594052020-01-23 11:59:30 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
6143 }
6144 }
6145
6146 /**
Hall Liu27d24262020-09-18 19:04:59 -07006147 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006148 */
6149 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006150 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006151 enforceModifyPermission();
6152 long identity = Binder.clearCallingIdentity();
6153 try {
Hall Liu27d24262020-09-18 19:04:59 -07006154 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6155
6156 Phone phone = getPhone(subId);
6157 if (phone == null) {
6158 try {
6159 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6160 } catch (RemoteException e) {
6161 // ignore
6162 }
6163 return;
6164 }
6165
SongFerngWang0e767992021-03-31 22:08:45 +08006166 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6167 PersistableBundle c = configManager.getConfigForSubId(subId);
6168 boolean requireUssd = c.getBoolean(
6169 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006170
SongFerngWang0e767992021-03-31 22:08:45 +08006171 if (DBG) log("getCallWaitingStatus: subId " + subId);
6172 if (requireUssd) {
6173 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6174 getSubscriptionCarrierId(subId));
6175 CarrierXmlParser.SsEntry.SSAction ssAction =
6176 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6177 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6178 String newUssdCommand = "";
6179 try {
6180 newUssdCommand = carrierXmlParser.getFeature(
6181 CarrierXmlParser.FEATURE_CALL_WAITING)
6182 .makeCommand(ssAction, null);
6183 } catch (NullPointerException e) {
6184 loge("Failed to generate USSD number" + e);
6185 }
6186 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6187 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6188 final String ussdCommand = newUssdCommand;
6189 Executors.newSingleThreadExecutor().execute(() -> {
6190 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6191 });
6192 } else {
6193 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6194 FunctionalUtils.ignoreRemoteException(callback::accept));
6195
6196 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6197 }
Shuo Qian4a594052020-01-23 11:59:30 -08006198 } finally {
6199 Binder.restoreCallingIdentity(identity);
6200 }
6201 }
6202
6203 /**
yinxub1bed742017-04-17 11:45:04 -07006204 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006205 *
yinxub1bed742017-04-17 11:45:04 -07006206 * @param subId id of the subscription
6207 * @param request contains the radio access networks with bands/channels to scan
6208 * @param messenger callback messenger for scan results or errors
6209 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006210 * @return the id of the requested scan which can be used to stop the scan.
6211 */
6212 @Override
6213 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006214 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6216 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006217 LocationAccessPolicy.LocationPermissionResult locationResult =
6218 LocationAccessPolicy.checkLocationPermission(mApp,
6219 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6220 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006221 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006222 .setCallingPid(Binder.getCallingPid())
6223 .setCallingUid(Binder.getCallingUid())
6224 .setMethod("requestNetworkScan")
6225 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006226 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6227 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006228 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006229 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006230 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6231 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006232 if (e != null) {
6233 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6234 throw e;
6235 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006236 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006237 return TelephonyScanManager.INVALID_SCAN_ID;
6238 }
6239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 }
Hall Liu912dfd32019-04-25 14:02:26 -07006241 int callingUid = Binder.getCallingUid();
6242 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006243 final long identity = Binder.clearCallingIdentity();
6244 try {
6245 return mNetworkScanRequestTracker.startNetworkScan(
6246 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006247 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
yinxu504e1392017-04-12 16:03:22 -07006251 }
6252
Hall Liub2ac8ef2019-02-28 15:56:23 -08006253 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006254 NetworkScanRequest request, int subId, String callingPackage) {
6255 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006256 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6257 boolean hasNetworkScanPermission =
6258 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6259 == PERMISSION_GRANTED;
6260
6261 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6262 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6263 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006264 }
6265
6266 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6267 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006268 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6269 return new SecurityException("Specific channels must not be"
6270 + " scanned without location access.");
6271 }
6272 }
6273 }
6274
Hall Liub2ac8ef2019-02-28 15:56:23 -08006275 return null;
6276 }
6277
yinxu504e1392017-04-12 16:03:22 -07006278 /**
6279 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006280 *
6281 * @param subId id of the subscription
6282 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006283 */
6284 @Override
6285 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6287 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288
Hall Liu912dfd32019-04-25 14:02:26 -07006289 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 final long identity = Binder.clearCallingIdentity();
6291 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006292 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 } finally {
6294 Binder.restoreCallingIdentity(identity);
6295 }
yinxu504e1392017-04-12 16:03:22 -07006296 }
6297
6298 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006299 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006300 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006301 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006302 */
6303 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006304 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006305 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006306 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006307 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308
6309 final long identity = Binder.clearCallingIdentity();
6310 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006311 if (DBG) log("getAllowedNetworkTypesBitmask");
6312 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6313 int networkTypesBitmask = (result != null ? result[0] : -1);
6314 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6315 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 } finally {
6317 Binder.restoreCallingIdentity(identity);
6318 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006319 }
6320
6321 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006322 * Get the allowed network types for certain reason.
6323 *
6324 * @param subId the id of the subscription.
6325 * @param reason the reason the allowed network type change is taking place
6326 * @return the allowed network types.
6327 */
6328 @Override
6329 public long getAllowedNetworkTypesForReason(int subId,
6330 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006331 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006332 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006333 final long identity = Binder.clearCallingIdentity();
6334 try {
6335 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6336 } finally {
6337 Binder.restoreCallingIdentity(identity);
6338 }
6339 }
6340
6341 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006342 * Enable/Disable E-UTRA-NR Dual Connectivity
6343 * @param subId subscription id of the sim card
6344 * @param nrDualConnectivityState expected NR dual connectivity state
6345 * This can be passed following states
6346 * <ol>
6347 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6348 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6349 * <li>Disable NR dual connectivity and force secondary cell to be released
6350 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6351 * </ol>
6352 * @return operation result.
6353 */
6354 @Override
6355 public int setNrDualConnectivityState(int subId,
6356 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6358 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006359 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006360 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6361 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6362 }
6363
Sooraj Sasindran37444802020-08-11 10:40:43 -07006364 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6365 final long identity = Binder.clearCallingIdentity();
6366 try {
6367 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6368 nrDualConnectivityState, subId,
6369 workSource);
6370 if (DBG) log("enableNRDualConnectivity result: " + result);
6371 return result;
6372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
6375 }
6376
6377 /**
6378 * Is E-UTRA-NR Dual Connectivity enabled
6379 * @return true if dual connectivity is enabled else false
6380 */
6381 @Override
6382 public boolean isNrDualConnectivityEnabled(int subId) {
6383 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006384 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006385 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006386 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006387 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6388 return false;
6389 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006390 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6394 null, subId, workSource);
6395 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6396 return isEnabled;
6397 } finally {
6398 Binder.restoreCallingIdentity(identity);
6399 }
6400 }
6401
6402 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006403 * Set the allowed network types of the device and
6404 * provide the reason triggering the allowed network change.
6405 *
6406 * @param subId the id of the subscription.
6407 * @param reason the reason the allowed network type change is taking place
6408 * @param allowedNetworkTypes the allowed network types.
6409 * @return true on success; false on any failure.
6410 */
6411 @Override
6412 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006413 @TelephonyManager.AllowedNetworkTypesReason int reason,
6414 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6416 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006417 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006418 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6419 return false;
6420 }
6421 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6422 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006423 return false;
6424 }
6425
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006426 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6427 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6428
6429
6430 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6431 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6432 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006433 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006434
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006435 final long identity = Binder.clearCallingIdentity();
6436 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006437 Boolean success = (Boolean) sendRequest(
6438 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6439 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6440
6441 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6442 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006443 } finally {
6444 Binder.restoreCallingIdentity(identity);
6445 }
6446 }
6447
6448 /**
Miaoa84611c2019-03-15 09:21:10 +08006449 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006450 *
Miaoa84611c2019-03-15 09:21:10 +08006451 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006452 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006453 * @hide
6454 */
6455 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006456 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006457 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006459 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 try {
Miaoa84611c2019-03-15 09:21:10 +08006461 if (phone != null) {
6462 return phone.hasMatchedTetherApnSetting();
6463 } else {
6464 return false;
6465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006466 } finally {
6467 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006468 }
Junda Liu475951f2014-11-07 16:45:03 -08006469 }
6470
6471 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006472 * Get the user enabled state of Mobile Data.
6473 *
6474 * TODO: remove and use isUserDataEnabled.
6475 * This can't be removed now because some vendor codes
6476 * calls through ITelephony directly while they should
6477 * use TelephonyManager.
6478 *
6479 * @return true on enabled
6480 */
6481 @Override
6482 public boolean getDataEnabled(int subId) {
6483 return isUserDataEnabled(subId);
6484 }
6485
6486 /**
6487 * Get whether mobile data is enabled per user setting.
6488 *
6489 * There are other factors deciding whether mobile data is actually enabled, but they are
6490 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006491 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006492 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006493 *
6494 * @return {@code true} if data is enabled else {@code false}
6495 */
6496 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006497 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006498 try {
6499 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6500 null);
6501 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6503 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006504 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006505
6506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 int phoneId = mSubscriptionController.getPhoneId(subId);
6509 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6510 Phone phone = PhoneFactory.getPhone(phoneId);
6511 if (phone != null) {
6512 boolean retVal = phone.isUserDataEnabled();
6513 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6514 return retVal;
6515 } else {
6516 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6517 return false;
6518 }
6519 } finally {
6520 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006521 }
6522 }
6523
6524 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006525 * Checks if the device is capable of mobile data by considering whether whether the
6526 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6527 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006528 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006529 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006530 */
6531 @Override
6532 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006533 try {
6534 try {
6535 mApp.enforceCallingOrSelfPermission(
6536 android.Manifest.permission.ACCESS_NETWORK_STATE,
6537 null);
6538 } catch (Exception e) {
6539 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6540 "isDataEnabled");
6541 }
6542 } catch (Exception e) {
6543 enforceReadPrivilegedPermission("isDataEnabled");
6544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545
6546 final long identity = Binder.clearCallingIdentity();
6547 try {
6548 int phoneId = mSubscriptionController.getPhoneId(subId);
6549 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6550 Phone phone = PhoneFactory.getPhone(phoneId);
6551 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006552 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006553 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6554 return retVal;
6555 } else {
6556 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6557 return false;
6558 }
6559 } finally {
6560 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006561 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006562 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006563
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006564 /**
6565 * Check if data is enabled for a specific reason
6566 * @param subId Subscription index
6567 * @param reason the reason the data enable change is taking place
6568 * @return {@code true} if the overall data is enabled; {@code false} if not.
6569 */
6570 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006571 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006572 @TelephonyManager.DataEnabledReason int reason) {
6573 try {
6574 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6575 null);
6576 } catch (Exception e) {
6577 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006578 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006579 }
6580
6581
6582 final long identity = Binder.clearCallingIdentity();
6583 try {
6584 int phoneId = mSubscriptionController.getPhoneId(subId);
6585 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006586 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006587 + " reason=" + reason);
6588 }
6589 Phone phone = PhoneFactory.getPhone(phoneId);
6590 if (phone != null) {
6591 boolean retVal;
6592 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6593 retVal = phone.isUserDataEnabled();
6594 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006595 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006596 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006597 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006598 return retVal;
6599 } else {
6600 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006601 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006602 + subId + " retVal=false");
6603 }
6604 return false;
6605 }
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
6609 }
6610
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006611 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006612 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006613 if (uid == Process.PHONE_UID) {
6614 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6615 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006616 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6617 }
6618
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006619 //load access rules from carrier configs, and check those as well: b/139133814
6620 SubscriptionController subController = SubscriptionController.getInstance();
6621 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6622 || subController == null) return privilegeFromSim;
6623
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006624 PackageManager pkgMgr = phone.getContext().getPackageManager();
6625 String[] packages = pkgMgr.getPackagesForUid(uid);
6626
6627 final long identity = Binder.clearCallingIdentity();
6628 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006629 int subId = phone.getSubId();
6630 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6631 // A test override is in place for the privileges for this subId, so don't try to
6632 // read the subscription privileges.
6633 return privilegeFromSim;
6634 }
6635 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006636 SubscriptionManager subManager = (SubscriptionManager)
6637 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6638 for (String pkg : packages) {
6639 if (subManager.canManageSubscription(subInfo, pkg)) {
6640 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6641 }
6642 }
6643 return privilegeFromSim;
6644 } finally {
6645 Binder.restoreCallingIdentity(identity);
6646 }
6647 }
6648
6649 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6650 String pkgName) {
6651 //load access rules from carrier configs, and check those as well: b/139133814
6652 SubscriptionController subController = SubscriptionController.getInstance();
6653 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6654 || subController == null) return privilegeFromSim;
6655
6656 final long identity = Binder.clearCallingIdentity();
6657 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006658 int subId = phone.getSubId();
6659 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6660 // A test override is in place for the privileges for this subId, so don't try to
6661 // read the subscription privileges.
6662 return privilegeFromSim;
6663 }
6664 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006665 SubscriptionManager subManager = (SubscriptionManager)
6666 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6667 return subManager.canManageSubscription(subInfo, pkgName)
6668 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6669 } finally {
6670 Binder.restoreCallingIdentity(identity);
6671 }
6672 }
6673
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006674 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006675 public int getCarrierPrivilegeStatus(int subId) {
6676 final Phone phone = getPhone(subId);
6677 if (phone == null) {
6678 loge("getCarrierPrivilegeStatus: Invalid subId");
6679 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6680 }
6681 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006682 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006683 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006684 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6685 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006686
6687 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6688 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006689 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006690 }
Junda Liu29340342014-07-10 15:23:27 -07006691
6692 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006693 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006694 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006695 final Phone phone = getPhone(subId);
6696 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006697 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006698 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6699 }
6700 UiccProfile profile =
6701 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6702 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006703 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006704 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6705 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006706 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006707 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006708 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006709 }
6710
6711 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006712 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006713 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006714 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006715 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006716 }
6717
6718 int phoneId = SubscriptionManager.getPhoneId(subId);
6719 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006720 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006721 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006722 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6723 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006724 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6725 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6726 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006727 }
6728
6729 @Override
6730 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006731 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006732 if (TextUtils.isEmpty(pkgName))
6733 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006734 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6735 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6736 UiccCard card = UiccController.getInstance().getUiccCard(i);
6737 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006738 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006739 continue;
6740 }
6741
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006742 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6743 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6744 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006745 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6746 break;
6747 }
6748 }
6749
6750 return result;
Junda Liu29340342014-07-10 15:23:27 -07006751 }
Derek Tan89e89d42014-07-08 17:00:10 -07006752
6753 @Override
Junda Liue64de782015-04-16 17:19:16 -07006754 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006755 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006756 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6757 loge("phoneId " + phoneId + " is not valid.");
6758 return null;
6759 }
6760 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006761 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006762 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006763 return null ;
6764 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006765 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006766 }
6767
Amith Yamasani6e118872016-02-19 12:53:51 -08006768 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006769 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006770 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006771 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006772 List<String> privilegedPackages = new ArrayList<>();
6773 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006774 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6775 // has UICC in that slot.
6776 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006777 if (card.hasCarrierPrivilegeRules()) {
6778 if (packages == null) {
6779 // Only check packages in user 0 for now
6780 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006781 PackageManager.MATCH_DISABLED_COMPONENTS
6782 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006783 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006784 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006785 }
6786 for (int p = packages.size() - 1; p >= 0; p--) {
6787 PackageInfo pkgInfo = packages.get(p);
6788 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006789 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6790 card.getCarrierPrivilegeStatus(pkgInfo),
6791 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006792 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006793 privilegedPackages.add(pkgInfo.packageName);
6794 }
6795 }
6796 }
6797 }
6798 return privilegedPackages;
6799 }
6800
chen xuf7e9fe82019-05-09 19:31:02 -07006801 @Override
6802 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006803 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6804
6805 final long identity = Binder.clearCallingIdentity();
6806
chen xuf7e9fe82019-05-09 19:31:02 -07006807 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006808 try {
6809 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6810 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6811 }
6812 } finally {
6813 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006814 }
6815 return privilegedPackages;
6816 }
6817
Wink Savilleb564aae2014-10-23 10:18:09 -07006818 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006819 final Phone phone = getPhone(subId);
6820 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006821 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006822 return null;
6823 }
6824 String iccId = card.getIccId();
6825 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006826 return null;
6827 }
6828 return iccId;
6829 }
6830
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006831 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006832 public void setCallComposerStatus(int subId, int status) {
6833 enforceModifyPermission();
6834
6835 final long identity = Binder.clearCallingIdentity();
6836 try {
6837 Phone phone = getPhone(subId);
6838 if (phone != null) {
6839 Phone defaultPhone = phone.getImsPhone();
6840 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6841 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6842 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006843 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6844 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006845 }
6846 }
Shuo Qian284ae752020-12-22 19:10:14 -08006847 } catch (ImsException e) {
6848 throw new ServiceSpecificException(e.getCode());
6849 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006850 Binder.restoreCallingIdentity(identity);
6851 }
6852 }
6853
6854 @Override
6855 public int getCallComposerStatus(int subId) {
6856 enforceReadPrivilegedPermission("getCallComposerStatus");
6857
6858 final long identity = Binder.clearCallingIdentity();
6859 try {
6860 Phone phone = getPhone(subId);
6861 if (phone != null) {
6862 Phone defaultPhone = phone.getImsPhone();
6863 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6864 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6865 return imsPhone.getCallComposerStatus();
6866 }
6867 }
6868 } finally {
6869 Binder.restoreCallingIdentity(identity);
6870 }
6871 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6872 }
6873
6874 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006875 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6876 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006877 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006878 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006880 final long identity = Binder.clearCallingIdentity();
6881 try {
6882 final String iccId = getIccId(subId);
6883 final Phone phone = getPhone(subId);
6884 if (phone == null) {
6885 return false;
6886 }
6887 final String subscriberId = phone.getSubscriberId();
6888
6889 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006890 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 + subscriberId + " to " + number);
6892 }
6893
6894 if (TextUtils.isEmpty(iccId)) {
6895 return false;
6896 }
6897
6898 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6899
6900 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6901 if (alphaTag == null) {
6902 editor.remove(alphaTagPrefKey);
6903 } else {
6904 editor.putString(alphaTagPrefKey, alphaTag);
6905 }
6906
6907 // Record both the line number and IMSI for this ICCID, since we need to
6908 // track all merged IMSIs based on line number
6909 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6910 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6911 if (number == null) {
6912 editor.remove(numberPrefKey);
6913 editor.remove(subscriberPrefKey);
6914 } else {
6915 editor.putString(numberPrefKey, number);
6916 editor.putString(subscriberPrefKey, subscriberId);
6917 }
6918
6919 editor.commit();
6920 return true;
6921 } finally {
6922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006923 }
Derek Tan7226c842014-07-02 17:42:23 -07006924 }
6925
6926 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006927 public String getLine1NumberForDisplay(int subId, String callingPackage,
6928 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006929 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006931 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006932 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006933 return null;
6934 }
Derek Tan97ebb422014-09-05 16:55:38 -07006935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 final long identity = Binder.clearCallingIdentity();
6937 try {
6938 String iccId = getIccId(subId);
6939 if (iccId != null) {
6940 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6941 if (DBG_MERGE) {
6942 log("getLine1NumberForDisplay returning "
6943 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6944 }
6945 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6948 return null;
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006951 }
Derek Tan7226c842014-07-02 17:42:23 -07006952 }
6953
6954 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006955 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6956 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006958 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006959 return null;
6960 }
Derek Tan97ebb422014-09-05 16:55:38 -07006961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962 final long identity = Binder.clearCallingIdentity();
6963 try {
6964 String iccId = getIccId(subId);
6965 if (iccId != null) {
6966 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6967 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6968 }
6969 return null;
6970 } finally {
6971 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006972 }
Derek Tan7226c842014-07-02 17:42:23 -07006973 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006974
6975 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006976 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6977 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006978 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6979 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006980 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006981 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006982 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006983 return null;
6984 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006985
Jordan Liub49b04b2019-05-06 14:45:15 -07006986 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6987 // the process, where TelephonyManager was instantiated.
6988 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006989 final long identity = Binder.clearCallingIdentity();
6990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006991 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 final TelephonyManager tele = TelephonyManager.from(context);
6993 final SubscriptionManager sub = SubscriptionManager.from(context);
6994
6995 // Figure out what subscribers are currently active
6996 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997
Jordan Liub49b04b2019-05-06 14:45:15 -07006998 // Only consider subs which match the current subId
6999 // This logic can be simplified. See b/131189269 for progress.
7000 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007001 activeSubscriberIds.add(tele.getSubscriberId(subId));
7002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003
7004 // First pass, find a number override for an active subscriber
7005 String mergeNumber = null;
7006 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7007 for (String key : prefs.keySet()) {
7008 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7009 final String subscriberId = (String) prefs.get(key);
7010 if (activeSubscriberIds.contains(subscriberId)) {
7011 final String iccId = key.substring(
7012 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7013 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7014 mergeNumber = (String) prefs.get(numberKey);
7015 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007016 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 + " for active subscriber " + subscriberId);
7018 }
7019 if (!TextUtils.isEmpty(mergeNumber)) {
7020 break;
7021 }
7022 }
7023 }
7024 }
7025
7026 // Shortcut when no active merged subscribers
7027 if (TextUtils.isEmpty(mergeNumber)) {
7028 return null;
7029 }
7030
7031 // Second pass, find all subscribers under that line override
7032 final ArraySet<String> result = new ArraySet<>();
7033 for (String key : prefs.keySet()) {
7034 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7035 final String number = (String) prefs.get(key);
7036 if (mergeNumber.equals(number)) {
7037 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7038 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7039 final String subscriberId = (String) prefs.get(subscriberKey);
7040 if (!TextUtils.isEmpty(subscriberId)) {
7041 result.add(subscriberId);
7042 }
7043 }
7044 }
7045 }
7046
7047 final String[] resultArray = result.toArray(new String[result.size()]);
7048 Arrays.sort(resultArray);
7049 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007050 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7052 }
7053 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007054 } finally {
7055 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007056 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007057 }
7058
7059 @Override
zoey chen38003472019-12-13 17:16:31 +08007060 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7061 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007062
7063 final long identity = Binder.clearCallingIdentity();
7064 try {
7065 final TelephonyManager telephonyManager = mApp.getSystemService(
7066 TelephonyManager.class);
7067 String subscriberId = telephonyManager.getSubscriberId(subId);
7068 if (subscriberId == null) {
7069 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007070 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007071 + subId);
7072 }
7073 return null;
7074 }
7075
7076 final SubscriptionInfo info = SubscriptionController.getInstance()
7077 .getSubscriptionInfo(subId);
7078 final ParcelUuid groupUuid = info.getGroupUuid();
7079 // If it doesn't belong to any group, return just subscriberId of itself.
7080 if (groupUuid == null) {
7081 return new String[]{subscriberId};
7082 }
7083
7084 // Get all subscriberIds from the group.
7085 final List<String> mergedSubscriberIds = new ArrayList<>();
7086 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007087 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007088 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007089 for (SubscriptionInfo subInfo : groupInfos) {
7090 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7091 if (subscriberId != null) {
7092 mergedSubscriberIds.add(subscriberId);
7093 }
7094 }
7095
7096 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7097 } finally {
7098 Binder.restoreCallingIdentity(identity);
7099
7100 }
7101 }
7102
7103 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007104 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007105 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007106 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107
7108 final long identity = Binder.clearCallingIdentity();
7109 try {
7110 final Phone phone = getPhone(subId);
7111 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
7114 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007115 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007116
7117 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007118 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007119 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7120 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007121 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7122 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 final Phone phone = getPhone(subId);
7127 if (phone == null) {
7128 return false;
7129 }
7130 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7131 cdmaNonRoamingList);
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007134 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007135 }
7136
7137 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007138 @Deprecated
7139 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7140 enforceModifyPermission();
7141
7142 int returnValue = 0;
7143 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007144 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007145 if(result.exception == null) {
7146 if (result.result != null) {
7147 byte[] responseData = (byte[])(result.result);
7148 if(responseData.length > oemResp.length) {
7149 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7150 responseData.length + "bytes. Buffer Size is " +
7151 oemResp.length + "bytes.");
7152 }
7153 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7154 returnValue = responseData.length;
7155 }
7156 } else {
7157 CommandException ex = (CommandException) result.exception;
7158 returnValue = ex.getCommandError().ordinal();
7159 if(returnValue > 0) returnValue *= -1;
7160 }
7161 } catch (RuntimeException e) {
7162 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7163 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7164 if(returnValue > 0) returnValue *= -1;
7165 }
7166
7167 return returnValue;
7168 }
7169
7170 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007171 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007172 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007173 try {
7174 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007175 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007176 mApp, phone.getSubId(), "getRadioAccessFamily");
7177 } catch (SecurityException e) {
7178 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7179 throw e;
7180 }
chen xub97461a2018-10-26 14:17:57 -07007181 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007182 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007183 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 final long identity = Binder.clearCallingIdentity();
7186 try {
chen xub97461a2018-10-26 14:17:57 -07007187 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007188 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007189 mApp, phone.getSubId(), "getRadioAccessFamily");
7190 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 } finally {
7192 Binder.restoreCallingIdentity(identity);
7193 }
chen xub97461a2018-10-26 14:17:57 -07007194 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007195 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007196
7197 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007198 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007199 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007200 try {
7201 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7202 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007203 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007204 }
7205 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007206 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007207 }
7208 RoleManager rm = mApp.getSystemService(RoleManager.class);
7209 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7210 if (!dialerRoleHolders.contains(callingPackage)) {
7211 throw new SecurityException("App must be the dialer role holder to"
7212 + " upload a call composer pic");
7213 }
7214
7215 Executors.newSingleThreadExecutor().execute(() -> {
7216 ByteArrayOutputStream output = new ByteArrayOutputStream(
7217 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7218 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7219 boolean readUntilEnd = false;
7220 int totalBytesRead = 0;
7221 byte[] buffer = new byte[16 * 1024];
7222 while (true) {
7223 int numRead;
7224 try {
7225 numRead = input.read(buffer);
7226 } catch (IOException e) {
7227 try {
7228 fd.checkError();
7229 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7230 null);
7231 } catch (IOException e1) {
7232 // This means that the other side closed explicitly with an error. If this
7233 // happens, log and ignore.
7234 loge("Remote end of call composer picture pipe closed: " + e1);
7235 }
7236 break;
7237 }
7238 if (numRead == -1) {
7239 readUntilEnd = true;
7240 break;
7241 }
7242 totalBytesRead += numRead;
7243 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7244 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7245 try {
7246 input.close();
7247 } catch (IOException e) {
7248 // ignore
7249 }
7250 break;
7251 }
7252 output.write(buffer, 0, numRead);
7253 }
7254 // Generally, the remote end will close the file descriptors. The only case where we
7255 // close is above, where the picture size is too big.
7256
7257 try {
7258 fd.checkError();
7259 } catch (IOException e) {
7260 loge("Remote end for call composer closed with an error: " + e);
7261 return;
7262 }
7263
Hall Liuaa4211e2021-01-20 15:43:39 -08007264 if (!readUntilEnd) {
7265 loge("Did not finish reading entire image; aborting");
7266 return;
7267 }
Hall Liu82694d52020-12-11 18:22:04 -08007268
Hall Liuaa4211e2021-01-20 15:43:39 -08007269 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7270 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7271 new CallComposerPictureTransfer.Factory() {},
7272 imageData,
7273 (result) -> {
7274 if (result.first != null) {
7275 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7276 Bundle outputResult = new Bundle();
7277 outputResult.putParcelable(
7278 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7279 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7280 outputResult);
7281 } else {
7282 callback.send(result.second, null);
7283 }
7284 }
7285 );
Hall Liu82694d52020-12-11 18:22:04 -08007286 });
7287 }
7288
7289 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007290 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007291 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007292 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007296 ImsManager.getInstance(defaultPhone.getContext(),
7297 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298 } finally {
7299 Binder.restoreCallingIdentity(identity);
7300 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007301 }
7302
7303 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007304 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007305 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7307 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007308 return false;
7309 }
Svet Ganovb320e182015-04-16 12:30:10 -07007310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 // Check the user preference and the system-level IMS setting. Even if the user has
7314 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7315 // In the long run, we may instead need to check if there exists a connection service
7316 // which can support video calling.
7317 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007318 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 return imsManager.isVtEnabledByPlatform()
7320 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7321 && imsManager.isVtEnabledByUser();
7322 } finally {
7323 Binder.restoreCallingIdentity(identity);
7324 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007325 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007326
Andrew Leea1239f22015-03-02 17:44:07 -08007327 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007328 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7329 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007331 mApp, subId, callingPackage, callingFeatureId,
7332 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 return false;
7334 }
7335
7336 final long identity = Binder.clearCallingIdentity();
7337 try {
7338 CarrierConfigManager configManager =
7339 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007340 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
Andrew Leea1239f22015-03-02 17:44:07 -08007345 }
7346
7347 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007348 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007350 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 return false;
7352 }
7353
7354 final long identity = Binder.clearCallingIdentity();
7355 try {
7356 CarrierConfigManager configManager =
7357 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007358 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007359 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7360 } finally {
7361 Binder.restoreCallingIdentity(identity);
7362 }
Andrew Leea1239f22015-03-02 17:44:07 -08007363 }
7364
Andrew Lee9431b832015-03-09 18:46:45 -07007365 @Override
7366 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007367 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007368 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007369 }
7370
7371 @Override
7372 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 final long identity = Binder.clearCallingIdentity();
7374 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007375 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 } finally {
7377 Binder.restoreCallingIdentity(identity);
7378 }
Andrew Lee9431b832015-03-09 18:46:45 -07007379 }
7380
Hall Liuf6668912018-10-31 17:05:23 -07007381 /**
7382 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7383 * support for the feature and device firmware support.
7384 *
7385 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7386 */
7387 @Override
7388 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007390 final Phone phone = getPhone(subscriptionId);
7391 if (phone == null) {
7392 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7393 return false;
7394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007396 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007397 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7398 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007399 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 return isCarrierSupported && isDeviceSupported;
7401 } finally {
7402 Binder.restoreCallingIdentity(identity);
7403 }
Hall Liu98187582018-01-22 19:15:32 -08007404 }
7405
Hall Liuf6668912018-10-31 17:05:23 -07007406 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007407 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7408 * RTT setting, will return true if the device and carrier both support RTT.
7409 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007410 */
7411 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412 final long identity = Binder.clearCallingIdentity();
7413 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007414 boolean isRttSupported = isRttSupported(subscriptionId);
7415 boolean isUserRttSettingOn = Settings.Secure.getInt(
7416 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7417 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7418 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7419 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 } finally {
7421 Binder.restoreCallingIdentity(identity);
7422 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007423 }
7424
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007425 @Deprecated
7426 @Override
7427 public String getDeviceId(String callingPackage) {
7428 return getDeviceIdWithFeature(callingPackage, null);
7429 }
7430
Sanket Padawe7310cc72015-01-14 09:53:20 -08007431 /**
7432 * Returns the unique device ID of phone, for example, the IMEI for
7433 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7434 *
7435 * <p>Requires Permission:
7436 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7437 */
7438 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007440 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007441 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007442 return null;
7443 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007444 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007445 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007446 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007447 return null;
7448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449
7450 final long identity = Binder.clearCallingIdentity();
7451 try {
7452 return phone.getDeviceId();
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007456 }
7457
Ping Sunc67b7c22016-03-02 19:16:45 +08007458 /**
7459 * {@hide}
7460 * Returns the IMS Registration Status on a particular subid
7461 *
7462 * @param subId
7463 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007464 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007465 Phone phone = getPhone(subId);
7466 if (phone != null) {
7467 return phone.isImsRegistered();
7468 } else {
7469 return false;
7470 }
7471 }
7472
Santos Cordon7a1885b2015-02-03 11:15:19 -08007473 @Override
7474 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 final long identity = Binder.clearCallingIdentity();
7476 try {
7477 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007481 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007482
Tyler Gunnf70ed162019-04-03 15:28:53 -07007483 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007484 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007485 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007487 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007488 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7489 }
7490 final long identity = Binder.clearCallingIdentity();
7491 try {
7492 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
7496 }
7497
7498 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007499 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007500 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007501 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007502 mApp,
7503 subscriptionId,
7504 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007505 final long identity = Binder.clearCallingIdentity();
7506 try {
7507 Phone phone = getPhone(subscriptionId);
7508 if (phone == null) {
7509 return null;
7510 }
7511 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
7515 }
7516
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007517 /**
7518 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007519 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007520 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 Phone phone = getPhone(subId);
7524 if (phone != null) {
7525 return phone.isWifiCallingEnabled();
7526 } else {
7527 return false;
7528 }
7529 } finally {
7530 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007531 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007532 }
7533
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007534 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007535 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007536 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007537 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 Phone phone = getPhone(subId);
7541 if (phone != null) {
7542 return phone.isVideoEnabled();
7543 } else {
7544 return false;
7545 }
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007548 }
7549 }
7550
7551 /**
7552 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7553 * defined in {@link ImsRegistrationImplBase}.
7554 */
7555 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 final long identity = Binder.clearCallingIdentity();
7557 try {
7558 Phone phone = getPhone(subId);
7559 if (phone != null) {
7560 return phone.getImsRegistrationTech();
7561 } else {
7562 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7563 }
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007566 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007567 }
7568
Stuart Scott8eef64f2015-04-08 15:13:54 -07007569 @Override
7570 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007571 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007572 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7573 return;
7574 }
Kai Shif70f46f2021-03-03 13:59:46 -08007575 Phone defaultPhone = getDefaultPhone();
7576 if (defaultPhone != null) {
7577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7578 mApp, getDefaultPhone().getSubId(), "factoryReset");
7579 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007580 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007581
Svet Ganovcc087f82015-05-12 20:35:54 -07007582 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007583 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7584 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007585 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007586 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007587 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007588 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007589 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007590 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007591 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007592 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007593 // There has been issues when Sms raw table somehow stores orphan
7594 // fragments. They lead to garbled message when new fragments come
7595 // in and combined with those stale ones. In case this happens again,
7596 // user can reset all network settings which will clean up this table.
7597 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007598 // Clean up IMS settings as well here.
7599 int slotId = getSlotIndex(subId);
7600 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7601 ImsManager.getInstance(mApp, slotId).factoryReset();
7602 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007603
Kai Shif70f46f2021-03-03 13:59:46 -08007604 if (defaultPhone == null) {
7605 return;
7606 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007607 // Erase modem config if erase modem on network setting is enabled.
7608 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7609 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7610 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007611 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007612 }
Kai Shif70f46f2021-03-03 13:59:46 -08007613
7614 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007615 } finally {
7616 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007617 }
7618 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007619
SongFerngWangfd89b102021-05-27 22:44:54 +08007620 @VisibleForTesting
7621 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7622 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7623 return;
7624 }
7625 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7626 RILConstants.PREFERRED_NETWORK_MODE);
7627 SubscriptionManager.setSubscriptionProperty(subId,
7628 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7629 "user=" + defaultNetworkType);
7630 phone.loadAllowedNetworksFromSubscriptionDatabase();
7631 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7632 defaultNetworkType, null);
7633 }
7634
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007635 private void cleanUpSmsRawTable(Context context) {
7636 ContentResolver resolver = context.getContentResolver();
7637 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7638 resolver.delete(uri, null, null);
7639 }
7640
Narayan Kamath1c496c22015-04-16 14:40:19 +01007641 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007642 public String getSimLocaleForSubscriber(int subId) {
7643 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7644 final Phone phone = getPhone(subId);
7645 if (phone == null) {
7646 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007647 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649 final long identity = Binder.clearCallingIdentity();
7650 try {
chen xu5d3637b2019-01-21 23:31:38 -08007651 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007652 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007653 if (info == null) {
7654 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7655 return null;
7656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 // Try and fetch the locale from the carrier properties or from the SIM language
7658 // preferences (EF-PL and EF-LI)...
7659 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007661 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7662 if (localeFromDefaultSim != null) {
7663 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7664 if (DBG) log("Using locale from subId: " + subId + " locale: "
7665 + localeFromDefaultSim);
7666 return localeFromDefaultSim.toLanguageTag();
7667 } else {
7668 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669 }
7670 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 // The SIM language preferences only store a language (e.g. fr = French), not an
7673 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7674 // the SIM and carrier preferences does not include a country we add the country
7675 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007676 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007678 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 return mccLocale.toLanguageTag();
7680 }
7681
7682 if (DBG) log("No locale found - returning null");
7683 return null;
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
7686 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007687 }
7688
7689 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007690 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007691 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007692 }
7693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 /**
7695 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7696 */
7697 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007698 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007699 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007700 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007701
Chenjie Yu1ba97252018-01-11 18:16:20 -08007702 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007703 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007704
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007705 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007706 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7707 * representing the state of the modem.
7708 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007709 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7710 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007711 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007712 */
7713 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007714 public void requestModemActivityInfo(ResultReceiver result) {
7715 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007716 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717
7718 final long identity = Binder.clearCallingIdentity();
7719 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007720 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007721 } finally {
7722 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007723 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007724 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007725
Siddharth Rayb8114062018-06-17 15:02:38 -07007726 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7727 // less than total activity duration.
7728 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7729 if (info == null) {
7730 return false;
7731 }
7732 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007733 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7734 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7735
Siddharth Rayb8114062018-06-17 15:02:38 -07007736 return (info.isValid()
7737 && (info.getSleepTimeMillis() <= activityDurationMs)
7738 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007739 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007740 && (totalTxTimeMs <= activityDurationMs));
7741 }
7742
Jack Yu85bd38a2015-11-09 11:34:32 -08007743 /**
7744 * {@hide}
7745 * Returns the service state information on specified subscription.
7746 */
7747 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007748 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7749 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007750 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007751 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007752 return null;
7753 }
7754
Hall Liuf19c44f2018-11-27 14:38:17 -08007755 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7756 LocationAccessPolicy.checkLocationPermission(mApp,
7757 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7758 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007759 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007760 .setCallingPid(Binder.getCallingPid())
7761 .setCallingUid(Binder.getCallingUid())
7762 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007763 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007764 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007765 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7766 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007767 .build());
7768
7769 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7770 LocationAccessPolicy.checkLocationPermission(mApp,
7771 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7772 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007773 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007774 .setCallingPid(Binder.getCallingPid())
7775 .setCallingUid(Binder.getCallingUid())
7776 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007777 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007778 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007779 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7780 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007781 .build());
7782 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7783 boolean hasFinePermission =
7784 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7785 boolean hasCoarsePermission =
7786 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7787
Jack Yu479f40e2020-10-27 21:29:25 -07007788 final Phone phone = getPhone(subId);
7789 if (phone == null) {
7790 return null;
7791 }
7792
Jordan Liu0f2bc442020-11-18 16:47:37 -08007793 final long identity = Binder.clearCallingIdentity();
7794
Jack Yu479f40e2020-10-27 21:29:25 -07007795 boolean isCallingPackageDataService = phone.getDataServicePackages()
7796 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007798 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7799 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7800 Rlog.d(LOG_TAG,
7801 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7802 return null;
7803 }
7804
Hall Liuf19c44f2018-11-27 14:38:17 -08007805 ServiceState ss = phone.getServiceState();
7806
7807 // Scrub out the location info in ServiceState depending on what level of access
7808 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007809 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007810 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7811 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 } finally {
7813 Binder.restoreCallingIdentity(identity);
7814 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007815 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007816
7817 /**
7818 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7819 *
7820 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7821 * voicemail ringtone.
7822 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7823 * PhoneAccount.
7824 */
7825 @Override
7826 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007827 final long identity = Binder.clearCallingIdentity();
7828 try {
7829 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7830 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007831 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007832 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007838 }
7839
7840 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007841 * Sets the per-account voicemail ringtone.
7842 *
7843 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7844 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7845 *
7846 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7847 * voicemail ringtone.
7848 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7849 * PhoneAccount.
7850 */
7851 @Override
7852 public void setVoicemailRingtoneUri(String callingPackage,
7853 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007854 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007855 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007856 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7857 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7859 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7860 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007862
7863 final long identity = Binder.clearCallingIdentity();
7864 try {
7865 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7866 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007867 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868 }
7869 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7870 } finally {
7871 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007872 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007873 }
7874
7875 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007876 * Returns whether vibration is set for voicemail notification in Phone settings.
7877 *
7878 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7879 * voicemail vibration setting.
7880 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7881 */
7882 @Override
7883 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007884 final long identity = Binder.clearCallingIdentity();
7885 try {
7886 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7887 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007888 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007889 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007895 }
7896
Youhan Wange64578a2016-05-02 15:32:42 -07007897 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007898 * Sets the per-account voicemail vibration.
7899 *
7900 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7901 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7902 *
7903 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7904 * voicemail vibration setting.
7905 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7906 * specific PhoneAccount.
7907 */
7908 @Override
7909 public void setVoicemailVibrationEnabled(String callingPackage,
7910 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007911 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007913 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7914 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7916 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7917 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007918 }
7919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007920 final long identity = Binder.clearCallingIdentity();
7921 try {
7922 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7923 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007924 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 }
7926 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7927 } finally {
7928 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007929 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007930 }
7931
7932 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007933 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7934 *
7935 * @throws SecurityException if the caller does not have the required permission
7936 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007937 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007938 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007939 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007940 }
7941
7942 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007943 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7944 * permission.
7945 *
7946 * @throws SecurityException if the caller does not have the required permission
7947 */
7948 private void enforceSendSmsPermission() {
7949 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7950 }
7951
7952 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007953 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007954 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007955 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007956 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007957 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 final long identity = Binder.clearCallingIdentity();
7959 try {
7960 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007961 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 if (componentName == null) {
7963 throw new SecurityException(
7964 "Caller not current active visual voicemail package[null]");
7965 }
7966 String vvmPackage = componentName.getPackageName();
7967 if (!callingPackage.equals(vvmPackage)) {
7968 throw new SecurityException("Caller not current active visual voicemail package["
7969 + vvmPackage + "]");
7970 }
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007973 }
7974 }
7975
7976 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007977 * Return the application ID for the app type.
7978 *
7979 * @param subId the subscription ID that this request applies to.
7980 * @param appType the uicc app type.
7981 * @return Application ID for specificied app type, or null if no uicc.
7982 */
7983 @Override
7984 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007985 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007986 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987
7988 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007989 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990 if (phone == null) {
7991 return null;
7992 }
7993 String aid = null;
7994 try {
7995 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7996 .getApplicationByType(appType).getAid();
7997 } catch (Exception e) {
7998 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7999 }
8000 return aid;
8001 } finally {
8002 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008003 }
Youhan Wange64578a2016-05-02 15:32:42 -07008004 }
8005
Youhan Wang4001d252016-05-11 10:29:41 -07008006 /**
8007 * Return the Electronic Serial Number.
8008 *
8009 * @param subId the subscription ID that this request applies to.
8010 * @return ESN or null if error.
8011 */
8012 @Override
8013 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008014 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008015 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008016
8017 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008018 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 if (phone == null) {
8020 return null;
8021 }
8022 String esn = null;
8023 try {
8024 esn = phone.getEsn();
8025 } catch (Exception e) {
8026 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8027 }
8028 return esn;
8029 } finally {
8030 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008031 }
Youhan Wang4001d252016-05-11 10:29:41 -07008032 }
8033
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008034 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008035 * Return the Preferred Roaming List Version.
8036 *
8037 * @param subId the subscription ID that this request applies to.
8038 * @return PRLVersion or null if error.
8039 */
8040 @Override
8041 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008042 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008043 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008044
8045 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008046 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 if (phone == null) {
8048 return null;
8049 }
8050 String cdmaPrlVersion = null;
8051 try {
8052 cdmaPrlVersion = phone.getCdmaPrlVersion();
8053 } catch (Exception e) {
8054 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8055 }
8056 return cdmaPrlVersion;
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008059 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008060 }
8061
8062 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008063 * Get snapshot of Telephony histograms
8064 * @return List of Telephony histograms
8065 * @hide
8066 */
8067 @Override
8068 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8070 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071
8072 final long identity = Binder.clearCallingIdentity();
8073 try {
8074 return RIL.getTelephonyRILTimingHistograms();
8075 } finally {
8076 Binder.restoreCallingIdentity(identity);
8077 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008078 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008079
8080 /**
8081 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008082 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8083 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008084 * Require system privileges. In the future we may add this to carrier APIs.
8085 *
Michele Berionne482f8202018-11-27 18:57:59 -08008086 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008087 */
8088 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008089 @TelephonyManager.SetCarrierRestrictionResult
8090 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008091 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008093
Michele Berionne482f8202018-11-27 18:57:59 -08008094 if (carrierRestrictionRules == null) {
8095 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008096 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098 final long identity = Binder.clearCallingIdentity();
8099 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008100 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008101 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008105 }
8106
8107 /**
8108 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008109 * Get the allowed carrier list and the excluded carrier list, including the priority between
8110 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008111 * Require system privileges. In the future we may add this to carrier APIs.
8112 *
Michele Berionne482f8202018-11-27 18:57:59 -08008113 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008114 */
8115 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008116 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008117 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008118 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119
8120 final long identity = Binder.clearCallingIdentity();
8121 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008122 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8123 if (response instanceof CarrierRestrictionRules) {
8124 return (CarrierRestrictionRules) response;
8125 }
8126 // Response is an Exception of some kind,
8127 // which is signalled to the user as a NULL retval
8128 return null;
8129 } catch (Exception e) {
8130 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8131 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 } finally {
8133 Binder.restoreCallingIdentity(identity);
8134 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008135 }
8136
fionaxu59545b42016-05-25 15:53:37 -07008137 /**
fionaxu59545b42016-05-25 15:53:37 -07008138 * Action set from carrier signalling broadcast receivers to enable/disable radio
8139 * @param subId the subscription ID that this action applies to.
8140 * @param enabled control enable or disable radio.
8141 * {@hide}
8142 */
8143 @Override
8144 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8145 enforceModifyPermission();
8146 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008147
8148 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008149 if (phone == null) {
8150 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8151 return;
8152 }
8153 try {
8154 phone.carrierActionSetRadioEnabled(enabled);
8155 } catch (Exception e) {
8156 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157 } finally {
8158 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008159 }
8160 }
8161
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008162 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008163 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8164 * network status based on which carrier apps could apply actions accordingly,
8165 * enable/disable default url handler for example.
8166 *
8167 * @param subId the subscription ID that this action applies to.
8168 * @param report control start/stop reporting the default network status.
8169 * {@hide}
8170 */
8171 @Override
8172 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8173 enforceModifyPermission();
8174 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175
8176 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008177 if (phone == null) {
8178 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8179 return;
8180 }
8181 try {
8182 phone.carrierActionReportDefaultNetworkStatus(report);
8183 } catch (Exception e) {
8184 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008185 } finally {
8186 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008187 }
8188 }
8189
8190 /**
fionaxud9622282017-07-17 17:51:30 -07008191 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8192 * @param subId the subscription ID that this action applies to.
8193 * {@hide}
8194 */
8195 @Override
8196 public void carrierActionResetAll(int subId) {
8197 enforceModifyPermission();
8198 final Phone phone = getPhone(subId);
8199 if (phone == null) {
8200 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8201 return;
8202 }
8203 try {
8204 phone.carrierActionResetAll();
8205 } catch (Exception e) {
8206 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8207 }
8208 }
8209
8210 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008211 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8212 * bug report is being generated.
8213 */
8214 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008215 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008216 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8217 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008218 writer.println("Permission Denial: can't dump Phone from pid="
8219 + Binder.getCallingPid()
8220 + ", uid=" + Binder.getCallingUid()
8221 + "without permission "
8222 + android.Manifest.permission.DUMP);
8223 return;
8224 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008225 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008226 }
Jack Yueb89b242016-06-22 13:27:47 -07008227
Brad Ebingerdac2f002018-04-03 15:17:52 -07008228 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008229 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8230 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8231 @NonNull String[] args) {
8232 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8233 this, in.getFileDescriptor(), out.getFileDescriptor(),
8234 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008235 }
8236
Jack Yueb89b242016-06-22 13:27:47 -07008237 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008238 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008239 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008240 * @param reason the reason the data enable change is taking place
8241 * @param enabled True if enabling the data, otherwise disabling.
8242 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008243 */
8244 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008245 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008246 boolean enabled) {
8247 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8248 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8249 try {
8250 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008251 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008252 } catch (SecurityException se) {
8253 enforceModifyPermission();
8254 }
8255 } else {
8256 enforceModifyPermission();
8257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258
8259 final long identity = Binder.clearCallingIdentity();
8260 try {
8261 Phone phone = getPhone(subId);
8262 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008263 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8264 phone.carrierActionSetMeteredApnsEnabled(enabled);
8265 } else {
8266 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008268 }
8269 } finally {
8270 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008271 }
8272 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008273
8274 /**
8275 * Get Client request stats
8276 * @return List of Client Request Stats
8277 * @hide
8278 */
8279 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008280 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8281 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008283 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008284 return null;
8285 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008286 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 final long identity = Binder.clearCallingIdentity();
8289 try {
8290 if (phone != null) {
8291 return phone.getClientRequestStats();
8292 }
8293
8294 return null;
8295 } finally {
8296 Binder.restoreCallingIdentity(identity);
8297 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008298 }
8299
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008300 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008301 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008302 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008303 }
Jack Yueb4124c2017-02-16 15:32:43 -08008304
8305 /**
Grace Chen70990072017-03-24 17:21:30 -07008306 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008307 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008308 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008309 * @param state State of SIM (power down, power up, pass through)
8310 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8311 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8312 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008313 *
8314 **/
8315 @Override
Grace Chen70990072017-03-24 17:21:30 -07008316 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008317 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008318 Phone phone = PhoneFactory.getPhone(slotIndex);
8319
vagdeviaf9a5b92018-08-15 16:01:53 -07008320 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8321
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008322 final long identity = Binder.clearCallingIdentity();
8323 try {
8324 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008325 phone.setSimPowerState(state, null, workSource);
8326 }
8327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
8330 }
8331
8332 /**
8333 * Set SIM card power state.
8334 *
8335 * @param slotIndex SIM slot id.
8336 * @param state State of SIM (power down, power up, pass through)
8337 * @param callback callback to trigger after success or failure
8338 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8339 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8340 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8341 *
8342 **/
8343 @Override
8344 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8345 IIntegerConsumer callback) {
8346 enforceModifyPermission();
8347 Phone phone = PhoneFactory.getPhone(slotIndex);
8348
8349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8350
8351 final long identity = Binder.clearCallingIdentity();
8352 try {
8353 if (phone != null) {
8354 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8355 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008356 }
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008359 }
8360 }
Shuo Qiandd210312017-04-12 22:11:33 +00008361
Tyler Gunn65d45c22017-06-05 11:22:26 -07008362 private boolean isUssdApiAllowed(int subId) {
8363 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008364 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008365 if (configManager == null) {
8366 return false;
8367 }
8368 PersistableBundle pb = configManager.getConfigForSubId(subId);
8369 if (pb == null) {
8370 return false;
8371 }
8372 return pb.getBoolean(
8373 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8374 }
8375
Shuo Qiandd210312017-04-12 22:11:33 +00008376 /**
8377 * Check if phone is in emergency callback mode
8378 * @return true if phone is in emergency callback mode
8379 * @param subId sub id
8380 */
goneil9c5f4872017-12-05 14:07:56 -08008381 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008382 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008383 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008384 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385
8386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 if (phone != null) {
8389 return phone.isInEcm();
8390 } else {
8391 return false;
8392 }
8393 } finally {
8394 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008395 }
8396 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008397
8398 /**
8399 * Get the current signal strength information for the given subscription.
8400 * Because this information is not updated when the device is in a low power state
8401 * it should not be relied-upon to be current.
8402 * @param subId Subscription index
8403 * @return the most recent cached signal strength info from the modem
8404 */
8405 @Override
8406 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 final long identity = Binder.clearCallingIdentity();
8408 try {
8409 Phone p = getPhone(subId);
8410 if (p == null) {
8411 return null;
8412 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008413
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414 return p.getSignalStrength();
8415 } finally {
8416 Binder.restoreCallingIdentity(identity);
8417 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008418 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008419
Pengquan Meng77b7f132018-08-22 14:49:57 -07008420 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008421 * Get the current modem radio state for the given slot.
8422 * @param slotIndex slot index.
8423 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008424 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008425 * @return the current radio power state from the modem
8426 */
8427 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008428 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008429 Phone phone = PhoneFactory.getPhone(slotIndex);
8430 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8432 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008433 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8434 }
8435
8436 final long identity = Binder.clearCallingIdentity();
8437 try {
8438 return phone.getRadioPowerState();
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
8441 }
8442 }
8443 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8444 }
8445
8446 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008447 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8448 *
8449 * <p>Requires one of the following permissions:
8450 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8451 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8452 * privileges.
8453 *
8454 * @param subId subscription id
8455 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8456 * {@code false}.
8457 */
8458 @Override
8459 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008460 try {
8461 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8462 null);
8463 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008464 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008465 mApp, subId, "isDataRoamingEnabled");
8466 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008467
Pengquan Menga1bb6272018-09-06 09:59:22 -07008468 boolean isEnabled = false;
8469 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008470 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008471 Phone phone = getPhone(subId);
8472 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008473 } finally {
8474 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008475 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008476 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008477 }
8478
8479
8480 /**
8481 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8482 *
8483 * <p> Requires permission:
8484 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8485 * privileges.
8486 *
8487 * @param subId subscription id
8488 * @param isEnabled {@code true} means enable, {@code false} means disable.
8489 */
8490 @Override
8491 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8493 mApp, subId, "setDataRoamingEnabled");
8494
Pengquan Menga1bb6272018-09-06 09:59:22 -07008495 final long identity = Binder.clearCallingIdentity();
8496 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008497 Phone phone = getPhone(subId);
8498 if (phone != null) {
8499 phone.setDataRoamingEnabled(isEnabled);
8500 }
8501 } finally {
8502 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008503 }
8504 }
8505
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008506 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008507 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008508 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008509 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008510 mApp, subId, "isManualNetworkSelectionAllowed");
8511
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008512 boolean isAllowed = true;
8513 final long identity = Binder.clearCallingIdentity();
8514 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008515 Phone phone = getPhone(subId);
8516 if (phone != null) {
8517 isAllowed = phone.isCspPlmnEnabled();
8518 }
8519 } finally {
8520 Binder.restoreCallingIdentity(identity);
8521 }
8522 return isAllowed;
8523 }
8524
8525 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008526 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008527 // Verify that tha callingPackage belongs to the calling UID
8528 mApp.getSystemService(AppOpsManager.class)
8529 .checkPackage(Binder.getCallingUid(), callingPackage);
8530
Jordan Liu1e142fc2019-04-22 15:10:43 -07008531 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008532 try {
8533 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008534 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008535 } catch (SecurityException e) {
8536 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8537 // has carrier privileges on an active UICC
8538 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8539 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008540 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008541 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008542 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008543
8544 final long identity = Binder.clearCallingIdentity();
8545 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008546 UiccController uiccController = UiccController.getInstance();
8547 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008548 if (hasReadPermission) {
8549 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008550 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008551
8552 // Remove private info if the caller doesn't have access
8553 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8554 for (UiccCardInfo cardInfo : cardInfos) {
8555 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8556 // is available
8557 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8558 if (card == null || card.getUiccProfile() == null) {
8559 // assume no access if the card or profile is unavailable
8560 filteredInfos.add(cardInfo.getUnprivileged());
8561 continue;
8562 }
8563 UiccProfile profile = card.getUiccProfile();
8564 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8565 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8566 filteredInfos.add(cardInfo);
8567 } else {
8568 filteredInfos.add(cardInfo.getUnprivileged());
8569 }
8570 }
8571 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008572 } finally {
8573 Binder.restoreCallingIdentity(identity);
8574 }
8575 }
8576
8577 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008578 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008579 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008581 final long identity = Binder.clearCallingIdentity();
8582 try {
8583 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8584 if (slots == null) {
8585 Rlog.i(LOG_TAG, "slots is null.");
8586 return null;
8587 }
8588
8589 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8590 for (int i = 0; i < slots.length; i++) {
8591 UiccSlot slot = slots[i];
8592 if (slot == null) {
8593 continue;
8594 }
8595
Jordan Liu7be7e652019-05-06 18:55:02 +00008596 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 UiccCard card = slot.getUiccCard();
8598 if (card != null) {
8599 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008600 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008601 cardId = slot.getEid();
8602 if (TextUtils.isEmpty(cardId)) {
8603 cardId = slot.getIccId();
8604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 }
8606
Jordan Liu857451f2019-05-09 16:35:35 -07008607 if (cardId != null) {
8608 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8609 // if cardId is an EID, it's all digits so this is fine
8610 cardId = IccUtils.stripTrailingFs(cardId);
8611 }
8612
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008613 int cardState = 0;
8614 switch (slot.getCardState()) {
8615 case CARDSTATE_ABSENT:
8616 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8617 break;
8618 case CARDSTATE_PRESENT:
8619 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8620 break;
8621 case CARDSTATE_ERROR:
8622 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8623 break;
8624 case CARDSTATE_RESTRICTED:
8625 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8626 break;
8627 default:
8628 break;
8629
8630 }
8631
8632 infos[i] = new UiccSlotInfo(
8633 slot.isActive(),
8634 slot.isEuicc(),
8635 cardId,
8636 cardState,
8637 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008638 slot.isExtendedApduSupported(),
8639 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008640 }
8641 return infos;
8642 } finally {
8643 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008644 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008645 }
8646
8647 @Override
8648 public boolean switchSlots(int[] physicalSlots) {
8649 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008650
8651 final long identity = Binder.clearCallingIdentity();
8652 try {
8653 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8654 } finally {
8655 Binder.restoreCallingIdentity(identity);
8656 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008657 }
Jack Yu4c988042018-02-27 15:30:01 -08008658
8659 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008660 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008661 final long identity = Binder.clearCallingIdentity();
8662 try {
8663 return UiccController.getInstance().getCardIdForDefaultEuicc();
8664 } finally {
8665 Binder.restoreCallingIdentity(identity);
8666 }
8667 }
8668
Pengquan Meng85728fb2018-03-12 16:31:21 -07008669 /**
goneil47ffb6e2018-04-06 15:40:58 -07008670 * A test API to reload the UICC profile.
8671 *
8672 * <p>Requires that the calling app has permission
8673 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8674 * @hide
8675 */
8676 @Override
8677 public void refreshUiccProfile(int subId) {
8678 enforceModifyPermission();
8679
8680 final long identity = Binder.clearCallingIdentity();
8681 try {
8682 Phone phone = getPhone(subId);
8683 if (phone == null) {
8684 return;
8685 }
8686 UiccCard uiccCard = phone.getUiccCard();
8687 if (uiccCard == null) {
8688 return;
8689 }
8690 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8691 if (uiccProfile == null) {
8692 return;
8693 }
8694 uiccProfile.refresh();
8695 } finally {
8696 Binder.restoreCallingIdentity(identity);
8697 }
8698 }
8699
8700 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008701 * Returns false if the mobile data is disabled by default, otherwise return true.
8702 */
8703 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008704 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008705 }
8706
8707 /**
8708 * Returns true if the data roaming is enabled by default, i.e the system property
8709 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8710 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8711 */
8712 private boolean getDefaultDataRoamingEnabled(int subId) {
8713 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008714 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008715 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008716 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8717 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8718 return isDataRoamingEnabled;
8719 }
8720
8721 /**
8722 * Returns the default network type for the given {@code subId}, if the default network type is
8723 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8724 */
8725 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008726 List<Integer> list = TelephonyProperties.default_network();
8727 int phoneId = mSubscriptionController.getPhoneId(subId);
8728 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8729 return list.get(phoneId);
8730 }
8731 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008732 }
fionaxua13278b2018-03-21 00:08:13 -07008733
8734 @Override
8735 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008736 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008738
8739 final long identity = Binder.clearCallingIdentity();
8740 try {
8741 final Phone phone = getPhone(subId);
8742 if (phone == null) {
8743 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8744 return;
8745 }
chen xueaba88a2019-03-15 13:15:10 -07008746 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8747 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008748 if (carrierPrivilegeRules == null) {
8749 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8750 } else {
8751 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8752 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008753 } finally {
8754 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008755 }
fionaxua13278b2018-03-21 00:08:13 -07008756 }
8757
8758 @Override
8759 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008760 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008761
8762 final long identity = Binder.clearCallingIdentity();
8763 try {
8764 final Phone phone = getPhone(subId);
8765 if (phone == null) {
8766 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8767 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8768 }
8769 return phone.getCarrierIdListVersion();
8770 } finally {
8771 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008772 }
fionaxua13278b2018-03-21 00:08:13 -07008773 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008774
8775 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008776 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8777 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008779 mApp, subId, callingPackage, callingFeatureId,
8780 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008781 return -1;
8782 }
8783
8784 final long identity = Binder.clearCallingIdentity();
8785 try {
8786 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8787 } finally {
8788 Binder.restoreCallingIdentity(identity);
8789 }
8790 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008791
8792 @Override
8793 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008794 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008795 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008796 mApp, subId, "getCdmaRoamingMode");
8797
8798 final long identity = Binder.clearCallingIdentity();
8799 try {
8800 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8801 } finally {
8802 Binder.restoreCallingIdentity(identity);
8803 }
8804 }
8805
8806 @Override
8807 public boolean setCdmaRoamingMode(int subId, int mode) {
8808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8809 mApp, subId, "setCdmaRoamingMode");
8810
8811 final long identity = Binder.clearCallingIdentity();
8812 try {
8813 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8814 } finally {
8815 Binder.restoreCallingIdentity(identity);
8816 }
8817 }
8818
8819 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008820 public int getCdmaSubscriptionMode(int subId) {
8821 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008822 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008823 mApp, subId, "getCdmaSubscriptionMode");
8824
8825 final long identity = Binder.clearCallingIdentity();
8826 try {
8827 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8828 } finally {
8829 Binder.restoreCallingIdentity(identity);
8830 }
8831 }
8832
8833 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008834 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8836 mApp, subId, "setCdmaSubscriptionMode");
8837
8838 final long identity = Binder.clearCallingIdentity();
8839 try {
8840 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8841 } finally {
8842 Binder.restoreCallingIdentity(identity);
8843 }
8844 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008845
sqianc5eccab2018-10-19 18:46:41 -07008846 @Override
sqian8c685422019-02-22 15:55:18 -08008847 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008848 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008850 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8851 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008852 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8853 }
8854 final long identity = Binder.clearCallingIdentity();
8855 try {
sqian854d44b2018-12-12 16:48:18 -08008856 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8857 for (Phone phone: PhoneFactory.getPhones()) {
8858 if (phone.getEmergencyNumberTracker() != null
8859 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8860 emergencyNumberListInternal.put(
8861 phone.getSubId(),
8862 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8863 }
sqian11b7a0e2018-12-05 18:48:28 -08008864 }
sqian854d44b2018-12-12 16:48:18 -08008865 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008866 } finally {
8867 Binder.restoreCallingIdentity(identity);
8868 }
sqianc5eccab2018-10-19 18:46:41 -07008869 }
8870
8871 @Override
sqian8c685422019-02-22 15:55:18 -08008872 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008873 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008874 if (!exactMatch) {
8875 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008876 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008877 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008878 }
8879 final long identity = Binder.clearCallingIdentity();
8880 try {
sqian854d44b2018-12-12 16:48:18 -08008881 for (Phone phone: PhoneFactory.getPhones()) {
8882 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008883 && phone.getEmergencyNumberTracker()
8884 .isEmergencyNumber(number, exactMatch)) {
8885 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008886 }
sqian11b7a0e2018-12-05 18:48:28 -08008887 }
8888 return false;
8889 } finally {
8890 Binder.restoreCallingIdentity(identity);
8891 }
8892 }
8893
sqianf4ca7ed2019-01-15 18:32:07 -08008894 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008895 * Start emergency callback mode for GsmCdmaPhone for testing.
8896 */
8897 @Override
8898 public void startEmergencyCallbackMode() {
8899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8900 "startEmergencyCallbackMode");
8901 enforceModifyPermission();
8902 final long identity = Binder.clearCallingIdentity();
8903 try {
8904 for (Phone phone : PhoneFactory.getPhones()) {
8905 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8906 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8907 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8908 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8909 gsmCdmaPhone.obtainMessage(
8910 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8911 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8912 }
8913 }
8914 } finally {
8915 Binder.restoreCallingIdentity(identity);
8916 }
8917 }
8918
8919 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008920 * Update emergency number list for test mode.
8921 */
8922 @Override
8923 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8924 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8925 "updateEmergencyNumberListTestMode");
8926
8927 final long identity = Binder.clearCallingIdentity();
8928 try {
8929 for (Phone phone: PhoneFactory.getPhones()) {
8930 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8931 if (tracker != null) {
8932 tracker.executeEmergencyNumberTestModeCommand(action, num);
8933 }
8934 }
8935 } finally {
8936 Binder.restoreCallingIdentity(identity);
8937 }
8938 }
8939
8940 /**
8941 * Get the full emergency number list for test mode.
8942 */
8943 @Override
8944 public List<String> getEmergencyNumberListTestMode() {
8945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8946 "getEmergencyNumberListTestMode");
8947
8948 final long identity = Binder.clearCallingIdentity();
8949 try {
8950 Set<String> emergencyNumbers = new HashSet<>();
8951 for (Phone phone: PhoneFactory.getPhones()) {
8952 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8953 if (tracker != null) {
8954 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8955 emergencyNumbers.add(num.getNumber());
8956 }
8957 }
8958 }
8959 return new ArrayList<>(emergencyNumbers);
8960 } finally {
8961 Binder.restoreCallingIdentity(identity);
8962 }
8963 }
8964
chen xud6b45bd2018-10-30 22:27:10 -07008965 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008966 public int getEmergencyNumberDbVersion(int subId) {
8967 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8968
8969 final long identity = Binder.clearCallingIdentity();
8970 try {
8971 final Phone phone = getPhone(subId);
8972 if (phone == null) {
8973 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8974 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8975 }
8976 return phone.getEmergencyNumberDbVersion();
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
8979 }
8980 }
8981
8982 @Override
8983 public void notifyOtaEmergencyNumberDbInstalled() {
8984 enforceModifyPermission();
8985
8986 final long identity = Binder.clearCallingIdentity();
8987 try {
8988 for (Phone phone: PhoneFactory.getPhones()) {
8989 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8990 if (tracker != null) {
8991 tracker.updateOtaEmergencyNumberDatabase();
8992 }
8993 }
8994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
8998
8999 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009000 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009001 enforceActiveEmergencySessionPermission();
9002
9003 final long identity = Binder.clearCallingIdentity();
9004 try {
9005 for (Phone phone: PhoneFactory.getPhones()) {
9006 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9007 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009008 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9009 }
9010 }
9011 } finally {
9012 Binder.restoreCallingIdentity(identity);
9013 }
9014 }
9015
9016 @Override
9017 public void resetOtaEmergencyNumberDbFilePath() {
9018 enforceActiveEmergencySessionPermission();
9019
9020 final long identity = Binder.clearCallingIdentity();
9021 try {
9022 for (Phone phone: PhoneFactory.getPhones()) {
9023 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9024 if (tracker != null) {
9025 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009026 }
9027 }
9028 } finally {
9029 Binder.restoreCallingIdentity(identity);
9030 }
9031 }
9032
9033 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009034 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9035 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9036 Phone phone = getPhone(subId);
9037 if (phone == null) {
9038 return null;
9039 }
9040 final long identity = Binder.clearCallingIdentity();
9041 try {
9042 UiccProfile profile = UiccController.getInstance()
9043 .getUiccProfileForPhone(phone.getPhoneId());
9044 if (profile != null) {
9045 return profile.getCertsFromCarrierPrivilegeAccessRules();
9046 }
9047 } finally {
9048 Binder.restoreCallingIdentity(identity);
9049 }
9050 return null;
9051 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009052
9053 /**
9054 * Enable or disable a modem stack.
9055 */
9056 @Override
9057 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9058 enforceModifyPermission();
9059
9060 final long identity = Binder.clearCallingIdentity();
9061 try {
9062 Phone phone = PhoneFactory.getPhone(slotIndex);
9063 if (phone == null) {
9064 return false;
9065 } else {
9066 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9067 }
9068 } finally {
9069 Binder.restoreCallingIdentity(identity);
9070 }
9071 }
Michelecea4cf22018-12-21 15:00:11 -08009072
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009073 /**
9074 * Whether a modem stack is enabled or not.
9075 */
9076 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009077 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9078 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009079 Phone phone = PhoneFactory.getPhone(slotIndex);
9080 if (phone == null) return false;
9081
9082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009083 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9084 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009085 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9086 }
9087
9088 final long identity = Binder.clearCallingIdentity();
9089 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009090 try {
9091 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9092 } catch (NoSuchElementException ex) {
9093 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9094 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009095 } finally {
9096 Binder.restoreCallingIdentity(identity);
9097 }
9098 }
9099
Michelecea4cf22018-12-21 15:00:11 -08009100 @Override
Michele0ea7d782019-03-19 14:58:42 -07009101 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009102 enforceModifyPermission();
9103
9104 final long identity = Binder.clearCallingIdentity();
9105 try {
9106 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009107 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009108 .commit();
9109 } finally {
9110 Binder.restoreCallingIdentity(identity);
9111 }
9112 }
9113
9114 @Override
Michele0ea7d782019-03-19 14:58:42 -07009115 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009116 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009118 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9119 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009120 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009121 }
Michelecea4cf22018-12-21 15:00:11 -08009122
9123 final long identity = Binder.clearCallingIdentity();
9124 try {
Michele0ea7d782019-03-19 14:58:42 -07009125 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009126 } finally {
9127 Binder.restoreCallingIdentity(identity);
9128 }
9129 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009130
Michele0ea7d782019-03-19 14:58:42 -07009131 @TelephonyManager.IsMultiSimSupportedResult
9132 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009133 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9134 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9135 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009136 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9137 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009138 }
9139 // Check if the hardware supports multisim functionality. If usage of multisim is not
9140 // supported by the modem, indicate that it is restricted.
9141 PhoneCapability staticCapability =
9142 mPhoneConfigurationManager.getStaticPhoneCapability();
9143 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009144 loge("isMultiSimSupportedInternal: no static configuration available");
9145 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009146 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009147 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009148 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9149 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009150 }
9151 // Check if support of multiple SIMs is restricted by carrier
9152 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009153 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009154 }
9155
Michele0ea7d782019-03-19 14:58:42 -07009156 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009157 }
9158
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009159 /**
9160 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009161 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9162 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9163 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009164 * @param numOfSims number of active sims we want to switch to
9165 */
9166 @Override
9167 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009168 if (numOfSims == 1) {
9169 enforceModifyPermission();
9170 } else {
9171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9172 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9173 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009174 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009175
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009176 try {
Michele30b57b22019-03-01 12:01:14 -08009177 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009178 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009179 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9180 return;
9181 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009182 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
9187
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009188 @Override
9189 public boolean isApplicationOnUicc(int subId, int appType) {
9190 enforceReadPrivilegedPermission("isApplicationOnUicc");
9191 Phone phone = getPhone(subId);
9192 if (phone == null) {
9193 return false;
9194 }
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 UiccCard uiccCard = phone.getUiccCard();
9198 if (uiccCard == null) {
9199 return false;
9200 }
9201 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9202 if (uiccProfile == null) {
9203 return false;
9204 }
9205 if (TelephonyManager.APPTYPE_SIM <= appType
9206 && appType <= TelephonyManager.APPTYPE_ISIM) {
9207 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9208 }
9209 return false;
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
9214
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009215 /**
chen xub4baa772019-04-03 10:23:41 -07009216 * Get whether making changes to modem configurations will trigger reboot.
9217 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009218 */
9219 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009220 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9221 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009222 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009223 mApp, subId, callingPackage, callingFeatureId,
9224 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009225 return false;
9226 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9230 } finally {
9231 Binder.restoreCallingIdentity(identity);
9232 }
9233 }
9234
Nathan Harold29f5f052019-02-15 13:41:57 -08009235 private void updateModemStateMetrics() {
9236 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9237 // TODO: check the state for each modem if the api is ready.
9238 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9239 }
9240
Pengquan Meng3889a572019-01-23 11:16:29 -08009241 @Override
9242 public int[] getSlotsMapping() {
9243 enforceReadPrivilegedPermission("getSlotsMapping");
9244
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9248 // All logical slots should have a mapping to a physical slot.
9249 int[] logicalSlotsMapping = new int[phoneCount];
9250 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9251 for (int i = 0; i < slotInfos.length; i++) {
9252 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9253 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9254 }
9255 }
9256 return logicalSlotsMapping;
9257 } finally {
9258 Binder.restoreCallingIdentity(identity);
9259 }
9260 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009261
9262 /**
9263 * Get the IRadio HAL Version
9264 */
9265 @Override
9266 public int getRadioHalVersion() {
9267 Phone phone = getDefaultPhone();
9268 if (phone == null) return -1;
9269 HalVersion hv = phone.getHalVersion();
9270 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9271 return hv.major * 100 + hv.minor;
9272 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009273
9274 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009275 * Get the current calling package name.
9276 * @return the current calling package name
9277 */
9278 @Override
9279 public String getCurrentPackageName() {
9280 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9281 }
9282
9283 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009284 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9285 * corresponding network requests on a subId.
9286 *
9287 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009288 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009289 * 2) APN is un-metered for this subscription, or
9290 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009291 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009292 *
9293 * @return whether data is allowed for a apn type.
9294 *
9295 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009296 */
9297 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009298 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009299 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9300 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009301
9302 // Now that all security checks passes, perform the operation as ourselves.
9303 final long identity = Binder.clearCallingIdentity();
9304 try {
9305 Phone phone = getPhone(subId);
9306 if (phone == null) return false;
9307
Jack Yu41407ee2019-05-13 16:54:09 -07009308 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009309 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9310 } finally {
9311 Binder.restoreCallingIdentity(identity);
9312 }
9313 }
9314
9315 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009316 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009317 enforceReadPrivilegedPermission("isApnMetered");
9318
9319 // Now that all security checks passes, perform the operation as ourselves.
9320 final long identity = Binder.clearCallingIdentity();
9321 try {
9322 Phone phone = getPhone(subId);
9323 if (phone == null) return true; // By default return true.
9324
Jack Yu41407ee2019-05-13 16:54:09 -07009325 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
9329 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009330
9331 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009332 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9333 int subscriptionId, IBooleanConsumer resultCallback) {
9334 enforceModifyPermission();
9335 long token = Binder.clearCallingIdentity();
9336 try {
9337 Phone phone = getPhone(subscriptionId);
9338 if (phone == null) {
9339 try {
9340 if (resultCallback != null) {
9341 resultCallback.accept(false);
9342 }
9343 } catch (RemoteException e) {
9344 // ignore
9345 }
9346 return;
9347 }
9348 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9349 Pair.create(specifiers, (x) -> {
9350 try {
9351 if (resultCallback != null) {
9352 resultCallback.accept(x);
9353 }
9354 } catch (RemoteException e) {
9355 // ignore
9356 }
9357 });
9358 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9359 } finally {
9360 Binder.restoreCallingIdentity(token);
9361 }
9362 }
9363
9364 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009365 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9366 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009367 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009368 mApp, subId, "getSystemSelectionChannels");
9369 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9370 final long identity = Binder.clearCallingIdentity();
9371 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009372 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9373 if (result instanceof IllegalStateException) {
9374 throw (IllegalStateException) result;
9375 }
9376 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009377 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9378 return specifiers;
9379 } finally {
9380 Binder.restoreCallingIdentity(identity);
9381 }
9382 }
9383
9384 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009385 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009386 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009387 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9388 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9389 if (iccRecords == null) {
9390 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9391 return false;
9392 }
9393 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9394 }
9395
9396 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009397 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9398 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009399 if (callingPackage == null) {
9400 callingPackage = getCurrentPackageName();
9401 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009402 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9403 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009404 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9405 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009406 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9407 }
9408 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9409 Intent intent = new Intent();
9410 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9411 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9412 // Bring up choose default SMS subscription dialog right now
9413 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9414 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9415 mApp.startActivity(intent);
9416 }
chen xud5ca2d52019-05-28 15:20:57 -07009417
9418 @Override
9419 public String getMmsUAProfUrl(int subId) {
9420 //TODO investigate if this API should require proper permission check in R b/133791609
9421 final long identity = Binder.clearCallingIdentity();
9422 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009423 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9424 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9425 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9426 return carrierUAProfUrl;
9427 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009428 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9429 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009430 } finally {
9431 Binder.restoreCallingIdentity(identity);
9432 }
9433 }
9434
9435 @Override
9436 public String getMmsUserAgent(int subId) {
9437 //TODO investigate if this API should require proper permission check in R b/133791609
9438 final long identity = Binder.clearCallingIdentity();
9439 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009440 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9441 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9442 if (!TextUtils.isEmpty(carrierUserAgent)) {
9443 return carrierUserAgent;
9444 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009445 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9446 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009447 } finally {
9448 Binder.restoreCallingIdentity(identity);
9449 }
9450 }
Jack Yub07d4972019-05-28 16:12:25 -07009451
9452 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009453 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9454 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009455
Jack Yub07d4972019-05-28 16:12:25 -07009456 final long identity = Binder.clearCallingIdentity();
9457 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009458 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009459 if (phone == null) return false;
9460
Hall Liua62f5da2020-09-25 10:42:19 -07009461 switch (policy) {
9462 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9463 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9464 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9465 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9466 default:
9467 throw new IllegalArgumentException(policy + " is not a valid policy");
9468 }
Jack Yub07d4972019-05-28 16:12:25 -07009469 } finally {
9470 Binder.restoreCallingIdentity(identity);
9471 }
9472 }
9473
9474 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009475 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009476 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009477 enforceModifyPermission();
9478
changbettyd5c246e2019-12-24 15:40:37 +08009479 final long identity = Binder.clearCallingIdentity();
9480 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009481 Phone phone = getPhone(subscriptionId);
9482 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009483
Hall Liua62f5da2020-09-25 10:42:19 -07009484 switch (policy) {
9485 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9486 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9487 break;
9488 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9489 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9490 break;
9491 default:
9492 throw new IllegalArgumentException(policy + " is not a valid policy");
9493 }
changbettyd5c246e2019-12-24 15:40:37 +08009494 } finally {
9495 Binder.restoreCallingIdentity(identity);
9496 }
9497 }
9498
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009499 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009500 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009501 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9502 * otherwise.
9503 */
9504 @Override
9505 public void setCepEnabled(boolean isCepEnabled) {
9506 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9507
9508 final long identity = Binder.clearCallingIdentity();
9509 try {
9510 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9511 for (Phone phone : PhoneFactory.getPhones()) {
9512 Phone defaultPhone = phone.getImsPhone();
9513 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9514 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9515 ImsPhoneCallTracker imsPhoneCallTracker =
9516 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9517 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9518 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9519 + imsPhone.getMsisdn());
9520 }
9521 }
9522 } finally {
9523 Binder.restoreCallingIdentity(identity);
9524 }
9525 }
allenwtsu46dcc572020-01-08 18:24:03 +08009526
9527 /**
9528 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9529 *
9530 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9531 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9532 * before being read.
9533 */
9534 @Override
9535 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9536 isCompressed) {
9537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9538 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009539 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9540 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9541 }
9542 if (!isImsAvailableOnDevice()) {
9543 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9544 "IMS not available on device.");
9545 }
9546
9547 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009548 try {
Hui Wang761a6682020-10-31 05:12:53 +00009549 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9550 } finally {
9551 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009552 }
9553 }
zoey chene02881a2019-12-30 16:11:23 +08009554
9555 @Override
9556 public boolean isIccLockEnabled(int subId) {
9557 enforceReadPrivilegedPermission("isIccLockEnabled");
9558
9559 // Now that all security checks passes, perform the operation as ourselves.
9560 final long identity = Binder.clearCallingIdentity();
9561 try {
9562 Phone phone = getPhone(subId);
9563 if (phone != null && phone.getIccCard() != null) {
9564 return phone.getIccCard().getIccLockEnabled();
9565 } else {
9566 return false;
9567 }
9568 } finally {
9569 Binder.restoreCallingIdentity(identity);
9570 }
9571 }
9572
9573 /**
9574 * Set the ICC pin lock enabled or disabled.
9575 *
9576 * @return an integer representing the status of IccLock enabled or disabled in the following
9577 * three cases:
9578 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9579 * successfully.
9580 * - Positive number and zero for remaining password attempts.
9581 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9582 *
9583 */
9584 @Override
9585 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9586 enforceModifyPermission();
9587
9588 Phone phone = getPhone(subId);
9589 if (phone == null) {
9590 return 0;
9591 }
9592 // Now that all security checks passes, perform the operation as ourselves.
9593 final long identity = Binder.clearCallingIdentity();
9594 try {
9595 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9596 new Pair<Boolean, String>(enabled, password), phone, null);
9597 return attemptsRemaining;
9598
9599 } catch (Exception e) {
9600 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9601 } finally {
9602 Binder.restoreCallingIdentity(identity);
9603 }
9604 return 0;
9605 }
9606
9607 /**
9608 * Change the ICC password used in ICC pin lock.
9609 *
9610 * @return an integer representing the status of IccLock changed in the following three cases:
9611 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9612 * - Positive number and zero for remaining password attempts.
9613 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9614 *
9615 */
9616 @Override
9617 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9618 enforceModifyPermission();
9619
9620 Phone phone = getPhone(subId);
9621 if (phone == null) {
9622 return 0;
9623 }
9624 // Now that all security checks passes, perform the operation as ourselves.
9625 final long identity = Binder.clearCallingIdentity();
9626 try {
9627 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9628 new Pair<String, String>(oldPassword, newPassword), phone, null);
9629 return attemptsRemaining;
9630
9631 } catch (Exception e) {
9632 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9633 } finally {
9634 Binder.restoreCallingIdentity(identity);
9635 }
9636 return 0;
9637 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009638
9639 /**
9640 * Request for receiving user activity notification
9641 */
9642 @Override
9643 public void requestUserActivityNotification() {
9644 if (!mNotifyUserActivity.get()
9645 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9646 mNotifyUserActivity.set(true);
9647 }
9648 }
9649
9650 /**
9651 * Called when userActivity is signalled in the power manager.
9652 * This is safe to call from any thread, with any window manager locks held or not.
9653 */
9654 @Override
9655 public void userActivity() {
9656 // ***************************************
9657 // * Inherited from PhoneWindowManager *
9658 // ***************************************
9659 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9660 // WITH ITS LOCKS HELD.
9661 //
9662 // This code must be VERY careful about the locks
9663 // it acquires.
9664 // In fact, the current code acquires way too many,
9665 // and probably has lurking deadlocks.
9666
9667 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9668 throw new SecurityException("Only the OS may call notifyUserActivity()");
9669 }
9670
9671 if (mNotifyUserActivity.getAndSet(false)) {
9672 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9673 USER_ACTIVITY_NOTIFICATION_DELAY);
9674 }
9675 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009676
9677 @Override
9678 public boolean canConnectTo5GInDsdsMode() {
9679 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9680 }
Jack Yud10cdd42020-09-28 20:28:01 -07009681
9682 @Override
9683 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9684 String callingFeatureId) {
9685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9686 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9687 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9688 }
9689
9690 Phone phone = getPhone(subId);
9691 if (phone == null) {
9692 throw new RuntimeException("phone is not available");
9693 }
9694 // Now that all security checks passes, perform the operation as ourselves.
9695 final long identity = Binder.clearCallingIdentity();
9696 try {
9697 return phone.getEquivalentHomePlmns();
9698 } finally {
9699 Binder.restoreCallingIdentity(identity);
9700 }
9701 }
Daniel Bright59e67312020-11-13 11:49:37 -08009702
9703 @Override
9704 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009705 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9706 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009707 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009708 if (radioInterfaceCapabilities == null) {
9709 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009710 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009711 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009712 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009713
Hui Wang641e81c2020-10-12 12:14:23 -07009714 @Override
9715 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9716 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009717 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9718 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9719 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9720 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9721 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009722 if (DBG) {
9723 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9724 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9725 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9726 }
9727
9728 if (!SubscriptionManager.isValidSubscriptionId(subId)
9729 || appType < TelephonyManager.APPTYPE_UNKNOWN
9730 || appType > TelephonyManager.APPTYPE_ISIM
9731 || nafUrl == null || securityProtocol == null || callback == null) {
9732 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9733 if (callback != null) {
9734 try {
9735 callback.onAuthenticationFailure(
9736 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9737 } catch (RemoteException exception) {
9738 log("Fail to notify onAuthenticationFailure due to " + exception);
9739 }
9740 return;
9741 }
9742 }
9743
9744 final long token = Binder.clearCallingIdentity();
9745 try {
9746 getGbaManager(subId).bootstrapAuthenticationRequest(
9747 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9748 forceBootStrapping, callback));
9749 } finally {
9750 Binder.restoreCallingIdentity(token);
9751 }
9752 }
9753
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009754 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009755 * Attempts to set the radio power state for all phones for thermal reason.
9756 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009757 * requested radio power state will actually be set. See {@link
9758 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9759 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009760 * @param enable {@code true} if trying to turn radio on.
9761 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9762 * false}.
9763 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009764 private boolean setRadioPowerForThermal(boolean enable) {
9765 boolean isPhoneAvailable = false;
9766 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9767 Phone phone = PhoneFactory.getPhone(i);
9768 if (phone != null) {
9769 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9770 isPhoneAvailable = true;
9771 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009772 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009773
9774 // return true if successfully informed the phone object about the thermal radio power
9775 // request.
9776 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009777 }
9778
9779 private int handleDataThrottlingRequest(int subId,
9780 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009781 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9782 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9783 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9784 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9785 throw new IllegalArgumentException("modem does not support data throttling");
9786 }
9787
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009788 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9789 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009790 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009791 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9792 }
9793
9794 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9795
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009796 if (isDataThrottlingSupported) {
9797 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009798 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009799 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9800 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9801 } else if (thermalMitigationResult
9802 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009803 log("Modem likely does not support data throttling on secondary carrier. Data " +
9804 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9805 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009806 }
9807 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009808 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009809
9810 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009811 }
9812
Jack Nudelman644b91a2021-03-12 14:09:48 -08009813 private static List<String> getThermalMitigationAllowlist(Context context) {
9814 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9815 for (String pckg : context.getResources()
9816 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9817 sThermalMitigationAllowlistedPackages.add(pckg);
9818 }
9819 }
9820
9821 return sThermalMitigationAllowlistedPackages;
9822 }
9823
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009824 private boolean isAnyPhoneInEmergencyState() {
9825 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9826 if (tm.isInEmergencyCall()) {
9827 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9828 return true;
9829 }
9830 for (Phone phone : PhoneFactory.getPhones()) {
9831 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9832 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9833 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9834 + phone.isInEcm());
9835 return true;
9836 }
9837 }
9838
9839 return false;
9840 }
9841
Jack Nudelman644b91a2021-03-12 14:09:48 -08009842 /**
9843 * Used by shell commands to add an authorized package name for thermal mitigation.
9844 * @param packageName name of package to be allowlisted
9845 * @param context
9846 */
9847 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9848 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9849 sThermalMitigationAllowlistedPackages.add(packageName);
9850 }
9851
9852 /**
9853 * Used by shell commands to remove an authorized package name for thermal mitigation.
9854 * @param packageName name of package to remove from allowlist
9855 * @param context
9856 */
9857 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9858 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9859 sThermalMitigationAllowlistedPackages.remove(packageName);
9860 }
9861
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009862 /**
9863 * Thermal mitigation request to control functionalities at modem.
9864 *
9865 * @param subId the id of the subscription.
9866 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009867 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009868 *
9869 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9870 */
9871 @Override
9872 @ThermalMitigationResult
9873 public int sendThermalMitigationRequest(
9874 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009875 ThermalMitigationRequest thermalMitigationRequest,
9876 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009877 enforceModifyPermission();
9878
Jack Nudelman644b91a2021-03-12 14:09:48 -08009879 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9880 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9881 .contains(callingPackage)) {
9882 throw new SecurityException("Calling package must be configured in the device config. "
9883 + "calling package: " + callingPackage);
9884 }
9885
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9887 final long identity = Binder.clearCallingIdentity();
9888
9889 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9890 try {
9891 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9892 switch (thermalMitigationAction) {
9893 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9894 thermalMitigationResult =
9895 handleDataThrottlingRequest(subId,
9896 thermalMitigationRequest.getDataThrottlingRequest());
9897 break;
9898 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9899 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9900 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9901 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9902 }
9903
9904 // Ensure that radio is on. If not able to power on due to phone being
9905 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009906 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009907 thermalMitigationResult =
9908 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9909 break;
9910 }
9911
9912 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9913 false);
9914 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9915 break;
9916 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9917 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9918 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9919 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9920 }
9921
9922 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9923 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009924 Phone phone = getPhone(subId);
9925 if (phone == null) {
9926 thermalMitigationResult =
9927 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9928 break;
9929 }
9930
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009931 TelephonyConnectionService service =
9932 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -07009933 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009934 Log.e(LOG_TAG, "An emergency call is pending");
9935 thermalMitigationResult =
9936 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9937 break;
9938 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009939 thermalMitigationResult =
9940 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9941 break;
9942 }
9943 } else {
9944 thermalMitigationResult =
9945 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9946 break;
9947 }
9948
9949 // Turn radio off. If not able to power off due to phone being unavailable,
9950 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009951 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009952 thermalMitigationResult =
9953 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9954 break;
9955 }
9956 thermalMitigationResult =
9957 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9958 break;
9959 default:
9960 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9961 + "not exist. Requested action: " + thermalMitigationAction);
9962 }
9963 } catch (IllegalArgumentException e) {
9964 throw e;
9965 } catch (Exception e) {
9966 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9967 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9968 } finally {
9969 Binder.restoreCallingIdentity(identity);
9970 }
9971
9972 if (DBG) {
9973 log("thermalMitigationRequest returning with thermalMitigationResult: "
9974 + thermalMitigationResult);
9975 }
9976
9977 return thermalMitigationResult;
9978 }
Hui Wang641e81c2020-10-12 12:14:23 -07009979
9980 /**
9981 * Set the GbaService Package Name that Telephony will bind to.
9982 *
9983 * @param subId The sim that the GbaService is associated with.
9984 * @param packageName The name of the package to be replaced with.
9985 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9986 */
9987 @Override
9988 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9989 enforceModifyPermission();
9990
9991 final long identity = Binder.clearCallingIdentity();
9992 try {
9993 return getGbaManager(subId).overrideServicePackage(packageName);
9994 } finally {
9995 Binder.restoreCallingIdentity(identity);
9996 }
9997 }
9998
9999 /**
10000 * Return the package name of the currently bound GbaService.
10001 *
10002 * @param subId The sim that the GbaService is associated with.
10003 * @return the package name of the GbaService configuration, null if GBA is not supported.
10004 */
10005 @Override
10006 public String getBoundGbaService(int subId) {
10007 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10008
10009 final long identity = Binder.clearCallingIdentity();
10010 try {
10011 return getGbaManager(subId).getServicePackage();
10012 } finally {
10013 Binder.restoreCallingIdentity(identity);
10014 }
10015 }
10016
10017 /**
10018 * Set the release time for telephony to unbind GbaService.
10019 *
10020 * @param subId The sim that the GbaService is associated with.
10021 * @param interval The release time to unbind GbaService by millisecond.
10022 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10023 */
10024 @Override
10025 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10026 enforceModifyPermission();
10027
10028 final long identity = Binder.clearCallingIdentity();
10029 try {
10030 return getGbaManager(subId).overrideReleaseTime(interval);
10031 } finally {
10032 Binder.restoreCallingIdentity(identity);
10033 }
10034 }
10035
10036 /**
10037 * Return the release time for telephony to unbind GbaService.
10038 *
10039 * @param subId The sim that the GbaService is associated with.
10040 * @return The release time to unbind GbaService by millisecond.
10041 */
10042 @Override
10043 public int getGbaReleaseTime(int subId) {
10044 enforceReadPrivilegedPermission("getGbaReleaseTime");
10045
10046 final long identity = Binder.clearCallingIdentity();
10047 try {
10048 return getGbaManager(subId).getReleaseTime();
10049 } finally {
10050 Binder.restoreCallingIdentity(identity);
10051 }
10052 }
10053
10054 private GbaManager getGbaManager(int subId) {
10055 GbaManager instance = GbaManager.getInstance(subId);
10056 if (instance == null) {
10057 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10058 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10059 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10060 }
10061 return instance;
10062 }
Hui Wang761a6682020-10-31 05:12:53 +000010063
10064 /**
10065 * indicate whether the device and the carrier can support
10066 * RCS VoLTE single registration.
10067 */
10068 @Override
10069 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010070 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10071 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10072 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10073 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010074
10075 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10076 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10077 }
10078
10079 final long identity = Binder.clearCallingIdentity();
10080 try {
10081 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10082 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010083 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10084 if (isCapable != null) {
10085 return isCapable;
10086 }
Hui Wang761a6682020-10-31 05:12:53 +000010087 }
Hui Wang67af90e2021-06-04 16:57:15 -070010088 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10089 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010090 } finally {
10091 Binder.restoreCallingIdentity(identity);
10092 }
10093 }
10094
10095 /**
10096 * Register RCS provisioning callback.
10097 */
10098 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010099 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010100 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010101 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010102 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010103 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10104 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010105
10106 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10107 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10108 }
10109 if (!isImsAvailableOnDevice()) {
10110 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10111 "IMS not available on device.");
10112 }
10113
10114 final long identity = Binder.clearCallingIdentity();
10115 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010116 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010117 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010118 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10119 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010120 }
Hui Wang761a6682020-10-31 05:12:53 +000010121 } finally {
10122 Binder.restoreCallingIdentity(identity);
10123 }
10124 }
10125
10126 /**
10127 * Unregister RCS provisioning callback.
10128 */
10129 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010130 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010131 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010132 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010133 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010134 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10135 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010136
10137 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10138 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10139 }
10140 if (!isImsAvailableOnDevice()) {
10141 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10142 "IMS not available on device.");
10143 }
10144
10145 final long identity = Binder.clearCallingIdentity();
10146 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010147 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010148 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010149 } finally {
10150 Binder.restoreCallingIdentity(identity);
10151 }
10152 }
10153
10154 /**
10155 * trigger RCS reconfiguration.
10156 */
10157 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010158 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10159 "triggerRcsReconfiguration",
10160 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010161
10162 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10163 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10164 }
10165 if (!isImsAvailableOnDevice()) {
10166 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10167 "IMS not available on device.");
10168 }
10169
10170 final long identity = Binder.clearCallingIdentity();
10171 try {
10172 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10173 } finally {
10174 Binder.restoreCallingIdentity(identity);
10175 }
10176 }
10177
10178 /**
10179 * Provide the client configuration parameters of the RCS application.
10180 */
10181 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010182 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10183 "setRcsClientConfiguration",
10184 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010185
10186 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10187 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10188 }
10189 if (!isImsAvailableOnDevice()) {
10190 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10191 "IMS not available on device.");
10192 }
10193
10194 final long identity = Binder.clearCallingIdentity();
10195
10196 try {
10197 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10198 if (configBinder == null) {
10199 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010200 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10201 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010202 } else {
10203 configBinder.setRcsClientConfiguration(rcc);
10204 }
10205 } catch (RemoteException e) {
10206 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010207 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10208 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010209 } finally {
10210 Binder.restoreCallingIdentity(identity);
10211 }
10212 }
10213
10214 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010215 * Enables or disables the test mode for RCS VoLTE single registration.
10216 */
10217 @Override
10218 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10219 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10220 "setRcsSingleRegistrationTestModeEnabled");
10221
10222 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10223 }
10224
10225 /**
10226 * Gets the test mode for RCS VoLTE single registration.
10227 */
10228 @Override
10229 public boolean getRcsSingleRegistrationTestModeEnabled() {
10230 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10231 "getRcsSingleRegistrationTestModeEnabled");
10232
10233 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10234 }
10235
10236 /**
Hui Wang761a6682020-10-31 05:12:53 +000010237 * Overrides the config of RCS VoLTE single registration enabled for the device.
10238 */
10239 @Override
10240 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10241 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10242 "setDeviceSingleRegistrationEnabledOverride");
10243 enforceModifyPermission();
10244
10245 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10246 : Boolean.parseBoolean(enabledStr);
10247 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010248 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010249 }
10250
10251 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010252 * Sends a device to device communication message. Only usable via shell.
10253 * @param message message to send.
10254 * @param value message value.
10255 */
10256 @Override
10257 public void sendDeviceToDeviceMessage(int message, int value) {
10258 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010259 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010260 enforceModifyPermission();
10261
10262 final long identity = Binder.clearCallingIdentity();
10263 try {
10264 TelephonyConnectionService service =
10265 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10266 if (service == null) {
10267 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10268 return;
10269 }
10270 service.sendTestDeviceToDeviceMessage(message, value);
10271 } finally {
10272 Binder.restoreCallingIdentity(identity);
10273 }
10274 }
10275
Tyler Gunnbabbda02021-02-10 11:05:02 -080010276 /**
10277 * Sets the specified device to device transport active.
10278 * @param transport The transport to set active.
10279 */
10280 @Override
10281 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10282 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10283 "setActiveDeviceToDeviceTransport");
10284 enforceModifyPermission();
10285
10286 final long identity = Binder.clearCallingIdentity();
10287 try {
10288 TelephonyConnectionService service =
10289 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10290 if (service == null) {
10291 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10292 return;
10293 }
10294 service.setActiveDeviceToDeviceTransport(transport);
10295 } finally {
10296 Binder.restoreCallingIdentity(identity);
10297 }
10298 }
Tyler Gunn92479152021-01-20 16:30:10 -080010299
Tyler Gunnd4575212021-05-03 14:46:49 -070010300 @Override
10301 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10302 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10303 "setDeviceToDeviceForceEnabled");
10304
10305 final long identity = Binder.clearCallingIdentity();
10306 try {
10307 Arrays.stream(PhoneFactory.getPhones()).forEach(
10308 p -> {
10309 Phone thePhone = p.getImsPhone();
10310 if (thePhone != null && thePhone instanceof ImsPhone) {
10311 ImsPhone imsPhone = (ImsPhone) thePhone;
10312 CallTracker tracker = imsPhone.getCallTracker();
10313 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10314 ImsPhoneCallTracker imsPhoneCallTracker =
10315 (ImsPhoneCallTracker) tracker;
10316 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10317 }
10318 }
10319 }
10320 );
10321 } finally {
10322 Binder.restoreCallingIdentity(identity);
10323 }
10324 }
10325
Tyler Gunn92479152021-01-20 16:30:10 -080010326 /**
Hui Wang761a6682020-10-31 05:12:53 +000010327 * Gets the config of RCS VoLTE single registration enabled for the device.
10328 */
10329 @Override
10330 public boolean getDeviceSingleRegistrationEnabled() {
10331 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10332 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10333 }
10334
10335 /**
10336 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10337 */
10338 @Override
10339 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10340 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10341 "setCarrierSingleRegistrationEnabledOverride");
10342 enforceModifyPermission();
10343
10344 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10345 : Boolean.parseBoolean(enabledStr);
10346 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10347 subId, enabled);
10348 }
10349
10350 /**
10351 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10352 */
10353 @Override
10354 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10355 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10356 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10357 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010358
10359 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010360 * Overrides the ims feature validation result
10361 */
10362 @Override
10363 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10364 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10365 "setImsFeatureValidationOverride");
10366
10367 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10368 : Boolean.parseBoolean(enabledStr);
10369 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10370 subId, enabled);
10371 }
10372
10373 /**
10374 * Gets the ims feature validation override value
10375 */
10376 @Override
10377 public boolean getImsFeatureValidationOverride(int subId) {
10378 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10379 "getImsFeatureValidationOverride");
10380 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10381 }
10382
10383 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010384 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10385 * their mobile plan.
10386 */
10387 @Override
10388 public String getMobileProvisioningUrl() {
10389 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10390 final long identity = Binder.clearCallingIdentity();
10391 try {
10392 return getDefaultPhone().getMobileProvisioningUrl();
10393 } finally {
10394 Binder.restoreCallingIdentity(identity);
10395 }
10396 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010397
James.cf Linbcdf8b32021-01-14 16:44:13 +080010398 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010399 * Get the EAB contact from the EAB database.
10400 */
10401 @Override
10402 public String getContactFromEab(String contact) {
10403 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10404 enforceModifyPermission();
10405 final long identity = Binder.clearCallingIdentity();
10406 try {
10407 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10408 } finally {
10409 Binder.restoreCallingIdentity(identity);
10410 }
10411 }
10412
10413 /**
Calvin Pana1434322021-07-01 19:27:01 +080010414 * Get the EAB capability from the EAB database.
10415 */
10416 @Override
10417 public String getCapabilityFromEab(String contact) {
10418 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10419 enforceModifyPermission();
10420 final long identity = Binder.clearCallingIdentity();
10421 try {
10422 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10423 } finally {
10424 Binder.restoreCallingIdentity(identity);
10425 }
10426 }
10427
10428 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010429 * Remove the EAB contacts from the EAB database.
10430 */
10431 @Override
10432 public int removeContactFromEab(int subId, String contacts) {
10433 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10434 enforceModifyPermission();
10435 final long identity = Binder.clearCallingIdentity();
10436 try {
10437 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10438 } finally {
10439 Binder.restoreCallingIdentity(identity);
10440 }
10441 }
10442
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010443 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010444 public boolean getDeviceUceEnabled() {
10445 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10446 final long identity = Binder.clearCallingIdentity();
10447 try {
10448 return mApp.getDeviceUceEnabled();
10449 } finally {
10450 Binder.restoreCallingIdentity(identity);
10451 }
10452 }
10453
10454 @Override
10455 public void setDeviceUceEnabled(boolean isEnabled) {
10456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10457 final long identity = Binder.clearCallingIdentity();
10458 try {
10459 mApp.setDeviceUceEnabled(isEnabled);
10460 } finally {
10461 Binder.restoreCallingIdentity(identity);
10462 }
10463 }
10464
Brad Ebinger14d467f2021-02-12 06:18:28 +000010465 /**
10466 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10467 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10468 */
10469 // Used for SHELL command only right now.
10470 @Override
10471 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10472 List<String> featureTags) {
10473 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10474 "addUceRegistrationOverrideShell");
10475 final long identity = Binder.clearCallingIdentity();
10476 try {
10477 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10478 new ArraySet<>(featureTags));
10479 } catch (ImsException e) {
10480 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10481 } finally {
10482 Binder.restoreCallingIdentity(identity);
10483 }
10484 }
10485
10486 /**
10487 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10488 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10489 */
10490 // Used for SHELL command only right now.
10491 @Override
10492 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10493 List<String> featureTags) {
10494 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10495 "removeUceRegistrationOverrideShell");
10496 final long identity = Binder.clearCallingIdentity();
10497 try {
10498 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10499 new ArraySet<>(featureTags));
10500 } catch (ImsException e) {
10501 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10502 } finally {
10503 Binder.restoreCallingIdentity(identity);
10504 }
10505 }
10506
10507 /**
10508 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10509 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10510 */
10511 // Used for SHELL command only right now.
10512 @Override
10513 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10514 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10515 "clearUceRegistrationOverrideShell");
10516 final long identity = Binder.clearCallingIdentity();
10517 try {
10518 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10519 } catch (ImsException e) {
10520 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10521 } finally {
10522 Binder.restoreCallingIdentity(identity);
10523 }
10524 }
10525
10526 /**
10527 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10528 */
10529 // Used for SHELL command only right now.
10530 @Override
10531 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10532 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10533 "getLatestRcsContactUceCapabilityShell");
10534 final long identity = Binder.clearCallingIdentity();
10535 try {
10536 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10537 } catch (ImsException e) {
10538 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10539 } finally {
10540 Binder.restoreCallingIdentity(identity);
10541 }
10542 }
10543
10544 /**
10545 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10546 * device does not have an active PUBLISH.
10547 */
10548 // Used for SHELL command only right now.
10549 @Override
10550 public String getLastUcePidfXmlShell(int subId) {
10551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10552 final long identity = Binder.clearCallingIdentity();
10553 try {
10554 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10555 } catch (ImsException e) {
10556 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10557 } finally {
10558 Binder.restoreCallingIdentity(identity);
10559 }
10560 }
10561
James.cf Line8713a42021-04-29 16:04:26 +080010562 /**
10563 * Remove UCE requests cannot be sent to the network status.
10564 */
10565 // Used for SHELL command only right now.
10566 @Override
10567 public boolean removeUceRequestDisallowedStatus(int subId) {
10568 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10569 final long identity = Binder.clearCallingIdentity();
10570 try {
10571 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10572 } catch (ImsException e) {
10573 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10574 } finally {
10575 Binder.restoreCallingIdentity(identity);
10576 }
10577 }
10578
James.cf Lin0fc71b02021-05-25 01:37:38 +080010579 /**
10580 * Remove UCE requests cannot be sent to the network status.
10581 */
10582 // Used for SHELL command only.
10583 @Override
10584 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10586 final long identity = Binder.clearCallingIdentity();
10587 try {
10588 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10589 } catch (ImsException e) {
10590 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010595
James.cf Lin4b784aa2021-01-31 03:25:15 +080010596 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010597 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10598 String callingPackage) {
10599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10600 mApp, subId, "setSignalStrengthUpdateRequest");
10601
10602 final int callingUid = Binder.getCallingUid();
10603 // Verify that tha callingPackage belongs to the calling UID
10604 mApp.getSystemService(AppOpsManager.class)
10605 .checkPackage(callingUid, callingPackage);
10606
Rambo Wang3607f502021-02-01 21:51:40 -080010607 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010608
10609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10612 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10613
10614 if (result instanceof IllegalStateException) {
10615 throw (IllegalStateException) result;
10616 }
10617 } finally {
10618 Binder.restoreCallingIdentity(identity);
10619 }
10620 }
10621
10622 @Override
10623 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10624 String callingPackage) {
10625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10626 mApp, subId, "clearSignalStrengthUpdateRequest");
10627
10628 final int callingUid = Binder.getCallingUid();
10629 // Verify that tha callingPackage belongs to the calling UID
10630 mApp.getSystemService(AppOpsManager.class)
10631 .checkPackage(callingUid, callingPackage);
10632
10633 final long identity = Binder.clearCallingIdentity();
10634 try {
10635 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10636 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10637
10638 if (result instanceof IllegalStateException) {
10639 throw (IllegalStateException) result;
10640 }
10641 } finally {
10642 Binder.restoreCallingIdentity(identity);
10643 }
10644 }
10645
Rambo Wang3607f502021-02-01 21:51:40 -080010646 private static void validateSignalStrengthUpdateRequest(Context context,
10647 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010648 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10649 // phone/system process do not have further restriction on request
10650 return;
10651 }
10652
10653 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010654 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010655 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010656 context.enforceCallingOrSelfPermission(
10657 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10658 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010659 }
10660
10661 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10662 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10663 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10664 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10665 || info.isEnabled()) {
10666 throw new IllegalArgumentException(
10667 "Only system can set hide fields in SignalThresholdInfo");
10668 }
10669
10670 // Thresholds length for each RAN need in range. This has been validated in
10671 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10672 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10673 final int[] thresholds = info.getThresholds();
10674 Objects.requireNonNull(thresholds);
10675 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10676 || thresholds.length
10677 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10678 throw new IllegalArgumentException(
10679 "thresholds length is out of range: " + thresholds.length);
10680 }
10681 }
10682 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010683
10684 /**
10685 * Gets the current phone capability.
10686 *
10687 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10688 * @return the PhoneCapability which describes the data connection capability of modem.
10689 * It's used to evaluate possible phone config change, for example from single
10690 * SIM device to multi-SIM device.
10691 */
10692 @Override
10693 public PhoneCapability getPhoneCapability() {
10694 enforceReadPrivilegedPermission("getPhoneCapability");
10695 final long identity = Binder.clearCallingIdentity();
10696 try {
10697 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10698 } finally {
10699 Binder.restoreCallingIdentity(identity);
10700 }
10701 }
Michele Berionne5e411512020-11-13 02:36:59 +000010702
10703 /**
10704 * Prepare TelephonyManager for an unattended reboot. The reboot is
10705 * required to be done shortly after the API is invoked.
10706 */
10707 @Override
10708 @TelephonyManager.PrepareUnattendedRebootResult
10709 public int prepareForUnattendedReboot() {
10710 enforceRebootPermission();
10711
10712 final long identity = Binder.clearCallingIdentity();
10713 try {
10714 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10715 } finally {
10716 Binder.restoreCallingIdentity(identity);
10717 }
10718 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010719
10720 /**
10721 * Request to get the current slicing configuration including URSP rules and
10722 * NSSAIs (configured, allowed and rejected).
10723 *
10724 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10725 */
10726 @Override
10727 public void getSlicingConfig(ResultReceiver callback) {
10728 enforceReadPrivilegedPermission("getSlicingConfig");
10729
10730 final long identity = Binder.clearCallingIdentity();
10731 try {
10732 Phone phone = getDefaultPhone();
10733 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10734 } finally {
10735 Binder.restoreCallingIdentity(identity);
10736 }
10737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010738}