blob: a0b227764ad4fc3c6719f1ca4ee361a2de11b925 [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;
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +0000155import com.android.internal.telephony.IImsStateCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700156import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800157import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700158import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800159import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700160import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700161import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700162import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700164import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800165import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700166import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700167import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700168import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700169import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800170import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800171import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700172import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700173import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700174import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800175import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800176import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800177import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700178import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800179import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700180import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800181import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700182import com.android.internal.telephony.imsphone.ImsPhone;
183import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800184import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700185import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800187import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700190import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800191import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192import com.android.internal.telephony.uicc.UiccController;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000193import com.android.internal.telephony.uicc.UiccPort;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800194import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000195import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800196import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700197import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700198import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800199import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800200import com.android.phone.callcomposer.CallComposerPictureManager;
201import com.android.phone.callcomposer.CallComposerPictureTransfer;
202import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700203import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800205import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700206import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700207import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800208import com.android.services.telephony.TelecomAccountRegistry;
209import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800210import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800211
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700213import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800214import java.io.IOException;
215import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700216import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800218import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800219import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800220import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800221import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100222import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800223import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700224import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800226import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800227import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800228import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800229import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230
231/**
232 * Implementation of the ITelephony interface.
233 */
Santos Cordon117fee72014-05-16 17:56:12 -0700234public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235 private static final String LOG_TAG = "PhoneInterfaceManager";
236 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
237 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800238 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700239
240 // Message codes used with mMainThreadHandler
241 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700242 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
243 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700244 private static final int CMD_OPEN_CHANNEL = 9;
245 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
246 private static final int CMD_CLOSE_CHANNEL = 11;
247 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800248 private static final int CMD_NV_READ_ITEM = 13;
249 private static final int EVENT_NV_READ_ITEM_DONE = 14;
250 private static final int CMD_NV_WRITE_ITEM = 15;
251 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
252 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
253 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700254 private static final int CMD_RESET_MODEM_CONFIG = 19;
255 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800256 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
257 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800258 private static final int CMD_SEND_ENVELOPE = 25;
259 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000260 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
261 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700262 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
263 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
264 private static final int CMD_EXCHANGE_SIM_IO = 31;
265 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800266 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
267 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700268 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
269 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700270 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
271 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700272 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
273 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
274 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
275 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700276 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
277 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
278 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
279 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700280 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800281 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
282 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000283 private static final int CMD_SWITCH_SLOTS = 50;
284 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700285 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
286 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
287 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
288 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
289 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
290 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
291 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
292 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700293 private static final int CMD_GET_ALL_CELL_INFO = 60;
294 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
295 private static final int CMD_GET_CELL_LOCATION = 62;
296 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700297 private static final int CMD_MODEM_REBOOT = 64;
298 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700299 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
300 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800301 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
302 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700303 private static final int CMD_GET_MODEM_STATUS = 70;
304 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700305 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
306 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700307 private static final int CMD_ERASE_MODEM_CONFIG = 74;
308 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800309 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
310 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
311 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
312 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800313 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
314 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800315 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800316 private static final int CMD_GET_CALL_FORWARDING = 83;
317 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
318 private static final int CMD_SET_CALL_FORWARDING = 85;
319 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
320 private static final int CMD_GET_CALL_WAITING = 87;
321 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
322 private static final int CMD_SET_CALL_WAITING = 89;
323 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700324 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
325 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
326 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
327 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700328 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
329 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800330 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
331 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800332 private static final int CMD_SET_DATA_THROTTLING = 99;
333 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800334 private static final int CMD_SET_SIM_POWER = 101;
335 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800336 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
337 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
338 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
339 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800340 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
341 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000342 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800343 private static final int CMD_GET_SLICING_CONFIG = 110;
344 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800345 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700346 private static final int CMD_ENABLE_VONR = 113;
347 private static final int EVENT_ENABLE_VONR_DONE = 114;
348 private static final int CMD_IS_VONR_ENABLED = 115;
349 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800351 // Parameters of select command.
352 private static final int SELECT_COMMAND = 0xA4;
353 private static final int SELECT_P1 = 0x04;
354 private static final int SELECT_P2 = 0;
355 private static final int SELECT_P3 = 0x10;
356
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 /** The singleton instance. */
358 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800359 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800362 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800363 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700364 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800365 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700366 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800368 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800369 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700370 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800371 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 /** User Activity */
374 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800375 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
376
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700377 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
378
Derek Tan97ebb422014-09-05 16:55:38 -0700379 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
380 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800381 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800382 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700383
Michelecea4cf22018-12-21 15:00:11 -0800384 // String to store multi SIM allowed
385 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
386
Derek Tan740e1672017-06-27 14:56:27 -0700387 // The AID of ISD-R.
388 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
389
yinxub1bed742017-04-17 11:45:04 -0700390 private NetworkScanRequestTracker mNetworkScanRequestTracker;
391
David Kelly5e06a7f2018-03-12 14:10:59 +0000392 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
393 private static final int MANUFACTURER_CODE_LENGTH = 8;
394
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800396 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800397
Derek Tan89e89d42014-07-08 17:00:10 -0700398 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700399 * Experiment flag to enable erase modem config on reset network, default value is false
400 */
401 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
402 "reset_network_erase_modem_config_enabled";
403
Rambo Wang0f050d82021-02-12 11:43:36 -0800404 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
405
Naina Nallurid63128d2019-09-17 14:10:30 -0700406 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700407 * A request object to use for transmitting data to an ICC.
408 */
409 private static final class IccAPDUArgument {
410 public int channel, cla, command, p1, p2, p3;
411 public String data;
412
413 public IccAPDUArgument(int channel, int cla, int command,
414 int p1, int p2, int p3, String data) {
415 this.channel = channel;
416 this.cla = cla;
417 this.command = command;
418 this.p1 = p1;
419 this.p2 = p2;
420 this.p3 = p3;
421 this.data = data;
422 }
423 }
424
425 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700426 * A request object to use for transmitting data to an ICC.
427 */
428 private static final class ManualNetworkSelectionArgument {
429 public OperatorInfo operatorInfo;
430 public boolean persistSelection;
431
432 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
433 this.operatorInfo = operatorInfo;
434 this.persistSelection = persistSelection;
435 }
436 }
437
438 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
440 * request after sending. The main thread will notify the request when it is complete.
441 */
442 private static final class MainThreadRequest {
443 /** The argument to use for the request */
444 public Object argument;
445 /** The result of the request that is run on the main thread */
446 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800447 // The subscriber id that this request applies to. Defaults to
448 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
449 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450
Nathan Harold92bed182018-10-12 18:16:49 -0700451 // In cases where subId is unavailable, the caller needs to specify the phone.
452 public Phone phone;
453
vagdeviaf9a5b92018-08-15 16:01:53 -0700454 public WorkSource workSource;
455
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 public MainThreadRequest(Object argument) {
457 this.argument = argument;
458 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800459
Nathan Harold92bed182018-10-12 18:16:49 -0700460 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
461 this.argument = argument;
462 if (phone != null) {
463 this.phone = phone;
464 }
465 this.workSource = workSource;
466 }
467
vagdeviaf9a5b92018-08-15 16:01:53 -0700468 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800469 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800470 if (subId != null) {
471 this.subId = subId;
472 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700473 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 }
476
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800477 private static final class IncomingThirdPartyCallArgs {
478 public final ComponentName component;
479 public final String callId;
480 public final String callerDisplayName;
481
482 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
483 String callerDisplayName) {
484 this.component = component;
485 this.callId = callId;
486 this.callerDisplayName = callerDisplayName;
487 }
488 }
489
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700490 /**
491 * A handler that processes messages on the main thread in the phone process. Since many
492 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
493 * inbound binder threads to the main thread in the phone process. The Binder thread
494 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
495 * on, which will be notified when the operation completes and will contain the result of the
496 * request.
497 *
498 * <p>If a MainThreadRequest object is provided in the msg.obj field,
499 * note that request.result must be set to something non-null for the calling thread to
500 * unblock.
501 */
502 private final class MainThreadHandler extends Handler {
503 @Override
504 public void handleMessage(Message msg) {
505 MainThreadRequest request;
506 Message onCompleted;
507 AsyncResult ar;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000508 UiccPort uiccPort;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800510 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511
512 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 case CMD_HANDLE_USSD_REQUEST: {
514 request = (MainThreadRequest) msg.obj;
515 final Phone phone = getPhoneFromRequest(request);
516 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
517 String ussdRequest = ussdObject.first;
518 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700519
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 if (!isUssdApiAllowed(request.subId)) {
521 // Carrier does not support use of this API, return failure.
522 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
523 UssdResponse response = new UssdResponse(ussdRequest, null);
524 Bundle returnData = new Bundle();
525 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
526 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700527
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 request.result = true;
529 notifyRequester(request);
530 return;
531 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700532
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 try {
534 request.result = phone != null
535 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
536 } catch (CallStateException cse) {
537 request.result = false;
538 }
539 // Wake up the requesting thread
540 notifyRequester(request);
541 break;
pkanwar32d516d2016-10-14 19:37:38 -0700542 }
543
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700546 final Phone phone = getPhoneFromRequest(request);
547 request.result = phone != null ?
548 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
549 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700554
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000558 uiccPort = getUiccPortFromRequest(request);
559 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 loge("iccTransmitApduLogicalChannel: No UICC");
561 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
565 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000566 uiccPort.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 iccArgument.channel, iccArgument.cla, iccArgument.command,
568 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 break;
572
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 ar = (AsyncResult) msg.obj;
575 request = (MainThreadRequest) ar.userObj;
576 if (ar.exception == null && ar.result != null) {
577 request.result = ar.result;
578 } else {
579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
580 if (ar.result == null) {
581 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800582 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800584 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 } else {
586 loge("iccTransmitApduLogicalChannel: Unknown exception");
587 }
588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 break;
591
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
594 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000595 uiccPort = getUiccPortFromRequest(request);
596 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 loge("iccTransmitApduBasicChannel: No UICC");
598 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
602 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000603 uiccPort.iccTransmitApduBasicChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
605 iccArgument.p3, iccArgument.data, onCompleted);
606 }
607 break;
608
609 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
610 ar = (AsyncResult) msg.obj;
611 request = (MainThreadRequest) ar.userObj;
612 if (ar.exception == null && ar.result != null) {
613 request.result = ar.result;
614 } else {
615 request.result = new IccIoResult(0x6F, 0, (byte[])null);
616 if (ar.result == null) {
617 loge("iccTransmitApduBasicChannel: Empty response");
618 } else if (ar.exception instanceof CommandException) {
619 loge("iccTransmitApduBasicChannel: CommandException: " +
620 ar.exception);
621 } else {
622 loge("iccTransmitApduBasicChannel: Unknown exception");
623 }
624 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 break;
627
628 case CMD_EXCHANGE_SIM_IO:
629 request = (MainThreadRequest) msg.obj;
630 iccArgument = (IccAPDUArgument) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000631 uiccPort = getUiccPortFromRequest(request);
632 if (uiccPort == null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 loge("iccExchangeSimIO: No UICC");
634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 } else {
637 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
638 request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000639 uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
641 iccArgument.data, onCompleted);
642 }
643 break;
644
645 case EVENT_EXCHANGE_SIM_IO_DONE:
646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result;
650 } else {
651 request.result = new IccIoResult(0x6f, 0, (byte[])null);
652 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 break;
655
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 case CMD_SEND_ENVELOPE:
657 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000658 uiccPort = getUiccPortFromRequest(request);
659 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 loge("sendEnvelopeWithStatus: No UICC");
661 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 } else {
664 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000665 uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700666 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800667 break;
668
669 case EVENT_SEND_ENVELOPE_DONE:
670 ar = (AsyncResult) msg.obj;
671 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700672 if (ar.exception == null && ar.result != null) {
673 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700675 request.result = new IccIoResult(0x6F, 0, (byte[])null);
676 if (ar.result == null) {
677 loge("sendEnvelopeWithStatus: Empty response");
678 } else if (ar.exception instanceof CommandException) {
679 loge("sendEnvelopeWithStatus: CommandException: " +
680 ar.exception);
681 } else {
682 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
683 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800686 break;
687
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 case CMD_OPEN_CHANNEL:
689 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000690 uiccPort = getUiccPortFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800691 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000692 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800694 request.result = new IccOpenLogicalChannelResponse(-1,
695 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700696 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700697 } else {
698 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000699 uiccPort.iccOpenLogicalChannel(openChannelArgs.first,
Ajay Nambid7454d32015-12-03 13:50:00 -0800700 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700701 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 break;
703
704 case EVENT_OPEN_CHANNEL_DONE:
705 ar = (AsyncResult) msg.obj;
706 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 int[] result = (int[]) ar.result;
710 int channelId = result[0];
711 byte[] selectResponse = null;
712 if (result.length > 1) {
713 selectResponse = new byte[result.length - 1];
714 for (int i = 1; i < result.length; ++i) {
715 selectResponse[i - 1] = (byte) result[i];
716 }
717 }
718 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 if (ar.result == null) {
722 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700723 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 if (ar.exception != null) {
725 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
726 }
727
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700728 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700729 if (ar.exception instanceof CommandException) {
730 CommandException.Error error =
731 ((CommandException) (ar.exception)).getCommandError();
732 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700733 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700734 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700735 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700736 }
737 }
738 openChannelResp = new IccOpenLogicalChannelResponse(
739 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700741 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 break;
744
745 case CMD_CLOSE_CHANNEL:
746 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000747 uiccPort = getUiccPortFromRequest(request);
748 if (uiccPort == null) {
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700749 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900750 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700751 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700752 } else {
753 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
Muralidhar Reddy864fe982021-09-29 19:38:40 +0000754 uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 break;
757
758 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800759 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
760 break;
761
762 case CMD_NV_READ_ITEM:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800765 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
766 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800767 break;
768
769 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800772 if (ar.exception == null && ar.result != null) {
773 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800775 request.result = "";
776 if (ar.result == null) {
777 loge("nvReadItem: Empty response");
778 } else if (ar.exception instanceof CommandException) {
779 loge("nvReadItem: CommandException: " +
780 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800782 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700783 }
784 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700785 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700786 break;
787
Jake Hambye994d462014-02-03 13:10:13 -0800788 case CMD_NV_WRITE_ITEM:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
791 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800792 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700793 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800794 break;
795
796 case EVENT_NV_WRITE_ITEM_DONE:
797 handleNullReturnEvent(msg, "nvWriteItem");
798 break;
799
800 case CMD_NV_WRITE_CDMA_PRL:
801 request = (MainThreadRequest) msg.obj;
802 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800803 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800804 break;
805
806 case EVENT_NV_WRITE_CDMA_PRL_DONE:
807 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
808 break;
809
chen xu6dac5ab2018-10-26 17:39:23 -0700810 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800811 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700812 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800813 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800814 break;
815
chen xu6dac5ab2018-10-26 17:39:23 -0700816 case EVENT_RESET_MODEM_CONFIG_DONE:
817 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800818 break;
819
Sooraj Sasindran37444802020-08-11 10:40:43 -0700820 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
823 request);
824 Phone phone = getPhoneFromRequest(request);
825 if (phone != null) {
826 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
827 } else {
828 loge("isNRDualConnectivityEnabled: No phone object");
829 request.result = false;
830 notifyRequester(request);
831 }
832 break;
833 }
834
835 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null && ar.result != null) {
839 request.result = ar.result;
840 } else {
841 // request.result must be set to something non-null
842 // for the calling thread to unblock
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700843 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700844 request.result = ar.result;
845 } else {
846 request.result = false;
847 }
848 if (ar.result == null) {
849 loge("isNRDualConnectivityEnabled: Empty response");
850 } else if (ar.exception instanceof CommandException) {
851 loge("isNRDualConnectivityEnabled: CommandException: "
852 + ar.exception);
853 } else {
854 loge("isNRDualConnectivityEnabled: Unknown exception");
855 }
856 }
857 notifyRequester(request);
858 break;
859
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700860 case CMD_IS_VONR_ENABLED: {
861 request = (MainThreadRequest) msg.obj;
862 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
863 request);
864 Phone phone = getPhoneFromRequest(request);
865 if (phone != null) {
866 phone.isVoNrEnabled(onCompleted, request.workSource);
867 } else {
868 loge("isVoNrEnabled: No phone object");
869 request.result = false;
870 notifyRequester(request);
871 }
872 break;
873 }
874
875 case EVENT_IS_VONR_ENABLED_DONE:
876 ar = (AsyncResult) msg.obj;
877 request = (MainThreadRequest) ar.userObj;
878 if (ar.exception == null && ar.result != null) {
879 request.result = ar.result;
880 } else {
881 // request.result must be set to something non-null
882 // for the calling thread to unblock
883 if (ar.result != null) {
884 request.result = ar.result;
885 } else {
886 request.result = false;
887 }
888 if (ar.result == null) {
889 loge("isVoNrEnabled: Empty response");
890 } else if (ar.exception instanceof CommandException) {
891 loge("isVoNrEnabled: CommandException: "
892 + ar.exception);
893 } else {
894 loge("isVoNrEnabled: Unknown exception");
895 }
896 }
897 notifyRequester(request);
898 break;
899
Sooraj Sasindran37444802020-08-11 10:40:43 -0700900 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
901 request = (MainThreadRequest) msg.obj;
902 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
903 Phone phone = getPhoneFromRequest(request);
904 if (phone != null) {
905 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
906 request.workSource);
907 } else {
908 loge("enableNrDualConnectivity: No phone object");
909 request.result =
910 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
911 notifyRequester(request);
912 }
913 break;
914 }
915
916 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null) {
920 request.result =
921 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
922 } else {
923 request.result =
924 TelephonyManager
925 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
926 if (ar.exception instanceof CommandException) {
927 CommandException.Error error =
928 ((CommandException) (ar.exception)).getCommandError();
929 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
930 request.result =
931 TelephonyManager
932 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000933 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
934 request.result =
935 TelephonyManager
936 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700937 }
938 loge("enableNrDualConnectivity" + ": CommandException: "
939 + ar.exception);
940 } else {
941 loge("enableNrDualConnectivity" + ": Unknown exception");
942 }
943 }
944 notifyRequester(request);
945 break;
946 }
947
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -0700948 case CMD_ENABLE_VONR: {
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
951 Phone phone = getPhoneFromRequest(request);
952 if (phone != null) {
953 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
954 request.workSource);
955 } else {
956 loge("setVoNrEnabled: No phone object");
957 request.result =
958 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
959 notifyRequester(request);
960 }
961 break;
962 }
963
964 case EVENT_ENABLE_VONR_DONE: {
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 if (ar.exception == null) {
968 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
969 } else {
970 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
971 if (ar.exception instanceof CommandException) {
972 CommandException.Error error =
973 ((CommandException) (ar.exception)).getCommandError();
974 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
975 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
976 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
977 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
978 } else {
979 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
980 }
981 loge("setVoNrEnabled" + ": CommandException: "
982 + ar.exception);
983 } else {
984 loge("setVoNrEnabled" + ": Unknown exception");
985 }
986 }
987 notifyRequester(request);
988 break;
989 }
990
SongFerngWang3ef3e072020-12-21 16:41:52 +0800991 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800992 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800993 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
994 request);
995 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800996 break;
997
SongFerngWang3ef3e072020-12-21 16:41:52 +0800998 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception == null && ar.result != null) {
1002 request.result = ar.result; // Integer
1003 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301004 // request.result must be set to something non-null
1005 // for the calling thread to unblock
1006 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001007 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001009 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001010 loge("getAllowedNetworkTypesBitmask: CommandException: "
1011 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001013 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001014 }
1015 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001016 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001017 break;
1018
SongFerngWang3ef3e072020-12-21 16:41:52 +08001019 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001020 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001021 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1022 request);
1023 Pair<Integer, Long> reasonWithNetworkTypes =
1024 (Pair<Integer, Long>) request.argument;
1025 getPhoneFromRequest(request).setAllowedNetworkTypes(
1026 reasonWithNetworkTypes.first,
1027 reasonWithNetworkTypes.second,
1028 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001029 break;
1030
SongFerngWang3ef3e072020-12-21 16:41:52 +08001031 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1032 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001033 break;
1034
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001035 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1036 request = (MainThreadRequest)msg.obj;
1037 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001038 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001039 break;
1040
1041 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1042 ar = (AsyncResult)msg.obj;
1043 request = (MainThreadRequest)ar.userObj;
1044 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001045 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001046 break;
1047
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001048 case CMD_SET_VOICEMAIL_NUMBER:
1049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1051 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001052 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1053 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001054 break;
1055
1056 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1057 handleNullReturnEvent(msg, "setVoicemailNumber");
1058 break;
1059
Stuart Scott54788802015-03-30 13:18:01 -07001060 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1061 request = (MainThreadRequest) msg.obj;
1062 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1063 request);
1064 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1065 break;
1066
1067 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1068 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1069 break;
1070
Shishir Agrawal302c8692015-06-19 13:49:39 -07001071 case CMD_PERFORM_NETWORK_SCAN:
1072 request = (MainThreadRequest) msg.obj;
1073 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1074 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1075 break;
1076
Hall Liu27d24262020-09-18 19:04:59 -07001077 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001078 request = (MainThreadRequest) msg.obj;
1079 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001080 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1081 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1082 request.argument;
1083 int callForwardingReason = args.first;
1084 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001085 break;
Hall Liu27d24262020-09-18 19:04:59 -07001086 }
1087 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001088 ar = (AsyncResult) msg.obj;
1089 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001090 TelephonyManager.CallForwardingInfoCallback callback =
1091 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1092 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001094 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001095 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1096 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1097 // Service Class is a bit mask per 3gpp 27.007. Search for
1098 // any service for voice call.
1099 if ((callForwardInfo.serviceClass
1100 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Yuchen Dong69cc1412021-09-27 20:27:01 +08001101 callForwardingInfo = new CallForwardingInfo(
1102 callForwardInfo.status
1103 == CommandsInterface.CF_ACTION_ENABLE,
Hall Liu27d24262020-09-18 19:04:59 -07001104 callForwardInfo.reason,
1105 callForwardInfo.number,
1106 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001107 break;
1108 }
1109 }
1110 // Didn't find a call forward info for voice call.
1111 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001112 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1113 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001114 }
Hall Liu27d24262020-09-18 19:04:59 -07001115 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001116 } else {
1117 if (ar.result == null) {
1118 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1119 }
1120 if (ar.exception != null) {
1121 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1122 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001123 int errorCode = TelephonyManager
1124 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001125 if (ar.exception instanceof CommandException) {
1126 CommandException.Error error =
1127 ((CommandException) (ar.exception)).getCommandError();
1128 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001129 errorCode = TelephonyManager
1130 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001131 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001132 errorCode = TelephonyManager
1133 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001134 }
1135 }
Hall Liu27d24262020-09-18 19:04:59 -07001136 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001137 }
Shuo Qian4a594052020-01-23 11:59:30 -08001138 break;
Hall Liu27d24262020-09-18 19:04:59 -07001139 }
Shuo Qian4a594052020-01-23 11:59:30 -08001140
Hall Liu27d24262020-09-18 19:04:59 -07001141 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001142 request = (MainThreadRequest) msg.obj;
1143 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001144 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001145 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001146 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1147 request.argument).first;
1148 request.phone.setCallForwardingOption(
1149 callForwardingInfoToSet.isEnabled()
1150 ? CommandsInterface.CF_ACTION_ENABLE
1151 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001152 callForwardingInfoToSet.getReason(),
1153 callForwardingInfoToSet.getNumber(),
1154 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1155 break;
Hall Liu27d24262020-09-18 19:04:59 -07001156 }
Shuo Qian4a594052020-01-23 11:59:30 -08001157
Hall Liu27d24262020-09-18 19:04:59 -07001158 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001161 Consumer<Integer> callback =
1162 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1163 request.argument).second;
1164 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001165 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001166 int errorCode = TelephonyManager.CallForwardingInfoCallback
1167 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001168 if (ar.exception instanceof CommandException) {
1169 CommandException.Error error =
1170 ((CommandException) (ar.exception)).getCommandError();
1171 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001172 errorCode = TelephonyManager.CallForwardingInfoCallback
1173 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001174 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001175 errorCode = TelephonyManager.CallForwardingInfoCallback
1176 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001177 }
1178 }
1179 callback.accept(errorCode);
1180 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001181 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001182 }
Shuo Qian4a594052020-01-23 11:59:30 -08001183 break;
Hall Liu27d24262020-09-18 19:04:59 -07001184 }
Shuo Qian4a594052020-01-23 11:59:30 -08001185
Hall Liu27d24262020-09-18 19:04:59 -07001186 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001187 request = (MainThreadRequest) msg.obj;
1188 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1189 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1190 break;
Hall Liu27d24262020-09-18 19:04:59 -07001191 }
Shuo Qian4a594052020-01-23 11:59:30 -08001192
Hall Liu27d24262020-09-18 19:04:59 -07001193 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001194 ar = (AsyncResult) msg.obj;
1195 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001196 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001197 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1198 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001199 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001200 // Service Class is a bit mask per 3gpp 27.007.
1201 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001202 if (callForwardResults.length > 1
1203 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001204 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001205 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001206 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1207 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001208 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001209 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001210 }
1211 } else {
1212 if (ar.result == null) {
1213 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1214 }
1215 if (ar.exception != null) {
1216 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1217 }
1218 if (ar.exception instanceof CommandException) {
1219 CommandException.Error error =
1220 ((CommandException) (ar.exception)).getCommandError();
1221 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1222 callForwardingStatus =
1223 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1224 }
1225 }
1226 }
Hall Liu27d24262020-09-18 19:04:59 -07001227 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001228 break;
Hall Liu27d24262020-09-18 19:04:59 -07001229 }
Shuo Qian4a594052020-01-23 11:59:30 -08001230
Hall Liu27d24262020-09-18 19:04:59 -07001231 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001232 request = (MainThreadRequest) msg.obj;
1233 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001234 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1235 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001236 break;
Hall Liu27d24262020-09-18 19:04:59 -07001237 }
Shuo Qian4a594052020-01-23 11:59:30 -08001238
Hall Liu27d24262020-09-18 19:04:59 -07001239 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001240 ar = (AsyncResult) msg.obj;
1241 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001242 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1243 Consumer<Integer> callback =
1244 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1245 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001246 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001247 if (ar.exception instanceof CommandException) {
1248 CommandException.Error error =
1249 ((CommandException) (ar.exception)).getCommandError();
1250 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1251 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1252 } else {
1253 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1254 }
1255 } else {
1256 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1257 }
1258 } else {
1259 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1260 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001261 }
Shuo Qian4a594052020-01-23 11:59:30 -08001262 break;
Hall Liu27d24262020-09-18 19:04:59 -07001263 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001264 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1265 ar = (AsyncResult) msg.obj;
1266 request = (MainThreadRequest) ar.userObj;
1267 CellNetworkScanResult cellScanResult;
1268 if (ar.exception == null && ar.result != null) {
1269 cellScanResult = new CellNetworkScanResult(
1270 CellNetworkScanResult.STATUS_SUCCESS,
1271 (List<OperatorInfo>) ar.result);
1272 } else {
1273 if (ar.result == null) {
1274 loge("getCellNetworkScanResults: Empty response");
1275 }
1276 if (ar.exception != null) {
1277 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1278 }
1279 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1280 if (ar.exception instanceof CommandException) {
1281 CommandException.Error error =
1282 ((CommandException) (ar.exception)).getCommandError();
1283 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1284 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1285 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1286 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1287 }
1288 }
1289 cellScanResult = new CellNetworkScanResult(errorCode, null);
1290 }
1291 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001292 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001293 break;
1294
1295 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1296 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001297 ManualNetworkSelectionArgument selArg =
1298 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001299 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1300 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001301 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1302 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001303 break;
1304
1305 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001306 ar = (AsyncResult) msg.obj;
1307 request = (MainThreadRequest) ar.userObj;
1308 if (ar.exception == null) {
1309 request.result = true;
1310 } else {
1311 request.result = false;
1312 loge("setNetworkSelectionModeManual " + ar.exception);
1313 }
1314 notifyRequester(request);
1315 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001316 break;
1317
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001318 case CMD_GET_MODEM_ACTIVITY_INFO:
1319 request = (MainThreadRequest) msg.obj;
1320 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001321 if (defaultPhone != null) {
1322 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001323 } else {
1324 ResultReceiver result = (ResultReceiver) request.argument;
1325 Bundle bundle = new Bundle();
1326 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001327 new ModemActivityInfo(0, 0, 0,
1328 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001329 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001330 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001331 break;
1332
Hall Liud0f208c2020-10-14 16:54:44 -07001333 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001334 ar = (AsyncResult) msg.obj;
1335 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001336 ResultReceiver result = (ResultReceiver) request.argument;
1337
Hall Liud0f208c2020-10-14 16:54:44 -07001338 ModemActivityInfo ret = null;
1339 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001340 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001341 // Update the last modem activity info and the result of the request.
1342 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1343 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001344 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001345 int[] txTimeMs = info.getTransmitTimeMillis();
1346 int[] lastModemTxTimeMs = mLastModemActivityInfo
1347 .getTransmitTimeMillis();
1348 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1349 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1350 }
Hall Liu49656c02020-10-09 19:00:11 -07001351 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001352 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1353 + mLastModemActivityInfo.getSleepTimeMillis());
1354 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1355 + mLastModemActivityInfo.getIdleTimeMillis());
1356 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1357 mLastModemActivityInfo.setReceiveTimeMillis(
1358 info.getReceiveTimeMillis()
1359 + mLastModemActivityInfo.getReceiveTimeMillis());
1360 }
Hall Liu49656c02020-10-09 19:00:11 -07001361 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001362 mLastModemActivityInfo.getSleepTimeMillis(),
1363 mLastModemActivityInfo.getIdleTimeMillis(),
1364 mLastModemActivityInfo.getTransmitTimeMillis(),
1365 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001366 } else {
1367 if (ar.result == null) {
1368 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001369 error = TelephonyManager.ModemActivityInfoException
1370 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001371 } else if (ar.exception instanceof CommandException) {
1372 loge("queryModemActivityInfo: CommandException: " +
1373 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001374 error = TelephonyManager.ModemActivityInfoException
1375 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001376 } else {
1377 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001378 error = TelephonyManager.ModemActivityInfoException
1379 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001380 }
1381 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001382 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001383 if (ret != null) {
1384 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1385 } else {
1386 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1387 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001388 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001389 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001390 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001391 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001392
Meng Wang1a7c35a2016-05-05 20:56:15 -07001393 case CMD_SET_ALLOWED_CARRIERS:
1394 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001395 CarrierRestrictionRules argument =
1396 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001397 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001398 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001399 break;
1400
1401 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 if (ar.exception == null && ar.result != null) {
1405 request.result = ar.result;
1406 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001407 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1408 if (ar.exception instanceof CommandException) {
1409 loge("setAllowedCarriers: CommandException: " + ar.exception);
1410 CommandException.Error error =
1411 ((CommandException) (ar.exception)).getCommandError();
1412 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1413 request.result =
1414 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1415 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001416 } else {
1417 loge("setAllowedCarriers: Unknown exception");
1418 }
1419 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001420 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001421 break;
1422
1423 case CMD_GET_ALLOWED_CARRIERS:
1424 request = (MainThreadRequest) msg.obj;
1425 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001426 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001427 break;
1428
1429 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1430 ar = (AsyncResult) msg.obj;
1431 request = (MainThreadRequest) ar.userObj;
1432 if (ar.exception == null && ar.result != null) {
1433 request.result = ar.result;
1434 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001435 request.result = new IllegalStateException(
1436 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001437 if (ar.result == null) {
1438 loge("getAllowedCarriers: Empty response");
1439 } else if (ar.exception instanceof CommandException) {
1440 loge("getAllowedCarriers: CommandException: " +
1441 ar.exception);
1442 } else {
1443 loge("getAllowedCarriers: Unknown exception");
1444 }
1445 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001446 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001447 break;
1448
Nathan Haroldb3014052017-01-25 15:57:32 -08001449 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 if (ar.exception == null && ar.result != null) {
1453 request.result = ar.result;
1454 } else {
1455 request.result = new IllegalArgumentException(
1456 "Failed to retrieve Forbidden Plmns");
1457 if (ar.result == null) {
1458 loge("getForbiddenPlmns: Empty response");
1459 } else {
1460 loge("getForbiddenPlmns: Unknown exception");
1461 }
1462 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001463 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001464 break;
1465
1466 case CMD_GET_FORBIDDEN_PLMNS:
1467 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001468 uiccPort = getUiccPortFromRequest(request);
1469 if (uiccPort == null) {
1470 loge("getForbiddenPlmns() UiccPort is null");
Nathan Haroldb3014052017-01-25 15:57:32 -08001471 request.result = new IllegalArgumentException(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001472 "getForbiddenPlmns() UiccPort is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001473 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001474 break;
1475 }
1476 Integer appType = (Integer) request.argument;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001477 UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType);
Nathan Haroldb3014052017-01-25 15:57:32 -08001478 if (uiccApp == null) {
1479 loge("getForbiddenPlmns() no app with specified type -- "
1480 + appType);
1481 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001482 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001483 break;
1484 } else {
1485 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1486 + " specified type -- " + appType);
1487 }
1488 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1489 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1490 onCompleted);
1491 break;
1492
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001493 case CMD_SWITCH_SLOTS:
1494 request = (MainThreadRequest) msg.obj;
1495 int[] physicalSlots = (int[]) request.argument;
1496 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1497 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1498 break;
1499
1500 case EVENT_SWITCH_SLOTS_DONE:
1501 ar = (AsyncResult) msg.obj;
1502 request = (MainThreadRequest) ar.userObj;
1503 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001504 notifyRequester(request);
1505 break;
1506 case CMD_GET_NETWORK_SELECTION_MODE:
1507 request = (MainThreadRequest) msg.obj;
1508 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1509 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1510 break;
1511
1512 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1513 ar = (AsyncResult) msg.obj;
1514 request = (MainThreadRequest) ar.userObj;
1515 if (ar.exception != null) {
1516 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1517 } else {
1518 int mode = ((int[]) ar.result)[0];
1519 if (mode == 0) {
1520 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1521 } else {
1522 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1523 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001524 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001525 notifyRequester(request);
1526 break;
1527 case CMD_GET_CDMA_ROAMING_MODE:
1528 request = (MainThreadRequest) msg.obj;
1529 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1530 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1531 break;
1532 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1533 ar = (AsyncResult) msg.obj;
1534 request = (MainThreadRequest) ar.userObj;
1535 if (ar.exception != null) {
1536 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1537 } else {
1538 request.result = ((int[]) ar.result)[0];
1539 }
1540 notifyRequester(request);
1541 break;
1542 case CMD_SET_CDMA_ROAMING_MODE:
1543 request = (MainThreadRequest) msg.obj;
1544 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1545 int mode = (int) request.argument;
1546 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1547 break;
1548 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 request.result = ar.exception == null;
1552 notifyRequester(request);
1553 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001554 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1555 request = (MainThreadRequest) msg.obj;
1556 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1557 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1558 break;
1559 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1560 ar = (AsyncResult) msg.obj;
1561 request = (MainThreadRequest) ar.userObj;
1562 if (ar.exception != null) {
1563 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1564 } else {
1565 request.result = ((int[]) ar.result)[0];
1566 }
1567 notifyRequester(request);
1568 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001569 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1570 request = (MainThreadRequest) msg.obj;
1571 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1572 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001573 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1574 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001575 break;
1576 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1577 ar = (AsyncResult) msg.obj;
1578 request = (MainThreadRequest) ar.userObj;
1579 request.result = ar.exception == null;
1580 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001581 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 case CMD_GET_ALL_CELL_INFO:
1583 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001585 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001586 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001587 case EVENT_GET_ALL_CELL_INFO_DONE:
1588 ar = (AsyncResult) msg.obj;
1589 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001590 // If a timeout occurs, the response will be null
1591 request.result = (ar.exception == null && ar.result != null)
1592 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001593 synchronized (request) {
1594 request.notifyAll();
1595 }
1596 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001597 case CMD_REQUEST_CELL_INFO_UPDATE:
1598 request = (MainThreadRequest) msg.obj;
1599 request.phone.requestCellInfoUpdate(request.workSource,
1600 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1601 break;
1602 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1603 ar = (AsyncResult) msg.obj;
1604 request = (MainThreadRequest) ar.userObj;
1605 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1606 try {
1607 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001608 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001609 cb.onError(
1610 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1611 ar.exception.getClass().getName(),
1612 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001613 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001614 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001615 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001616 } else {
1617 // use the result as returned
1618 cb.onCellInfo((List<CellInfo>) ar.result);
1619 }
1620 } catch (RemoteException re) {
1621 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1622 }
1623 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001624 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001625 request = (MainThreadRequest) msg.obj;
1626 WorkSource ws = (WorkSource) request.argument;
1627 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001628 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001629 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001630 }
1631 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001632 ar = (AsyncResult) msg.obj;
1633 request = (MainThreadRequest) ar.userObj;
1634 if (ar.exception == null) {
1635 request.result = ar.result;
1636 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001637 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001638 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001639 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001640 }
1641
1642 synchronized (request) {
1643 request.notifyAll();
1644 }
1645 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001646 }
chen xu6dac5ab2018-10-26 17:39:23 -07001647 case CMD_MODEM_REBOOT:
1648 request = (MainThreadRequest) msg.obj;
1649 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001650 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001651 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001652 case EVENT_CMD_MODEM_REBOOT_DONE:
1653 handleNullReturnEvent(msg, "rebootModem");
1654 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001655 case CMD_REQUEST_ENABLE_MODEM:
1656 request = (MainThreadRequest) msg.obj;
1657 boolean enable = (boolean) request.argument;
1658 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001659 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001660 PhoneConfigurationManager.getInstance()
1661 .enablePhone(request.phone, enable, onCompleted);
1662 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001663 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
1666 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001667 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001668 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001669 if ((boolean) request.result) {
1670 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1671 updateModemStateMetrics();
1672 } else {
1673 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1674 + ar.exception);
1675 }
1676 notifyRequester(request);
1677 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001678 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001679 case CMD_GET_MODEM_STATUS:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1682 PhoneConfigurationManager.getInstance()
1683 .getPhoneStatusFromModem(request.phone, onCompleted);
1684 break;
1685 case EVENT_GET_MODEM_STATUS_DONE:
1686 ar = (AsyncResult) msg.obj;
1687 request = (MainThreadRequest) ar.userObj;
1688 int id = request.phone.getPhoneId();
1689 if (ar.exception == null && ar.result != null) {
1690 request.result = ar.result;
1691 //update the cache as modem status has changed
1692 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1693 (boolean) request.result);
1694 } else {
1695 // Return true if modem status cannot be retrieved. For most cases,
1696 // modem status is on. And for older version modems, GET_MODEM_STATUS
1697 // and disable modem are not supported. Modem is always on.
1698 // TODO: this should be fixed in R to support a third
1699 // status UNKNOWN b/131631629
1700 request.result = true;
1701 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1702 + ar.exception);
1703 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001704 notifyRequester(request);
1705 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001706 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1707 request = (MainThreadRequest) msg.obj;
1708 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1709 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1710 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1711 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1712 break;
1713 }
1714 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1715 ar = (AsyncResult) msg.obj;
1716 request = (MainThreadRequest) ar.userObj;
1717 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1718 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1719 args.second.accept(ar.exception == null);
1720 notifyRequester(request);
1721 break;
1722 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001723 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1724 request = (MainThreadRequest) msg.obj;
1725 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1726 Phone phone = getPhoneFromRequest(request);
1727 if (phone != null) {
1728 phone.getSystemSelectionChannels(onCompleted);
1729 } else {
1730 loge("getSystemSelectionChannels: No phone object");
1731 request.result = new ArrayList<RadioAccessSpecifier>();
1732 notifyRequester(request);
1733 }
1734 break;
1735 }
1736 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1737 ar = (AsyncResult) msg.obj;
1738 request = (MainThreadRequest) ar.userObj;
1739 if (ar.exception == null && ar.result != null) {
1740 request.result = ar.result;
1741 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001742 request.result = new IllegalStateException(
1743 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001744 if (ar.result == null) {
1745 loge("getSystemSelectionChannels: Empty response");
1746 } else {
1747 loge("getSystemSelectionChannels: Unknown exception");
1748 }
1749 }
1750 notifyRequester(request);
1751 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001752 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1753 ar = (AsyncResult) msg.obj;
1754 request = (MainThreadRequest) ar.userObj;
1755 if (ar.exception == null && ar.result != null) {
1756 request.result = ar.result;
1757 } else {
1758 request.result = -1;
1759 loge("Failed to set Forbidden Plmns");
1760 if (ar.result == null) {
1761 loge("setForbidenPlmns: Empty response");
1762 } else if (ar.exception != null) {
1763 loge("setForbiddenPlmns: Exception: " + ar.exception);
1764 request.result = -1;
1765 } else {
1766 loge("setForbiddenPlmns: Unknown exception");
1767 }
1768 }
1769 notifyRequester(request);
1770 break;
1771 case CMD_SET_FORBIDDEN_PLMNS:
1772 request = (MainThreadRequest) msg.obj;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001773 uiccPort = getUiccPortFromRequest(request);
1774 if (uiccPort == null) {
1775 loge("setForbiddenPlmns: UiccPort is null");
yincheng zhao2737e882019-09-06 17:06:54 -07001776 request.result = -1;
1777 notifyRequester(request);
1778 break;
1779 }
1780 Pair<Integer, List<String>> setFplmnsArgs =
1781 (Pair<Integer, List<String>>) request.argument;
1782 appType = setFplmnsArgs.first;
1783 List<String> fplmns = setFplmnsArgs.second;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00001784 uiccApp = uiccPort.getApplicationByType(appType);
yincheng zhao2737e882019-09-06 17:06:54 -07001785 if (uiccApp == null) {
1786 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1787 request.result = -1;
1788 loge("Failed to get UICC App");
1789 notifyRequester(request);
1790 } else {
1791 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1792 ((SIMRecords) uiccApp.getIccRecords())
1793 .setForbiddenPlmns(onCompleted, fplmns);
1794 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001795 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001796 case CMD_ERASE_MODEM_CONFIG:
1797 request = (MainThreadRequest) msg.obj;
1798 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1799 defaultPhone.eraseModemConfig(onCompleted);
1800 break;
1801 case EVENT_ERASE_MODEM_CONFIG_DONE:
1802 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001803 break;
zoey chene02881a2019-12-30 16:11:23 +08001804
Kai Shif70f46f2021-03-03 13:59:46 -08001805 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1806 request = (MainThreadRequest) msg.obj;
1807 request.result = defaultPhone.eraseDataInSharedPreferences();
1808 notifyRequester(request);
1809 break;
1810
zoey chene02881a2019-12-30 16:11:23 +08001811 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1812 request = (MainThreadRequest) msg.obj;
1813 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1814 Pair<String, String> changed = (Pair<String, String>) request.argument;
1815 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1816 changed.first, changed.second, onCompleted);
1817 break;
1818 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1819 ar = (AsyncResult) msg.obj;
1820 request = (MainThreadRequest) ar.userObj;
1821 if (ar.exception == null) {
1822 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001823 // If the operation is successful, update the PIN storage
1824 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1825 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001826 UiccController.getInstance().getPinStorage()
1827 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001828 } else {
1829 request.result = msg.arg1;
1830 }
1831 notifyRequester(request);
1832 break;
1833
Michele Berionne5e411512020-11-13 02:36:59 +00001834 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001835 request = (MainThreadRequest) msg.obj;
1836 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1837 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1838 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1839 enabled.first, enabled.second, onCompleted);
1840 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001841 }
zoey chene02881a2019-12-30 16:11:23 +08001842 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1843 ar = (AsyncResult) msg.obj;
1844 request = (MainThreadRequest) ar.userObj;
1845 if (ar.exception == null) {
1846 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001847 // If the operation is successful, update the PIN storage
1848 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1849 int phoneId = getPhoneFromRequest(request).getPhoneId();
1850 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001851 UiccController.getInstance().getPinStorage()
1852 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001853 } else {
1854 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1855 }
zoey chene02881a2019-12-30 16:11:23 +08001856 } else {
1857 request.result = msg.arg1;
1858 }
Michele Berionne5e411512020-11-13 02:36:59 +00001859
1860
zoey chene02881a2019-12-30 16:11:23 +08001861 notifyRequester(request);
1862 break;
1863
Peter Wangdafb9ac2020-01-15 14:13:38 -08001864 case MSG_NOTIFY_USER_ACTIVITY:
1865 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001866 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001867 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1868 getDefaultPhone().getContext().sendBroadcastAsUser(
1869 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1870 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001871
1872 case CMD_SET_DATA_THROTTLING: {
1873 request = (MainThreadRequest) msg.obj;
1874 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1875 DataThrottlingRequest dataThrottlingRequest =
1876 (DataThrottlingRequest) request.argument;
1877 Phone phone = getPhoneFromRequest(request);
1878 if (phone != null) {
1879 phone.setDataThrottling(onCompleted,
1880 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1881 dataThrottlingRequest.getCompletionDurationMillis());
1882 } else {
1883 loge("setDataThrottling: No phone object");
1884 request.result =
1885 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1886 notifyRequester(request);
1887 }
1888
1889 break;
1890 }
1891 case EVENT_SET_DATA_THROTTLING_DONE:
1892 ar = (AsyncResult) msg.obj;
1893 request = (MainThreadRequest) ar.userObj;
1894
1895 if (ar.exception == null) {
1896 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1897 } else if (ar.exception instanceof CommandException) {
1898 loge("setDataThrottling: CommandException: " + ar.exception);
1899 CommandException.Error error =
1900 ((CommandException) (ar.exception)).getCommandError();
1901
1902 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1903 request.result = TelephonyManager
1904 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1905 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1906 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001907 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1908 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001909 } else {
1910 request.result =
1911 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1912 }
1913 } else {
1914 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1915 }
1916 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1917 notifyRequester(request);
1918 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001919
1920 case CMD_SET_SIM_POWER: {
1921 request = (MainThreadRequest) msg.obj;
1922 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1923 request = (MainThreadRequest) msg.obj;
1924 int stateToSet =
1925 ((Pair<Integer, IIntegerConsumer>)
1926 request.argument).first;
1927 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1928 break;
1929 }
1930 case EVENT_SET_SIM_POWER_DONE: {
1931 ar = (AsyncResult) msg.obj;
1932 request = (MainThreadRequest) ar.userObj;
1933 IIntegerConsumer callback =
1934 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1935 if (ar.exception != null) {
1936 loge("setSimPower exception: " + ar.exception);
1937 int errorCode = TelephonyManager.CallForwardingInfoCallback
1938 .RESULT_ERROR_UNKNOWN;
1939 if (ar.exception instanceof CommandException) {
1940 CommandException.Error error =
1941 ((CommandException) (ar.exception)).getCommandError();
1942 if (error == CommandException.Error.SIM_ERR) {
1943 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1944 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1945 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1946 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1947 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1948 } else {
1949 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1950 }
1951 }
1952 try {
1953 callback.accept(errorCode);
1954 } catch (RemoteException e) {
1955 // Ignore if the remote process is no longer available to call back.
1956 Log.w(LOG_TAG, "setSimPower: callback not available.");
1957 }
1958 } else {
1959 try {
1960 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1961 } catch (RemoteException e) {
1962 // Ignore if the remote process is no longer available to call back.
1963 Log.w(LOG_TAG, "setSimPower: callback not available.");
1964 }
1965 }
1966 break;
1967 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001968 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1969 request = (MainThreadRequest) msg.obj;
1970
1971 final Phone phone = getPhoneFromRequest(request);
1972 if (phone == null || phone.getServiceStateTracker() == null) {
1973 request.result = new IllegalStateException("Phone or SST is null");
1974 notifyRequester(request);
1975 break;
1976 }
1977
1978 Pair<Integer, SignalStrengthUpdateRequest> pair =
1979 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1980 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1981 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001982 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001983 request.subId, pair.first /*callingUid*/,
1984 pair.second /*request*/, onCompleted);
1985 break;
1986 }
1987 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1988 ar = (AsyncResult) msg.obj;
1989 request = (MainThreadRequest) ar.userObj;
1990 // request.result will be the exception of ar if present, true otherwise.
1991 // Be cautious not to leave result null which will wait() forever
1992 request.result = ar.exception != null ? ar.exception : true;
1993 notifyRequester(request);
1994 break;
1995 }
1996 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1997 request = (MainThreadRequest) msg.obj;
1998
1999 Phone phone = getPhoneFromRequest(request);
2000 if (phone == null || phone.getServiceStateTracker() == null) {
2001 request.result = new IllegalStateException("Phone or SST is null");
2002 notifyRequester(request);
2003 break;
2004 }
2005
2006 Pair<Integer, SignalStrengthUpdateRequest> pair =
2007 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2008 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2009 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002010 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002011 request.subId, pair.first /*callingUid*/,
2012 pair.second /*request*/, onCompleted);
2013 break;
2014 }
2015 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2016 ar = (AsyncResult) msg.obj;
2017 request = (MainThreadRequest) ar.userObj;
2018 request.result = ar.exception != null ? ar.exception : true;
2019 notifyRequester(request);
2020 break;
2021 }
Jordan Liu109698e2020-11-24 14:50:34 -08002022
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002023 case CMD_GET_SLICING_CONFIG: {
2024 request = (MainThreadRequest) msg.obj;
2025 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2026 request.phone.getSlicingConfig(onCompleted);
2027 break;
2028 }
2029 case EVENT_GET_SLICING_CONFIG_DONE: {
2030 ar = (AsyncResult) msg.obj;
2031 request = (MainThreadRequest) ar.userObj;
2032 ResultReceiver result = (ResultReceiver) request.argument;
2033
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002034 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002035 Bundle bundle = new Bundle();
2036 int resultCode = 0;
2037 if (ar.exception != null) {
2038 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2039 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002040 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002041 } else if (ar.result == null) {
2042 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002043 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002044 } else {
2045 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002046 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2047 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002048 }
2049
2050 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002051 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002052 }
2053 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2054 result.send(resultCode, bundle);
2055 notifyRequester(request);
2056 break;
2057 }
2058
Michele Berionne5e411512020-11-13 02:36:59 +00002059 case CMD_PREPARE_UNATTENDED_REBOOT:
2060 request = (MainThreadRequest) msg.obj;
2061 request.result =
2062 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2063 notifyRequester(request);
2064 break;
2065
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 default:
2067 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2068 break;
2069 }
2070 }
Jake Hambye994d462014-02-03 13:10:13 -08002071
Pengquan Menga1bb6272018-09-06 09:59:22 -07002072 private void notifyRequester(MainThreadRequest request) {
2073 synchronized (request) {
2074 request.notifyAll();
2075 }
2076 }
2077
Jake Hambye994d462014-02-03 13:10:13 -08002078 private void handleNullReturnEvent(Message msg, String command) {
2079 AsyncResult ar = (AsyncResult) msg.obj;
2080 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2081 if (ar.exception == null) {
2082 request.result = true;
2083 } else {
2084 request.result = false;
2085 if (ar.exception instanceof CommandException) {
2086 loge(command + ": CommandException: " + ar.exception);
2087 } else {
2088 loge(command + ": Unknown exception");
2089 }
2090 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002091 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
2094
2095 /**
2096 * Posts the specified command to be executed on the main thread,
2097 * waits for the request to complete, and returns the result.
2098 * @see #sendRequestAsync
2099 */
2100 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002101 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2102 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002103 }
2104
2105 /**
2106 * Posts the specified command to be executed on the main thread,
2107 * waits for the request to complete, and returns the result.
2108 * @see #sendRequestAsync
2109 */
2110 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2111 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002112 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002113 }
2114
2115 /**
2116 * Posts the specified command to be executed on the main thread,
2117 * waits for the request to complete, and returns the result.
2118 * @see #sendRequestAsync
2119 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002120 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002121 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2122 }
2123
2124 /**
2125 * Posts the specified command to be executed on the main thread,
2126 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2127 * if not timeout or null otherwise.
2128 * @see #sendRequestAsync
2129 */
2130 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2131 long timeoutInMs) {
2132 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002133 }
2134
2135 /**
2136 * Posts the specified command to be executed on the main thread,
2137 * waits for the request to complete, and returns the result.
2138 * @see #sendRequestAsync
2139 */
Nathan Harold92bed182018-10-12 18:16:49 -07002140 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002141 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002142 }
2143
2144 /**
2145 * Posts the specified command to be executed on the main thread,
2146 * waits for the request to complete, and returns the result.
2147 * @see #sendRequestAsync
2148 */
2149 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002150 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2151 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002152 }
2153
2154 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002155 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2156 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2157 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002158 * @see #sendRequestAsync
2159 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002160 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2161 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2163 throw new RuntimeException("This method will deadlock if called from the main thread.");
2164 }
2165
Nathan Harold92bed182018-10-12 18:16:49 -07002166 MainThreadRequest request = null;
2167 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2168 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2169 } else if (phone != null) {
2170 request = new MainThreadRequest(argument, phone, workSource);
2171 } else {
2172 request = new MainThreadRequest(argument, subId, workSource);
2173 }
2174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 Message msg = mMainThreadHandler.obtainMessage(command, request);
2176 msg.sendToTarget();
2177
Rambo Wang0f050d82021-02-12 11:43:36 -08002178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002180 if (timeoutInMs >= 0) {
2181 // Wait for at least timeoutInMs before returning null request result
2182 long now = SystemClock.elapsedRealtime();
2183 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002184 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002185 try {
2186 request.wait(deadline - now);
2187 } catch (InterruptedException e) {
2188 // Do nothing, go back and check if request is completed or timeout
2189 } finally {
2190 now = SystemClock.elapsedRealtime();
2191 }
2192 }
2193 } else {
2194 // Wait for the request to complete
2195 while (request.result == null) {
2196 try {
2197 request.wait();
2198 } catch (InterruptedException e) {
2199 // Do nothing, go back and wait until the request is complete
2200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 }
2202 }
2203 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002204 if (request.result == null) {
2205 Log.wtf(LOG_TAG,
2206 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 return request.result;
2209 }
2210
2211 /**
2212 * Asynchronous ("fire and forget") version of sendRequest():
2213 * Posts the specified command to be executed on the main thread, and
2214 * returns immediately.
2215 * @see #sendRequest
2216 */
2217 private void sendRequestAsync(int command) {
2218 mMainThreadHandler.sendEmptyMessage(command);
2219 }
2220
2221 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002222 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002223 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002224 */
2225 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002226 sendRequestAsync(command, argument, null, null);
2227 }
2228
2229 /**
2230 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2231 * @see {@link #sendRequest(int,Object)}
2232 */
2233 private void sendRequestAsync(
2234 int command, Object argument, Phone phone, WorkSource workSource) {
2235 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002236 Message msg = mMainThreadHandler.obtainMessage(command, request);
2237 msg.sendToTarget();
2238 }
2239
2240 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 * Initialize the singleton PhoneInterfaceManager instance.
2242 * This is only done once, at startup, from PhoneApp.onCreate().
2243 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002244 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 synchronized (PhoneInterfaceManager.class) {
2246 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002247 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 } else {
2249 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2250 }
2251 return sInstance;
2252 }
2253 }
2254
2255 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002256 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002259 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002260 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002262 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002264 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002265 mTelephonySharedPreferences =
2266 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002267 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002268 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002269 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002270 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002271
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 publish();
2273 }
2274
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 private Phone getDefaultPhone() {
2276 Phone thePhone = getPhone(getDefaultSubscription());
2277 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2278 }
2279
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 private void publish() {
2281 if (DBG) log("publish: " + this);
2282
Peter Wangc035ce42020-01-08 21:00:22 -08002283 TelephonyFrameworkInitializer
2284 .getTelephonyServiceManager()
2285 .getTelephonyServiceRegisterer()
2286 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 }
2288
Stuart Scott584921c2015-01-15 17:10:34 -08002289 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002290 if (request.phone != null) {
2291 return request.phone;
2292 } else {
2293 return getPhoneFromSubId(request.subId);
2294 }
2295 }
2296
2297 private Phone getPhoneFromSubId(int subId) {
2298 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2299 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002300 }
2301
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002302 private UiccPort getUiccPortFromRequest(MainThreadRequest request) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002303 Phone phone = getPhoneFromRequest(request);
2304 return phone == null ? null :
Muralidhar Reddy864fe982021-09-29 19:38:40 +00002305 UiccController.getInstance().getUiccPort(phone.getPhoneId());
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002306 }
2307
Wink Saville36469e72014-06-11 15:17:00 -07002308 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002309 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002310 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312
Kai Shif70f46f2021-03-03 13:59:46 -08002313 private void sendEraseModemConfig(@NonNull Phone phone) {
2314 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2315 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2316 }
2317
2318 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2319 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2320 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002321 }
2322
Peter Wang44b186e2020-01-13 23:33:09 -08002323 private boolean isImsAvailableOnDevice() {
2324 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2325 if (pm == null) {
2326 // For some reason package manger is not available.. This will fail internally anyway,
2327 // so do not throw error and allow.
2328 return true;
2329 }
2330 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2331 }
2332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002334 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
Wink Savilleb564aae2014-10-23 10:18:09 -07002337 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 if (DBG) log("dial: " + number);
2339 // No permission check needed here: This is just a wrapper around the
2340 // ACTION_DIAL intent, which is available to any app since it puts up
2341 // the UI before it does anything.
2342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 String url = createTelUrl(number);
2346 if (url == null) {
2347 return;
2348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350 // PENDING: should we just silently fail if phone is offhook or ringing?
2351 PhoneConstants.State state = mCM.getState(subId);
2352 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2353 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2354 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2355 mApp.startActivity(intent);
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360 }
2361
2362 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002363 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002364 }
2365
Wink Savilleb564aae2014-10-23 10:18:09 -07002366 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 if (DBG) log("call: " + number);
2368
2369 // This is just a wrapper around the ACTION_CALL intent, but we still
2370 // need to do a permission check since we're calling startActivity()
2371 // from the context of the phone app.
2372 enforceCallPermission();
2373
Jordan Liu1617b712019-07-10 15:06:26 -07002374 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 != AppOpsManager.MODE_ALLOWED) {
2376 return;
2377 }
2378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 String url = createTelUrl(number);
2382 if (url == null) {
2383 return;
2384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386 boolean isValid = false;
2387 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2388 if (slist != null) {
2389 for (SubscriptionInfo subInfoRecord : slist) {
2390 if (subInfoRecord.getSubscriptionId() == subId) {
2391 isValid = true;
2392 break;
2393 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002394 }
Wink Saville08874612014-08-31 19:19:58 -07002395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 if (!isValid) {
2397 return;
2398 }
Wink Saville08874612014-08-31 19:19:58 -07002399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002400 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2401 intent.putExtra(SUBSCRIPTION_KEY, subId);
2402 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2403 mApp.startActivity(intent);
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 }
2408
Wink Savilleb564aae2014-10-23 10:18:09 -07002409 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002410 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002411 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2412 }
2413
Wink Savilleb564aae2014-10-23 10:18:09 -07002414 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002415 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002416 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2417 }
2418
Wink Savilleb564aae2014-10-23 10:18:09 -07002419 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421
2422 final long identity = Binder.clearCallingIdentity();
2423 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002424 Phone phone = getPhone(subId);
2425 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426 checkSimPin.start();
2427 return checkSimPin.unlockSim(null, pin);
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435
2436 final long identity = Binder.clearCallingIdentity();
2437 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002438 Phone phone = getPhone(subId);
2439 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440 checkSimPuk.start();
2441 return checkSimPuk.unlockSim(puk, pin);
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
2444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
2447 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002448 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 * a synchronous one.
2450 */
2451 private static class UnlockSim extends Thread {
2452
2453 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002454 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
2456 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002457 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2458 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459
2460 // For replies from SimCard interface
2461 private Handler mHandler;
2462
2463 // For async handler to identify request type
2464 private static final int SUPPLY_PIN_COMPLETE = 100;
2465
Michele Berionne5e411512020-11-13 02:36:59 +00002466 UnlockSim(int phoneId, IccCard simCard) {
2467 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 mSimCard = simCard;
2469 }
2470
2471 @Override
2472 public void run() {
2473 Looper.prepare();
2474 synchronized (UnlockSim.this) {
2475 mHandler = new Handler() {
2476 @Override
2477 public void handleMessage(Message msg) {
2478 AsyncResult ar = (AsyncResult) msg.obj;
2479 switch (msg.what) {
2480 case SUPPLY_PIN_COMPLETE:
2481 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2482 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002483 mRetryCount = msg.arg1;
2484 if (ar.exception != null) {
2485 if (ar.exception instanceof CommandException &&
2486 ((CommandException)(ar.exception)).getCommandError()
2487 == CommandException.Error.PASSWORD_INCORRECT) {
2488 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002489 } //When UiccCardApp dispose,handle message and return exception
2490 else if (ar.exception instanceof CommandException &&
2491 ((CommandException) (ar.exception)).getCommandError()
2492 == CommandException.Error.ABORTED) {
2493 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002494 } else {
2495 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2496 }
2497 } else {
2498 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 mDone = true;
2501 UnlockSim.this.notifyAll();
2502 }
2503 break;
2504 }
2505 }
2506 };
2507 UnlockSim.this.notifyAll();
2508 }
2509 Looper.loop();
2510 }
2511
2512 /*
2513 * Use PIN or PUK to unlock SIM card
2514 *
2515 * If PUK is null, unlock SIM card with PIN
2516 *
2517 * If PUK is not null, unlock SIM card with PUK and set PIN code
2518 */
Wink Saville9de0f752013-10-22 19:04:03 -07002519 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520
2521 while (mHandler == null) {
2522 try {
2523 wait();
2524 } catch (InterruptedException e) {
2525 Thread.currentThread().interrupt();
2526 }
2527 }
2528 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2529
2530 if (puk == null) {
2531 mSimCard.supplyPin(pin, callback);
2532 } else {
2533 mSimCard.supplyPuk(puk, pin, callback);
2534 }
2535
2536 while (!mDone) {
2537 try {
2538 Log.d(LOG_TAG, "wait for done");
2539 wait();
2540 } catch (InterruptedException e) {
2541 // Restore the interrupted status
2542 Thread.currentThread().interrupt();
2543 }
2544 }
2545 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002546 int[] resultArray = new int[2];
2547 resultArray[0] = mResult;
2548 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002549
2550 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002551 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002552 }
2553
Wink Saville9de0f752013-10-22 19:04:03 -07002554 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 }
2556 }
2557
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002558 /**
2559 * This method has been removed due to privacy and stability concerns.
2560 */
2561 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002563 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2564 return;
Wink Saville36469e72014-06-11 15:17:00 -07002565 }
2566
Nathan Harold1f889d82020-06-04 17:05:26 -07002567 @Override
2568 public void updateServiceLocationWithPackageName(String callingPackage) {
2569 mApp.getSystemService(AppOpsManager.class)
2570 .checkPackage(Binder.getCallingUid(), callingPackage);
2571
Nathan Haroldf096d982020-11-18 17:18:06 -08002572 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002573 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2574 // Callers targeting S have no business invoking this method.
2575 return;
2576 }
2577
2578 LocationAccessPolicy.LocationPermissionResult locationResult =
2579 LocationAccessPolicy.checkLocationPermission(mApp,
2580 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2581 .setCallingPackage(callingPackage)
2582 .setCallingFeatureId(null)
2583 .setCallingPid(Binder.getCallingPid())
2584 .setCallingUid(Binder.getCallingUid())
2585 .setMethod("updateServiceLocation")
2586 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2587 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2588 .build());
2589 // Apps that lack location permission have no business calling this method;
2590 // however, because no permission was declared in the public API, denials must
2591 // all be "soft".
2592 switch (locationResult) {
2593 case DENIED_HARD: /* fall through */
2594 case DENIED_SOFT:
2595 return;
2596 }
2597
2598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 final long identity = Binder.clearCallingIdentity();
2600 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002601 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002603 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 }
2605 } finally {
2606 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002608 }
2609
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002610 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002611 @Override
2612 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002613 return isRadioOnWithFeature(callingPackage, null);
2614 }
2615
2616
2617 @Override
2618 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2619 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2620 callingFeatureId);
2621 }
2622
2623 @Deprecated
2624 @Override
2625 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2626 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002627 }
2628
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002629 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2631 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002633 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002634 return false;
2635 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636
2637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 return isRadioOnForSubscriber(subId);
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002643 }
2644
2645 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 final Phone phone = getPhone(subId);
2649 if (phone != null) {
2650 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2651 } else {
2652 return false;
2653 }
2654 } finally {
2655 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
2658
2659 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002660 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 }
Wink Saville36469e72014-06-11 15:17:00 -07002662
Wink Savilleb564aae2014-10-23 10:18:09 -07002663 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665
2666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 final Phone phone = getPhone(subId);
2669 if (phone != null) {
2670 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 }
Wink Saville36469e72014-06-11 15:17:00 -07002675 }
2676
2677 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002678 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002679 }
2680
Wink Savilleb564aae2014-10-23 10:18:09 -07002681 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002682 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 final Phone phone = getPhone(subId);
2687 if (phone == null) {
2688 return false;
2689 }
2690 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2691 toggleRadioOnOffForSubscriber(subId);
2692 }
2693 return true;
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
Wink Saville36469e72014-06-11 15:17:00 -07002698
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002699 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002700 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002701 /*
2702 * If any of the Radios are available, it will need to be
2703 * shutdown. So return true if any Radio is available.
2704 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2708 Phone phone = PhoneFactory.getPhone(i);
2709 if (phone != null && phone.isRadioAvailable()) return true;
2710 }
2711 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2712 return false;
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002715 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 }
2717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002719 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002720 enforceModifyPermission();
2721
2722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2725 logv("Shutting down Phone " + i);
2726 shutdownRadioUsingPhoneId(i);
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002730 }
2731 }
2732
2733 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002734 Phone phone = PhoneFactory.getPhone(phoneId);
2735 if (phone != null && phone.isRadioAvailable()) {
2736 phone.shutdownRadio();
2737 }
2738 }
2739
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742
2743 final long identity = Binder.clearCallingIdentity();
2744 try {
2745 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2746 if (defaultPhone != null) {
2747 defaultPhone.setRadioPower(turnOn);
2748 return true;
2749 } else {
2750 loge("There's no default phone.");
2751 return false;
2752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002755 }
Wink Saville36469e72014-06-11 15:17:00 -07002756 }
2757
Wink Savilleb564aae2014-10-23 10:18:09 -07002758 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 final Phone phone = getPhone(subId);
2764 if (phone != null) {
2765 phone.setRadioPower(turnOn);
2766 return true;
2767 } else {
2768 return false;
2769 }
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002773 }
2774
Wink Saville36469e72014-06-11 15:17:00 -07002775 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 public boolean enableDataConnectivity() {
2778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779
2780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 int subId = mSubscriptionController.getDefaultDataSubId();
2783 final Phone phone = getPhone(subId);
2784 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002785 phone.getDataEnabledSettings().setDataEnabled(
2786 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 return true;
2788 } else {
2789 return false;
2790 }
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 }
2795
Wink Saville36469e72014-06-11 15:17:00 -07002796 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002797 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 public boolean disableDataConnectivity() {
2799 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 int subId = mSubscriptionController.getDefaultDataSubId();
2804 final Phone phone = getPhone(subId);
2805 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002806 phone.getDataEnabledSettings().setDataEnabled(
2807 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002808 return true;
2809 } else {
2810 return false;
2811 }
2812 } finally {
2813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 }
2816
Sanket Padawe356d7632015-06-22 14:03:32 -07002817 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002818 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 final Phone phone = getPhone(subId);
2822 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002823 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 } else {
2825 return false;
2826 }
2827 } finally {
2828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002830 }
2831
2832 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002833 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002834 }
2835
pkanwarae03a6b2016-11-06 20:37:09 -08002836 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837 enforceCallPermission();
2838
2839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2842 return;
2843 }
2844 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2845 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
2848 }
pkanwar32d516d2016-10-14 19:37:38 -07002849 };
2850
Wink Savilleb564aae2014-10-23 10:18:09 -07002851 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853
2854 final long identity = Binder.clearCallingIdentity();
2855 try {
2856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2857 return false;
2858 }
2859 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002862 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002863 }
2864
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002865 /**
2866 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2867 * tag on getCallState Binder call.
2868 */
2869 @Deprecated
2870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002871 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002872 if (CompatChanges.isChangeEnabled(
2873 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2874 Binder.getCallingUid())) {
2875 // Do not allow this API to be called on API version 31+, it should only be
2876 // called on old apps using this Binder call directly.
2877 throw new SecurityException("This method can only be used for applications "
2878 + "targeting API version 30 or less.");
2879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 final long identity = Binder.clearCallingIdentity();
2881 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002882 Phone phone = getPhone(getDefaultSubscription());
2883 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2884 PhoneConstantConversions.convertCallState(phone.getState());
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
2888 }
2889
2890 @Override
2891 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2892 if (CompatChanges.isChangeEnabled(
2893 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2894 Binder.getCallingUid())) {
2895 // Check READ_PHONE_STATE for API version 31+
2896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2897 featureId, "getCallStateForSubscription")) {
2898 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2899 + "targeting API level 31+.");
2900 }
2901 }
2902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2906 PhoneConstantConversions.convertCallState(phone.getState());
2907 } finally {
2908 Binder.restoreCallingIdentity(identity);
2909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002910 }
2911
Sanket Padawe356d7632015-06-22 14:03:32 -07002912 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002913 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002914 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2915 }
2916
2917 @Override
2918 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 final long identity = Binder.clearCallingIdentity();
2920 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002921 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002922 if (phone != null) {
2923 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2924 } else {
2925 return PhoneConstantConversions.convertDataState(
2926 PhoneConstants.DataState.DISCONNECTED);
2927 }
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
Sanket Padawe356d7632015-06-22 14:03:32 -07002933 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002934 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002935 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2936 }
2937
2938 @Override
2939 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 final long identity = Binder.clearCallingIdentity();
2941 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002942 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943 if (phone != null) {
2944 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2945 } else {
2946 return TelephonyManager.DATA_ACTIVITY_NONE;
2947 }
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 }
2952
2953 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002954 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002956 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002957
2958 LocationAccessPolicy.LocationPermissionResult locationResult =
2959 LocationAccessPolicy.checkLocationPermission(mApp,
2960 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2961 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002962 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002963 .setCallingPid(Binder.getCallingPid())
2964 .setCallingUid(Binder.getCallingUid())
2965 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002966 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002967 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2968 .build());
2969 switch (locationResult) {
2970 case DENIED_HARD:
2971 throw new SecurityException("Not allowed to access cell location");
2972 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002973 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2974 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
2976
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002977 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002981 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002982 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Svetoslav64fad262015-04-14 14:35:21 -07002986 }
2987
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002988 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002989 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002990 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2991 // registered cell info, so return a NULL country instead.
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002994 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2995 // Get default phone in this case.
2996 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2997 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002998 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003000 if (phone == null) return "";
3001 ServiceStateTracker sst = phone.getServiceStateTracker();
3002 if (sst == null) return "";
3003 LocaleTracker lt = sst.getLocaleTracker();
3004 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003005 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003009 }
3010
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003011 /**
3012 * This method was removed due to potential issues caused by performing partial
3013 * updates of service state, and lack of a credible use case.
3014 *
3015 * This has the ability to break the telephony implementation by disabling notification of
3016 * changes in device connectivity. DO NOT USE THIS!
3017 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003018 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 public void enableLocationUpdates() {
3020 mApp.enforceCallingOrSelfPermission(
3021 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003022 }
3023
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003024 /**
3025 * This method was removed due to potential issues caused by performing partial
3026 * updates of service state, and lack of a credible use case.
3027 *
3028 * This has the ability to break the telephony implementation by disabling notification of
3029 * changes in device connectivity. DO NOT USE THIS!
3030 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 @Override
3032 public void disableLocationUpdates() {
3033 mApp.enforceCallingOrSelfPermission(
3034 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003035 }
3036
3037 @Override
3038 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003039 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3040 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08003041 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003042 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3043 throw new SecurityException(
3044 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3045 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003046
Jordan Liu1617b712019-07-10 15:06:26 -07003047 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3049 return null;
3050 }
Svetoslav64fad262015-04-14 14:35:21 -07003051
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003052 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003054 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003055 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056
Nathan Haroldf180aac2018-06-01 18:43:55 -07003057 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3058 for (CellInfo ci : info) {
3059 if (ci instanceof CellInfoGsm) {
3060 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3061 } else if (ci instanceof CellInfoWcdma) {
3062 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003065 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 }
3067
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003068 private List<CellInfo> getCachedCellInfo() {
3069 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3070 for (Phone phone : PhoneFactory.getPhones()) {
3071 List<CellInfo> info = phone.getAllCellInfo();
3072 if (info != null) cellInfos.addAll(info);
3073 }
3074 return cellInfos;
3075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003076
3077 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003078 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003079 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003080 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003081
3082 LocationAccessPolicy.LocationPermissionResult locationResult =
3083 LocationAccessPolicy.checkLocationPermission(mApp,
3084 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3085 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003086 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003087 .setCallingPid(Binder.getCallingPid())
3088 .setCallingUid(Binder.getCallingUid())
3089 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003090 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003091 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3092 .build());
3093 switch (locationResult) {
3094 case DENIED_HARD:
3095 throw new SecurityException("Not allowed to access cell info");
3096 case DENIED_SOFT:
3097 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 }
3099
Nathan Haroldf096d982020-11-18 17:18:06 -08003100 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003101 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3102 return getCachedCellInfo();
3103 }
3104
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003105 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003106 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3110 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003111 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003112 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113 if (info != null) cellInfos.addAll(info);
3114 }
3115 return cellInfos;
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003118 }
3119 }
3120
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003121 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003122 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3123 String callingFeatureId) {
3124 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3125 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003126 }
3127
3128 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003129 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3130 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003131 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003132 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003133 }
3134
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003135 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3136 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003137 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003138 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003139
3140 LocationAccessPolicy.LocationPermissionResult locationResult =
3141 LocationAccessPolicy.checkLocationPermission(mApp,
3142 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3143 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003144 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003145 .setCallingPid(Binder.getCallingPid())
3146 .setCallingUid(Binder.getCallingUid())
3147 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003148 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3149 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003150 .build());
3151 switch (locationResult) {
3152 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003153 if (TelephonyPermissions
3154 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003155 // Safetynet logging for b/154934934
3156 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3157 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003158 throw new SecurityException("Not allowed to access cell info");
3159 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003160 if (TelephonyPermissions
3161 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003162 // Safetynet logging for b/154934934
3163 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3164 }
Nathan Harold5320c422019-05-09 10:26:08 -07003165 try {
3166 cb.onCellInfo(new ArrayList<CellInfo>());
3167 } catch (RemoteException re) {
3168 // Drop without consequences
3169 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003170 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003171 }
3172
Nathan Harolda939a962019-05-09 10:13:47 -07003173
3174 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003175 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3176
3177 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3178 }
3179
3180 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003181 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003182 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003183 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003187 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 }
3192
Shishir Agrawala9f32182016-04-12 12:00:16 -07003193 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003194 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003195 Phone phone = PhoneFactory.getPhone(slotIndex);
3196 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003197 return null;
3198 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003199 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003200 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003201 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003202 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003203 return null;
3204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003205
3206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 return phone.getImei();
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003212 }
3213
3214 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003215 public String getTypeAllocationCodeForSlot(int slotIndex) {
3216 Phone phone = PhoneFactory.getPhone(slotIndex);
3217 String tac = null;
3218 if (phone != null) {
3219 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003220 try {
3221 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3222 } catch (IndexOutOfBoundsException e) {
3223 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3224 return null;
3225 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003226 }
3227 return tac;
3228 }
3229
3230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003231 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003232 Phone phone = PhoneFactory.getPhone(slotIndex);
3233 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003234 return null;
3235 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003236
Jeff Davidson913390f2018-02-23 17:11:49 -08003237 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003238 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003239 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003240 return null;
3241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003242
3243 final long identity = Binder.clearCallingIdentity();
3244 try {
3245 return phone.getMeid();
3246 } finally {
3247 Binder.restoreCallingIdentity(identity);
3248 }
Jack Yu2af8d712017-03-15 17:14:14 -07003249 }
3250
3251 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003252 public String getManufacturerCodeForSlot(int slotIndex) {
3253 Phone phone = PhoneFactory.getPhone(slotIndex);
3254 String manufacturerCode = null;
3255 if (phone != null) {
3256 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003257 try {
3258 manufacturerCode =
3259 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3260 } catch (IndexOutOfBoundsException e) {
3261 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3262 return null;
3263 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003264 }
3265 return manufacturerCode;
3266 }
3267
3268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003269 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3270 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003271 Phone phone = PhoneFactory.getPhone(slotIndex);
3272 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003273 return null;
3274 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003275 int subId = phone.getSubId();
3276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003277 mApp, subId, callingPackage, callingFeatureId,
3278 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003279 return null;
3280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 return phone.getDeviceSvn();
3285 } finally {
3286 Binder.restoreCallingIdentity(identity);
3287 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003288 }
3289
fionaxu43304da2017-11-27 22:51:16 -08003290 @Override
3291 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 final Phone phone = getPhone(subId);
3295 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
fionaxu43304da2017-11-27 22:51:16 -08003299 }
3300
3301 @Override
3302 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 final long identity = Binder.clearCallingIdentity();
3304 try {
3305 final Phone phone = getPhone(subId);
3306 return phone == null ? null : phone.getCarrierName();
3307 } finally {
3308 Binder.restoreCallingIdentity(identity);
3309 }
fionaxu43304da2017-11-27 22:51:16 -08003310 }
3311
calvinpanffe225e2018-11-01 19:43:06 +08003312 @Override
chen xu0026ca62019-03-06 15:28:50 -08003313 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 final Phone phone = getPhone(subId);
3317 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003318 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
3322 }
3323
3324 @Override
chen xu0026ca62019-03-06 15:28:50 -08003325 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003329 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
3333 }
3334
chen xu651eec72018-11-11 19:03:44 -08003335 @Override
chen xu864e11c2018-12-06 22:10:03 -08003336 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3337 if (!isSubscriptionMccMnc) {
3338 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3339 }
chen xu651eec72018-11-11 19:03:44 -08003340 final Phone phone = PhoneFactory.getPhone(slotIndex);
3341 if (phone == null) {
3342 return TelephonyManager.UNKNOWN_CARRIER_ID;
3343 }
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
3349 }
3350 }
3351
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003352 //
3353 // Internal helper methods.
3354 //
3355
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003356 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003357 * Make sure the caller is the calling package itself
3358 *
3359 * @throws SecurityException if the caller is not the calling package
3360 */
3361 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3362 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003363 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3364 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003365 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003366 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003367 } catch (PackageManager.NameNotFoundException e) {
3368 // packageUid is -1
3369 }
3370 if (packageUid != callingUid) {
3371 throw new SecurityException(message + ": Package " + callingPackage
3372 + " does not belong to " + callingUid);
3373 }
3374 }
3375
3376 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003377 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3378 *
3379 * @throws SecurityException if the caller does not have the required permission
3380 */
3381 private void enforceModifyPermission() {
3382 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3383 }
3384
Shuo Qian3b6ee772019-11-13 17:43:31 -08003385 private void enforceActiveEmergencySessionPermission() {
3386 mApp.enforceCallingOrSelfPermission(
3387 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3388 }
3389
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 /**
3391 * Make sure the caller has the CALL_PHONE permission.
3392 *
3393 * @throws SecurityException if the caller does not have the required permission
3394 */
3395 private void enforceCallPermission() {
3396 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3397 }
3398
paulhu5a773602019-08-23 19:17:33 +08003399 private void enforceSettingsPermission() {
3400 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003401 }
3402
Michele Berionne5e411512020-11-13 02:36:59 +00003403 private void enforceRebootPermission() {
3404 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3405 }
3406
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003407 private String createTelUrl(String number) {
3408 if (TextUtils.isEmpty(number)) {
3409 return null;
3410 }
3411
Jake Hambye994d462014-02-03 13:10:13 -08003412 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 }
3414
Ihab Awadf9e92732013-12-05 18:02:52 -08003415 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003416 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3417 }
3418
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003419 private static void logv(String msg) {
3420 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3421 }
3422
Ihab Awadf9e92732013-12-05 18:02:52 -08003423 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003424 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3425 }
3426
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003427 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003429 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003430 }
3431
Sanket Padawe356d7632015-06-22 14:03:32 -07003432 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003433 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 final Phone phone = PhoneFactory.getPhone(slotIndex);
3437 if (phone == null) {
3438 return PhoneConstants.PHONE_TYPE_NONE;
3439 } else {
3440 return phone.getPhoneType();
3441 }
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446
3447 /**
3448 * Returns the CDMA ERI icon index to display
3449 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003450 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003451 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3452 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3453 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003454 }
3455
Sanket Padawe356d7632015-06-22 14:03:32 -07003456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003457 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3458 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003460 mApp, subId, callingPackage, callingFeatureId,
3461 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003462 return -1;
3463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464
3465 final long identity = Binder.clearCallingIdentity();
3466 try {
3467 final Phone phone = getPhone(subId);
3468 if (phone != null) {
3469 return phone.getCdmaEriIconIndex();
3470 } else {
3471 return -1;
3472 }
3473 } finally {
3474 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003475 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003476 }
3477
3478 /**
3479 * Returns the CDMA ERI icon mode,
3480 * 0 - ON
3481 * 1 - FLASHING
3482 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003483 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003484 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3485 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3486 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003487 }
3488
Sanket Padawe356d7632015-06-22 14:03:32 -07003489 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003490 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3491 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003493 mApp, subId, callingPackage, callingFeatureId,
3494 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003495 return -1;
3496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003497
3498 final long identity = Binder.clearCallingIdentity();
3499 try {
3500 final Phone phone = getPhone(subId);
3501 if (phone != null) {
3502 return phone.getCdmaEriIconMode();
3503 } else {
3504 return -1;
3505 }
3506 } finally {
3507 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003508 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003509 }
3510
3511 /**
3512 * Returns the CDMA ERI text,
3513 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003515 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3516 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3517 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003518 }
3519
Sanket Padawe356d7632015-06-22 14:03:32 -07003520 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003521 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3522 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003524 mApp, subId, callingPackage, callingFeatureId,
3525 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003526 return null;
3527 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 final Phone phone = getPhone(subId);
3532 if (phone != null) {
3533 return phone.getCdmaEriText();
3534 } else {
3535 return null;
3536 }
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003540 }
3541
3542 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003543 * Returns the CDMA MDN.
3544 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003545 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003546 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3548 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003553 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554 return phone.getLine1Number();
3555 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003556 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557 return null;
3558 }
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003561 }
3562 }
3563
3564 /**
3565 * Returns the CDMA MIN.
3566 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003567 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003568 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3570 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571
3572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 final Phone phone = getPhone(subId);
3575 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3576 return phone.getCdmaMin();
3577 } else {
3578 return null;
3579 }
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003582 }
3583 }
3584
Hall Liud892bec2018-11-30 14:51:45 -08003585 @Override
3586 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3587 INumberVerificationCallback callback, String callingPackage) {
3588 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3589 != PERMISSION_GRANTED) {
3590 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3591 }
3592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3593
3594 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3595 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003596 throw new SecurityException("Calling package must be configured in the device config: "
3597 + "calling package: " + callingPackage
3598 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003599 }
3600
3601 if (range == null) {
3602 throw new NullPointerException("Range must be non-null");
3603 }
3604
3605 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003606 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003607
3608 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3609 }
3610
Junda Liuca05d5d2014-08-14 22:36:34 -07003611 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003612 * Returns true if CDMA provisioning needs to run.
3613 */
3614 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003615 final long identity = Binder.clearCallingIdentity();
3616 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003617 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003621 }
3622
3623 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003624 * Sets the voice mail number of a given subId.
3625 */
3626 @Override
3627 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003628 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3629 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630
3631 final long identity = Binder.clearCallingIdentity();
3632 try {
3633 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3634 new Pair<String, String>(alphaTag, number), new Integer(subId));
3635 return success;
3636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003639 }
3640
Ta-wei Yen87c49842016-05-13 21:19:52 -07003641 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003642 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003644 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3645 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003646 if (!TextUtils.equals(callingPackage, systemDialer)) {
3647 throw new SecurityException("caller must be system dialer");
3648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649
3650 final long identity = Binder.clearCallingIdentity();
3651 try {
3652 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3653 if (phoneAccountHandle == null) {
3654 return null;
3655 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 } finally {
3658 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003659 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003660 }
3661
3662 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003663 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3664 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003667 mApp, subId, callingPackage, callingFeatureId,
3668 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003669 return null;
3670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003672 final long identity = Binder.clearCallingIdentity();
3673 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003674 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003675 } finally {
3676 Binder.restoreCallingIdentity(identity);
3677 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003678 }
3679
3680 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003681 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3682 VisualVoicemailSmsFilterSettings settings) {
3683 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003688 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689 } finally {
3690 Binder.restoreCallingIdentity(identity);
3691 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003692 }
3693
3694 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003695 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003697
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003701 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003705 }
3706
3707 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003708 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3709 String callingPackage, int subId) {
3710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711
3712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003715 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003719 }
3720
3721 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003722 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003732 }
3733
3734 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003735 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3736 String callingAttributionTag, int subId, String number, int port, String text,
3737 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003739 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003740 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003741 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003742 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3743 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003744 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003745
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003746 /**
fionaxu0152e512016-11-14 13:36:14 -08003747 * Sets the voice activation state of a given subId.
3748 */
3749 @Override
3750 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3752 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753
3754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 final Phone phone = getPhone(subId);
3757 if (phone != null) {
3758 phone.setVoiceActivationState(activationState);
3759 } else {
3760 loge("setVoiceActivationState fails with invalid subId: " + subId);
3761 }
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003764 }
3765 }
3766
3767 /**
3768 * Sets the data activation state of a given subId.
3769 */
3770 @Override
3771 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3773 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774
3775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 final Phone phone = getPhone(subId);
3778 if (phone != null) {
3779 phone.setDataActivationState(activationState);
3780 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003781 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003782 }
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003785 }
3786 }
3787
3788 /**
3789 * Returns the voice activation state of a given subId.
3790 */
3791 @Override
3792 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794
fionaxu0152e512016-11-14 13:36:14 -08003795 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 if (phone != null) {
3799 return phone.getVoiceActivationState();
3800 } else {
3801 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3802 }
3803 } finally {
3804 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003805 }
3806 }
3807
3808 /**
3809 * Returns the data activation state of a given subId.
3810 */
3811 @Override
3812 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003813 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814
fionaxu0152e512016-11-14 13:36:14 -08003815 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816 final long identity = Binder.clearCallingIdentity();
3817 try {
3818 if (phone != null) {
3819 return phone.getDataActivationState();
3820 } else {
3821 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3822 }
3823 } finally {
3824 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003825 }
3826 }
3827
3828 /**
Wink Saville36469e72014-06-11 15:17:00 -07003829 * Returns the unread count of voicemails for a subId
3830 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003832 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3833 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003835 mApp, subId, callingPackage, callingFeatureId,
3836 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003837 return 0;
3838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 final Phone phone = getPhone(subId);
3842 if (phone != null) {
3843 return phone.getVoiceMessageCount();
3844 } else {
3845 return 0;
3846 }
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003850 }
3851
3852 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003853 * returns true, if the device is in a state where both voice and data
3854 * are supported simultaneously. This can change based on location or network condition.
3855 */
3856 @Override
3857 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003858 final long identity = Binder.clearCallingIdentity();
3859 try {
3860 final Phone phone = getPhone(subId);
3861 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3862 } finally {
3863 Binder.restoreCallingIdentity(identity);
3864 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003865 }
3866
3867 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003868 * Send the dialer code if called from the current default dialer or the caller has
3869 * carrier privilege.
3870 * @param inputCode The dialer code to send
3871 */
3872 @Override
3873 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003874 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003875 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003876 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3877 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003878 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003879 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003880 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882
3883 final long identity = Binder.clearCallingIdentity();
3884 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003885 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 } finally {
3887 Binder.restoreCallingIdentity(identity);
3888 }
fionaxu235cc5e2017-03-06 22:25:57 -08003889 }
3890
Pengquan Menga1bb6272018-09-06 09:59:22 -07003891 @Override
3892 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003893 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003894 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003895 mApp, subId, "getNetworkSelectionMode");
3896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 if (!isActiveSubscription(subId)) {
3899 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3900 }
3901 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003904 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003905 }
3906
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003908 public boolean isInEmergencySmsMode() {
3909 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3910 final long identity = Binder.clearCallingIdentity();
3911 try {
3912 for (Phone phone : PhoneFactory.getPhones()) {
3913 if (phone.isInEmergencySmsMode()) {
3914 return true;
3915 }
3916 }
3917 } finally {
3918 Binder.restoreCallingIdentity(identity);
3919 }
3920 return false;
3921 }
3922
shilu366312e2019-12-17 09:28:10 -08003923 /**
3924 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3925 * @param subId The subscription to use to check the configuration.
3926 * @param c The callback that will be used to send the result.
3927 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003928 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003929 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3930 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003931 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003932 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003933
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003934 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3935 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3936 "IMS not available on device.");
3937 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 final long token = Binder.clearCallingIdentity();
3939 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003940 int slotId = getSlotIndexOrException(subId);
3941 verifyImsMmTelConfiguredOrThrow(slotId);
3942 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003943 } catch (ImsException e) {
3944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 } finally {
3946 Binder.restoreCallingIdentity(token);
3947 }
3948 }
3949
shilu366312e2019-12-17 09:28:10 -08003950 /**
3951 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3952 * @param subId The subscription to use to check the configuration.
3953 * @param c The callback that will be used to send the result.
3954 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003956 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003957 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003958 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003959 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3960 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3961 }
Meng Wangafbc5852019-09-19 17:37:13 -07003962 final long token = Binder.clearCallingIdentity();
3963 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003964 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3965 .removeRegistrationCallbackForSubscription(c, subId);
3966 } catch (ImsException e) {
3967 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3968 + "is inactive, ignoring unregister.");
3969 // If the subscription is no longer active, just return, since the callback
3970 // will already have been removed internally.
3971 } finally {
3972 Binder.restoreCallingIdentity(token);
3973 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 }
3975
Brad Ebingera34a6c22019-10-22 17:36:18 -07003976 /**
3977 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3978 */
3979 @Override
3980 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3981 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3982 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3983 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3984 "IMS not available on device.");
3985 }
3986 final long token = Binder.clearCallingIdentity();
3987 try {
3988 Phone phone = getPhone(subId);
3989 if (phone == null) {
3990 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3991 + subId + "'");
3992 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3993 }
3994 phone.getImsRegistrationState(regState -> {
3995 try {
3996 consumer.accept((regState == null)
3997 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3998 } catch (RemoteException e) {
3999 // Ignore if the remote process is no longer available to call back.
4000 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4001 }
4002 });
4003 } finally {
4004 Binder.restoreCallingIdentity(token);
4005 }
4006 }
4007
4008 /**
4009 * Get the transport type for the IMS service registration state.
4010 */
4011 @Override
4012 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004013 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004014 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004015 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4016 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4017 "IMS not available on device.");
4018 }
4019 final long token = Binder.clearCallingIdentity();
4020 try {
4021 Phone phone = getPhone(subId);
4022 if (phone == null) {
4023 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4024 + subId + "'");
4025 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4026 }
4027 phone.getImsRegistrationTech(regTech -> {
4028 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4029 int regTechConverted = (regTech == null)
4030 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4031 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4032 regTechConverted);
4033 try {
4034 consumer.accept(regTechConverted);
4035 } catch (RemoteException e) {
4036 // Ignore if the remote process is no longer available to call back.
4037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4038 }
4039 });
4040 } finally {
4041 Binder.restoreCallingIdentity(token);
4042 }
4043 }
4044
shilu366312e2019-12-17 09:28:10 -08004045 /**
4046 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4047 * @param subId The subscription to use to check the configuration.
4048 * @param c The callback that will be used to send the result.
4049 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004051 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4052 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004053 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004054 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004055 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4056 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4057 "IMS not available on device.");
4058 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 final long token = Binder.clearCallingIdentity();
4060 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004061 int slotId = getSlotIndexOrException(subId);
4062 verifyImsMmTelConfiguredOrThrow(slotId);
4063 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004064 } catch (ImsException e) {
4065 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 } finally {
4067 Binder.restoreCallingIdentity(token);
4068 }
4069 }
4070
shilu366312e2019-12-17 09:28:10 -08004071 /**
4072 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4073 * @param subId The subscription to use to check the configuration.
4074 * @param c The callback that will be used to send the result.
4075 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004077 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004078 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004079 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004080 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4081 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4082 }
Meng Wangafbc5852019-09-19 17:37:13 -07004083
4084 final long token = Binder.clearCallingIdentity();
4085 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004086 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004087 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004088 } catch (ImsException e) {
4089 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4090 + "is inactive, ignoring unregister.");
4091 // If the subscription is no longer active, just return, since the callback
4092 // will already have been removed internally.
4093 } finally {
4094 Binder.restoreCallingIdentity(token);
4095 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004096 }
4097
4098 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004099 public boolean isCapable(int subId, int capability, int regTech) {
4100 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 final long token = Binder.clearCallingIdentity();
4102 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004103 int slotId = getSlotIndexOrException(subId);
4104 verifyImsMmTelConfiguredOrThrow(slotId);
4105 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004106 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4108 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004109 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004110 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4111 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 } finally {
4113 Binder.restoreCallingIdentity(token);
4114 }
4115 }
4116
4117 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004118 public boolean isAvailable(int subId, int capability, int regTech) {
4119 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004120 final long token = Binder.clearCallingIdentity();
4121 try {
4122 Phone phone = getPhone(subId);
4123 if (phone == null) return false;
4124 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004125 } catch (com.android.ims.ImsException e) {
4126 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4127 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 } finally {
4129 Binder.restoreCallingIdentity(token);
4130 }
4131 }
4132
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004133 /**
4134 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4135 * subscription.
4136 * @param subId The subscription to use to check the configuration.
4137 * @param callback The callback that will be used to send the result.
4138 * @param capability The MmTelFeature capability that will be used to send the result.
4139 * @param transportType The transport type of the MmTelFeature capability.
4140 */
4141 @Override
4142 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4143 int transportType) {
4144 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4145 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4146 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4147 "IMS not available on device.");
4148 }
4149 final long token = Binder.clearCallingIdentity();
4150 try {
4151 int slotId = getSlotIndex(subId);
4152 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4153 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4154 + subId + "'");
4155 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4156 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004157 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004158 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4159 transportType, aBoolean -> {
4160 try {
4161 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4162 } catch (RemoteException e) {
4163 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4164 + "running. Ignore");
4165 }
4166 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004167 } catch (ImsException e) {
4168 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004169 } finally {
4170 Binder.restoreCallingIdentity(token);
4171 }
4172 }
4173
shilu366312e2019-12-17 09:28:10 -08004174 /**
4175 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4176 * @param subId The subscription to use to check the configuration.
4177 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 @Override
4179 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004180 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004181 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004182
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 final long token = Binder.clearCallingIdentity();
4184 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004185 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004186 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004187 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004188 } catch (ImsException e) {
4189 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 } finally {
4191 Binder.restoreCallingIdentity(token);
4192 }
4193 }
4194
4195 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004196 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004198 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 final long identity = Binder.clearCallingIdentity();
4200 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004201 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004202 // This setting doesn't require an active ImsService connection, so do not verify. The
4203 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004204 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (ImsException e) {
4206 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
4210 }
4211
shilu366312e2019-12-17 09:28:10 -08004212 /**
4213 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4214 * @param subId The subscription to use to check the configuration.
4215 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004217 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004218 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004219 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 final long identity = Binder.clearCallingIdentity();
4221 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004222 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004223 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004224 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004225 } catch (ImsException e) {
4226 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
4230 }
4231
4232 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004233 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004235 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 final long identity = Binder.clearCallingIdentity();
4237 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004238 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004239 // This setting doesn't require an active ImsService connection, so do not verify. The
4240 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004241 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
shilu366312e2019-12-17 09:28:10 -08004249 /**
4250 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4251 * @param subId The subscription to use to check the configuration.
4252 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 @Override
4254 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004255 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004256 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 final long identity = Binder.clearCallingIdentity();
4258 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004259 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004260 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004262 } catch (ImsException e) {
4263 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
4267 }
4268
4269 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004270 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004272 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004275 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004276 // This setting doesn't require an active ImsService connection, so do not verify. The
4277 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004279 } catch (ImsException e) {
4280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
4284 }
4285
shilu366312e2019-12-17 09:28:10 -08004286 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004287 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4288 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4289 * @param subId The subscription to use to check the configuration.
4290 */
4291 @Override
4292 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004293 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004294 mApp, subId, "isCrossSimCallingEnabledByUser");
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
4302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
4305 }
4306
4307 /**
4308 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4309 * Requires MODIFY_PHONE_STATE permission.
4310 * @param subId The subscription to use to check the configuration.
4311 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4312 * false otherwise
4313 */
4314 @Override
4315 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4317 "setCrossSimCallingEnabled");
4318 final long identity = Binder.clearCallingIdentity();
4319 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004320 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004321 // This setting doesn't require an active ImsService connection, so do not verify. The
4322 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004323 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004324 } catch (ImsException e) {
4325 throw new ServiceSpecificException(e.getCode());
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
4329 }
4330
4331 /**
shilu366312e2019-12-17 09:28:10 -08004332 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4333 * @param subId The subscription to use to check the configuration.
4334 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004336
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004338 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004339 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 final long identity = Binder.clearCallingIdentity();
4341 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004342 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004343 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004344 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004345 } catch (ImsException e) {
4346 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
4350 }
4351
4352 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004353 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004355 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 final long identity = Binder.clearCallingIdentity();
4357 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004359 // This setting doesn't require an active ImsService connection, so do not verify. The
4360 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004362 } catch (ImsException e) {
4363 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
4367 }
4368
4369 @Override
4370 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4372 "setVoWiFiNonPersistent");
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004375 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004376 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004377 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004378 } catch (ImsException e) {
4379 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
4383 }
4384
shilu366312e2019-12-17 09:28:10 -08004385 /**
4386 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4387 * @param subId The subscription to use to check the configuration.
4388 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004389 @Override
4390 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004391 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004392 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004393 final long identity = Binder.clearCallingIdentity();
4394 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004395 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004396 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004397 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004398 } catch (ImsException e) {
4399 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004400 } finally {
4401 Binder.restoreCallingIdentity(identity);
4402 }
4403 }
4404
4405 @Override
4406 public void setVoWiFiModeSetting(int subId, int mode) {
4407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4408 "setVoWiFiModeSetting");
4409 final long identity = Binder.clearCallingIdentity();
4410 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004412 // This setting doesn't require an active ImsService connection, so do not verify. The
4413 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004414 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004415 } catch (ImsException e) {
4416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
4420 }
4421
4422 @Override
4423 public int getVoWiFiRoamingModeSetting(int subId) {
4424 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4425 final long identity = Binder.clearCallingIdentity();
4426 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004427 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004428 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004429 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004430 } catch (ImsException e) {
4431 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
4435 }
4436
4437 @Override
4438 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4440 "setVoWiFiRoamingModeSetting");
4441 final long identity = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004444 // This setting doesn't require an active ImsService connection, so do not verify. The
4445 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004446 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004447 } catch (ImsException e) {
4448 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
4452 }
4453
4454 @Override
4455 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4457 "setRttCapabilityEnabled");
4458 final long identity = Binder.clearCallingIdentity();
4459 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004460 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004461 // This setting doesn't require an active ImsService connection, so do not verify. The
4462 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004463 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004464 } catch (ImsException e) {
4465 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
shilu366312e2019-12-17 09:28:10 -08004471 /**
4472 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4473 * @param subId The subscription to use to check the configuration.
4474 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004475 @Override
4476 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004477 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004478 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004479 final long identity = Binder.clearCallingIdentity();
4480 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004481 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004482 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004484 } catch (ImsException e) {
4485 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
4489 }
4490
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004491 @Override
4492 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4493 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4494 final long identity = Binder.clearCallingIdentity();
4495 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004496 if (!isImsAvailableOnDevice()) {
4497 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4498 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004499 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004500 int slotId = getSlotIndexOrException(subId);
4501 verifyImsMmTelConfiguredOrThrow(slotId);
4502 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004503 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004504 } catch (ImsException e) {
4505 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
4509 }
4510
4511 @Override
4512 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4513 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4514 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004515 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4516 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4517 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004518 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004519 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004520 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004521 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004522 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4523 + "is inactive, ignoring unregister.");
4524 // If the subscription is no longer active, just return, since the callback will already
4525 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
4529 }
4530
allenwtsu99c623b2020-01-03 18:24:23 +08004531
4532 private void checkModifyPhoneStatePermission(int subId, String message) {
4533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4534 message);
4535 }
4536
4537 private boolean isImsProvisioningRequired(int subId, int capability,
4538 boolean isMmtelCapability) {
4539 Phone phone = getPhone(subId);
4540 if (phone == null) {
4541 loge("phone instance null for subid " + subId);
4542 return false;
4543 }
4544 if (isMmtelCapability) {
4545 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4546 return false;
4547 }
4548 } else {
4549 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4550 return false;
4551 }
4552 }
4553 return true;
4554 }
4555
4556 @Override
4557 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4558 boolean isProvisioned) {
4559 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4560
4561 final long identity = Binder.clearCallingIdentity();
4562 try {
4563 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4564 if (!isImsProvisioningRequired(subId, capability, false)) {
4565 return;
4566 }
4567
4568 // this capability requires provisioning, route to the correct API.
4569 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4570 switch (capability) {
4571 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4572 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4573 ims.setEabProvisioned(isProvisioned);
4574 break;
4575 default: {
4576 throw new IllegalArgumentException("Tried to set provisioning for "
4577 + "rcs capability '" + capability + "', which does not require "
4578 + "provisioning.");
4579 }
4580 }
4581 } finally {
4582 Binder.restoreCallingIdentity(identity);
4583 }
4584
4585 }
4586
4587
4588 @Override
4589 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4590 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4594 if (!isImsProvisioningRequired(subId, capability, false)) {
4595 return true;
4596 }
4597
4598 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4599 switch (capability) {
4600 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4601 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4602 return ims.isEabProvisionedOnDevice();
4603
4604 default: {
4605 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4606 + "capability '" + capability + "', which does not require "
4607 + "provisioning.");
4608 }
4609 }
4610
4611 } finally {
4612 Binder.restoreCallingIdentity(identity);
4613 }
4614 }
4615
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004616 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004617 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4618 boolean isProvisioned) {
4619 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004620 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4621 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4622 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004623 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4624 }
allenwtsu99c623b2020-01-03 18:24:23 +08004625 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004626 final long identity = Binder.clearCallingIdentity();
4627 try {
4628 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004629 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004630 return;
4631 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004632 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4633 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4634 loge("setImsProvisioningStatusForCapability: called for technology that does "
4635 + "not support provisioning - " + tech);
4636 return;
4637 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004638
4639 // this capability requires provisioning, route to the correct API.
4640 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4641 switch (capability) {
4642 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4643 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4644 ims.setVolteProvisioned(isProvisioned);
4645 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4646 ims.setWfcProvisioned(isProvisioned);
4647 }
4648 break;
4649 }
4650 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4651 // There is currently no difference in VT provisioning type.
4652 ims.setVtProvisioned(isProvisioned);
4653 break;
4654 }
4655 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4656 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4657 // change the capability of the feature instead if needed.
4658 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4659 == isProvisioned) {
4660 // No change in provisioning.
4661 return;
4662 }
4663 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4664 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004665 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004666 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004667 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4668 + ", Exception" + e.getMessage());
4669 }
4670 break;
4671 }
4672 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004673 throw new IllegalArgumentException("Tried to set provisioning for "
4674 + "MmTel capability '" + capability + "', which does not require "
4675 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004676 }
4677 }
4678
4679 } finally {
4680 Binder.restoreCallingIdentity(identity);
4681 }
4682 }
4683
4684 @Override
4685 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4686 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004687 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4688 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4689 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4691 }
4692 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4693 final long identity = Binder.clearCallingIdentity();
4694 try {
4695 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004696 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004697 return true;
4698 }
4699
Brad Ebinger0d79c572021-04-17 15:20:49 -07004700 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4701 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4702 loge("getImsProvisioningStatusForCapability: called for technology that does "
4703 + "not support provisioning - " + tech);
4704 return true;
4705 }
4706
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004707 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4708 switch (capability) {
4709 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4710 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4711 return ims.isVolteProvisionedOnDevice();
4712 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4713 return ims.isWfcProvisionedOnDevice();
4714 }
4715 // This should never happen, since we are checking tech above to make sure it
4716 // is either LTE or IWLAN.
4717 throw new IllegalArgumentException("Invalid radio technology for voice "
4718 + "capability.");
4719 }
4720 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4721 // There is currently no difference in VT provisioning type.
4722 return ims.isVtProvisionedOnDevice();
4723 }
4724 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4725 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4726 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4727 }
4728 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004729 throw new IllegalArgumentException(
4730 "Tried to get provisioning for MmTel capability '" + capability
4731 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004732 }
4733 }
4734
4735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
4738 }
4739
4740 @Override
4741 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4742 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4743 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4744 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4745 }
4746 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4747 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4748 return (provisionedBits & capability) > 0;
4749 }
4750
4751 @Override
4752 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4753 boolean isProvisioned) {
4754 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4755 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4756 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4757 }
4758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4759 "setProvisioningStatusForCapability");
4760 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4761 // If the current provisioning status for capability already matches isProvisioned,
4762 // do nothing.
4763 if (((provisionedBits & capability) > 0) == isProvisioned) {
4764 return;
4765 }
4766 if (isProvisioned) {
4767 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4768 } else {
4769 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4770 }
4771 }
4772
4773 /**
4774 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4775 * technology. The bitfield should mirror the bitfield defined by
4776 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4777 */
4778 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4779 String key = getMmTelProvisioningKey(subId, tech);
4780 // Default is no capabilities are provisioned.
4781 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4782 }
4783
4784 /**
4785 * Sets the MmTel capability provisioning bitfield (defined by
4786 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4787 * technology specified.
4788 *
4789 * Note: This is a synchronous command and should not be called on UI thread.
4790 */
4791 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4792 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4793 String key = getMmTelProvisioningKey(subId, tech);
4794 editor.putInt(key, newField);
4795 editor.commit();
4796 }
4797
4798 private static String getMmTelProvisioningKey(int subId, int tech) {
4799 // resulting key is provision_ims_mmtel_{subId}_{tech}
4800 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4801 }
4802
4803 /**
4804 * Query CarrierConfig to see if the specified capability requires provisioning for the
4805 * carrier associated with the subscription id.
4806 */
4807 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4808 int capability) {
4809 CarrierConfigManager configManager = new CarrierConfigManager(context);
4810 PersistableBundle c = configManager.getConfigForSubId(subId);
4811 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004812 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004813 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4814 false);
4815 boolean requireVoiceVtProvisioning = c.getBoolean(
4816 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4817
4818 // First check to make sure that the capability requires provisioning.
4819 switch (capability) {
4820 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4821 // intentional fallthrough
4822 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4823 if (requireVoiceVtProvisioning) {
4824 // Voice and Video requires provisioning
4825 return true;
4826 }
4827 break;
4828 }
4829 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4830 if (requireUtProvisioning) {
4831 // UT requires provisioning
4832 return true;
4833 }
4834 break;
4835 }
4836 }
4837 return false;
4838 }
4839
allenwtsu99c623b2020-01-03 18:24:23 +08004840 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4841 int capability) {
4842 CarrierConfigManager configManager = new CarrierConfigManager(context);
4843 PersistableBundle c = configManager.getConfigForSubId(subId);
4844
4845 boolean requireRcsProvisioning = c.getBoolean(
4846 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4847
4848 // First check to make sure that the capability requires provisioning.
4849 switch (capability) {
4850 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4851 // intentional fallthrough
4852 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4853 if (requireRcsProvisioning) {
4854 // OPTION or PRESENCE requires provisioning
4855 return true;
4856 }
4857 break;
4858 }
4859 }
4860 return false;
4861 }
4862
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004863 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004864 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4866 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4867 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004868 enforceReadPrivilegedPermission("getImsProvisioningInt");
4869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004872 int slotId = getSlotIndex(subId);
4873 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4874 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4875 + subId + "' for key:" + key);
4876 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4877 }
calvinpanb5a34062021-02-08 19:59:36 +08004878 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004879 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004880 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4881 + subId + "' for key:" + key);
4882 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004883 } finally {
4884 Binder.restoreCallingIdentity(identity);
4885 }
4886 }
4887
4888 @Override
4889 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4891 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4892 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004893 enforceReadPrivilegedPermission("getImsProvisioningString");
4894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004897 int slotId = getSlotIndex(subId);
4898 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4899 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4900 + subId + "' for key:" + key);
4901 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4902 }
calvinpanb5a34062021-02-08 19:59:36 +08004903 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004904 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004905 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4906 + subId + "' for key:" + key);
4907 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004908 } finally {
4909 Binder.restoreCallingIdentity(identity);
4910 }
4911 }
4912
4913 @Override
4914 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004915 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4916 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4917 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4919 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 final long identity = Binder.clearCallingIdentity();
4921 try {
4922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004923 int slotId = getSlotIndex(subId);
4924 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4925 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4926 + subId + "' for key:" + key);
4927 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4928 }
calvinpanb5a34062021-02-08 19:59:36 +08004929 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4930 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004932 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004933 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
4937 }
4938
4939 @Override
4940 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004941 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4942 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4943 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4945 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004946 final long identity = Binder.clearCallingIdentity();
4947 try {
4948 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004949 int slotId = getSlotIndex(subId);
4950 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4951 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4952 + subId + "' for key:" + key);
4953 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4954 }
calvinpanb5a34062021-02-08 19:59:36 +08004955 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4956 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004958 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004959 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004960 } finally {
4961 Binder.restoreCallingIdentity(identity);
4962 }
4963 }
4964
Brad Ebinger919631e2021-06-02 17:46:35 -07004965 /**
4966 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4967 * for the given slot ID or no ImsResolver instance has been created.
4968 * @param slotId The slot ID that the IMS service is created for.
4969 * @throws ImsException If there is no ImsService configured for this slot.
4970 */
4971 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4972 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4973 ImsFeature.FEATURE_MMTEL)) {
4974 throw new ImsException("This subscription does not support MMTEL over IMS",
4975 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4976 }
4977 }
4978
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004979 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004980 int slotId = SubscriptionManager.getSlotIndex(subId);
4981 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004982 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4983 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004984 }
4985 return slotId;
4986 }
4987
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004988 private int getSlotIndex(int subId) {
4989 int slotId = SubscriptionManager.getSlotIndex(subId);
4990 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4991 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4992 }
4993 return slotId;
4994 }
4995
Wink Saville36469e72014-06-11 15:17:00 -07004996 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004997 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004998 */
4999 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005000 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5001 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08005002 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005003 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005004 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005005 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005006 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005007 mApp, subId, callingPackage, callingFeatureId,
5008 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005009 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5010 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 final long identity = Binder.clearCallingIdentity();
5013 try {
5014 final Phone phone = getPhone(subId);
5015 if (phone != null) {
5016 return phone.getServiceState().getDataNetworkType();
5017 } else {
5018 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5019 }
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005023 }
5024
5025 /**
5026 * Returns the data network type
5027 */
5028 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005029 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005030 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5031 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005032 }
5033
5034 /**
5035 * Returns the data network type for a subId
5036 */
5037 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5039 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005041 mApp, subId, callingPackage, callingFeatureId,
5042 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005043 return TelephonyManager.NETWORK_TYPE_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 phone.getServiceState().getDataNetworkType();
5051 } else {
5052 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5053 }
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005057 }
5058
5059 /**
Wink Saville36469e72014-06-11 15:17:00 -07005060 * Returns the Voice network type for a subId
5061 */
5062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005063 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5064 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005065 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005066 mApp, subId, callingPackage, callingFeatureId,
5067 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005068 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5069 }
5070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 final Phone phone = getPhone(subId);
5074 if (phone != null) {
5075 return phone.getServiceState().getVoiceNetworkType();
5076 } else {
5077 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5078 }
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005081 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005082 }
5083
5084 /**
5085 * @return true if a ICC card is present
5086 */
5087 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005088 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005089 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5090 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005091 }
5092
5093 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005094 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005095 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005096 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005097 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 final long identity = Binder.clearCallingIdentity();
5099 try {
5100 final Phone phone = PhoneFactory.getPhone(slotIndex);
5101 if (phone != null) {
5102 return phone.getIccCard().hasIccCard();
5103 } else {
5104 return false;
5105 }
5106 } finally {
5107 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005109 }
5110
5111 /**
5112 * Return if the current radio is LTE on CDMA. This
5113 * is a tri-state return value as for a period of time
5114 * the mode may be unknown.
5115 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005116 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005117 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005118 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005119 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005120 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005121 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5122 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5123 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005124 }
5125
Sanket Padawe356d7632015-06-22 14:03:32 -07005126 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005127 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5128 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005129 try {
5130 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5131 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005132 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5133 }
5134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 final long identity = Binder.clearCallingIdentity();
5136 try {
5137 final Phone phone = getPhone(subId);
5138 if (phone == null) {
5139 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5140 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005141 return TelephonyProperties.lte_on_cdma_device()
5142 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 }
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005146 }
Wink Saville36469e72014-06-11 15:17:00 -07005147 }
5148
Wink Saville36469e72014-06-11 15:17:00 -07005149 /**
5150 * {@hide}
5151 * Returns Default subId, 0 in the case of single standby.
5152 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005153 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005154 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005155 }
5156
Shishir Agrawala9f32182016-04-12 12:00:16 -07005157 private int getSlotForDefaultSubscription() {
5158 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5159 }
5160
Wink Savilleb564aae2014-10-23 10:18:09 -07005161 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005162 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005163 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005164
Pengquan Menge92a50d2018-09-21 15:54:48 -07005165 private boolean isActiveSubscription(int subId) {
5166 return mSubscriptionController.isActiveSubId(subId);
5167 }
5168
Ihab Awadf2177b72013-11-25 13:33:23 -08005169 /**
5170 * @see android.telephony.TelephonyManager.WifiCallingChoices
5171 */
5172 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 final long identity = Binder.clearCallingIdentity();
5174 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005175 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5177 getWhenToMakeWifiCallsDefaultPreference());
5178 } finally {
5179 Binder.restoreCallingIdentity(identity);
5180 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005181 }
5182
5183 /**
5184 * @see android.telephony.TelephonyManager.WifiCallingChoices
5185 */
5186 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005190 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005195 }
5196
Sailesh Nepald1e68152013-12-12 19:08:02 -08005197 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005198 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005199 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005200 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005201
Jordan Liu4c733742019-02-28 12:03:40 -08005202 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5203 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5204 if (phoneId == -1) {
5205 throw new IllegalArgumentException("Given slot index: " + slotIndex
5206 + " does not correspond to an active phone");
5207 }
5208 return PhoneFactory.getPhone(phoneId);
5209 }
5210
Shishir Agrawal566b7612013-10-28 14:41:00 -07005211 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005212 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5213 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5215 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005217 if (DBG) {
5218 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5219 }
5220 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5221 p2);
5222 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005223
Jordan Liu4c733742019-02-28 12:03:40 -08005224
5225 @Override
5226 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5227 int slotIndex, String callingPackage, String aid, int p2) {
5228 enforceModifyPermission();
5229 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5230 if (DBG) {
5231 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5232 }
5233 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5234 callingPackage, aid, p2);
5235 }
5236
5237 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5238 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
5241 if (TextUtils.equals(ISDR_AID, aid)) {
5242 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005243 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5244 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 if (bestComponent == null
5246 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5247 loge("The calling package is not allowed to access ISD-R.");
5248 throw new SecurityException(
5249 "The calling package is not allowed to access ISD-R.");
5250 }
Derek Tan740e1672017-06-27 14:56:27 -07005251 }
Derek Tan740e1672017-06-27 14:56:27 -07005252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005254 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5255 null /* workSource */);
5256 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 return response;
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005261 }
5262
5263 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005264 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5266 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005267 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5268 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5269 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005270
Jordan Liu4c733742019-02-28 12:03:40 -08005271 @Override
5272 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5273 enforceModifyPermission();
5274 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5275 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5276 channel);
5277 }
5278
5279 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 final long identity = Binder.clearCallingIdentity();
5281 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 if (channel < 0) {
5283 return false;
5284 }
Jordan Liu4c733742019-02-28 12:03:40 -08005285 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5286 null /* workSource */);
5287 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 return success;
5289 } finally {
5290 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005291 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005292 }
5293
5294 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005295 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005296 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005297 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5298 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005299 if (DBG) {
5300 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5301 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5302 + p3 + " data=" + data);
5303 }
5304 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5305 command, p1, p2, p3, data);
5306 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005307
Jordan Liu4c733742019-02-28 12:03:40 -08005308 @Override
5309 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5310 int command, int p1, int p2, int p3, String data) {
5311 enforceModifyPermission();
5312 if (DBG) {
5313 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5314 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5315 + p3 + " data=" + data);
5316 }
5317 return iccTransmitApduLogicalChannelWithPermission(
5318 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5319 data);
5320 }
5321
5322 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5323 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005326 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 return "";
5328 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005331 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5332 null /* workSource */);
5333 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 // Append the returned status code to the end of the response payload.
5336 String s = Integer.toHexString(
5337 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5338 if (response.payload != null) {
5339 s = IccUtils.bytesToHexString(response.payload) + s;
5340 }
5341 return s;
5342 } finally {
5343 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005344 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005345 }
Jake Hambye994d462014-02-03 13:10:13 -08005346
Evan Charltonc66da362014-05-16 14:06:40 -07005347 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005348 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5349 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5351 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005353 if (DBG) {
5354 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5355 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5356 }
5357 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5358 cla, command, p1, p2, p3, data);
5359 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005360
Jordan Liu4c733742019-02-28 12:03:40 -08005361 @Override
5362 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5363 int command, int p1, int p2, int p3, String data) {
5364 enforceModifyPermission();
5365 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5366 if (DBG) {
5367 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5368 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5369 + " data=" + data);
5370 }
5371
5372 return iccTransmitApduBasicChannelWithPermission(
5373 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5374 p2, p3, data);
5375 }
5376
5377 // open APDU basic channel assuming the caller has sufficient permissions
5378 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5379 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 final long identity = Binder.clearCallingIdentity();
5381 try {
5382 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5383 && TextUtils.equals(ISDR_AID, data)) {
5384 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005385 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5386 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387 if (bestComponent == null
5388 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5389 loge("The calling package is not allowed to select ISD-R.");
5390 throw new SecurityException(
5391 "The calling package is not allowed to select ISD-R.");
5392 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005393 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005396 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5397 null /* workSource */);
5398 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 // Append the returned status code to the end of the response payload.
5401 String s = Integer.toHexString(
5402 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5403 if (response.payload != null) {
5404 s = IccUtils.bytesToHexString(response.payload) + s;
5405 }
5406 return s;
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005409 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005410 }
5411
5412 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005413 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005414 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5416 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 final long identity = Binder.clearCallingIdentity();
5419 try {
5420 if (DBG) {
5421 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5422 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5423 }
5424
5425 IccIoResult response =
5426 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5427 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5428 subId);
5429
5430 if (DBG) {
5431 log("Exchange SIM_IO [R]" + response);
5432 }
5433
5434 byte[] result = null;
5435 int length = 2;
5436 if (response.payload != null) {
5437 length = 2 + response.payload.length;
5438 result = new byte[length];
5439 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5440 } else {
5441 result = new byte[length];
5442 }
5443
5444 result[length - 1] = (byte) response.sw2;
5445 result[length - 2] = (byte) response.sw1;
5446 return result;
5447 } finally {
5448 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005449 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005450 }
5451
Nathan Haroldb3014052017-01-25 15:57:32 -08005452 /**
5453 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5454 * on a particular subscription
5455 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005456 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5457 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005459 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005460 return null;
5461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462
5463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 if (appType != TelephonyManager.APPTYPE_USIM
5466 && appType != TelephonyManager.APPTYPE_SIM) {
5467 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5468 return null;
5469 }
5470 Object response = sendRequest(
5471 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5472 if (response instanceof String[]) {
5473 return (String[]) response;
5474 }
yincheng zhao2737e882019-09-06 17:06:54 -07005475 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005477 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 } finally {
5479 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005480 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005481 }
5482
yincheng zhao2737e882019-09-06 17:06:54 -07005483 /**
5484 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5485 * subscription.
5486 *
5487 * @param subId the id of the subscription.
5488 * @param appType the uicc app type, must be USIM or SIM.
5489 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5490 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005491 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005492 * @return number of fplmns that is successfully written to the SIM.
5493 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005494 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5495 String callingFeatureId) {
5496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5497 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005498 if (DBG) logv("no permissions for setForbiddenplmns");
5499 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5500 }
5501 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5502 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5503 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5504 }
5505 if (fplmns == null) {
5506 throw new IllegalArgumentException("Fplmn List provided is null");
5507 }
5508 for (String fplmn : fplmns) {
5509 if (!CellIdentity.isValidPlmn(fplmn)) {
5510 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5511 }
5512 }
5513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 Object response = sendRequest(
5516 CMD_SET_FORBIDDEN_PLMNS,
5517 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5518 subId);
5519 return (int) response;
5520 } finally {
5521 Binder.restoreCallingIdentity(identity);
5522 }
5523 }
5524
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005525 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005526 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5528 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005529
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005530 final long identity = Binder.clearCallingIdentity();
5531 try {
5532 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5533 if (response.payload == null) {
5534 return "";
5535 }
Evan Charltonc66da362014-05-16 14:06:40 -07005536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005537 // Append the returned status code to the end of the response payload.
5538 String s = Integer.toHexString(
5539 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5540 s = IccUtils.bytesToHexString(response.payload) + s;
5541 return s;
5542 } finally {
5543 Binder.restoreCallingIdentity(identity);
5544 }
Evan Charltonc66da362014-05-16 14:06:40 -07005545 }
5546
Jake Hambye994d462014-02-03 13:10:13 -08005547 /**
5548 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5549 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5550 *
5551 * @param itemID the ID of the item to read
5552 * @return the NV item as a String, or null on error.
5553 */
5554 @Override
5555 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5558 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559
5560 final long identity = Binder.clearCallingIdentity();
5561 try {
5562 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005563 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5565 return value;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
Jake Hambye994d462014-02-03 13:10:13 -08005569 }
5570
5571 /**
5572 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5573 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5574 *
5575 * @param itemID the ID of the item to read
5576 * @param itemValue the value to write, as a String
5577 * @return true on success; false on any failure
5578 */
5579 @Override
5580 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005581 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5583 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584
5585 final long identity = Binder.clearCallingIdentity();
5586 try {
5587 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5588 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005589 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5591 return success;
5592 } finally {
5593 Binder.restoreCallingIdentity(identity);
5594 }
Jake Hambye994d462014-02-03 13:10:13 -08005595 }
5596
5597 /**
5598 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5599 * Used for device configuration by some CDMA operators.
5600 *
5601 * @param preferredRoamingList byte array containing the new PRL
5602 * @return true on success; false on any failure
5603 */
5604 @Override
5605 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005606 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5607 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608
5609 final long identity = Binder.clearCallingIdentity();
5610 try {
5611 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5612 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5613 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5614 return success;
5615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
Jake Hambye994d462014-02-03 13:10:13 -08005618 }
5619
5620 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005621 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005622 * Used for device configuration by some CDMA operators.
5623 *
chen xu6dac5ab2018-10-26 17:39:23 -07005624 * @param slotIndex - device slot.
5625 *
Jake Hambye994d462014-02-03 13:10:13 -08005626 * @return true on success; false on any failure
5627 */
5628 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005629 public boolean resetModemConfig(int slotIndex) {
5630 Phone phone = PhoneFactory.getPhone(slotIndex);
5631 if (phone != null) {
5632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5633 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634
chen xu6dac5ab2018-10-26 17:39:23 -07005635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5638 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5639 return success;
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 }
chen xu6dac5ab2018-10-26 17:39:23 -07005644 return false;
5645 }
5646
5647 /**
5648 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5649 *
5650 * @param slotIndex - device slot.
5651 *
5652 * @return true on success; false on any failure
5653 */
5654 @Override
5655 public boolean rebootModem(int slotIndex) {
5656 Phone phone = PhoneFactory.getPhone(slotIndex);
5657 if (phone != null) {
5658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5659 mApp, phone.getSubId(), "rebootModem");
5660
5661 final long identity = Binder.clearCallingIdentity();
5662 try {
5663 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5664 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5665 return success;
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
5669 }
5670 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005671 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005672
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005673 public String[] getPcscfAddress(String apnType, String callingPackage,
5674 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005675 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005676 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5677 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005678 return new String[0];
5679 }
5680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 final long identity = Binder.clearCallingIdentity();
5682 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005683 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
Wink Saville36469e72014-06-11 15:17:00 -07005687 }
5688
Brad Ebinger51f743a2017-01-23 13:50:20 -08005689 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005690 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5691 * {@link #disableIms(int)}.
5692 * @param slotIndex device slot.
5693 */
5694 public void resetIms(int slotIndex) {
5695 enforceModifyPermission();
5696
5697 final long identity = Binder.clearCallingIdentity();
5698 try {
5699 if (mImsResolver == null) {
5700 // may happen if the does not support IMS.
5701 return;
5702 }
5703 mImsResolver.disableIms(slotIndex);
5704 mImsResolver.enableIms(slotIndex);
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
5708 }
5709
5710 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005711 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5712 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005713 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005714 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005715 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005719 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005720 // may happen if the device does not support IMS.
5721 return;
5722 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005723 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005727 }
5728
5729 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005730 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5731 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005732 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005733 public void disableIms(int slotId) {
5734 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005739 // may happen if the device does not support IMS.
5740 return;
5741 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005746 }
5747
5748 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005749 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5750 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005751 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005752 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005753 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005758 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005759 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5760 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005761 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005762 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005766 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005767 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005768 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5769 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005770 @Override
5771 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005772 enforceModifyPermission();
5773
5774 final long identity = Binder.clearCallingIdentity();
5775 try {
5776 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005777 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
5781 }
5782
5783 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005784 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005785 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005786 */
5787 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5788 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789
5790 final long identity = Binder.clearCallingIdentity();
5791 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005792 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005793 // may happen if the device does not support IMS.
5794 return null;
5795 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005796 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005800 }
5801
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005802 /**
5803 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005804 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005805 */
5806 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808
5809 final long identity = Binder.clearCallingIdentity();
5810 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005811 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005812 // may happen if the device does not support IMS.
5813 return null;
5814 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005815 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 } finally {
5817 Binder.restoreCallingIdentity(identity);
5818 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005819 }
5820
Brad Ebinger884c07b2018-02-15 16:17:40 -08005821 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005822 * Sets the ImsService Package Name that Telephony will bind to.
5823 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005824 * @param slotIndex the slot ID that the ImsService should bind for.
5825 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005826 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005827 * @param featureTypes An integer array of feature types associated with a packageName.
5828 * @param packageName The name of the package that the current configuration will be replaced
5829 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005830 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005831 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005832 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5833 int[] featureTypes, String packageName) {
5834 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5835 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5837 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005838 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 final long identity = Binder.clearCallingIdentity();
5841 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005843 // may happen if the device does not support IMS.
5844 return false;
5845 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005846 Map<Integer, String> featureConfig = new HashMap<>();
5847 for (int featureType : featureTypes) {
5848 featureConfig.put(featureType, packageName);
5849 }
5850 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5851 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852 } finally {
5853 Binder.restoreCallingIdentity(identity);
5854 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005855 }
5856
5857 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005858 * Clears any carrier ImsService overrides for the slot index specified that were previously
5859 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5860 *
5861 * This should only be used for testing.
5862 *
5863 * @param slotIndex the slot ID that the ImsService should bind for.
5864 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5865 */
5866 @Override
5867 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5868 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5869 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5870 "clearCarrierImsServiceOverride");
5871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5872 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5873 "clearCarrierImsServiceOverride");
5874
5875 final long identity = Binder.clearCallingIdentity();
5876 try {
5877 if (mImsResolver == null) {
5878 // may happen if the device does not support IMS.
5879 return false;
5880 }
5881 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
5885 }
5886
5887 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005888 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005889 *
5890 * @param slotId The slot that the ImsService is associated with.
5891 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5892 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005893 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005894 * @return the package name of the ImsService configuration.
5895 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005896 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5897 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005898 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005899 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005900 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005901 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5902 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904 final long identity = Binder.clearCallingIdentity();
5905 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005906 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005907 // may happen if the device does not support IMS.
5908 return "";
5909 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005910 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005911 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5912 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913 } finally {
5914 Binder.restoreCallingIdentity(identity);
5915 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005916 }
5917
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005918 /**
5919 * Get the MmTelFeature state associated with the requested subscription id.
5920 * @param subId The subscription that the MmTelFeature is associated with.
5921 * @param callback A callback with an integer containing the
5922 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5923 */
5924 @Override
5925 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5926 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5927 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5928 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5929 "IMS not available on device.");
5930 }
5931 final long token = Binder.clearCallingIdentity();
5932 try {
5933 int slotId = getSlotIndex(subId);
5934 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5935 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5936 + subId + "'");
5937 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5938 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005939 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005940 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5941 try {
5942 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5943 } catch (RemoteException e) {
5944 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5945 + "Ignore");
5946 }
5947 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005948 } catch (ImsException e) {
5949 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005950 } finally {
5951 Binder.restoreCallingIdentity(token);
5952 }
5953 }
5954
Daniel Brightbb5840b2021-01-12 15:48:18 -08005955 /**
5956 * Sets the ims registration state on all valid {@link Phone}s.
5957 */
5958 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005959 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960
5961 final long identity = Binder.clearCallingIdentity();
5962 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005963 // NOTE: Before S, this method only set the default phone.
5964 for (final Phone phone : PhoneFactory.getPhones()) {
5965 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5966 phone.setImsRegistrationState(registered);
5967 }
5968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005969 } finally {
5970 Binder.restoreCallingIdentity(identity);
5971 }
Wink Saville36469e72014-06-11 15:17:00 -07005972 }
5973
5974 /**
Stuart Scott54788802015-03-30 13:18:01 -07005975 * Set the network selection mode to automatic.
5976 *
5977 */
5978 @Override
5979 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5981 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982
5983 final long identity = Binder.clearCallingIdentity();
5984 try {
shilufc958392020-01-20 11:36:01 -08005985 if (!isActiveSubscription(subId)) {
5986 return;
5987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005989 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5990 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 } finally {
5992 Binder.restoreCallingIdentity(identity);
5993 }
Stuart Scott54788802015-03-30 13:18:01 -07005994 }
5995
Jack Yud10cdd42020-09-28 20:28:01 -07005996 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005997 * Ask the radio to connect to the input network and change selection mode to manual.
5998 *
5999 * @param subId the id of the subscription.
6000 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6001 * the operator to attach to.
6002 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6003 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6004 * normal network selection next time.
6005 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006006 */
6007 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006008 public boolean setNetworkSelectionModeManual(
6009 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6011 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006012
6013 if (!isActiveSubscription(subId)) {
6014 return false;
6015 }
6016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 final long identity = Binder.clearCallingIdentity();
6018 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006019 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006021 if (DBG) {
6022 log("setNetworkSelectionModeManual: subId: " + subId
6023 + " operator: " + operatorInfo);
6024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6026 } finally {
6027 Binder.restoreCallingIdentity(identity);
6028 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006029 }
shilu84f6e8b2019-12-19 13:58:01 -08006030 /**
6031 * Get the manual network selection
6032 *
6033 * @param subId the id of the subscription.
6034 *
6035 * @return the previously saved user selected PLMN
6036 */
6037 @Override
6038 public String getManualNetworkSelectionPlmn(int subId) {
6039 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006040 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006041 mApp, subId, "getManualNetworkSelectionPlmn");
6042
6043 final long identity = Binder.clearCallingIdentity();
6044 try {
6045 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006046 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006047 }
6048
6049 final Phone phone = getPhone(subId);
6050 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006051 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006052 }
6053 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6054 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6055 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
6059 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006060
6061 /**
6062 * Scans for available networks.
6063 */
6064 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006065 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6066 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6068 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006069 LocationAccessPolicy.LocationPermissionResult locationResult =
6070 LocationAccessPolicy.checkLocationPermission(mApp,
6071 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6072 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006073 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006074 .setCallingPid(Binder.getCallingPid())
6075 .setCallingUid(Binder.getCallingUid())
6076 .setMethod("getCellNetworkScanResults")
6077 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006078 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6079 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006080 .build());
6081 switch (locationResult) {
6082 case DENIED_HARD:
6083 throw new SecurityException("Not allowed to access scan results -- location");
6084 case DENIED_SOFT:
6085 return null;
6086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087
Pengquan Menga1bb6272018-09-06 09:59:22 -07006088 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 try {
6090 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006091 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006093 } finally {
6094 Binder.restoreCallingIdentity(identity);
6095 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006096 }
6097
6098 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006099 * Get the call forwarding info, given the call forwarding reason.
6100 */
6101 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006102 public void getCallForwarding(int subId, int callForwardingReason,
6103 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006104 enforceReadPrivilegedPermission("getCallForwarding");
6105 long identity = Binder.clearCallingIdentity();
6106 try {
6107 if (DBG) {
6108 log("getCallForwarding: subId " + subId
6109 + " callForwardingReason" + callForwardingReason);
6110 }
Hall Liu27d24262020-09-18 19:04:59 -07006111
6112 Phone phone = getPhone(subId);
6113 if (phone == null) {
6114 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006115 callback.onError(
6116 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006117 } catch (RemoteException e) {
6118 // ignore
6119 }
6120 return;
6121 }
6122
6123 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6124 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6125 @Override
6126 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6127 try {
6128 callback.onCallForwardingInfoAvailable(info);
6129 } catch (RemoteException e) {
6130 // ignore
6131 }
6132 }
6133
6134 @Override
6135 public void onError(int error) {
6136 try {
6137 callback.onError(error);
6138 } catch (RemoteException e) {
6139 // ignore
6140 }
6141 }
6142 });
6143 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006144 } finally {
6145 Binder.restoreCallingIdentity(identity);
6146 }
6147 }
6148
6149 /**
6150 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6151 * reason, the number to forward, and the timeout before the forwarding is attempted.
6152 */
6153 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006154 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6155 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006156 enforceModifyPermission();
6157 long identity = Binder.clearCallingIdentity();
6158 try {
6159 if (DBG) {
6160 log("setCallForwarding: subId " + subId
6161 + " callForwardingInfo" + callForwardingInfo);
6162 }
Hall Liu27d24262020-09-18 19:04:59 -07006163
6164 Phone phone = getPhone(subId);
6165 if (phone == null) {
6166 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006167 callback.accept(
6168 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006169 } catch (RemoteException e) {
6170 // ignore
6171 }
6172 return;
6173 }
6174
6175 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6176 FunctionalUtils.ignoreRemoteException(callback::accept));
6177
6178 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
6182 }
6183
6184 /**
Hall Liu27d24262020-09-18 19:04:59 -07006185 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006186 */
6187 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006188 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006189 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006190 long identity = Binder.clearCallingIdentity();
6191 try {
Hall Liu27d24262020-09-18 19:04:59 -07006192 Phone phone = getPhone(subId);
6193 if (phone == null) {
6194 try {
6195 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6196 } catch (RemoteException e) {
6197 // ignore
6198 }
6199 return;
6200 }
SongFerngWang0e767992021-03-31 22:08:45 +08006201 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6202 PersistableBundle c = configManager.getConfigForSubId(subId);
6203 boolean requireUssd = c.getBoolean(
6204 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006205
Shuo Qian4a594052020-01-23 11:59:30 -08006206 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006207 if (requireUssd) {
6208 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6209 getSubscriptionCarrierId(subId));
6210 String newUssdCommand = "";
6211 try {
6212 newUssdCommand = carrierXmlParser.getFeature(
6213 CarrierXmlParser.FEATURE_CALL_WAITING)
6214 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6215 } catch (NullPointerException e) {
6216 loge("Failed to generate USSD number" + e);
6217 }
6218 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6219 mMainThreadHandler, callback, carrierXmlParser,
6220 CarrierXmlParser.SsEntry.SSAction.QUERY);
6221 final String ussdCommand = newUssdCommand;
6222 Executors.newSingleThreadExecutor().execute(() -> {
6223 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6224 });
6225 } else {
6226 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6227 callback::accept);
6228 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6229 }
Shuo Qian4a594052020-01-23 11:59:30 -08006230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
6233 }
6234
6235 /**
Hall Liu27d24262020-09-18 19:04:59 -07006236 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006237 */
6238 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006239 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006240 enforceModifyPermission();
6241 long identity = Binder.clearCallingIdentity();
6242 try {
Hall Liu27d24262020-09-18 19:04:59 -07006243 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6244
6245 Phone phone = getPhone(subId);
6246 if (phone == null) {
6247 try {
6248 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6249 } catch (RemoteException e) {
6250 // ignore
6251 }
6252 return;
6253 }
6254
SongFerngWang0e767992021-03-31 22:08:45 +08006255 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6256 PersistableBundle c = configManager.getConfigForSubId(subId);
6257 boolean requireUssd = c.getBoolean(
6258 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006259
SongFerngWang0e767992021-03-31 22:08:45 +08006260 if (DBG) log("getCallWaitingStatus: subId " + subId);
6261 if (requireUssd) {
6262 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6263 getSubscriptionCarrierId(subId));
6264 CarrierXmlParser.SsEntry.SSAction ssAction =
6265 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6266 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6267 String newUssdCommand = "";
6268 try {
6269 newUssdCommand = carrierXmlParser.getFeature(
6270 CarrierXmlParser.FEATURE_CALL_WAITING)
6271 .makeCommand(ssAction, null);
6272 } catch (NullPointerException e) {
6273 loge("Failed to generate USSD number" + e);
6274 }
6275 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6276 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6277 final String ussdCommand = newUssdCommand;
6278 Executors.newSingleThreadExecutor().execute(() -> {
6279 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6280 });
6281 } else {
6282 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6283 FunctionalUtils.ignoreRemoteException(callback::accept));
6284
6285 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6286 }
Shuo Qian4a594052020-01-23 11:59:30 -08006287 } finally {
6288 Binder.restoreCallingIdentity(identity);
6289 }
6290 }
6291
6292 /**
yinxub1bed742017-04-17 11:45:04 -07006293 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006294 *
yinxub1bed742017-04-17 11:45:04 -07006295 * @param subId id of the subscription
6296 * @param request contains the radio access networks with bands/channels to scan
6297 * @param messenger callback messenger for scan results or errors
6298 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006299 * @return the id of the requested scan which can be used to stop the scan.
6300 */
6301 @Override
6302 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006303 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6305 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006306 LocationAccessPolicy.LocationPermissionResult locationResult =
6307 LocationAccessPolicy.checkLocationPermission(mApp,
6308 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6309 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006310 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006311 .setCallingPid(Binder.getCallingPid())
6312 .setCallingUid(Binder.getCallingUid())
6313 .setMethod("requestNetworkScan")
6314 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006315 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6316 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006317 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006318 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006319 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6320 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006321 if (e != null) {
6322 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6323 throw e;
6324 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006325 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006326 return TelephonyScanManager.INVALID_SCAN_ID;
6327 }
6328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 }
Hall Liu912dfd32019-04-25 14:02:26 -07006330 int callingUid = Binder.getCallingUid();
6331 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 return mNetworkScanRequestTracker.startNetworkScan(
6335 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006336 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
yinxu504e1392017-04-12 16:03:22 -07006340 }
6341
Hall Liub2ac8ef2019-02-28 15:56:23 -08006342 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006343 NetworkScanRequest request, int subId, String callingPackage) {
6344 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006345 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6346 boolean hasNetworkScanPermission =
6347 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6348 == PERMISSION_GRANTED;
6349
6350 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6351 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6352 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 }
6354
6355 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6356 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006357 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6358 return new SecurityException("Specific channels must not be"
6359 + " scanned without location access.");
6360 }
6361 }
6362 }
6363
Hall Liub2ac8ef2019-02-28 15:56:23 -08006364 return null;
6365 }
6366
yinxu504e1392017-04-12 16:03:22 -07006367 /**
6368 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006369 *
6370 * @param subId id of the subscription
6371 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006372 */
6373 @Override
6374 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006375 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6376 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377
Hall Liu912dfd32019-04-25 14:02:26 -07006378 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 final long identity = Binder.clearCallingIdentity();
6380 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006381 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
yinxu504e1392017-04-12 16:03:22 -07006385 }
6386
6387 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006388 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006389 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006390 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006391 */
6392 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006393 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006394 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006395 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006396 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397
6398 final long identity = Binder.clearCallingIdentity();
6399 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006400 if (DBG) log("getAllowedNetworkTypesBitmask");
6401 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6402 int networkTypesBitmask = (result != null ? result[0] : -1);
6403 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6404 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 } finally {
6406 Binder.restoreCallingIdentity(identity);
6407 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006408 }
6409
6410 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006411 * Get the allowed network types for certain reason.
6412 *
6413 * @param subId the id of the subscription.
6414 * @param reason the reason the allowed network type change is taking place
6415 * @return the allowed network types.
6416 */
6417 @Override
6418 public long getAllowedNetworkTypesForReason(int subId,
6419 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006420 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006421 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006422 final long identity = Binder.clearCallingIdentity();
6423 try {
6424 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
6428 }
6429
6430 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006431 * Enable/Disable E-UTRA-NR Dual Connectivity
6432 * @param subId subscription id of the sim card
6433 * @param nrDualConnectivityState expected NR dual connectivity state
6434 * This can be passed following states
6435 * <ol>
6436 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6437 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6438 * <li>Disable NR dual connectivity and force secondary cell to be released
6439 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6440 * </ol>
6441 * @return operation result.
6442 */
6443 @Override
6444 public int setNrDualConnectivityState(int subId,
6445 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6447 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006448 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006449 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6450 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6451 }
6452
Sooraj Sasindran37444802020-08-11 10:40:43 -07006453 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6454 final long identity = Binder.clearCallingIdentity();
6455 try {
6456 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6457 nrDualConnectivityState, subId,
6458 workSource);
6459 if (DBG) log("enableNRDualConnectivity result: " + result);
6460 return result;
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
6464 }
6465
6466 /**
6467 * Is E-UTRA-NR Dual Connectivity enabled
6468 * @return true if dual connectivity is enabled else false
6469 */
6470 @Override
6471 public boolean isNrDualConnectivityEnabled(int subId) {
6472 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006473 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006474 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006475 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006476 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6477 return false;
6478 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006479 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6480 final long identity = Binder.clearCallingIdentity();
6481 try {
6482 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6483 null, subId, workSource);
6484 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6485 return isEnabled;
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
6491 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006492 * Set the allowed network types of the device and
6493 * provide the reason triggering the allowed network change.
6494 *
6495 * @param subId the id of the subscription.
6496 * @param reason the reason the allowed network type change is taking place
6497 * @param allowedNetworkTypes the allowed network types.
6498 * @return true on success; false on any failure.
6499 */
6500 @Override
6501 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006502 @TelephonyManager.AllowedNetworkTypesReason int reason,
6503 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6505 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006506 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006507 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6508 return false;
6509 }
6510 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6511 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006512 return false;
6513 }
6514
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006515 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6516 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6517
6518
6519 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6520 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6521 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006522 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006523
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006524 final long identity = Binder.clearCallingIdentity();
6525 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006526 Boolean success = (Boolean) sendRequest(
6527 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6528 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6529
6530 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6531 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
6535 }
6536
6537 /**
Miaoa84611c2019-03-15 09:21:10 +08006538 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006539 *
Miaoa84611c2019-03-15 09:21:10 +08006540 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006541 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006542 * @hide
6543 */
6544 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006545 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006546 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006547 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006548 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549 try {
Miaoa84611c2019-03-15 09:21:10 +08006550 if (phone != null) {
6551 return phone.hasMatchedTetherApnSetting();
6552 } else {
6553 return false;
6554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 } finally {
6556 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006557 }
Junda Liu475951f2014-11-07 16:45:03 -08006558 }
6559
6560 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006561 * Get the user enabled state of Mobile Data.
6562 *
6563 * TODO: remove and use isUserDataEnabled.
6564 * This can't be removed now because some vendor codes
6565 * calls through ITelephony directly while they should
6566 * use TelephonyManager.
6567 *
6568 * @return true on enabled
6569 */
6570 @Override
6571 public boolean getDataEnabled(int subId) {
6572 return isUserDataEnabled(subId);
6573 }
6574
6575 /**
6576 * Get whether mobile data is enabled per user setting.
6577 *
6578 * There are other factors deciding whether mobile data is actually enabled, but they are
6579 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006580 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006581 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006582 *
6583 * @return {@code true} if data is enabled else {@code false}
6584 */
6585 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006586 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006587 try {
6588 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6589 null);
6590 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6592 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594
6595 final long identity = Binder.clearCallingIdentity();
6596 try {
6597 int phoneId = mSubscriptionController.getPhoneId(subId);
6598 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6599 Phone phone = PhoneFactory.getPhone(phoneId);
6600 if (phone != null) {
6601 boolean retVal = phone.isUserDataEnabled();
6602 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6603 return retVal;
6604 } else {
6605 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6606 return false;
6607 }
6608 } finally {
6609 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006610 }
6611 }
6612
6613 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006614 * Checks if the device is capable of mobile data by considering whether whether the
6615 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6616 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006617 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006618 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006619 */
6620 @Override
6621 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006622 try {
6623 try {
6624 mApp.enforceCallingOrSelfPermission(
6625 android.Manifest.permission.ACCESS_NETWORK_STATE,
6626 null);
6627 } catch (Exception e) {
6628 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6629 "isDataEnabled");
6630 }
6631 } catch (Exception e) {
6632 enforceReadPrivilegedPermission("isDataEnabled");
6633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634
6635 final long identity = Binder.clearCallingIdentity();
6636 try {
6637 int phoneId = mSubscriptionController.getPhoneId(subId);
6638 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6639 Phone phone = PhoneFactory.getPhone(phoneId);
6640 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006641 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006642 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6643 return retVal;
6644 } else {
6645 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6646 return false;
6647 }
6648 } finally {
6649 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006650 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006651 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006652
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006653 /**
6654 * Check if data is enabled for a specific reason
6655 * @param subId Subscription index
6656 * @param reason the reason the data enable change is taking place
6657 * @return {@code true} if the overall data is enabled; {@code false} if not.
6658 */
6659 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006660 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006661 @TelephonyManager.DataEnabledReason int reason) {
6662 try {
6663 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6664 null);
6665 } catch (Exception e) {
6666 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006667 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006668 }
6669
6670
6671 final long identity = Binder.clearCallingIdentity();
6672 try {
6673 int phoneId = mSubscriptionController.getPhoneId(subId);
6674 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006675 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006676 + " reason=" + reason);
6677 }
6678 Phone phone = PhoneFactory.getPhone(phoneId);
6679 if (phone != null) {
6680 boolean retVal;
6681 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6682 retVal = phone.isUserDataEnabled();
6683 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006684 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006685 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006686 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006687 return retVal;
6688 } else {
6689 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006690 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006691 + subId + " retVal=false");
6692 }
6693 return false;
6694 }
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
6697 }
6698 }
6699
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006700 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006701 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006702 if (uid == Process.PHONE_UID) {
6703 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6704 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006705 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6706 }
6707
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006708 //load access rules from carrier configs, and check those as well: b/139133814
6709 SubscriptionController subController = SubscriptionController.getInstance();
6710 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6711 || subController == null) return privilegeFromSim;
6712
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006713 PackageManager pkgMgr = phone.getContext().getPackageManager();
6714 String[] packages = pkgMgr.getPackagesForUid(uid);
6715
6716 final long identity = Binder.clearCallingIdentity();
6717 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006718 int subId = phone.getSubId();
6719 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6720 // A test override is in place for the privileges for this subId, so don't try to
6721 // read the subscription privileges.
6722 return privilegeFromSim;
6723 }
6724 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006725 SubscriptionManager subManager = (SubscriptionManager)
6726 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6727 for (String pkg : packages) {
6728 if (subManager.canManageSubscription(subInfo, pkg)) {
6729 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6730 }
6731 }
6732 return privilegeFromSim;
6733 } finally {
6734 Binder.restoreCallingIdentity(identity);
6735 }
6736 }
6737
6738 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6739 String pkgName) {
6740 //load access rules from carrier configs, and check those as well: b/139133814
6741 SubscriptionController subController = SubscriptionController.getInstance();
6742 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6743 || subController == null) return privilegeFromSim;
6744
6745 final long identity = Binder.clearCallingIdentity();
6746 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006747 int subId = phone.getSubId();
6748 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6749 // A test override is in place for the privileges for this subId, so don't try to
6750 // read the subscription privileges.
6751 return privilegeFromSim;
6752 }
6753 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006754 SubscriptionManager subManager = (SubscriptionManager)
6755 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6756 return subManager.canManageSubscription(subInfo, pkgName)
6757 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
6761 }
6762
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006763 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006764 public int getCarrierPrivilegeStatus(int subId) {
6765 final Phone phone = getPhone(subId);
6766 if (phone == null) {
6767 loge("getCarrierPrivilegeStatus: Invalid subId");
6768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6769 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006770 UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId());
6771 if (port == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006772 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6774 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006775
6776 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006777 port.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006778 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006779 }
Junda Liu29340342014-07-10 15:23:27 -07006780
6781 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006782 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006783 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006784 final Phone phone = getPhone(subId);
6785 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006786 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006787 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6788 }
6789 UiccProfile profile =
6790 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6791 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006792 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006793 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6794 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006795 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006796 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006797 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006798 }
6799
6800 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006801 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006802 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006803 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006804 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006805 }
6806
6807 int phoneId = SubscriptionManager.getPhoneId(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006808 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6809 if (port == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006810 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006811 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6812 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006813 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006814 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006815 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006816 }
6817
6818 @Override
6819 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006820 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006821 if (TextUtils.isEmpty(pkgName))
6822 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006823 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6824 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006825 UiccPort port = UiccController.getInstance().getUiccPort(i);
6826 if (port == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006827 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006828 continue;
6829 }
6830
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006831 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006832 port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006833 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006834 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6835 break;
6836 }
6837 }
6838
6839 return result;
Junda Liu29340342014-07-10 15:23:27 -07006840 }
Derek Tan89e89d42014-07-08 17:00:10 -07006841
6842 @Override
Junda Liue64de782015-04-16 17:19:16 -07006843 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006844 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006845 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6846 loge("phoneId " + phoneId + " is not valid.");
6847 return null;
6848 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006849 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
6850 if (port == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006851 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006852 return null ;
6853 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006854 return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006855 }
6856
Amith Yamasani6e118872016-02-19 12:53:51 -08006857 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006858 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006859 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006860 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006861 List<String> privilegedPackages = new ArrayList<>();
6862 List<PackageInfo> packages = null;
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006863 UiccPort port = UiccController.getInstance().getUiccPort(phoneId);
chen xuf7e9fe82019-05-09 19:31:02 -07006864 // has UICC in that slot.
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006865 if (port != null) {
6866 if (port.hasCarrierPrivilegeRules()) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006867 if (packages == null) {
6868 // Only check packages in user 0 for now
6869 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006870 PackageManager.MATCH_DISABLED_COMPONENTS
6871 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006872 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006873 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006874 }
6875 for (int p = packages.size() - 1; p >= 0; p--) {
6876 PackageInfo pkgInfo = packages.get(p);
6877 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006878 && getCarrierPrivilegeStatusFromCarrierConfigRules(
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006879 port.getCarrierPrivilegeStatus(pkgInfo),
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006880 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006881 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006882 privilegedPackages.add(pkgInfo.packageName);
6883 }
6884 }
6885 }
6886 }
6887 return privilegedPackages;
6888 }
6889
chen xuf7e9fe82019-05-09 19:31:02 -07006890 @Override
6891 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006892 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6893
6894 final long identity = Binder.clearCallingIdentity();
6895
chen xuf7e9fe82019-05-09 19:31:02 -07006896 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006897 try {
6898 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6899 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6900 }
6901 } finally {
6902 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006903 }
6904 return privilegedPackages;
6905 }
6906
Wink Savilleb564aae2014-10-23 10:18:09 -07006907 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006908 final Phone phone = getPhone(subId);
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006909 UiccPort port = phone == null ? null : phone.getUiccPort();
6910 if (port == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006911 return null;
6912 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00006913 String iccId = port.getIccId();
Derek Tan97ebb422014-09-05 16:55:38 -07006914 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006915 return null;
6916 }
6917 return iccId;
6918 }
6919
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006920 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006921 public void setCallComposerStatus(int subId, int status) {
6922 enforceModifyPermission();
6923
6924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 Phone phone = getPhone(subId);
6927 if (phone != null) {
6928 Phone defaultPhone = phone.getImsPhone();
6929 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6930 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6931 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006932 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6933 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006934 }
6935 }
Shuo Qian284ae752020-12-22 19:10:14 -08006936 } catch (ImsException e) {
6937 throw new ServiceSpecificException(e.getCode());
6938 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006939 Binder.restoreCallingIdentity(identity);
6940 }
6941 }
6942
6943 @Override
6944 public int getCallComposerStatus(int subId) {
6945 enforceReadPrivilegedPermission("getCallComposerStatus");
6946
6947 final long identity = Binder.clearCallingIdentity();
6948 try {
6949 Phone phone = getPhone(subId);
6950 if (phone != null) {
6951 Phone defaultPhone = phone.getImsPhone();
6952 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6953 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6954 return imsPhone.getCallComposerStatus();
6955 }
6956 }
6957 } finally {
6958 Binder.restoreCallingIdentity(identity);
6959 }
6960 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6961 }
6962
6963 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006964 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6965 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006966 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006967 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006969 final long identity = Binder.clearCallingIdentity();
6970 try {
6971 final String iccId = getIccId(subId);
6972 final Phone phone = getPhone(subId);
6973 if (phone == null) {
6974 return false;
6975 }
6976 final String subscriberId = phone.getSubscriberId();
6977
6978 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006979 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 + subscriberId + " to " + number);
6981 }
6982
6983 if (TextUtils.isEmpty(iccId)) {
6984 return false;
6985 }
6986
6987 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6988
6989 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6990 if (alphaTag == null) {
6991 editor.remove(alphaTagPrefKey);
6992 } else {
6993 editor.putString(alphaTagPrefKey, alphaTag);
6994 }
6995
6996 // Record both the line number and IMSI for this ICCID, since we need to
6997 // track all merged IMSIs based on line number
6998 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6999 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7000 if (number == null) {
7001 editor.remove(numberPrefKey);
7002 editor.remove(subscriberPrefKey);
7003 } else {
7004 editor.putString(numberPrefKey, number);
7005 editor.putString(subscriberPrefKey, subscriberId);
7006 }
7007
7008 editor.commit();
7009 return true;
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007012 }
Derek Tan7226c842014-07-02 17:42:23 -07007013 }
7014
7015 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007016 public String getLine1NumberForDisplay(int subId, String callingPackage,
7017 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007018 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007020 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007021 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007022 return null;
7023 }
Derek Tan97ebb422014-09-05 16:55:38 -07007024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 final long identity = Binder.clearCallingIdentity();
7026 try {
7027 String iccId = getIccId(subId);
7028 if (iccId != null) {
7029 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7030 if (DBG_MERGE) {
7031 log("getLine1NumberForDisplay returning "
7032 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7033 }
7034 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7037 return null;
7038 } finally {
7039 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007040 }
Derek Tan7226c842014-07-02 17:42:23 -07007041 }
7042
7043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007044 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7045 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007046 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007047 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007048 return null;
7049 }
Derek Tan97ebb422014-09-05 16:55:38 -07007050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 String iccId = getIccId(subId);
7054 if (iccId != null) {
7055 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7056 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7057 }
7058 return null;
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007061 }
Derek Tan7226c842014-07-02 17:42:23 -07007062 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007063
7064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007065 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7066 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007067 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7068 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007070 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007071 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007072 return null;
7073 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007074
Jordan Liub49b04b2019-05-06 14:45:15 -07007075 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7076 // the process, where TelephonyManager was instantiated.
7077 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007078 final long identity = Binder.clearCallingIdentity();
7079 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007080 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 final TelephonyManager tele = TelephonyManager.from(context);
7082 final SubscriptionManager sub = SubscriptionManager.from(context);
7083
7084 // Figure out what subscribers are currently active
7085 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086
Jordan Liub49b04b2019-05-06 14:45:15 -07007087 // Only consider subs which match the current subId
7088 // This logic can be simplified. See b/131189269 for progress.
7089 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007090 activeSubscriberIds.add(tele.getSubscriberId(subId));
7091 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092
7093 // First pass, find a number override for an active subscriber
7094 String mergeNumber = null;
7095 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7096 for (String key : prefs.keySet()) {
7097 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7098 final String subscriberId = (String) prefs.get(key);
7099 if (activeSubscriberIds.contains(subscriberId)) {
7100 final String iccId = key.substring(
7101 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7102 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7103 mergeNumber = (String) prefs.get(numberKey);
7104 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007105 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 + " for active subscriber " + subscriberId);
7107 }
7108 if (!TextUtils.isEmpty(mergeNumber)) {
7109 break;
7110 }
7111 }
7112 }
7113 }
7114
7115 // Shortcut when no active merged subscribers
7116 if (TextUtils.isEmpty(mergeNumber)) {
7117 return null;
7118 }
7119
7120 // Second pass, find all subscribers under that line override
7121 final ArraySet<String> result = new ArraySet<>();
7122 for (String key : prefs.keySet()) {
7123 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7124 final String number = (String) prefs.get(key);
7125 if (mergeNumber.equals(number)) {
7126 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7127 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7128 final String subscriberId = (String) prefs.get(subscriberKey);
7129 if (!TextUtils.isEmpty(subscriberId)) {
7130 result.add(subscriberId);
7131 }
7132 }
7133 }
7134 }
7135
7136 final String[] resultArray = result.toArray(new String[result.size()]);
7137 Arrays.sort(resultArray);
7138 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007139 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007140 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7141 }
7142 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007143 } finally {
7144 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007145 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007146 }
7147
7148 @Override
zoey chen38003472019-12-13 17:16:31 +08007149 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7150 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007151
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
7154 final TelephonyManager telephonyManager = mApp.getSystemService(
7155 TelephonyManager.class);
7156 String subscriberId = telephonyManager.getSubscriberId(subId);
7157 if (subscriberId == null) {
7158 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007159 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007160 + subId);
7161 }
7162 return null;
7163 }
7164
7165 final SubscriptionInfo info = SubscriptionController.getInstance()
7166 .getSubscriptionInfo(subId);
7167 final ParcelUuid groupUuid = info.getGroupUuid();
7168 // If it doesn't belong to any group, return just subscriberId of itself.
7169 if (groupUuid == null) {
7170 return new String[]{subscriberId};
7171 }
7172
7173 // Get all subscriberIds from the group.
7174 final List<String> mergedSubscriberIds = new ArrayList<>();
7175 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007176 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007177 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007178 for (SubscriptionInfo subInfo : groupInfos) {
7179 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7180 if (subscriberId != null) {
7181 mergedSubscriberIds.add(subscriberId);
7182 }
7183 }
7184
7185 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188
7189 }
7190 }
7191
7192 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007193 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007194 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007195 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196
7197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 final Phone phone = getPhone(subId);
7200 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7201 } finally {
7202 Binder.restoreCallingIdentity(identity);
7203 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007204 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007205
7206 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007207 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007208 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7209 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007210 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7211 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212
7213 final long identity = Binder.clearCallingIdentity();
7214 try {
7215 final Phone phone = getPhone(subId);
7216 if (phone == null) {
7217 return false;
7218 }
7219 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7220 cdmaNonRoamingList);
7221 } finally {
7222 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007223 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007224 }
7225
7226 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007227 @Deprecated
7228 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7229 enforceModifyPermission();
7230
7231 int returnValue = 0;
7232 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007233 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007234 if(result.exception == null) {
7235 if (result.result != null) {
7236 byte[] responseData = (byte[])(result.result);
7237 if(responseData.length > oemResp.length) {
7238 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7239 responseData.length + "bytes. Buffer Size is " +
7240 oemResp.length + "bytes.");
7241 }
7242 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7243 returnValue = responseData.length;
7244 }
7245 } else {
7246 CommandException ex = (CommandException) result.exception;
7247 returnValue = ex.getCommandError().ordinal();
7248 if(returnValue > 0) returnValue *= -1;
7249 }
7250 } catch (RuntimeException e) {
7251 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7252 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7253 if(returnValue > 0) returnValue *= -1;
7254 }
7255
7256 return returnValue;
7257 }
7258
7259 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007260 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007261 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007262 try {
7263 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007264 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007265 mApp, phone.getSubId(), "getRadioAccessFamily");
7266 } catch (SecurityException e) {
7267 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7268 throw e;
7269 }
chen xub97461a2018-10-26 14:17:57 -07007270 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007271 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007272 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 final long identity = Binder.clearCallingIdentity();
7275 try {
chen xub97461a2018-10-26 14:17:57 -07007276 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007277 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007278 mApp, phone.getSubId(), "getRadioAccessFamily");
7279 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
chen xub97461a2018-10-26 14:17:57 -07007283 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007284 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007285
7286 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007287 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007288 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007289 try {
7290 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7291 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007292 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007293 }
7294 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007295 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007296 }
7297 RoleManager rm = mApp.getSystemService(RoleManager.class);
7298 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7299 if (!dialerRoleHolders.contains(callingPackage)) {
7300 throw new SecurityException("App must be the dialer role holder to"
7301 + " upload a call composer pic");
7302 }
7303
7304 Executors.newSingleThreadExecutor().execute(() -> {
7305 ByteArrayOutputStream output = new ByteArrayOutputStream(
7306 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7307 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7308 boolean readUntilEnd = false;
7309 int totalBytesRead = 0;
7310 byte[] buffer = new byte[16 * 1024];
7311 while (true) {
7312 int numRead;
7313 try {
7314 numRead = input.read(buffer);
7315 } catch (IOException e) {
7316 try {
7317 fd.checkError();
7318 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7319 null);
7320 } catch (IOException e1) {
7321 // This means that the other side closed explicitly with an error. If this
7322 // happens, log and ignore.
7323 loge("Remote end of call composer picture pipe closed: " + e1);
7324 }
7325 break;
7326 }
7327 if (numRead == -1) {
7328 readUntilEnd = true;
7329 break;
7330 }
7331 totalBytesRead += numRead;
7332 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7333 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7334 try {
7335 input.close();
7336 } catch (IOException e) {
7337 // ignore
7338 }
7339 break;
7340 }
7341 output.write(buffer, 0, numRead);
7342 }
7343 // Generally, the remote end will close the file descriptors. The only case where we
7344 // close is above, where the picture size is too big.
7345
7346 try {
7347 fd.checkError();
7348 } catch (IOException e) {
7349 loge("Remote end for call composer closed with an error: " + e);
7350 return;
7351 }
7352
Hall Liuaa4211e2021-01-20 15:43:39 -08007353 if (!readUntilEnd) {
7354 loge("Did not finish reading entire image; aborting");
7355 return;
7356 }
Hall Liu82694d52020-12-11 18:22:04 -08007357
Hall Liuaa4211e2021-01-20 15:43:39 -08007358 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7359 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7360 new CallComposerPictureTransfer.Factory() {},
7361 imageData,
7362 (result) -> {
7363 if (result.first != null) {
7364 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7365 Bundle outputResult = new Bundle();
7366 outputResult.putParcelable(
7367 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7368 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7369 outputResult);
7370 } else {
7371 callback.send(result.second, null);
7372 }
7373 }
7374 );
Hall Liu82694d52020-12-11 18:22:04 -08007375 });
7376 }
7377
7378 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007379 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007380 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007381 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007382
7383 final long identity = Binder.clearCallingIdentity();
7384 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007385 ImsManager.getInstance(defaultPhone.getContext(),
7386 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007387 } finally {
7388 Binder.restoreCallingIdentity(identity);
7389 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007390 }
7391
7392 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007393 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007394 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7396 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007397 return false;
7398 }
Svet Ganovb320e182015-04-16 12:30:10 -07007399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400 final long identity = Binder.clearCallingIdentity();
7401 try {
7402 // Check the user preference and the system-level IMS setting. Even if the user has
7403 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7404 // In the long run, we may instead need to check if there exists a connection service
7405 // which can support video calling.
7406 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007407 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007408 return imsManager.isVtEnabledByPlatform()
7409 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7410 && imsManager.isVtEnabledByUser();
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007414 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007415
Andrew Leea1239f22015-03-02 17:44:07 -08007416 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007417 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7418 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007420 mApp, subId, callingPackage, callingFeatureId,
7421 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 return false;
7423 }
7424
7425 final long identity = Binder.clearCallingIdentity();
7426 try {
7427 CarrierConfigManager configManager =
7428 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007429 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007430 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7431 } finally {
7432 Binder.restoreCallingIdentity(identity);
7433 }
Andrew Leea1239f22015-03-02 17:44:07 -08007434 }
7435
7436 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007437 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007439 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 return false;
7441 }
7442
7443 final long identity = Binder.clearCallingIdentity();
7444 try {
7445 CarrierConfigManager configManager =
7446 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007447 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007448 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
Andrew Leea1239f22015-03-02 17:44:07 -08007452 }
7453
Andrew Lee9431b832015-03-09 18:46:45 -07007454 @Override
7455 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007456 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007457 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007458 }
7459
7460 @Override
7461 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007462 final long identity = Binder.clearCallingIdentity();
7463 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 } finally {
7466 Binder.restoreCallingIdentity(identity);
7467 }
Andrew Lee9431b832015-03-09 18:46:45 -07007468 }
7469
Hall Liuf6668912018-10-31 17:05:23 -07007470 /**
7471 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7472 * support for the feature and device firmware support.
7473 *
7474 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7475 */
7476 @Override
7477 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007479 final Phone phone = getPhone(subscriptionId);
7480 if (phone == null) {
7481 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7482 return false;
7483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007485 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7487 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007488 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 return isCarrierSupported && isDeviceSupported;
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Hall Liu98187582018-01-22 19:15:32 -08007493 }
7494
Hall Liuf6668912018-10-31 17:05:23 -07007495 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007496 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7497 * RTT setting, will return true if the device and carrier both support RTT.
7498 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007499 */
7500 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 final long identity = Binder.clearCallingIdentity();
7502 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007503 boolean isRttSupported = isRttSupported(subscriptionId);
7504 boolean isUserRttSettingOn = Settings.Secure.getInt(
7505 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7506 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7507 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7508 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007512 }
7513
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007514 @Deprecated
7515 @Override
7516 public String getDeviceId(String callingPackage) {
7517 return getDeviceIdWithFeature(callingPackage, null);
7518 }
7519
Sanket Padawe7310cc72015-01-14 09:53:20 -08007520 /**
7521 * Returns the unique device ID of phone, for example, the IMEI for
7522 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7523 *
7524 * <p>Requires Permission:
7525 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7526 */
7527 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007528 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007529 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007530 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007531 return null;
7532 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007533 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007534 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007535 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007536 return null;
7537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538
7539 final long identity = Binder.clearCallingIdentity();
7540 try {
7541 return phone.getDeviceId();
7542 } finally {
7543 Binder.restoreCallingIdentity(identity);
7544 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007545 }
7546
Ping Sunc67b7c22016-03-02 19:16:45 +08007547 /**
7548 * {@hide}
7549 * Returns the IMS Registration Status on a particular subid
7550 *
7551 * @param subId
7552 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007553 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007554 Phone phone = getPhone(subId);
7555 if (phone != null) {
7556 return phone.isImsRegistered();
7557 } else {
7558 return false;
7559 }
7560 }
7561
Santos Cordon7a1885b2015-02-03 11:15:19 -08007562 @Override
7563 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 final long identity = Binder.clearCallingIdentity();
7565 try {
7566 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007570 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007571
Tyler Gunnf70ed162019-04-03 15:28:53 -07007572 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007573 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007574 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007576 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007577 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7578 }
7579 final long identity = Binder.clearCallingIdentity();
7580 try {
7581 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
7585 }
7586
7587 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007588 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007589 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007590 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007591 mApp,
7592 subscriptionId,
7593 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007594 final long identity = Binder.clearCallingIdentity();
7595 try {
7596 Phone phone = getPhone(subscriptionId);
7597 if (phone == null) {
7598 return null;
7599 }
7600 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
7603 }
7604 }
7605
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007606 /**
7607 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007608 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007609 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 Phone phone = getPhone(subId);
7613 if (phone != null) {
7614 return phone.isWifiCallingEnabled();
7615 } else {
7616 return false;
7617 }
7618 } finally {
7619 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007620 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007621 }
7622
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007623 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007624 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007625 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007626 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007627 final long identity = Binder.clearCallingIdentity();
7628 try {
7629 Phone phone = getPhone(subId);
7630 if (phone != null) {
7631 return phone.isVideoEnabled();
7632 } else {
7633 return false;
7634 }
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007637 }
7638 }
7639
7640 /**
7641 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7642 * defined in {@link ImsRegistrationImplBase}.
7643 */
7644 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 final long identity = Binder.clearCallingIdentity();
7646 try {
7647 Phone phone = getPhone(subId);
7648 if (phone != null) {
7649 return phone.getImsRegistrationTech();
7650 } else {
7651 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7652 }
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007655 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007656 }
7657
Stuart Scott8eef64f2015-04-08 15:13:54 -07007658 @Override
7659 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007660 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007661 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7662 return;
7663 }
Kai Shif70f46f2021-03-03 13:59:46 -08007664 Phone defaultPhone = getDefaultPhone();
7665 if (defaultPhone != null) {
7666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7667 mApp, getDefaultPhone().getSubId(), "factoryReset");
7668 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007669 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007670
Svet Ganovcc087f82015-05-12 20:35:54 -07007671 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007672 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7673 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007674 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007675 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007676 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007677 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007678 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007679 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007680 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007681 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007682 // There has been issues when Sms raw table somehow stores orphan
7683 // fragments. They lead to garbled message when new fragments come
7684 // in and combined with those stale ones. In case this happens again,
7685 // user can reset all network settings which will clean up this table.
7686 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007687 // Clean up IMS settings as well here.
7688 int slotId = getSlotIndex(subId);
7689 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7690 ImsManager.getInstance(mApp, slotId).factoryReset();
7691 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007692
Kai Shif70f46f2021-03-03 13:59:46 -08007693 if (defaultPhone == null) {
7694 return;
7695 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007696 // Erase modem config if erase modem on network setting is enabled.
7697 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7698 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7699 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007700 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007701 }
Kai Shif70f46f2021-03-03 13:59:46 -08007702
7703 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007704 } finally {
7705 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007706 }
7707 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007708
SongFerngWangfd89b102021-05-27 22:44:54 +08007709 @VisibleForTesting
7710 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7711 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7712 return;
7713 }
7714 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7715 RILConstants.PREFERRED_NETWORK_MODE);
7716 SubscriptionManager.setSubscriptionProperty(subId,
7717 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7718 "user=" + defaultNetworkType);
7719 phone.loadAllowedNetworksFromSubscriptionDatabase();
7720 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7721 defaultNetworkType, null);
7722 }
7723
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007724 private void cleanUpSmsRawTable(Context context) {
7725 ContentResolver resolver = context.getContentResolver();
7726 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7727 resolver.delete(uri, null, null);
7728 }
7729
Narayan Kamath1c496c22015-04-16 14:40:19 +01007730 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007731 public String getSimLocaleForSubscriber(int subId) {
7732 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7733 final Phone phone = getPhone(subId);
7734 if (phone == null) {
7735 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007736 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007738 final long identity = Binder.clearCallingIdentity();
7739 try {
chen xu5d3637b2019-01-21 23:31:38 -08007740 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007741 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007742 if (info == null) {
7743 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7744 return null;
7745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746 // Try and fetch the locale from the carrier properties or from the SIM language
7747 // preferences (EF-PL and EF-LI)...
7748 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007750 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7751 if (localeFromDefaultSim != null) {
7752 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7753 if (DBG) log("Using locale from subId: " + subId + " locale: "
7754 + localeFromDefaultSim);
7755 return localeFromDefaultSim.toLanguageTag();
7756 } else {
7757 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 }
7759 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007760
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 // The SIM language preferences only store a language (e.g. fr = French), not an
7762 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7763 // the SIM and carrier preferences does not include a country we add the country
7764 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007765 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007767 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768 return mccLocale.toLanguageTag();
7769 }
7770
7771 if (DBG) log("No locale found - returning null");
7772 return null;
7773 } finally {
7774 Binder.restoreCallingIdentity(identity);
7775 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007776 }
7777
7778 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007779 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007780 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007781 }
7782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007783 /**
7784 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7785 */
7786 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007787 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007788 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007789 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007790
Chenjie Yu1ba97252018-01-11 18:16:20 -08007791 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007792 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007793
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007794 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007795 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7796 * representing the state of the modem.
7797 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007798 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7799 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007800 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007801 */
7802 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007803 public void requestModemActivityInfo(ResultReceiver result) {
7804 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007805 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806
7807 final long identity = Binder.clearCallingIdentity();
7808 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007809 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 } finally {
7811 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007812 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007813 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007814
Siddharth Rayb8114062018-06-17 15:02:38 -07007815 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7816 // less than total activity duration.
7817 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7818 if (info == null) {
7819 return false;
7820 }
7821 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007822 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7823 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7824
Siddharth Rayb8114062018-06-17 15:02:38 -07007825 return (info.isValid()
7826 && (info.getSleepTimeMillis() <= activityDurationMs)
7827 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007828 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007829 && (totalTxTimeMs <= activityDurationMs));
7830 }
7831
Jack Yu85bd38a2015-11-09 11:34:32 -08007832 /**
7833 * {@hide}
7834 * Returns the service state information on specified subscription.
7835 */
7836 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007837 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7838 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007839 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007840 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007841 return null;
7842 }
7843
Hall Liuf19c44f2018-11-27 14:38:17 -08007844 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7845 LocationAccessPolicy.checkLocationPermission(mApp,
7846 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7847 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007848 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007849 .setCallingPid(Binder.getCallingPid())
7850 .setCallingUid(Binder.getCallingUid())
7851 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007852 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007853 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007854 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7855 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007856 .build());
7857
7858 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7859 LocationAccessPolicy.checkLocationPermission(mApp,
7860 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7861 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007862 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007863 .setCallingPid(Binder.getCallingPid())
7864 .setCallingUid(Binder.getCallingUid())
7865 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007866 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007867 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007868 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7869 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007870 .build());
7871 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7872 boolean hasFinePermission =
7873 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7874 boolean hasCoarsePermission =
7875 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7876
Jack Yu479f40e2020-10-27 21:29:25 -07007877 final Phone phone = getPhone(subId);
7878 if (phone == null) {
7879 return null;
7880 }
7881
Jordan Liu0f2bc442020-11-18 16:47:37 -08007882 final long identity = Binder.clearCallingIdentity();
7883
Jack Yu479f40e2020-10-27 21:29:25 -07007884 boolean isCallingPackageDataService = phone.getDataServicePackages()
7885 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007887 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7888 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7889 Rlog.d(LOG_TAG,
7890 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7891 return null;
7892 }
7893
Hall Liuf19c44f2018-11-27 14:38:17 -08007894 ServiceState ss = phone.getServiceState();
7895
7896 // Scrub out the location info in ServiceState depending on what level of access
7897 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007898 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007899 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7900 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 } finally {
7902 Binder.restoreCallingIdentity(identity);
7903 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007904 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007905
7906 /**
7907 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7908 *
7909 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7910 * voicemail ringtone.
7911 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7912 * PhoneAccount.
7913 */
7914 @Override
7915 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007916 final long identity = Binder.clearCallingIdentity();
7917 try {
7918 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7919 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007920 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7924 } finally {
7925 Binder.restoreCallingIdentity(identity);
7926 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007927 }
7928
7929 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007930 * Sets the per-account voicemail ringtone.
7931 *
7932 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7933 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7934 *
7935 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7936 * voicemail ringtone.
7937 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7938 * PhoneAccount.
7939 */
7940 @Override
7941 public void setVoicemailRingtoneUri(String callingPackage,
7942 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007943 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007945 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7946 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7948 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7949 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951
7952 final long identity = Binder.clearCallingIdentity();
7953 try {
7954 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7955 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007956 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 }
7958 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007961 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007962 }
7963
7964 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007965 * Returns whether vibration is set for voicemail notification in Phone settings.
7966 *
7967 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7968 * voicemail vibration setting.
7969 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7970 */
7971 @Override
7972 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7976 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007977 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007984 }
7985
Youhan Wange64578a2016-05-02 15:32:42 -07007986 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007987 * Sets the per-account voicemail vibration.
7988 *
7989 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7990 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7991 *
7992 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7993 * voicemail vibration setting.
7994 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7995 * specific PhoneAccount.
7996 */
7997 @Override
7998 public void setVoicemailVibrationEnabled(String callingPackage,
7999 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008002 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8003 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8005 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8006 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
8008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008009 final long identity = Binder.clearCallingIdentity();
8010 try {
8011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8012 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008013 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 }
8015 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008018 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 }
8020
8021 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008022 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8023 *
8024 * @throws SecurityException if the caller does not have the required permission
8025 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008026 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008027 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008028 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008029 }
8030
8031 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008032 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8033 * permission.
8034 *
8035 * @throws SecurityException if the caller does not have the required permission
8036 */
8037 private void enforceSendSmsPermission() {
8038 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8039 }
8040
8041 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008042 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008043 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008044 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008045 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008046 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 final long identity = Binder.clearCallingIdentity();
8048 try {
8049 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008050 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 if (componentName == null) {
8052 throw new SecurityException(
8053 "Caller not current active visual voicemail package[null]");
8054 }
8055 String vvmPackage = componentName.getPackageName();
8056 if (!callingPackage.equals(vvmPackage)) {
8057 throw new SecurityException("Caller not current active visual voicemail package["
8058 + vvmPackage + "]");
8059 }
8060 } finally {
8061 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008062 }
8063 }
8064
8065 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008066 * Return the application ID for the app type.
8067 *
8068 * @param subId the subscription ID that this request applies to.
8069 * @param appType the uicc app type.
8070 * @return Application ID for specificied app type, or null if no uicc.
8071 */
8072 @Override
8073 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008074 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008075 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076
8077 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008078 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008079 if (phone == null) {
8080 return null;
8081 }
8082 String aid = null;
8083 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008084 aid = UiccController.getInstance().getUiccPort(phone.getPhoneId())
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008085 .getApplicationByType(appType).getAid();
8086 } catch (Exception e) {
8087 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8088 }
8089 return aid;
8090 } finally {
8091 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008092 }
Youhan Wange64578a2016-05-02 15:32:42 -07008093 }
8094
Youhan Wang4001d252016-05-11 10:29:41 -07008095 /**
8096 * Return the Electronic Serial Number.
8097 *
8098 * @param subId the subscription ID that this request applies to.
8099 * @return ESN or null if error.
8100 */
8101 @Override
8102 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008103 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008104 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105
8106 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008107 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 if (phone == null) {
8109 return null;
8110 }
8111 String esn = null;
8112 try {
8113 esn = phone.getEsn();
8114 } catch (Exception e) {
8115 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8116 }
8117 return esn;
8118 } finally {
8119 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008120 }
Youhan Wang4001d252016-05-11 10:29:41 -07008121 }
8122
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008123 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008124 * Return the Preferred Roaming List Version.
8125 *
8126 * @param subId the subscription ID that this request applies to.
8127 * @return PRLVersion or null if error.
8128 */
8129 @Override
8130 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008131 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008132 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133
8134 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008135 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 if (phone == null) {
8137 return null;
8138 }
8139 String cdmaPrlVersion = null;
8140 try {
8141 cdmaPrlVersion = phone.getCdmaPrlVersion();
8142 } catch (Exception e) {
8143 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8144 }
8145 return cdmaPrlVersion;
8146 } finally {
8147 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008148 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008149 }
8150
8151 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008152 * Get snapshot of Telephony histograms
8153 * @return List of Telephony histograms
8154 * @hide
8155 */
8156 @Override
8157 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8159 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008160
8161 final long identity = Binder.clearCallingIdentity();
8162 try {
8163 return RIL.getTelephonyRILTimingHistograms();
8164 } finally {
8165 Binder.restoreCallingIdentity(identity);
8166 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008167 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008168
8169 /**
8170 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008171 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8172 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008173 * Require system privileges. In the future we may add this to carrier APIs.
8174 *
Michele Berionne482f8202018-11-27 18:57:59 -08008175 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008176 */
8177 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008178 @TelephonyManager.SetCarrierRestrictionResult
8179 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008180 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008181 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008182
Michele Berionne482f8202018-11-27 18:57:59 -08008183 if (carrierRestrictionRules == null) {
8184 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008185 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008186
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008187 final long identity = Binder.clearCallingIdentity();
8188 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008189 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008190 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191 } finally {
8192 Binder.restoreCallingIdentity(identity);
8193 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008194 }
8195
8196 /**
8197 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008198 * Get the allowed carrier list and the excluded carrier list, including the priority between
8199 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008200 * Require system privileges. In the future we may add this to carrier APIs.
8201 *
Michele Berionne482f8202018-11-27 18:57:59 -08008202 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008203 */
8204 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008205 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008206 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008207 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208
8209 final long identity = Binder.clearCallingIdentity();
8210 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008211 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8212 if (response instanceof CarrierRestrictionRules) {
8213 return (CarrierRestrictionRules) response;
8214 }
8215 // Response is an Exception of some kind,
8216 // which is signalled to the user as a NULL retval
8217 return null;
8218 } catch (Exception e) {
8219 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8220 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008224 }
8225
fionaxu59545b42016-05-25 15:53:37 -07008226 /**
fionaxu59545b42016-05-25 15:53:37 -07008227 * Action set from carrier signalling broadcast receivers to enable/disable radio
8228 * @param subId the subscription ID that this action applies to.
8229 * @param enabled control enable or disable radio.
8230 * {@hide}
8231 */
8232 @Override
8233 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8234 enforceModifyPermission();
8235 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236
8237 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008238 if (phone == null) {
8239 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8240 return;
8241 }
8242 try {
8243 phone.carrierActionSetRadioEnabled(enabled);
8244 } catch (Exception e) {
8245 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 } finally {
8247 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008248 }
8249 }
8250
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008251 /**
Sooraj Sasindranbf5c79c2021-06-15 14:52:55 -07008252 * Enable or disable Voice over NR (VoNR)
8253 * @param subId the subscription ID that this action applies to.
8254 * @param enabled enable or disable VoNR.
8255 * @return operation result.
8256 */
8257 @Override
8258 public int setVoNrEnabled(int subId, boolean enabled) {
8259 enforceModifyPermission();
8260 final Phone phone = getPhone(subId);
8261
8262 final long identity = Binder.clearCallingIdentity();
8263 if (phone == null) {
8264 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8265 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8266 }
8267
8268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8269 try {
8270 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8271 workSource);
8272 if (DBG) log("setVoNrEnabled result: " + result);
8273 return result;
8274 } finally {
8275 Binder.restoreCallingIdentity(identity);
8276 }
8277 }
8278
8279 /**
8280 * Is voice over NR enabled
8281 * @return true if VoNR is enabled else false
8282 */
8283 @Override
8284 public boolean isVoNrEnabled(int subId) {
8285 enforceReadPrivilegedPermission("isVoNrEnabled");
8286 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8287 final long identity = Binder.clearCallingIdentity();
8288 try {
8289 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8290 null, subId, workSource);
8291 if (DBG) log("isVoNrEnabled: " + isEnabled);
8292 return isEnabled;
8293 } finally {
8294 Binder.restoreCallingIdentity(identity);
8295 }
8296 }
8297
8298 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008299 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8300 * network status based on which carrier apps could apply actions accordingly,
8301 * enable/disable default url handler for example.
8302 *
8303 * @param subId the subscription ID that this action applies to.
8304 * @param report control start/stop reporting the default network status.
8305 * {@hide}
8306 */
8307 @Override
8308 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8309 enforceModifyPermission();
8310 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008311
8312 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008313 if (phone == null) {
8314 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8315 return;
8316 }
8317 try {
8318 phone.carrierActionReportDefaultNetworkStatus(report);
8319 } catch (Exception e) {
8320 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008321 } finally {
8322 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008323 }
8324 }
8325
8326 /**
fionaxud9622282017-07-17 17:51:30 -07008327 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8328 * @param subId the subscription ID that this action applies to.
8329 * {@hide}
8330 */
8331 @Override
8332 public void carrierActionResetAll(int subId) {
8333 enforceModifyPermission();
8334 final Phone phone = getPhone(subId);
8335 if (phone == null) {
8336 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8337 return;
8338 }
8339 try {
8340 phone.carrierActionResetAll();
8341 } catch (Exception e) {
8342 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8343 }
8344 }
8345
8346 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008347 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8348 * bug report is being generated.
8349 */
8350 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008351 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008352 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8353 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008354 writer.println("Permission Denial: can't dump Phone from pid="
8355 + Binder.getCallingPid()
8356 + ", uid=" + Binder.getCallingUid()
8357 + "without permission "
8358 + android.Manifest.permission.DUMP);
8359 return;
8360 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008361 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008362 }
Jack Yueb89b242016-06-22 13:27:47 -07008363
Brad Ebingerdac2f002018-04-03 15:17:52 -07008364 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008365 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8366 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8367 @NonNull String[] args) {
8368 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8369 this, in.getFileDescriptor(), out.getFileDescriptor(),
8370 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008371 }
8372
Jack Yueb89b242016-06-22 13:27:47 -07008373 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008374 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008375 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008376 * @param reason the reason the data enable change is taking place
8377 * @param enabled True if enabling the data, otherwise disabling.
8378 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008379 */
8380 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008381 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008382 boolean enabled) {
8383 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8384 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8385 try {
8386 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008387 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008388 } catch (SecurityException se) {
8389 enforceModifyPermission();
8390 }
8391 } else {
8392 enforceModifyPermission();
8393 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
8397 Phone phone = getPhone(subId);
8398 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008399 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8400 phone.carrierActionSetMeteredApnsEnabled(enabled);
8401 } else {
8402 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008404 }
8405 } finally {
8406 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008407 }
8408 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008409
8410 /**
8411 * Get Client request stats
8412 * @return List of Client Request Stats
8413 * @hide
8414 */
8415 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008416 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8417 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008418 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008419 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008420 return null;
8421 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008422 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008424 final long identity = Binder.clearCallingIdentity();
8425 try {
8426 if (phone != null) {
8427 return phone.getClientRequestStats();
8428 }
8429
8430 return null;
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
8433 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008434 }
8435
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008436 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008437 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008438 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008439 }
Jack Yueb4124c2017-02-16 15:32:43 -08008440
8441 /**
Grace Chen70990072017-03-24 17:21:30 -07008442 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008443 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008444 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008445 * @param state State of SIM (power down, power up, pass through)
8446 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8447 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8448 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008449 *
8450 **/
8451 @Override
Grace Chen70990072017-03-24 17:21:30 -07008452 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008453 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008454 Phone phone = PhoneFactory.getPhone(slotIndex);
8455
vagdeviaf9a5b92018-08-15 16:01:53 -07008456 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008461 phone.setSimPowerState(state, null, workSource);
8462 }
8463 } finally {
8464 Binder.restoreCallingIdentity(identity);
8465 }
8466 }
8467
8468 /**
8469 * Set SIM card power state.
8470 *
8471 * @param slotIndex SIM slot id.
8472 * @param state State of SIM (power down, power up, pass through)
8473 * @param callback callback to trigger after success or failure
8474 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8475 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8476 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8477 *
8478 **/
8479 @Override
8480 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8481 IIntegerConsumer callback) {
8482 enforceModifyPermission();
8483 Phone phone = PhoneFactory.getPhone(slotIndex);
8484
8485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8486
8487 final long identity = Binder.clearCallingIdentity();
8488 try {
8489 if (phone != null) {
8490 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8491 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008492 }
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008495 }
8496 }
Shuo Qiandd210312017-04-12 22:11:33 +00008497
Tyler Gunn65d45c22017-06-05 11:22:26 -07008498 private boolean isUssdApiAllowed(int subId) {
8499 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008500 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008501 if (configManager == null) {
8502 return false;
8503 }
8504 PersistableBundle pb = configManager.getConfigForSubId(subId);
8505 if (pb == null) {
8506 return false;
8507 }
8508 return pb.getBoolean(
8509 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8510 }
8511
Shuo Qiandd210312017-04-12 22:11:33 +00008512 /**
8513 * Check if phone is in emergency callback mode
8514 * @return true if phone is in emergency callback mode
8515 * @param subId sub id
8516 */
goneil9c5f4872017-12-05 14:07:56 -08008517 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008518 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008519 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008520 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008521
8522 final long identity = Binder.clearCallingIdentity();
8523 try {
8524 if (phone != null) {
8525 return phone.isInEcm();
8526 } else {
8527 return false;
8528 }
8529 } finally {
8530 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008531 }
8532 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008533
8534 /**
8535 * Get the current signal strength information for the given subscription.
8536 * Because this information is not updated when the device is in a low power state
8537 * it should not be relied-upon to be current.
8538 * @param subId Subscription index
8539 * @return the most recent cached signal strength info from the modem
8540 */
8541 @Override
8542 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008543 final long identity = Binder.clearCallingIdentity();
8544 try {
8545 Phone p = getPhone(subId);
8546 if (p == null) {
8547 return null;
8548 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008550 return p.getSignalStrength();
8551 } finally {
8552 Binder.restoreCallingIdentity(identity);
8553 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008554 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008555
Pengquan Meng77b7f132018-08-22 14:49:57 -07008556 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008557 * Get the current modem radio state for the given slot.
8558 * @param slotIndex slot index.
8559 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008560 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008561 * @return the current radio power state from the modem
8562 */
8563 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008564 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008565 Phone phone = PhoneFactory.getPhone(slotIndex);
8566 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8568 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008569 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8570 }
8571
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
8574 return phone.getRadioPowerState();
8575 } finally {
8576 Binder.restoreCallingIdentity(identity);
8577 }
8578 }
8579 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8580 }
8581
8582 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008583 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8584 *
8585 * <p>Requires one of the following permissions:
8586 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8587 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8588 * privileges.
8589 *
8590 * @param subId subscription id
8591 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8592 * {@code false}.
8593 */
8594 @Override
8595 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008596 try {
8597 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8598 null);
8599 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008600 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008601 mApp, subId, "isDataRoamingEnabled");
8602 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008603
Pengquan Menga1bb6272018-09-06 09:59:22 -07008604 boolean isEnabled = false;
8605 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008606 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008607 Phone phone = getPhone(subId);
8608 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008609 } finally {
8610 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008611 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008612 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008613 }
8614
8615
8616 /**
8617 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8618 *
8619 * <p> Requires permission:
8620 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8621 * privileges.
8622 *
8623 * @param subId subscription id
8624 * @param isEnabled {@code true} means enable, {@code false} means disable.
8625 */
8626 @Override
8627 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008628 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8629 mApp, subId, "setDataRoamingEnabled");
8630
Pengquan Menga1bb6272018-09-06 09:59:22 -07008631 final long identity = Binder.clearCallingIdentity();
8632 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008633 Phone phone = getPhone(subId);
8634 if (phone != null) {
8635 phone.setDataRoamingEnabled(isEnabled);
8636 }
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008639 }
8640 }
8641
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008642 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008643 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008644 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008645 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008646 mApp, subId, "isManualNetworkSelectionAllowed");
8647
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008648 boolean isAllowed = true;
8649 final long identity = Binder.clearCallingIdentity();
8650 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008651 Phone phone = getPhone(subId);
8652 if (phone != null) {
8653 isAllowed = phone.isCspPlmnEnabled();
8654 }
8655 } finally {
8656 Binder.restoreCallingIdentity(identity);
8657 }
8658 return isAllowed;
8659 }
8660
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008661 private boolean haveCarrierPrivilegeAccess(UiccCard card, String callingPackage) {
8662 // TODO once MEP API refactoring CL is merged, loop port list from UiccCardInfo,
8663 // and if find the matching UiccPort by UiccController.getUiccPortForSlot(slot, portIdx)
8664 // Update each UiccPort object based on privilege access
8665 UiccPort[] uiccPorts = card.getUiccPortList();
8666 for (UiccPort port : uiccPorts) {
8667 UiccProfile profile = port.getUiccProfile();
8668 if (profile == null ||
8669 profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8670 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8671 return false;
8672 }
8673 }
8674 return true;
8675 }
8676
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008677 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008678 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008679 // Verify that tha callingPackage belongs to the calling UID
8680 mApp.getSystemService(AppOpsManager.class)
8681 .checkPackage(Binder.getCallingUid(), callingPackage);
8682
Jordan Liu1e142fc2019-04-22 15:10:43 -07008683 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008684 try {
8685 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008686 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008687 } catch (SecurityException e) {
8688 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8689 // has carrier privileges on an active UICC
8690 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8691 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008692 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008693 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008694 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008695
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008698 UiccController uiccController = UiccController.getInstance();
8699 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008700 if (hasReadPermission) {
8701 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008702 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008703
8704 // Remove private info if the caller doesn't have access
8705 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8706 for (UiccCardInfo cardInfo : cardInfos) {
8707 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8708 // is available
8709 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008710 // TODO remove card.getUiccPortList().length once MEP API refactoring CL is merged
8711 // Get UiccPortInfo from CardInfo and process further based on each UiccPort
8712 if (card == null || card.getUiccPortList().length == 0) {
8713 // assume no access if the card or ports are unavailable
Jordan Liu1e142fc2019-04-22 15:10:43 -07008714 filteredInfos.add(cardInfo.getUnprivileged());
8715 continue;
8716 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008717
8718 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008719 filteredInfos.add(cardInfo);
8720 } else {
8721 filteredInfos.add(cardInfo.getUnprivileged());
8722 }
8723 }
8724 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008725 } finally {
8726 Binder.restoreCallingIdentity(identity);
8727 }
8728 }
8729
8730 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008731 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008732 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008734 final long identity = Binder.clearCallingIdentity();
8735 try {
8736 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8737 if (slots == null) {
8738 Rlog.i(LOG_TAG, "slots is null.");
8739 return null;
8740 }
8741
8742 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8743 for (int i = 0; i < slots.length; i++) {
8744 UiccSlot slot = slots[i];
8745 if (slot == null) {
8746 continue;
8747 }
8748
Jordan Liu7be7e652019-05-06 18:55:02 +00008749 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008750 UiccCard card = slot.getUiccCard();
8751 if (card != null) {
8752 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008753 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008754 cardId = slot.getEid();
8755 if (TextUtils.isEmpty(cardId)) {
8756 cardId = slot.getIccId();
8757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008758 }
8759
Jordan Liu857451f2019-05-09 16:35:35 -07008760 if (cardId != null) {
8761 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8762 // if cardId is an EID, it's all digits so this is fine
8763 cardId = IccUtils.stripTrailingFs(cardId);
8764 }
8765
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008766 int cardState = 0;
8767 switch (slot.getCardState()) {
8768 case CARDSTATE_ABSENT:
8769 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8770 break;
8771 case CARDSTATE_PRESENT:
8772 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8773 break;
8774 case CARDSTATE_ERROR:
8775 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8776 break;
8777 case CARDSTATE_RESTRICTED:
8778 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8779 break;
8780 default:
8781 break;
8782
8783 }
8784
8785 infos[i] = new UiccSlotInfo(
8786 slot.isActive(),
8787 slot.isEuicc(),
8788 cardId,
8789 cardState,
8790 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008791 slot.isExtendedApduSupported(),
8792 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008793 }
8794 return infos;
8795 } finally {
8796 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008797 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008798 }
8799
8800 @Override
8801 public boolean switchSlots(int[] physicalSlots) {
8802 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008803
8804 final long identity = Binder.clearCallingIdentity();
8805 try {
8806 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8807 } finally {
8808 Binder.restoreCallingIdentity(identity);
8809 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008810 }
Jack Yu4c988042018-02-27 15:30:01 -08008811
8812 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008813 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008814 final long identity = Binder.clearCallingIdentity();
8815 try {
8816 return UiccController.getInstance().getCardIdForDefaultEuicc();
8817 } finally {
8818 Binder.restoreCallingIdentity(identity);
8819 }
8820 }
8821
Pengquan Meng85728fb2018-03-12 16:31:21 -07008822 /**
goneil47ffb6e2018-04-06 15:40:58 -07008823 * A test API to reload the UICC profile.
8824 *
8825 * <p>Requires that the calling app has permission
8826 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8827 * @hide
8828 */
8829 @Override
8830 public void refreshUiccProfile(int subId) {
8831 enforceModifyPermission();
8832
8833 final long identity = Binder.clearCallingIdentity();
8834 try {
8835 Phone phone = getPhone(subId);
8836 if (phone == null) {
8837 return;
8838 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008839 UiccPort uiccPort = phone.getUiccPort();
8840 if (uiccPort == null) {
goneil47ffb6e2018-04-06 15:40:58 -07008841 return;
8842 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00008843 UiccProfile uiccProfile = uiccPort.getUiccProfile();
goneil47ffb6e2018-04-06 15:40:58 -07008844 if (uiccProfile == null) {
8845 return;
8846 }
8847 uiccProfile.refresh();
8848 } finally {
8849 Binder.restoreCallingIdentity(identity);
8850 }
8851 }
8852
8853 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008854 * Returns false if the mobile data is disabled by default, otherwise return true.
8855 */
8856 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008857 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008858 }
8859
8860 /**
8861 * Returns true if the data roaming is enabled by default, i.e the system property
8862 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8863 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8864 */
8865 private boolean getDefaultDataRoamingEnabled(int subId) {
8866 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008867 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008868 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008869 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8870 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8871 return isDataRoamingEnabled;
8872 }
8873
8874 /**
8875 * Returns the default network type for the given {@code subId}, if the default network type is
8876 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8877 */
8878 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008879 List<Integer> list = TelephonyProperties.default_network();
8880 int phoneId = mSubscriptionController.getPhoneId(subId);
8881 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8882 return list.get(phoneId);
8883 }
8884 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008885 }
fionaxua13278b2018-03-21 00:08:13 -07008886
8887 @Override
8888 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008889 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008891
8892 final long identity = Binder.clearCallingIdentity();
8893 try {
8894 final Phone phone = getPhone(subId);
8895 if (phone == null) {
8896 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8897 return;
8898 }
chen xueaba88a2019-03-15 13:15:10 -07008899 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8900 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008901 if (carrierPrivilegeRules == null) {
8902 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8903 } else {
8904 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008906 } finally {
8907 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008908 }
fionaxua13278b2018-03-21 00:08:13 -07008909 }
8910
8911 @Override
8912 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008913 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008914
8915 final long identity = Binder.clearCallingIdentity();
8916 try {
8917 final Phone phone = getPhone(subId);
8918 if (phone == null) {
8919 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8920 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8921 }
8922 return phone.getCarrierIdListVersion();
8923 } finally {
8924 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008925 }
fionaxua13278b2018-03-21 00:08:13 -07008926 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008927
8928 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008929 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8930 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008931 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008932 mApp, subId, callingPackage, callingFeatureId,
8933 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008934 return -1;
8935 }
8936
8937 final long identity = Binder.clearCallingIdentity();
8938 try {
8939 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8940 } finally {
8941 Binder.restoreCallingIdentity(identity);
8942 }
8943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008944
8945 @Override
8946 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008947 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008948 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008949 mApp, subId, "getCdmaRoamingMode");
8950
8951 final long identity = Binder.clearCallingIdentity();
8952 try {
8953 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8954 } finally {
8955 Binder.restoreCallingIdentity(identity);
8956 }
8957 }
8958
8959 @Override
8960 public boolean setCdmaRoamingMode(int subId, int mode) {
8961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8962 mApp, subId, "setCdmaRoamingMode");
8963
8964 final long identity = Binder.clearCallingIdentity();
8965 try {
8966 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8967 } finally {
8968 Binder.restoreCallingIdentity(identity);
8969 }
8970 }
8971
8972 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008973 public int getCdmaSubscriptionMode(int subId) {
8974 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008975 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008976 mApp, subId, "getCdmaSubscriptionMode");
8977
8978 final long identity = Binder.clearCallingIdentity();
8979 try {
8980 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
8984 }
8985
8986 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008987 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8989 mApp, subId, "setCdmaSubscriptionMode");
8990
8991 final long identity = Binder.clearCallingIdentity();
8992 try {
8993 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008998
sqianc5eccab2018-10-19 18:46:41 -07008999 @Override
sqian8c685422019-02-22 15:55:18 -08009000 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009001 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009003 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9004 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009005 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9006 }
9007 final long identity = Binder.clearCallingIdentity();
9008 try {
sqian854d44b2018-12-12 16:48:18 -08009009 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9010 for (Phone phone: PhoneFactory.getPhones()) {
9011 if (phone.getEmergencyNumberTracker() != null
9012 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9013 emergencyNumberListInternal.put(
9014 phone.getSubId(),
9015 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9016 }
sqian11b7a0e2018-12-05 18:48:28 -08009017 }
sqian854d44b2018-12-12 16:48:18 -08009018 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009019 } finally {
9020 Binder.restoreCallingIdentity(identity);
9021 }
sqianc5eccab2018-10-19 18:46:41 -07009022 }
9023
9024 @Override
sqian8c685422019-02-22 15:55:18 -08009025 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009026 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009027 if (!exactMatch) {
9028 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009029 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009030 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009031 }
9032 final long identity = Binder.clearCallingIdentity();
9033 try {
sqian854d44b2018-12-12 16:48:18 -08009034 for (Phone phone: PhoneFactory.getPhones()) {
9035 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009036 && phone.getEmergencyNumberTracker()
9037 .isEmergencyNumber(number, exactMatch)) {
9038 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009039 }
sqian11b7a0e2018-12-05 18:48:28 -08009040 }
9041 return false;
9042 } finally {
9043 Binder.restoreCallingIdentity(identity);
9044 }
9045 }
9046
sqianf4ca7ed2019-01-15 18:32:07 -08009047 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009048 * Start emergency callback mode for GsmCdmaPhone for testing.
9049 */
9050 @Override
9051 public void startEmergencyCallbackMode() {
9052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9053 "startEmergencyCallbackMode");
9054 enforceModifyPermission();
9055 final long identity = Binder.clearCallingIdentity();
9056 try {
9057 for (Phone phone : PhoneFactory.getPhones()) {
9058 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9059 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9060 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9061 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9062 gsmCdmaPhone.obtainMessage(
9063 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9064 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9065 }
9066 }
9067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
9071
9072 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009073 * Update emergency number list for test mode.
9074 */
9075 @Override
9076 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9078 "updateEmergencyNumberListTestMode");
9079
9080 final long identity = Binder.clearCallingIdentity();
9081 try {
9082 for (Phone phone: PhoneFactory.getPhones()) {
9083 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9084 if (tracker != null) {
9085 tracker.executeEmergencyNumberTestModeCommand(action, num);
9086 }
9087 }
9088 } finally {
9089 Binder.restoreCallingIdentity(identity);
9090 }
9091 }
9092
9093 /**
9094 * Get the full emergency number list for test mode.
9095 */
9096 @Override
9097 public List<String> getEmergencyNumberListTestMode() {
9098 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9099 "getEmergencyNumberListTestMode");
9100
9101 final long identity = Binder.clearCallingIdentity();
9102 try {
9103 Set<String> emergencyNumbers = new HashSet<>();
9104 for (Phone phone: PhoneFactory.getPhones()) {
9105 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9106 if (tracker != null) {
9107 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9108 emergencyNumbers.add(num.getNumber());
9109 }
9110 }
9111 }
9112 return new ArrayList<>(emergencyNumbers);
9113 } finally {
9114 Binder.restoreCallingIdentity(identity);
9115 }
9116 }
9117
chen xud6b45bd2018-10-30 22:27:10 -07009118 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009119 public int getEmergencyNumberDbVersion(int subId) {
9120 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9121
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
9124 final Phone phone = getPhone(subId);
9125 if (phone == null) {
9126 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9127 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9128 }
9129 return phone.getEmergencyNumberDbVersion();
9130 } finally {
9131 Binder.restoreCallingIdentity(identity);
9132 }
9133 }
9134
9135 @Override
9136 public void notifyOtaEmergencyNumberDbInstalled() {
9137 enforceModifyPermission();
9138
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
9141 for (Phone phone: PhoneFactory.getPhones()) {
9142 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9143 if (tracker != null) {
9144 tracker.updateOtaEmergencyNumberDatabase();
9145 }
9146 }
9147 } finally {
9148 Binder.restoreCallingIdentity(identity);
9149 }
9150 }
9151
9152 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009153 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009154 enforceActiveEmergencySessionPermission();
9155
9156 final long identity = Binder.clearCallingIdentity();
9157 try {
9158 for (Phone phone: PhoneFactory.getPhones()) {
9159 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9160 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009161 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9162 }
9163 }
9164 } finally {
9165 Binder.restoreCallingIdentity(identity);
9166 }
9167 }
9168
9169 @Override
9170 public void resetOtaEmergencyNumberDbFilePath() {
9171 enforceActiveEmergencySessionPermission();
9172
9173 final long identity = Binder.clearCallingIdentity();
9174 try {
9175 for (Phone phone: PhoneFactory.getPhones()) {
9176 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9177 if (tracker != null) {
9178 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009179 }
9180 }
9181 } finally {
9182 Binder.restoreCallingIdentity(identity);
9183 }
9184 }
9185
9186 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009187 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9188 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9189 Phone phone = getPhone(subId);
9190 if (phone == null) {
9191 return null;
9192 }
9193 final long identity = Binder.clearCallingIdentity();
9194 try {
9195 UiccProfile profile = UiccController.getInstance()
9196 .getUiccProfileForPhone(phone.getPhoneId());
9197 if (profile != null) {
9198 return profile.getCertsFromCarrierPrivilegeAccessRules();
9199 }
9200 } finally {
9201 Binder.restoreCallingIdentity(identity);
9202 }
9203 return null;
9204 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009205
9206 /**
9207 * Enable or disable a modem stack.
9208 */
9209 @Override
9210 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9211 enforceModifyPermission();
9212
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
9215 Phone phone = PhoneFactory.getPhone(slotIndex);
9216 if (phone == null) {
9217 return false;
9218 } else {
9219 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9220 }
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 }
Michelecea4cf22018-12-21 15:00:11 -08009225
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009226 /**
9227 * Whether a modem stack is enabled or not.
9228 */
9229 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009230 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9231 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009232 Phone phone = PhoneFactory.getPhone(slotIndex);
9233 if (phone == null) return false;
9234
9235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009236 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9237 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009238 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9239 }
9240
9241 final long identity = Binder.clearCallingIdentity();
9242 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009243 try {
9244 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9245 } catch (NoSuchElementException ex) {
9246 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9247 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009248 } finally {
9249 Binder.restoreCallingIdentity(identity);
9250 }
9251 }
9252
Michelecea4cf22018-12-21 15:00:11 -08009253 @Override
Michele0ea7d782019-03-19 14:58:42 -07009254 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009255 enforceModifyPermission();
9256
9257 final long identity = Binder.clearCallingIdentity();
9258 try {
9259 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009260 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009261 .commit();
9262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 }
9266
9267 @Override
Michele0ea7d782019-03-19 14:58:42 -07009268 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009269 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009271 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9272 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009273 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009274 }
Michelecea4cf22018-12-21 15:00:11 -08009275
9276 final long identity = Binder.clearCallingIdentity();
9277 try {
Michele0ea7d782019-03-19 14:58:42 -07009278 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009283
Michele0ea7d782019-03-19 14:58:42 -07009284 @TelephonyManager.IsMultiSimSupportedResult
9285 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009286 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9287 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9288 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009289 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9290 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009291 }
9292 // Check if the hardware supports multisim functionality. If usage of multisim is not
9293 // supported by the modem, indicate that it is restricted.
9294 PhoneCapability staticCapability =
9295 mPhoneConfigurationManager.getStaticPhoneCapability();
9296 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009297 loge("isMultiSimSupportedInternal: no static configuration available");
9298 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009299 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009300 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009301 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9302 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009303 }
9304 // Check if support of multiple SIMs is restricted by carrier
9305 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009306 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009307 }
9308
Michele0ea7d782019-03-19 14:58:42 -07009309 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009310 }
9311
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009312 /**
9313 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009314 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9315 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9316 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009317 * @param numOfSims number of active sims we want to switch to
9318 */
9319 @Override
9320 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009321 if (numOfSims == 1) {
9322 enforceModifyPermission();
9323 } else {
9324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9325 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9326 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009327 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009328
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009329 try {
Michele30b57b22019-03-01 12:01:14 -08009330 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009331 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009332 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9333 return;
9334 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009335 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9336 } finally {
9337 Binder.restoreCallingIdentity(identity);
9338 }
9339 }
9340
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009341 @Override
9342 public boolean isApplicationOnUicc(int subId, int appType) {
9343 enforceReadPrivilegedPermission("isApplicationOnUicc");
9344 Phone phone = getPhone(subId);
9345 if (phone == null) {
9346 return false;
9347 }
9348 final long identity = Binder.clearCallingIdentity();
9349 try {
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009350 UiccPort uiccPort = phone.getUiccPort();
9351 if (uiccPort == null) {
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009352 return false;
9353 }
Muralidhar Reddy864fe982021-09-29 19:38:40 +00009354 UiccProfile uiccProfile = uiccPort.getUiccProfile();
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009355 if (uiccProfile == null) {
9356 return false;
9357 }
9358 if (TelephonyManager.APPTYPE_SIM <= appType
9359 && appType <= TelephonyManager.APPTYPE_ISIM) {
9360 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9361 }
9362 return false;
9363 } finally {
9364 Binder.restoreCallingIdentity(identity);
9365 }
9366 }
9367
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009368 /**
chen xub4baa772019-04-03 10:23:41 -07009369 * Get whether making changes to modem configurations will trigger reboot.
9370 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009371 */
9372 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009373 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9374 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009376 mApp, subId, callingPackage, callingFeatureId,
9377 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009378 return false;
9379 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009380 final long identity = Binder.clearCallingIdentity();
9381 try {
9382 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9383 } finally {
9384 Binder.restoreCallingIdentity(identity);
9385 }
9386 }
9387
Nathan Harold29f5f052019-02-15 13:41:57 -08009388 private void updateModemStateMetrics() {
9389 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9390 // TODO: check the state for each modem if the api is ready.
9391 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9392 }
9393
Pengquan Meng3889a572019-01-23 11:16:29 -08009394 @Override
9395 public int[] getSlotsMapping() {
9396 enforceReadPrivilegedPermission("getSlotsMapping");
9397
9398 final long identity = Binder.clearCallingIdentity();
9399 try {
9400 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9401 // All logical slots should have a mapping to a physical slot.
9402 int[] logicalSlotsMapping = new int[phoneCount];
9403 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9404 for (int i = 0; i < slotInfos.length; i++) {
9405 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9406 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9407 }
9408 }
9409 return logicalSlotsMapping;
9410 } finally {
9411 Binder.restoreCallingIdentity(identity);
9412 }
9413 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009414
9415 /**
9416 * Get the IRadio HAL Version
9417 */
9418 @Override
9419 public int getRadioHalVersion() {
9420 Phone phone = getDefaultPhone();
9421 if (phone == null) return -1;
9422 HalVersion hv = phone.getHalVersion();
9423 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9424 return hv.major * 100 + hv.minor;
9425 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009426
9427 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009428 * Get the current calling package name.
9429 * @return the current calling package name
9430 */
9431 @Override
9432 public String getCurrentPackageName() {
9433 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9434 }
9435
9436 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009437 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9438 * corresponding network requests on a subId.
9439 *
9440 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009441 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009442 * 2) APN is un-metered for this subscription, or
9443 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009444 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009445 *
9446 * @return whether data is allowed for a apn type.
9447 *
9448 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009449 */
9450 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009451 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009452 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9453 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009454
9455 // Now that all security checks passes, perform the operation as ourselves.
9456 final long identity = Binder.clearCallingIdentity();
9457 try {
9458 Phone phone = getPhone(subId);
9459 if (phone == null) return false;
9460
Jack Yu41407ee2019-05-13 16:54:09 -07009461 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009462 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9463 } finally {
9464 Binder.restoreCallingIdentity(identity);
9465 }
9466 }
9467
9468 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009469 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009470 enforceReadPrivilegedPermission("isApnMetered");
9471
9472 // Now that all security checks passes, perform the operation as ourselves.
9473 final long identity = Binder.clearCallingIdentity();
9474 try {
9475 Phone phone = getPhone(subId);
9476 if (phone == null) return true; // By default return true.
9477
Jack Yu41407ee2019-05-13 16:54:09 -07009478 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009479 } finally {
9480 Binder.restoreCallingIdentity(identity);
9481 }
9482 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009483
9484 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009485 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9486 int subscriptionId, IBooleanConsumer resultCallback) {
9487 enforceModifyPermission();
9488 long token = Binder.clearCallingIdentity();
9489 try {
9490 Phone phone = getPhone(subscriptionId);
9491 if (phone == null) {
9492 try {
9493 if (resultCallback != null) {
9494 resultCallback.accept(false);
9495 }
9496 } catch (RemoteException e) {
9497 // ignore
9498 }
9499 return;
9500 }
9501 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9502 Pair.create(specifiers, (x) -> {
9503 try {
9504 if (resultCallback != null) {
9505 resultCallback.accept(x);
9506 }
9507 } catch (RemoteException e) {
9508 // ignore
9509 }
9510 });
9511 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9512 } finally {
9513 Binder.restoreCallingIdentity(token);
9514 }
9515 }
9516
9517 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009518 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9519 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009520 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009521 mApp, subId, "getSystemSelectionChannels");
9522 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9523 final long identity = Binder.clearCallingIdentity();
9524 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009525 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9526 if (result instanceof IllegalStateException) {
9527 throw (IllegalStateException) result;
9528 }
9529 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009530 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9531 return specifiers;
9532 } finally {
9533 Binder.restoreCallingIdentity(identity);
9534 }
9535 }
9536
9537 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009538 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009539 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009540 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9541 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9542 if (iccRecords == null) {
9543 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9544 return false;
9545 }
9546 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9547 }
9548
9549 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009550 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9551 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009552 if (callingPackage == null) {
9553 callingPackage = getCurrentPackageName();
9554 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009555 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9556 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009557 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9558 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009559 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9560 }
9561 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9562 Intent intent = new Intent();
9563 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9564 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9565 // Bring up choose default SMS subscription dialog right now
9566 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9567 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9568 mApp.startActivity(intent);
9569 }
chen xud5ca2d52019-05-28 15:20:57 -07009570
9571 @Override
9572 public String getMmsUAProfUrl(int subId) {
9573 //TODO investigate if this API should require proper permission check in R b/133791609
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009576 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9577 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9578 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9579 return carrierUAProfUrl;
9580 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009581 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9582 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 }
9587
9588 @Override
9589 public String getMmsUserAgent(int subId) {
9590 //TODO investigate if this API should require proper permission check in R b/133791609
9591 final long identity = Binder.clearCallingIdentity();
9592 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009593 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9594 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9595 if (!TextUtils.isEmpty(carrierUserAgent)) {
9596 return carrierUserAgent;
9597 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009598 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9599 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009600 } finally {
9601 Binder.restoreCallingIdentity(identity);
9602 }
9603 }
Jack Yub07d4972019-05-28 16:12:25 -07009604
9605 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009606 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9607 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009608
Jack Yub07d4972019-05-28 16:12:25 -07009609 final long identity = Binder.clearCallingIdentity();
9610 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009611 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009612 if (phone == null) return false;
9613
Hall Liua62f5da2020-09-25 10:42:19 -07009614 switch (policy) {
9615 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9616 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9617 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9618 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9619 default:
9620 throw new IllegalArgumentException(policy + " is not a valid policy");
9621 }
Jack Yub07d4972019-05-28 16:12:25 -07009622 } finally {
9623 Binder.restoreCallingIdentity(identity);
9624 }
9625 }
9626
9627 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009628 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009629 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009630 enforceModifyPermission();
9631
changbettyd5c246e2019-12-24 15:40:37 +08009632 final long identity = Binder.clearCallingIdentity();
9633 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009634 Phone phone = getPhone(subscriptionId);
9635 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009636
Hall Liua62f5da2020-09-25 10:42:19 -07009637 switch (policy) {
9638 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9639 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9640 break;
9641 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9642 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9643 break;
9644 default:
9645 throw new IllegalArgumentException(policy + " is not a valid policy");
9646 }
changbettyd5c246e2019-12-24 15:40:37 +08009647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
9651
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009652 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009653 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009654 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9655 * otherwise.
9656 */
9657 @Override
9658 public void setCepEnabled(boolean isCepEnabled) {
9659 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9660
9661 final long identity = Binder.clearCallingIdentity();
9662 try {
9663 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9664 for (Phone phone : PhoneFactory.getPhones()) {
9665 Phone defaultPhone = phone.getImsPhone();
9666 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9667 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9668 ImsPhoneCallTracker imsPhoneCallTracker =
9669 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9670 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9671 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9672 + imsPhone.getMsisdn());
9673 }
9674 }
9675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
allenwtsu46dcc572020-01-08 18:24:03 +08009679
9680 /**
9681 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9682 *
9683 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9684 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9685 * before being read.
9686 */
9687 @Override
9688 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9689 isCompressed) {
9690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9691 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9693 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9694 }
9695 if (!isImsAvailableOnDevice()) {
9696 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9697 "IMS not available on device.");
9698 }
9699
9700 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009701 try {
Hui Wang761a6682020-10-31 05:12:53 +00009702 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9703 } finally {
9704 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009705 }
9706 }
zoey chene02881a2019-12-30 16:11:23 +08009707
9708 @Override
9709 public boolean isIccLockEnabled(int subId) {
9710 enforceReadPrivilegedPermission("isIccLockEnabled");
9711
9712 // Now that all security checks passes, perform the operation as ourselves.
9713 final long identity = Binder.clearCallingIdentity();
9714 try {
9715 Phone phone = getPhone(subId);
9716 if (phone != null && phone.getIccCard() != null) {
9717 return phone.getIccCard().getIccLockEnabled();
9718 } else {
9719 return false;
9720 }
9721 } finally {
9722 Binder.restoreCallingIdentity(identity);
9723 }
9724 }
9725
9726 /**
9727 * Set the ICC pin lock enabled or disabled.
9728 *
9729 * @return an integer representing the status of IccLock enabled or disabled in the following
9730 * three cases:
9731 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9732 * successfully.
9733 * - Positive number and zero for remaining password attempts.
9734 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9735 *
9736 */
9737 @Override
9738 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9739 enforceModifyPermission();
9740
9741 Phone phone = getPhone(subId);
9742 if (phone == null) {
9743 return 0;
9744 }
9745 // Now that all security checks passes, perform the operation as ourselves.
9746 final long identity = Binder.clearCallingIdentity();
9747 try {
9748 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9749 new Pair<Boolean, String>(enabled, password), phone, null);
9750 return attemptsRemaining;
9751
9752 } catch (Exception e) {
9753 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9754 } finally {
9755 Binder.restoreCallingIdentity(identity);
9756 }
9757 return 0;
9758 }
9759
9760 /**
9761 * Change the ICC password used in ICC pin lock.
9762 *
9763 * @return an integer representing the status of IccLock changed in the following three cases:
9764 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9765 * - Positive number and zero for remaining password attempts.
9766 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9767 *
9768 */
9769 @Override
9770 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9771 enforceModifyPermission();
9772
9773 Phone phone = getPhone(subId);
9774 if (phone == null) {
9775 return 0;
9776 }
9777 // Now that all security checks passes, perform the operation as ourselves.
9778 final long identity = Binder.clearCallingIdentity();
9779 try {
9780 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9781 new Pair<String, String>(oldPassword, newPassword), phone, null);
9782 return attemptsRemaining;
9783
9784 } catch (Exception e) {
9785 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9786 } finally {
9787 Binder.restoreCallingIdentity(identity);
9788 }
9789 return 0;
9790 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009791
9792 /**
9793 * Request for receiving user activity notification
9794 */
9795 @Override
9796 public void requestUserActivityNotification() {
9797 if (!mNotifyUserActivity.get()
9798 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9799 mNotifyUserActivity.set(true);
9800 }
9801 }
9802
9803 /**
9804 * Called when userActivity is signalled in the power manager.
9805 * This is safe to call from any thread, with any window manager locks held or not.
9806 */
9807 @Override
9808 public void userActivity() {
9809 // ***************************************
9810 // * Inherited from PhoneWindowManager *
9811 // ***************************************
9812 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9813 // WITH ITS LOCKS HELD.
9814 //
9815 // This code must be VERY careful about the locks
9816 // it acquires.
9817 // In fact, the current code acquires way too many,
9818 // and probably has lurking deadlocks.
9819
9820 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9821 throw new SecurityException("Only the OS may call notifyUserActivity()");
9822 }
9823
9824 if (mNotifyUserActivity.getAndSet(false)) {
9825 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9826 USER_ACTIVITY_NOTIFICATION_DELAY);
9827 }
9828 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009829
9830 @Override
9831 public boolean canConnectTo5GInDsdsMode() {
9832 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9833 }
Jack Yud10cdd42020-09-28 20:28:01 -07009834
9835 @Override
9836 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9837 String callingFeatureId) {
9838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9839 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9840 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9841 }
9842
9843 Phone phone = getPhone(subId);
9844 if (phone == null) {
9845 throw new RuntimeException("phone is not available");
9846 }
9847 // Now that all security checks passes, perform the operation as ourselves.
9848 final long identity = Binder.clearCallingIdentity();
9849 try {
9850 return phone.getEquivalentHomePlmns();
9851 } finally {
9852 Binder.restoreCallingIdentity(identity);
9853 }
9854 }
Daniel Bright59e67312020-11-13 11:49:37 -08009855
9856 @Override
9857 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009858 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9859 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009860 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009861 if (radioInterfaceCapabilities == null) {
9862 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009863 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009864 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009865 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009866
Hui Wang641e81c2020-10-12 12:14:23 -07009867 @Override
9868 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9869 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009870 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9871 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9872 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9873 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9874 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009875 if (DBG) {
9876 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9877 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9878 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9879 }
9880
9881 if (!SubscriptionManager.isValidSubscriptionId(subId)
9882 || appType < TelephonyManager.APPTYPE_UNKNOWN
9883 || appType > TelephonyManager.APPTYPE_ISIM
9884 || nafUrl == null || securityProtocol == null || callback == null) {
9885 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9886 if (callback != null) {
9887 try {
9888 callback.onAuthenticationFailure(
9889 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9890 } catch (RemoteException exception) {
9891 log("Fail to notify onAuthenticationFailure due to " + exception);
9892 }
9893 return;
9894 }
9895 }
9896
9897 final long token = Binder.clearCallingIdentity();
9898 try {
9899 getGbaManager(subId).bootstrapAuthenticationRequest(
9900 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9901 forceBootStrapping, callback));
9902 } finally {
9903 Binder.restoreCallingIdentity(token);
9904 }
9905 }
9906
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009907 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009908 * Attempts to set the radio power state for all phones for thermal reason.
9909 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009910 * requested radio power state will actually be set. See {@link
9911 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9912 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009913 * @param enable {@code true} if trying to turn radio on.
9914 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9915 * false}.
9916 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009917 private boolean setRadioPowerForThermal(boolean enable) {
9918 boolean isPhoneAvailable = false;
9919 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9920 Phone phone = PhoneFactory.getPhone(i);
9921 if (phone != null) {
9922 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9923 isPhoneAvailable = true;
9924 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009925 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009926
9927 // return true if successfully informed the phone object about the thermal radio power
9928 // request.
9929 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009930 }
9931
9932 private int handleDataThrottlingRequest(int subId,
9933 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009934 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9935 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9936 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9937 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9938 throw new IllegalArgumentException("modem does not support data throttling");
9939 }
9940
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009941 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9942 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009943 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009944 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9945 }
9946
9947 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9948
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009949 if (isDataThrottlingSupported) {
9950 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009951 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009952 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9953 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9954 } else if (thermalMitigationResult
9955 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009956 log("Modem likely does not support data throttling on secondary carrier. Data " +
9957 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9958 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009959 }
9960 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009961 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009962
9963 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009964 }
9965
Jack Nudelman644b91a2021-03-12 14:09:48 -08009966 private static List<String> getThermalMitigationAllowlist(Context context) {
9967 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9968 for (String pckg : context.getResources()
9969 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9970 sThermalMitigationAllowlistedPackages.add(pckg);
9971 }
9972 }
9973
9974 return sThermalMitigationAllowlistedPackages;
9975 }
9976
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009977 private boolean isAnyPhoneInEmergencyState() {
9978 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9979 if (tm.isInEmergencyCall()) {
9980 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9981 return true;
9982 }
9983 for (Phone phone : PhoneFactory.getPhones()) {
9984 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9985 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9986 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9987 + phone.isInEcm());
9988 return true;
9989 }
9990 }
9991
9992 return false;
9993 }
9994
Jack Nudelman644b91a2021-03-12 14:09:48 -08009995 /**
9996 * Used by shell commands to add an authorized package name for thermal mitigation.
9997 * @param packageName name of package to be allowlisted
9998 * @param context
9999 */
10000 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10001 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10002 sThermalMitigationAllowlistedPackages.add(packageName);
10003 }
10004
10005 /**
10006 * Used by shell commands to remove an authorized package name for thermal mitigation.
10007 * @param packageName name of package to remove from allowlist
10008 * @param context
10009 */
10010 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10011 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10012 sThermalMitigationAllowlistedPackages.remove(packageName);
10013 }
10014
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010015 /**
10016 * Thermal mitigation request to control functionalities at modem.
10017 *
10018 * @param subId the id of the subscription.
10019 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010020 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010021 *
10022 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10023 */
10024 @Override
10025 @ThermalMitigationResult
10026 public int sendThermalMitigationRequest(
10027 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010028 ThermalMitigationRequest thermalMitigationRequest,
10029 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010030 enforceModifyPermission();
10031
Jack Nudelman644b91a2021-03-12 14:09:48 -080010032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10033 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10034 .contains(callingPackage)) {
10035 throw new SecurityException("Calling package must be configured in the device config. "
10036 + "calling package: " + callingPackage);
10037 }
10038
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010039 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10040 final long identity = Binder.clearCallingIdentity();
10041
10042 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10043 try {
10044 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10045 switch (thermalMitigationAction) {
10046 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10047 thermalMitigationResult =
10048 handleDataThrottlingRequest(subId,
10049 thermalMitigationRequest.getDataThrottlingRequest());
10050 break;
10051 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10052 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10053 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10054 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10055 }
10056
10057 // Ensure that radio is on. If not able to power on due to phone being
10058 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010059 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010060 thermalMitigationResult =
10061 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10062 break;
10063 }
10064
10065 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10066 false);
10067 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10068 break;
10069 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10070 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10071 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10072 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10073 }
10074
10075 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10076 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010077 Phone phone = getPhone(subId);
10078 if (phone == null) {
10079 thermalMitigationResult =
10080 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10081 break;
10082 }
10083
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010084 TelephonyConnectionService service =
10085 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010086 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010087 Log.e(LOG_TAG, "An emergency call is pending");
10088 thermalMitigationResult =
10089 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10090 break;
10091 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010092 thermalMitigationResult =
10093 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10094 break;
10095 }
10096 } else {
10097 thermalMitigationResult =
10098 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10099 break;
10100 }
10101
10102 // Turn radio off. If not able to power off due to phone being unavailable,
10103 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010104 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010105 thermalMitigationResult =
10106 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10107 break;
10108 }
10109 thermalMitigationResult =
10110 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10111 break;
10112 default:
10113 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10114 + "not exist. Requested action: " + thermalMitigationAction);
10115 }
10116 } catch (IllegalArgumentException e) {
10117 throw e;
10118 } catch (Exception e) {
10119 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10120 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10121 } finally {
10122 Binder.restoreCallingIdentity(identity);
10123 }
10124
10125 if (DBG) {
10126 log("thermalMitigationRequest returning with thermalMitigationResult: "
10127 + thermalMitigationResult);
10128 }
10129
10130 return thermalMitigationResult;
10131 }
Hui Wang641e81c2020-10-12 12:14:23 -070010132
10133 /**
10134 * Set the GbaService Package Name that Telephony will bind to.
10135 *
10136 * @param subId The sim that the GbaService is associated with.
10137 * @param packageName The name of the package to be replaced with.
10138 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10139 */
10140 @Override
10141 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10142 enforceModifyPermission();
10143
10144 final long identity = Binder.clearCallingIdentity();
10145 try {
10146 return getGbaManager(subId).overrideServicePackage(packageName);
10147 } finally {
10148 Binder.restoreCallingIdentity(identity);
10149 }
10150 }
10151
10152 /**
10153 * Return the package name of the currently bound GbaService.
10154 *
10155 * @param subId The sim that the GbaService is associated with.
10156 * @return the package name of the GbaService configuration, null if GBA is not supported.
10157 */
10158 @Override
10159 public String getBoundGbaService(int subId) {
10160 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10161
10162 final long identity = Binder.clearCallingIdentity();
10163 try {
10164 return getGbaManager(subId).getServicePackage();
10165 } finally {
10166 Binder.restoreCallingIdentity(identity);
10167 }
10168 }
10169
10170 /**
10171 * Set the release time for telephony to unbind GbaService.
10172 *
10173 * @param subId The sim that the GbaService is associated with.
10174 * @param interval The release time to unbind GbaService by millisecond.
10175 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10176 */
10177 @Override
10178 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10179 enforceModifyPermission();
10180
10181 final long identity = Binder.clearCallingIdentity();
10182 try {
10183 return getGbaManager(subId).overrideReleaseTime(interval);
10184 } finally {
10185 Binder.restoreCallingIdentity(identity);
10186 }
10187 }
10188
10189 /**
10190 * Return the release time for telephony to unbind GbaService.
10191 *
10192 * @param subId The sim that the GbaService is associated with.
10193 * @return The release time to unbind GbaService by millisecond.
10194 */
10195 @Override
10196 public int getGbaReleaseTime(int subId) {
10197 enforceReadPrivilegedPermission("getGbaReleaseTime");
10198
10199 final long identity = Binder.clearCallingIdentity();
10200 try {
10201 return getGbaManager(subId).getReleaseTime();
10202 } finally {
10203 Binder.restoreCallingIdentity(identity);
10204 }
10205 }
10206
10207 private GbaManager getGbaManager(int subId) {
10208 GbaManager instance = GbaManager.getInstance(subId);
10209 if (instance == null) {
10210 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10211 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10212 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10213 }
10214 return instance;
10215 }
Hui Wang761a6682020-10-31 05:12:53 +000010216
10217 /**
10218 * indicate whether the device and the carrier can support
10219 * RCS VoLTE single registration.
10220 */
10221 @Override
10222 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010223 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10224 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10225 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10226 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010227
10228 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10229 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10230 }
10231
10232 final long identity = Binder.clearCallingIdentity();
10233 try {
10234 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10235 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010236 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10237 if (isCapable != null) {
10238 return isCapable;
10239 }
Hui Wang761a6682020-10-31 05:12:53 +000010240 }
Hui Wang67af90e2021-06-04 16:57:15 -070010241 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10242 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010243 } finally {
10244 Binder.restoreCallingIdentity(identity);
10245 }
10246 }
10247
10248 /**
10249 * Register RCS provisioning callback.
10250 */
10251 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010252 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010253 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010254 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010255 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010256 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10257 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010258
10259 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10260 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10261 }
10262 if (!isImsAvailableOnDevice()) {
10263 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10264 "IMS not available on device.");
10265 }
10266
10267 final long identity = Binder.clearCallingIdentity();
10268 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010269 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010270 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010271 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10272 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010273 }
Hui Wang761a6682020-10-31 05:12:53 +000010274 } finally {
10275 Binder.restoreCallingIdentity(identity);
10276 }
10277 }
10278
10279 /**
10280 * Unregister RCS provisioning callback.
10281 */
10282 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010283 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010284 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010285 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010286 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010287 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10288 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010289
10290 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10291 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10292 }
10293 if (!isImsAvailableOnDevice()) {
10294 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10295 "IMS not available on device.");
10296 }
10297
10298 final long identity = Binder.clearCallingIdentity();
10299 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010300 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010301 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010302 } finally {
10303 Binder.restoreCallingIdentity(identity);
10304 }
10305 }
10306
10307 /**
10308 * trigger RCS reconfiguration.
10309 */
10310 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010311 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10312 "triggerRcsReconfiguration",
10313 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010314
10315 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10316 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10317 }
10318 if (!isImsAvailableOnDevice()) {
10319 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10320 "IMS not available on device.");
10321 }
10322
10323 final long identity = Binder.clearCallingIdentity();
10324 try {
10325 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10326 } finally {
10327 Binder.restoreCallingIdentity(identity);
10328 }
10329 }
10330
10331 /**
10332 * Provide the client configuration parameters of the RCS application.
10333 */
10334 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010335 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10336 "setRcsClientConfiguration",
10337 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010338
10339 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10340 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10341 }
10342 if (!isImsAvailableOnDevice()) {
10343 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10344 "IMS not available on device.");
10345 }
10346
10347 final long identity = Binder.clearCallingIdentity();
10348
10349 try {
10350 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10351 if (configBinder == null) {
10352 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010353 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10354 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010355 } else {
10356 configBinder.setRcsClientConfiguration(rcc);
10357 }
10358 } catch (RemoteException e) {
10359 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010360 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10361 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010362 } finally {
10363 Binder.restoreCallingIdentity(identity);
10364 }
10365 }
10366
10367 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010368 * Enables or disables the test mode for RCS VoLTE single registration.
10369 */
10370 @Override
10371 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10372 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10373 "setRcsSingleRegistrationTestModeEnabled");
10374
10375 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10376 }
10377
10378 /**
10379 * Gets the test mode for RCS VoLTE single registration.
10380 */
10381 @Override
10382 public boolean getRcsSingleRegistrationTestModeEnabled() {
10383 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10384 "getRcsSingleRegistrationTestModeEnabled");
10385
10386 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10387 }
10388
10389 /**
Hui Wang761a6682020-10-31 05:12:53 +000010390 * Overrides the config of RCS VoLTE single registration enabled for the device.
10391 */
10392 @Override
10393 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10394 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10395 "setDeviceSingleRegistrationEnabledOverride");
10396 enforceModifyPermission();
10397
10398 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10399 : Boolean.parseBoolean(enabledStr);
10400 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010401 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010402 }
10403
10404 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010405 * Sends a device to device communication message. Only usable via shell.
10406 * @param message message to send.
10407 * @param value message value.
10408 */
10409 @Override
10410 public void sendDeviceToDeviceMessage(int message, int value) {
10411 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010412 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010413 enforceModifyPermission();
10414
10415 final long identity = Binder.clearCallingIdentity();
10416 try {
10417 TelephonyConnectionService service =
10418 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10419 if (service == null) {
10420 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10421 return;
10422 }
10423 service.sendTestDeviceToDeviceMessage(message, value);
10424 } finally {
10425 Binder.restoreCallingIdentity(identity);
10426 }
10427 }
10428
Tyler Gunnbabbda02021-02-10 11:05:02 -080010429 /**
10430 * Sets the specified device to device transport active.
10431 * @param transport The transport to set active.
10432 */
10433 @Override
10434 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10435 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10436 "setActiveDeviceToDeviceTransport");
10437 enforceModifyPermission();
10438
10439 final long identity = Binder.clearCallingIdentity();
10440 try {
10441 TelephonyConnectionService service =
10442 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10443 if (service == null) {
10444 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10445 return;
10446 }
10447 service.setActiveDeviceToDeviceTransport(transport);
10448 } finally {
10449 Binder.restoreCallingIdentity(identity);
10450 }
10451 }
Tyler Gunn92479152021-01-20 16:30:10 -080010452
Tyler Gunnd4575212021-05-03 14:46:49 -070010453 @Override
10454 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10455 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10456 "setDeviceToDeviceForceEnabled");
10457
10458 final long identity = Binder.clearCallingIdentity();
10459 try {
10460 Arrays.stream(PhoneFactory.getPhones()).forEach(
10461 p -> {
10462 Phone thePhone = p.getImsPhone();
10463 if (thePhone != null && thePhone instanceof ImsPhone) {
10464 ImsPhone imsPhone = (ImsPhone) thePhone;
10465 CallTracker tracker = imsPhone.getCallTracker();
10466 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10467 ImsPhoneCallTracker imsPhoneCallTracker =
10468 (ImsPhoneCallTracker) tracker;
10469 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10470 }
10471 }
10472 }
10473 );
10474 } finally {
10475 Binder.restoreCallingIdentity(identity);
10476 }
10477 }
10478
Tyler Gunn92479152021-01-20 16:30:10 -080010479 /**
Hui Wang761a6682020-10-31 05:12:53 +000010480 * Gets the config of RCS VoLTE single registration enabled for the device.
10481 */
10482 @Override
10483 public boolean getDeviceSingleRegistrationEnabled() {
10484 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10485 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10486 }
10487
10488 /**
10489 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10490 */
10491 @Override
10492 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10493 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10494 "setCarrierSingleRegistrationEnabledOverride");
10495 enforceModifyPermission();
10496
10497 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10498 : Boolean.parseBoolean(enabledStr);
10499 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10500 subId, enabled);
10501 }
10502
10503 /**
10504 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10505 */
10506 @Override
10507 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10508 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10509 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10510 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010511
10512 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010513 * Overrides the ims feature validation result
10514 */
10515 @Override
10516 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10517 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10518 "setImsFeatureValidationOverride");
10519
10520 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10521 : Boolean.parseBoolean(enabledStr);
10522 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10523 subId, enabled);
10524 }
10525
10526 /**
10527 * Gets the ims feature validation override value
10528 */
10529 @Override
10530 public boolean getImsFeatureValidationOverride(int subId) {
10531 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10532 "getImsFeatureValidationOverride");
10533 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10534 }
10535
10536 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010537 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10538 * their mobile plan.
10539 */
10540 @Override
10541 public String getMobileProvisioningUrl() {
10542 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10543 final long identity = Binder.clearCallingIdentity();
10544 try {
10545 return getDefaultPhone().getMobileProvisioningUrl();
10546 } finally {
10547 Binder.restoreCallingIdentity(identity);
10548 }
10549 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010550
James.cf Linbcdf8b32021-01-14 16:44:13 +080010551 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010552 * Get the EAB contact from the EAB database.
10553 */
10554 @Override
10555 public String getContactFromEab(String contact) {
10556 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10557 enforceModifyPermission();
10558 final long identity = Binder.clearCallingIdentity();
10559 try {
10560 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10561 } finally {
10562 Binder.restoreCallingIdentity(identity);
10563 }
10564 }
10565
10566 /**
Calvin Pana1434322021-07-01 19:27:01 +080010567 * Get the EAB capability from the EAB database.
10568 */
10569 @Override
10570 public String getCapabilityFromEab(String contact) {
10571 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10572 enforceModifyPermission();
10573 final long identity = Binder.clearCallingIdentity();
10574 try {
10575 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10576 } finally {
10577 Binder.restoreCallingIdentity(identity);
10578 }
10579 }
10580
10581 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010582 * Remove the EAB contacts from the EAB database.
10583 */
10584 @Override
10585 public int removeContactFromEab(int subId, String contacts) {
10586 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10587 enforceModifyPermission();
10588 final long identity = Binder.clearCallingIdentity();
10589 try {
10590 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 }
10595
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010596 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010597 public boolean getDeviceUceEnabled() {
10598 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10599 final long identity = Binder.clearCallingIdentity();
10600 try {
10601 return mApp.getDeviceUceEnabled();
10602 } finally {
10603 Binder.restoreCallingIdentity(identity);
10604 }
10605 }
10606
10607 @Override
10608 public void setDeviceUceEnabled(boolean isEnabled) {
10609 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10610 final long identity = Binder.clearCallingIdentity();
10611 try {
10612 mApp.setDeviceUceEnabled(isEnabled);
10613 } finally {
10614 Binder.restoreCallingIdentity(identity);
10615 }
10616 }
10617
Brad Ebinger14d467f2021-02-12 06:18:28 +000010618 /**
10619 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10620 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10621 */
10622 // Used for SHELL command only right now.
10623 @Override
10624 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10625 List<String> featureTags) {
10626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10627 "addUceRegistrationOverrideShell");
10628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10631 new ArraySet<>(featureTags));
10632 } catch (ImsException e) {
10633 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10634 } finally {
10635 Binder.restoreCallingIdentity(identity);
10636 }
10637 }
10638
10639 /**
10640 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10641 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10642 */
10643 // Used for SHELL command only right now.
10644 @Override
10645 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10646 List<String> featureTags) {
10647 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10648 "removeUceRegistrationOverrideShell");
10649 final long identity = Binder.clearCallingIdentity();
10650 try {
10651 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10652 new ArraySet<>(featureTags));
10653 } catch (ImsException e) {
10654 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10655 } finally {
10656 Binder.restoreCallingIdentity(identity);
10657 }
10658 }
10659
10660 /**
10661 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10662 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10663 */
10664 // Used for SHELL command only right now.
10665 @Override
10666 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10667 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10668 "clearUceRegistrationOverrideShell");
10669 final long identity = Binder.clearCallingIdentity();
10670 try {
10671 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10672 } catch (ImsException e) {
10673 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10674 } finally {
10675 Binder.restoreCallingIdentity(identity);
10676 }
10677 }
10678
10679 /**
10680 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10681 */
10682 // Used for SHELL command only right now.
10683 @Override
10684 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10685 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10686 "getLatestRcsContactUceCapabilityShell");
10687 final long identity = Binder.clearCallingIdentity();
10688 try {
10689 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10690 } catch (ImsException e) {
10691 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10692 } finally {
10693 Binder.restoreCallingIdentity(identity);
10694 }
10695 }
10696
10697 /**
10698 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10699 * device does not have an active PUBLISH.
10700 */
10701 // Used for SHELL command only right now.
10702 @Override
10703 public String getLastUcePidfXmlShell(int subId) {
10704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10708 } catch (ImsException e) {
10709 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10710 } finally {
10711 Binder.restoreCallingIdentity(identity);
10712 }
10713 }
10714
James.cf Line8713a42021-04-29 16:04:26 +080010715 /**
10716 * Remove UCE requests cannot be sent to the network status.
10717 */
10718 // Used for SHELL command only right now.
10719 @Override
10720 public boolean removeUceRequestDisallowedStatus(int subId) {
10721 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10722 final long identity = Binder.clearCallingIdentity();
10723 try {
10724 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10725 } catch (ImsException e) {
10726 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10727 } finally {
10728 Binder.restoreCallingIdentity(identity);
10729 }
10730 }
10731
James.cf Lin0fc71b02021-05-25 01:37:38 +080010732 /**
10733 * Remove UCE requests cannot be sent to the network status.
10734 */
10735 // Used for SHELL command only.
10736 @Override
10737 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10739 final long identity = Binder.clearCallingIdentity();
10740 try {
10741 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10742 } catch (ImsException e) {
10743 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010748
James.cf Lin4b784aa2021-01-31 03:25:15 +080010749 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010750 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10751 String callingPackage) {
10752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10753 mApp, subId, "setSignalStrengthUpdateRequest");
10754
10755 final int callingUid = Binder.getCallingUid();
10756 // Verify that tha callingPackage belongs to the calling UID
10757 mApp.getSystemService(AppOpsManager.class)
10758 .checkPackage(callingUid, callingPackage);
10759
Rambo Wang3607f502021-02-01 21:51:40 -080010760 validateSignalStrengthUpdateRequest(mApp, request, callingUid);
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010761
10762 final long identity = Binder.clearCallingIdentity();
10763 try {
10764 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10765 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10766
10767 if (result instanceof IllegalStateException) {
10768 throw (IllegalStateException) result;
10769 }
10770 } finally {
10771 Binder.restoreCallingIdentity(identity);
10772 }
10773 }
10774
10775 @Override
10776 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10777 String callingPackage) {
10778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10779 mApp, subId, "clearSignalStrengthUpdateRequest");
10780
10781 final int callingUid = Binder.getCallingUid();
10782 // Verify that tha callingPackage belongs to the calling UID
10783 mApp.getSystemService(AppOpsManager.class)
10784 .checkPackage(callingUid, callingPackage);
10785
10786 final long identity = Binder.clearCallingIdentity();
10787 try {
10788 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10789 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10790
10791 if (result instanceof IllegalStateException) {
10792 throw (IllegalStateException) result;
10793 }
10794 } finally {
10795 Binder.restoreCallingIdentity(identity);
10796 }
10797 }
10798
Rambo Wang3607f502021-02-01 21:51:40 -080010799 private static void validateSignalStrengthUpdateRequest(Context context,
10800 SignalStrengthUpdateRequest request, int callingUid) {
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010801 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10802 // phone/system process do not have further restriction on request
10803 return;
10804 }
10805
10806 // Applications has restrictions on how to use the request:
Rambo Wang3607f502021-02-01 21:51:40 -080010807 // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010808 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
Rambo Wang3607f502021-02-01 21:51:40 -080010809 context.enforceCallingOrSelfPermission(
10810 android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH,
10811 "validateSignalStrengthUpdateRequest");
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010812 }
10813
10814 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10815 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10816 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10817 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10818 || info.isEnabled()) {
10819 throw new IllegalArgumentException(
10820 "Only system can set hide fields in SignalThresholdInfo");
10821 }
10822
10823 // Thresholds length for each RAN need in range. This has been validated in
10824 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10825 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10826 final int[] thresholds = info.getThresholds();
10827 Objects.requireNonNull(thresholds);
10828 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10829 || thresholds.length
10830 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10831 throw new IllegalArgumentException(
10832 "thresholds length is out of range: " + thresholds.length);
10833 }
10834 }
10835 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010836
10837 /**
10838 * Gets the current phone capability.
10839 *
10840 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10841 * @return the PhoneCapability which describes the data connection capability of modem.
10842 * It's used to evaluate possible phone config change, for example from single
10843 * SIM device to multi-SIM device.
10844 */
10845 @Override
10846 public PhoneCapability getPhoneCapability() {
10847 enforceReadPrivilegedPermission("getPhoneCapability");
10848 final long identity = Binder.clearCallingIdentity();
10849 try {
10850 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10851 } finally {
10852 Binder.restoreCallingIdentity(identity);
10853 }
10854 }
Michele Berionne5e411512020-11-13 02:36:59 +000010855
10856 /**
10857 * Prepare TelephonyManager for an unattended reboot. The reboot is
10858 * required to be done shortly after the API is invoked.
10859 */
10860 @Override
10861 @TelephonyManager.PrepareUnattendedRebootResult
10862 public int prepareForUnattendedReboot() {
10863 enforceRebootPermission();
10864
10865 final long identity = Binder.clearCallingIdentity();
10866 try {
10867 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10868 } finally {
10869 Binder.restoreCallingIdentity(identity);
10870 }
10871 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010872
10873 /**
10874 * Request to get the current slicing configuration including URSP rules and
10875 * NSSAIs (configured, allowed and rejected).
10876 *
10877 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10878 */
10879 @Override
10880 public void getSlicingConfig(ResultReceiver callback) {
10881 enforceReadPrivilegedPermission("getSlicingConfig");
10882
10883 final long identity = Binder.clearCallingIdentity();
10884 try {
10885 Phone phone = getDefaultPhone();
10886 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10887 } finally {
10888 Binder.restoreCallingIdentity(identity);
10889 }
10890 }
Hunsuk Choic7ebc0f2021-11-15 23:46:41 +000010891
10892 /**
10893 * Register an IMS connection state callback
10894 */
10895 @Override
10896 public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb,
10897 String callingPackage) {
10898 if (feature == ImsFeature.FEATURE_MMTEL) {
10899 // ImsMmTelManager
10900 // The following also checks READ_PRIVILEGED_PHONE_STATE.
10901 TelephonyPermissions
10902 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
10903 mApp, subId, "registerImsStateCallback");
10904 } else if (feature == ImsFeature.FEATURE_RCS) {
10905 // ImsRcsManager or SipDelegateManager
10906 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10907 Binder.getCallingUid(), "registerImsStateCallback",
10908 Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
10909 Manifest.permission.READ_PRECISE_PHONE_STATE,
10910 Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE,
10911 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
10912 }
10913
10914 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
10915 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10916 "IMS not available on device.");
10917 }
10918
10919 if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
10920 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
10921 }
10922
10923 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10924 if (controller == null) {
10925 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10926 "IMS not available on device.");
10927 }
10928
10929 if (callingPackage == null) {
10930 callingPackage = getCurrentPackageName();
10931 }
10932
10933 final long token = Binder.clearCallingIdentity();
10934 try {
10935 int slotId = getSlotIndexOrException(subId);
10936 controller.registerImsStateCallback(subId, feature, cb, callingPackage);
10937 } catch (ImsException e) {
10938 throw new ServiceSpecificException(e.getCode());
10939 } finally {
10940 Binder.restoreCallingIdentity(token);
10941 }
10942 }
10943
10944 /**
10945 * Unregister an IMS connection state callback
10946 */
10947 @Override
10948 public void unregisterImsStateCallback(IImsStateCallback cb) {
10949 final long token = Binder.clearCallingIdentity();
10950 ImsStateCallbackController controller = ImsStateCallbackController.getInstance();
10951 if (controller == null) {
10952 return;
10953 }
10954 try {
10955 controller.unregisterImsStateCallback(cb);
10956 } finally {
10957 Binder.restoreCallingIdentity(token);
10958 }
10959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010960}