blob: 3e8cf429915ba50284ff68756054c8f6c345be0f [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700189import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800192import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000193import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800194import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700195import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800197import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800198import com.android.phone.callcomposer.CallComposerPictureManager;
199import com.android.phone.callcomposer.CallComposerPictureTransfer;
200import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700201import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800203import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700205import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800206import com.android.services.telephony.TelecomAccountRegistry;
207import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800208import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800209
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700211import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.IOException;
213import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700214import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800217import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800218import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800219import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100220import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700222import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800226import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800227import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229/**
230 * Implementation of the ITelephony interface.
231 */
Santos Cordon117fee72014-05-16 17:56:12 -0700232public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 private static final String LOG_TAG = "PhoneInterfaceManager";
234 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
235 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238 // Message codes used with mMainThreadHandler
239 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700240 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
241 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242 private static final int CMD_OPEN_CHANNEL = 9;
243 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
244 private static final int CMD_CLOSE_CHANNEL = 11;
245 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800246 private static final int CMD_NV_READ_ITEM = 13;
247 private static final int EVENT_NV_READ_ITEM_DONE = 14;
248 private static final int CMD_NV_WRITE_ITEM = 15;
249 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
250 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
251 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700252 private static final int CMD_RESET_MODEM_CONFIG = 19;
253 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800254 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
255 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800256 private static final int CMD_SEND_ENVELOPE = 25;
257 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000258 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
259 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700260 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
261 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
262 private static final int CMD_EXCHANGE_SIM_IO = 31;
263 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
265 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700266 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
267 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700268 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
269 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700270 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
271 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
272 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
273 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700274 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
275 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
276 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
277 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700278 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800279 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
280 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000281 private static final int CMD_SWITCH_SLOTS = 50;
282 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700283 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
284 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
285 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
286 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
287 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
288 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
289 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
290 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700291 private static final int CMD_GET_ALL_CELL_INFO = 60;
292 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
293 private static final int CMD_GET_CELL_LOCATION = 62;
294 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700295 private static final int CMD_MODEM_REBOOT = 64;
296 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700297 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
298 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800299 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
300 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700301 private static final int CMD_GET_MODEM_STATUS = 70;
302 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700303 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
304 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700305 private static final int CMD_ERASE_MODEM_CONFIG = 74;
306 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800307 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
308 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
309 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
310 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800311 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
312 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800314 private static final int CMD_GET_CALL_FORWARDING = 83;
315 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
316 private static final int CMD_SET_CALL_FORWARDING = 85;
317 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
318 private static final int CMD_GET_CALL_WAITING = 87;
319 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
320 private static final int CMD_SET_CALL_WAITING = 89;
321 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700322 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
323 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
324 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
325 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700326 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
327 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800328 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
329 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800330 private static final int CMD_SET_DATA_THROTTLING = 99;
331 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800332 private static final int CMD_SET_SIM_POWER = 101;
333 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800334 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
335 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
336 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
337 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800338 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
339 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000340 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800341 private static final int CMD_GET_SLICING_CONFIG = 110;
342 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800343 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800345 // Parameters of select command.
346 private static final int SELECT_COMMAND = 0xA4;
347 private static final int SELECT_P1 = 0x04;
348 private static final int SELECT_P2 = 0;
349 private static final int SELECT_P3 = 0x10;
350
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 /** The singleton instance. */
352 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800353 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
Wink Saville3ab207e2014-11-20 13:07:20 -0800355 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800356 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800357 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700358 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700360 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800362 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700364 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800365 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
Peter Wangdafb9ac2020-01-15 14:13:38 -0800367 /** User Activity */
368 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800369 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
370
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700371 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
372
Derek Tan97ebb422014-09-05 16:55:38 -0700373 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
374 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800375 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800376 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700377
Michelecea4cf22018-12-21 15:00:11 -0800378 // String to store multi SIM allowed
379 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
380
Derek Tan740e1672017-06-27 14:56:27 -0700381 // The AID of ISD-R.
382 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
383
yinxub1bed742017-04-17 11:45:04 -0700384 private NetworkScanRequestTracker mNetworkScanRequestTracker;
385
David Kelly5e06a7f2018-03-12 14:10:59 +0000386 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
387 private static final int MANUFACTURER_CODE_LENGTH = 8;
388
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800389 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800390 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800391
Derek Tan89e89d42014-07-08 17:00:10 -0700392 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700393 * Experiment flag to enable erase modem config on reset network, default value is false
394 */
395 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
396 "reset_network_erase_modem_config_enabled";
397
Rambo Wang0f050d82021-02-12 11:43:36 -0800398 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
399
Naina Nallurid63128d2019-09-17 14:10:30 -0700400 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700401 * A request object to use for transmitting data to an ICC.
402 */
403 private static final class IccAPDUArgument {
404 public int channel, cla, command, p1, p2, p3;
405 public String data;
406
407 public IccAPDUArgument(int channel, int cla, int command,
408 int p1, int p2, int p3, String data) {
409 this.channel = channel;
410 this.cla = cla;
411 this.command = command;
412 this.p1 = p1;
413 this.p2 = p2;
414 this.p3 = p3;
415 this.data = data;
416 }
417 }
418
419 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700420 * A request object to use for transmitting data to an ICC.
421 */
422 private static final class ManualNetworkSelectionArgument {
423 public OperatorInfo operatorInfo;
424 public boolean persistSelection;
425
426 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
427 this.operatorInfo = operatorInfo;
428 this.persistSelection = persistSelection;
429 }
430 }
431
432 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
434 * request after sending. The main thread will notify the request when it is complete.
435 */
436 private static final class MainThreadRequest {
437 /** The argument to use for the request */
438 public Object argument;
439 /** The result of the request that is run on the main thread */
440 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800441 // The subscriber id that this request applies to. Defaults to
442 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
443 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Nathan Harold92bed182018-10-12 18:16:49 -0700445 // In cases where subId is unavailable, the caller needs to specify the phone.
446 public Phone phone;
447
vagdeviaf9a5b92018-08-15 16:01:53 -0700448 public WorkSource workSource;
449
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 public MainThreadRequest(Object argument) {
451 this.argument = argument;
452 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800453
Nathan Harold92bed182018-10-12 18:16:49 -0700454 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
455 this.argument = argument;
456 if (phone != null) {
457 this.phone = phone;
458 }
459 this.workSource = workSource;
460 }
461
vagdeviaf9a5b92018-08-15 16:01:53 -0700462 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800463 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800464 if (subId != null) {
465 this.subId = subId;
466 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700467 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 }
470
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800471 private static final class IncomingThirdPartyCallArgs {
472 public final ComponentName component;
473 public final String callId;
474 public final String callerDisplayName;
475
476 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
477 String callerDisplayName) {
478 this.component = component;
479 this.callId = callId;
480 this.callerDisplayName = callerDisplayName;
481 }
482 }
483
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 /**
485 * A handler that processes messages on the main thread in the phone process. Since many
486 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
487 * inbound binder threads to the main thread in the phone process. The Binder thread
488 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
489 * on, which will be notified when the operation completes and will contain the result of the
490 * request.
491 *
492 * <p>If a MainThreadRequest object is provided in the msg.obj field,
493 * note that request.result must be set to something non-null for the calling thread to
494 * unblock.
495 */
496 private final class MainThreadHandler extends Handler {
497 @Override
498 public void handleMessage(Message msg) {
499 MainThreadRequest request;
500 Message onCompleted;
501 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800504 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505
506 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 case CMD_HANDLE_USSD_REQUEST: {
508 request = (MainThreadRequest) msg.obj;
509 final Phone phone = getPhoneFromRequest(request);
510 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
511 String ussdRequest = ussdObject.first;
512 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700513
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 if (!isUssdApiAllowed(request.subId)) {
515 // Carrier does not support use of this API, return failure.
516 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
517 UssdResponse response = new UssdResponse(ussdRequest, null);
518 Bundle returnData = new Bundle();
519 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
520 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700521
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 request.result = true;
523 notifyRequester(request);
524 return;
525 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700526
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 try {
528 request.result = phone != null
529 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
530 } catch (CallStateException cse) {
531 request.result = false;
532 }
533 // Wake up the requesting thread
534 notifyRequester(request);
535 break;
pkanwar32d516d2016-10-14 19:37:38 -0700536 }
537
Yorke Lee716f67e2015-06-17 15:39:16 -0700538 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700540 final Phone phone = getPhoneFromRequest(request);
541 request.result = phone != null ?
542 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
543 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccTransmitApduLogicalChannel: No UICC");
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
559 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 iccArgument.channel, iccArgument.cla, iccArgument.command,
562 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
572 } else {
573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
574 if (ar.result == null) {
575 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800576 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800578 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 } else {
580 loge("iccTransmitApduLogicalChannel: Unknown exception");
581 }
582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 break;
585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
587 request = (MainThreadRequest) msg.obj;
588 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 if (uiccCard == null) {
591 loge("iccTransmitApduBasicChannel: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
596 request);
597 uiccCard.iccTransmitApduBasicChannel(
598 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
599 iccArgument.p3, iccArgument.data, onCompleted);
600 }
601 break;
602
603 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("iccTransmitApduBasicChannel: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("iccTransmitApduBasicChannel: CommandException: " +
614 ar.exception);
615 } else {
616 loge("iccTransmitApduBasicChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 break;
621
622 case CMD_EXCHANGE_SIM_IO:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 if (uiccCard == null) {
627 loge("iccExchangeSimIO: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
632 request);
633 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
634 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
635 iccArgument.data, onCompleted);
636 }
637 break;
638
639 case EVENT_EXCHANGE_SIM_IO_DONE:
640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result;
644 } else {
645 request.result = new IccIoResult(0x6f, 0, (byte[])null);
646 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 break;
649
Derek Tan4d5e5c12014-02-04 11:54:58 -0800650 case CMD_SEND_ENVELOPE:
651 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800652 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 if (uiccCard == null) {
654 loge("sendEnvelopeWithStatus: No UICC");
655 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
659 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
660 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800661 break;
662
663 case EVENT_SEND_ENVELOPE_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800668 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700669 request.result = new IccIoResult(0x6F, 0, (byte[])null);
670 if (ar.result == null) {
671 loge("sendEnvelopeWithStatus: Empty response");
672 } else if (ar.exception instanceof CommandException) {
673 loge("sendEnvelopeWithStatus: CommandException: " +
674 ar.exception);
675 } else {
676 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
677 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800680 break;
681
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 case CMD_OPEN_CHANNEL:
683 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800684 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800685 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 if (uiccCard == null) {
687 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800688 request.result = new IccOpenLogicalChannelResponse(-1,
689 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 } else {
692 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800693 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
694 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
698 case EVENT_OPEN_CHANNEL_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 int[] result = (int[]) ar.result;
704 int channelId = result[0];
705 byte[] selectResponse = null;
706 if (result.length > 1) {
707 selectResponse = new byte[result.length - 1];
708 for (int i = 1; i < result.length; ++i) {
709 selectResponse[i - 1] = (byte) result[i];
710 }
711 }
712 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700713 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 if (ar.result == null) {
716 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 if (ar.exception != null) {
719 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
720 }
721
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700722 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700723 if (ar.exception instanceof CommandException) {
724 CommandException.Error error =
725 ((CommandException) (ar.exception)).getCommandError();
726 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700728 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700729 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700730 }
731 }
732 openChannelResp = new IccOpenLogicalChannelResponse(
733 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700735 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 break;
738
739 case CMD_CLOSE_CHANNEL:
740 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800741 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 if (uiccCard == null) {
743 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900744 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 } else {
747 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
748 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
749 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 break;
751
752 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800753 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
754 break;
755
756 case CMD_NV_READ_ITEM:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800759 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
760 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800761 break;
762
763 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 ar = (AsyncResult) msg.obj;
765 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800766 if (ar.exception == null && ar.result != null) {
767 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800769 request.result = "";
770 if (ar.result == null) {
771 loge("nvReadItem: Empty response");
772 } else if (ar.exception instanceof CommandException) {
773 loge("nvReadItem: CommandException: " +
774 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800776 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700777 }
778 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700779 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 break;
781
Jake Hambye994d462014-02-03 13:10:13 -0800782 case CMD_NV_WRITE_ITEM:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
785 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800786 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700787 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
790 case EVENT_NV_WRITE_ITEM_DONE:
791 handleNullReturnEvent(msg, "nvWriteItem");
792 break;
793
794 case CMD_NV_WRITE_CDMA_PRL:
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800797 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800798 break;
799
800 case EVENT_NV_WRITE_CDMA_PRL_DONE:
801 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
802 break;
803
chen xu6dac5ab2018-10-26 17:39:23 -0700804 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800805 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700806 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800807 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800808 break;
809
chen xu6dac5ab2018-10-26 17:39:23 -0700810 case EVENT_RESET_MODEM_CONFIG_DONE:
811 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
Sooraj Sasindran37444802020-08-11 10:40:43 -0700814 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
817 request);
818 Phone phone = getPhoneFromRequest(request);
819 if (phone != null) {
820 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
821 } else {
822 loge("isNRDualConnectivityEnabled: No phone object");
823 request.result = false;
824 notifyRequester(request);
825 }
826 break;
827 }
828
829 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null && ar.result != null) {
833 request.result = ar.result;
834 } else {
835 // request.result must be set to something non-null
836 // for the calling thread to unblock
837 if (request.result != null) {
838 request.result = ar.result;
839 } else {
840 request.result = false;
841 }
842 if (ar.result == null) {
843 loge("isNRDualConnectivityEnabled: Empty response");
844 } else if (ar.exception instanceof CommandException) {
845 loge("isNRDualConnectivityEnabled: CommandException: "
846 + ar.exception);
847 } else {
848 loge("isNRDualConnectivityEnabled: Unknown exception");
849 }
850 }
851 notifyRequester(request);
852 break;
853
854 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
855 request = (MainThreadRequest) msg.obj;
856 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
857 Phone phone = getPhoneFromRequest(request);
858 if (phone != null) {
859 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
860 request.workSource);
861 } else {
862 loge("enableNrDualConnectivity: No phone object");
863 request.result =
864 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
865 notifyRequester(request);
866 }
867 break;
868 }
869
870 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null) {
874 request.result =
875 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
876 } else {
877 request.result =
878 TelephonyManager
879 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
880 if (ar.exception instanceof CommandException) {
881 CommandException.Error error =
882 ((CommandException) (ar.exception)).getCommandError();
883 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
884 request.result =
885 TelephonyManager
886 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000887 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
888 request.result =
889 TelephonyManager
890 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700891 }
892 loge("enableNrDualConnectivity" + ": CommandException: "
893 + ar.exception);
894 } else {
895 loge("enableNrDualConnectivity" + ": Unknown exception");
896 }
897 }
898 notifyRequester(request);
899 break;
900 }
901
SongFerngWang3ef3e072020-12-21 16:41:52 +0800902 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800904 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
905 request);
906 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 break;
908
SongFerngWang3ef3e072020-12-21 16:41:52 +0800909 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result; // Integer
914 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530915 // request.result must be set to something non-null
916 // for the calling thread to unblock
917 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800919 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800921 loge("getAllowedNetworkTypesBitmask: CommandException: "
922 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800924 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800925 }
926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700927 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800928 break;
929
SongFerngWang3ef3e072020-12-21 16:41:52 +0800930 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800931 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800932 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
933 request);
934 Pair<Integer, Long> reasonWithNetworkTypes =
935 (Pair<Integer, Long>) request.argument;
936 getPhoneFromRequest(request).setAllowedNetworkTypes(
937 reasonWithNetworkTypes.first,
938 reasonWithNetworkTypes.second,
939 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800940 break;
941
SongFerngWang3ef3e072020-12-21 16:41:52 +0800942 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
943 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800944 break;
945
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000946 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
947 request = (MainThreadRequest)msg.obj;
948 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800949 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000950 break;
951
952 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
953 ar = (AsyncResult)msg.obj;
954 request = (MainThreadRequest)ar.userObj;
955 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000957 break;
958
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800959 case CMD_SET_VOICEMAIL_NUMBER:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
962 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800963 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
964 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800965 break;
966
967 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
968 handleNullReturnEvent(msg, "setVoicemailNumber");
969 break;
970
Stuart Scott54788802015-03-30 13:18:01 -0700971 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
974 request);
975 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
976 break;
977
978 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
979 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
980 break;
981
Shishir Agrawal302c8692015-06-19 13:49:39 -0700982 case CMD_PERFORM_NETWORK_SCAN:
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
985 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
986 break;
987
Hall Liu27d24262020-09-18 19:04:59 -0700988 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700991 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
992 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
993 request.argument;
994 int callForwardingReason = args.first;
995 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800996 break;
Hall Liu27d24262020-09-18 19:04:59 -0700997 }
998 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001001 TelephonyManager.CallForwardingInfoCallback callback =
1002 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1003 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001004 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001005 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001006 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1007 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1008 // Service Class is a bit mask per 3gpp 27.007. Search for
1009 // any service for voice call.
1010 if ((callForwardInfo.serviceClass
1011 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001012 callForwardingInfo = new CallForwardingInfo(true,
1013 callForwardInfo.reason,
1014 callForwardInfo.number,
1015 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001016 break;
1017 }
1018 }
1019 // Didn't find a call forward info for voice call.
1020 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001021 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1022 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001023 }
Hall Liu27d24262020-09-18 19:04:59 -07001024 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001025 } else {
1026 if (ar.result == null) {
1027 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1028 }
1029 if (ar.exception != null) {
1030 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1031 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001032 int errorCode = TelephonyManager
1033 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001034 if (ar.exception instanceof CommandException) {
1035 CommandException.Error error =
1036 ((CommandException) (ar.exception)).getCommandError();
1037 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001038 errorCode = TelephonyManager
1039 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001040 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001041 errorCode = TelephonyManager
1042 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001043 }
1044 }
Hall Liu27d24262020-09-18 19:04:59 -07001045 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001046 }
Shuo Qian4a594052020-01-23 11:59:30 -08001047 break;
Hall Liu27d24262020-09-18 19:04:59 -07001048 }
Shuo Qian4a594052020-01-23 11:59:30 -08001049
Hall Liu27d24262020-09-18 19:04:59 -07001050 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001053 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001054 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001055 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1056 request.argument).first;
1057 request.phone.setCallForwardingOption(
1058 callForwardingInfoToSet.isEnabled()
1059 ? CommandsInterface.CF_ACTION_ENABLE
1060 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001061 callForwardingInfoToSet.getReason(),
1062 callForwardingInfoToSet.getNumber(),
1063 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1064 break;
Hall Liu27d24262020-09-18 19:04:59 -07001065 }
Shuo Qian4a594052020-01-23 11:59:30 -08001066
Hall Liu27d24262020-09-18 19:04:59 -07001067 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001070 Consumer<Integer> callback =
1071 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1072 request.argument).second;
1073 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001074 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001075 int errorCode = TelephonyManager.CallForwardingInfoCallback
1076 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001077 if (ar.exception instanceof CommandException) {
1078 CommandException.Error error =
1079 ((CommandException) (ar.exception)).getCommandError();
1080 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001081 errorCode = TelephonyManager.CallForwardingInfoCallback
1082 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001083 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001084 errorCode = TelephonyManager.CallForwardingInfoCallback
1085 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001086 }
1087 }
1088 callback.accept(errorCode);
1089 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001090 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001091 }
Shuo Qian4a594052020-01-23 11:59:30 -08001092 break;
Hall Liu27d24262020-09-18 19:04:59 -07001093 }
Shuo Qian4a594052020-01-23 11:59:30 -08001094
Hall Liu27d24262020-09-18 19:04:59 -07001095 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1098 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1099 break;
Hall Liu27d24262020-09-18 19:04:59 -07001100 }
Shuo Qian4a594052020-01-23 11:59:30 -08001101
Hall Liu27d24262020-09-18 19:04:59 -07001102 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001105 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001106 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1107 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001108 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001109 // Service Class is a bit mask per 3gpp 27.007.
1110 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001111 if (callForwardResults.length > 1
1112 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001113 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001114 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001115 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1116 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001117 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001118 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001119 }
1120 } else {
1121 if (ar.result == null) {
1122 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1123 }
1124 if (ar.exception != null) {
1125 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1126 }
1127 if (ar.exception instanceof CommandException) {
1128 CommandException.Error error =
1129 ((CommandException) (ar.exception)).getCommandError();
1130 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1131 callForwardingStatus =
1132 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1133 }
1134 }
1135 }
Hall Liu27d24262020-09-18 19:04:59 -07001136 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001137 break;
Hall Liu27d24262020-09-18 19:04:59 -07001138 }
Shuo Qian4a594052020-01-23 11:59:30 -08001139
Hall Liu27d24262020-09-18 19:04:59 -07001140 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001141 request = (MainThreadRequest) msg.obj;
1142 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001143 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1144 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001145 break;
Hall Liu27d24262020-09-18 19:04:59 -07001146 }
Shuo Qian4a594052020-01-23 11:59:30 -08001147
Hall Liu27d24262020-09-18 19:04:59 -07001148 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001151 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1152 Consumer<Integer> callback =
1153 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1154 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001156 if (ar.exception instanceof CommandException) {
1157 CommandException.Error error =
1158 ((CommandException) (ar.exception)).getCommandError();
1159 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1160 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1161 } else {
1162 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1163 }
1164 } else {
1165 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1166 }
1167 } else {
1168 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1169 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001170 }
Shuo Qian4a594052020-01-23 11:59:30 -08001171 break;
Hall Liu27d24262020-09-18 19:04:59 -07001172 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001173 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1174 ar = (AsyncResult) msg.obj;
1175 request = (MainThreadRequest) ar.userObj;
1176 CellNetworkScanResult cellScanResult;
1177 if (ar.exception == null && ar.result != null) {
1178 cellScanResult = new CellNetworkScanResult(
1179 CellNetworkScanResult.STATUS_SUCCESS,
1180 (List<OperatorInfo>) ar.result);
1181 } else {
1182 if (ar.result == null) {
1183 loge("getCellNetworkScanResults: Empty response");
1184 }
1185 if (ar.exception != null) {
1186 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1187 }
1188 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1189 if (ar.exception instanceof CommandException) {
1190 CommandException.Error error =
1191 ((CommandException) (ar.exception)).getCommandError();
1192 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1193 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1194 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1195 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1196 }
1197 }
1198 cellScanResult = new CellNetworkScanResult(errorCode, null);
1199 }
1200 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001201 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001202 break;
1203
1204 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1205 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001206 ManualNetworkSelectionArgument selArg =
1207 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001208 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1209 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001210 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1211 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001212 break;
1213
1214 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001215 ar = (AsyncResult) msg.obj;
1216 request = (MainThreadRequest) ar.userObj;
1217 if (ar.exception == null) {
1218 request.result = true;
1219 } else {
1220 request.result = false;
1221 loge("setNetworkSelectionModeManual " + ar.exception);
1222 }
1223 notifyRequester(request);
1224 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001225 break;
1226
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 case CMD_GET_MODEM_ACTIVITY_INFO:
1228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001230 if (defaultPhone != null) {
1231 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001232 } else {
1233 ResultReceiver result = (ResultReceiver) request.argument;
1234 Bundle bundle = new Bundle();
1235 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001236 new ModemActivityInfo(0, 0, 0,
1237 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001238 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001239 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 break;
1241
Hall Liud0f208c2020-10-14 16:54:44 -07001242 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001243 ar = (AsyncResult) msg.obj;
1244 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001245 ResultReceiver result = (ResultReceiver) request.argument;
1246
Hall Liud0f208c2020-10-14 16:54:44 -07001247 ModemActivityInfo ret = null;
1248 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001249 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001250 // Update the last modem activity info and the result of the request.
1251 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1252 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001253 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001254 int[] txTimeMs = info.getTransmitTimeMillis();
1255 int[] lastModemTxTimeMs = mLastModemActivityInfo
1256 .getTransmitTimeMillis();
1257 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1258 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1259 }
Hall Liu49656c02020-10-09 19:00:11 -07001260 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001261 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1262 + mLastModemActivityInfo.getSleepTimeMillis());
1263 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1264 + mLastModemActivityInfo.getIdleTimeMillis());
1265 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1266 mLastModemActivityInfo.setReceiveTimeMillis(
1267 info.getReceiveTimeMillis()
1268 + mLastModemActivityInfo.getReceiveTimeMillis());
1269 }
Hall Liu49656c02020-10-09 19:00:11 -07001270 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001271 mLastModemActivityInfo.getSleepTimeMillis(),
1272 mLastModemActivityInfo.getIdleTimeMillis(),
1273 mLastModemActivityInfo.getTransmitTimeMillis(),
1274 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001275 } else {
1276 if (ar.result == null) {
1277 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001278 error = TelephonyManager.ModemActivityInfoException
1279 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001280 } else if (ar.exception instanceof CommandException) {
1281 loge("queryModemActivityInfo: CommandException: " +
1282 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001283 error = TelephonyManager.ModemActivityInfoException
1284 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001285 } else {
1286 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001287 error = TelephonyManager.ModemActivityInfoException
1288 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001289 }
1290 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001291 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001292 if (ret != null) {
1293 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1294 } else {
1295 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1296 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001297 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001298 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001299 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001300 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001301
Meng Wang1a7c35a2016-05-05 20:56:15 -07001302 case CMD_SET_ALLOWED_CARRIERS:
1303 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001304 CarrierRestrictionRules argument =
1305 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001307 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001308 break;
1309
1310 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1311 ar = (AsyncResult) msg.obj;
1312 request = (MainThreadRequest) ar.userObj;
1313 if (ar.exception == null && ar.result != null) {
1314 request.result = ar.result;
1315 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001316 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1317 if (ar.exception instanceof CommandException) {
1318 loge("setAllowedCarriers: CommandException: " + ar.exception);
1319 CommandException.Error error =
1320 ((CommandException) (ar.exception)).getCommandError();
1321 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1322 request.result =
1323 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1324 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001325 } else {
1326 loge("setAllowedCarriers: Unknown exception");
1327 }
1328 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001329 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001330 break;
1331
1332 case CMD_GET_ALLOWED_CARRIERS:
1333 request = (MainThreadRequest) msg.obj;
1334 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001335 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001336 break;
1337
1338 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1339 ar = (AsyncResult) msg.obj;
1340 request = (MainThreadRequest) ar.userObj;
1341 if (ar.exception == null && ar.result != null) {
1342 request.result = ar.result;
1343 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001344 request.result = new IllegalStateException(
1345 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001346 if (ar.result == null) {
1347 loge("getAllowedCarriers: Empty response");
1348 } else if (ar.exception instanceof CommandException) {
1349 loge("getAllowedCarriers: CommandException: " +
1350 ar.exception);
1351 } else {
1352 loge("getAllowedCarriers: Unknown exception");
1353 }
1354 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001355 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001356 break;
1357
Nathan Haroldb3014052017-01-25 15:57:32 -08001358 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1359 ar = (AsyncResult) msg.obj;
1360 request = (MainThreadRequest) ar.userObj;
1361 if (ar.exception == null && ar.result != null) {
1362 request.result = ar.result;
1363 } else {
1364 request.result = new IllegalArgumentException(
1365 "Failed to retrieve Forbidden Plmns");
1366 if (ar.result == null) {
1367 loge("getForbiddenPlmns: Empty response");
1368 } else {
1369 loge("getForbiddenPlmns: Unknown exception");
1370 }
1371 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001372 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001373 break;
1374
1375 case CMD_GET_FORBIDDEN_PLMNS:
1376 request = (MainThreadRequest) msg.obj;
1377 uiccCard = getUiccCardFromRequest(request);
1378 if (uiccCard == null) {
1379 loge("getForbiddenPlmns() UiccCard is null");
1380 request.result = new IllegalArgumentException(
1381 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001382 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001383 break;
1384 }
1385 Integer appType = (Integer) request.argument;
1386 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1387 if (uiccApp == null) {
1388 loge("getForbiddenPlmns() no app with specified type -- "
1389 + appType);
1390 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001391 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001392 break;
1393 } else {
1394 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1395 + " specified type -- " + appType);
1396 }
1397 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1398 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1399 onCompleted);
1400 break;
1401
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001402 case CMD_SWITCH_SLOTS:
1403 request = (MainThreadRequest) msg.obj;
1404 int[] physicalSlots = (int[]) request.argument;
1405 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1406 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1407 break;
1408
1409 case EVENT_SWITCH_SLOTS_DONE:
1410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001413 notifyRequester(request);
1414 break;
1415 case CMD_GET_NETWORK_SELECTION_MODE:
1416 request = (MainThreadRequest) msg.obj;
1417 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1418 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1419 break;
1420
1421 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 if (ar.exception != null) {
1425 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1426 } else {
1427 int mode = ((int[]) ar.result)[0];
1428 if (mode == 0) {
1429 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1430 } else {
1431 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1432 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001433 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 notifyRequester(request);
1435 break;
1436 case CMD_GET_CDMA_ROAMING_MODE:
1437 request = (MainThreadRequest) msg.obj;
1438 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1439 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1440 break;
1441 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1442 ar = (AsyncResult) msg.obj;
1443 request = (MainThreadRequest) ar.userObj;
1444 if (ar.exception != null) {
1445 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1446 } else {
1447 request.result = ((int[]) ar.result)[0];
1448 }
1449 notifyRequester(request);
1450 break;
1451 case CMD_SET_CDMA_ROAMING_MODE:
1452 request = (MainThreadRequest) msg.obj;
1453 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1454 int mode = (int) request.argument;
1455 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1456 break;
1457 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1458 ar = (AsyncResult) msg.obj;
1459 request = (MainThreadRequest) ar.userObj;
1460 request.result = ar.exception == null;
1461 notifyRequester(request);
1462 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001463 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1464 request = (MainThreadRequest) msg.obj;
1465 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1466 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1467 break;
1468 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
1471 if (ar.exception != null) {
1472 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1473 } else {
1474 request.result = ((int[]) ar.result)[0];
1475 }
1476 notifyRequester(request);
1477 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001478 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1479 request = (MainThreadRequest) msg.obj;
1480 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1481 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001482 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1483 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001484 break;
1485 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1486 ar = (AsyncResult) msg.obj;
1487 request = (MainThreadRequest) ar.userObj;
1488 request.result = ar.exception == null;
1489 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001490 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 case CMD_GET_ALL_CELL_INFO:
1492 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001494 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001496 case EVENT_GET_ALL_CELL_INFO_DONE:
1497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001499 // If a timeout occurs, the response will be null
1500 request.result = (ar.exception == null && ar.result != null)
1501 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 synchronized (request) {
1503 request.notifyAll();
1504 }
1505 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001506 case CMD_REQUEST_CELL_INFO_UPDATE:
1507 request = (MainThreadRequest) msg.obj;
1508 request.phone.requestCellInfoUpdate(request.workSource,
1509 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1510 break;
1511 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1512 ar = (AsyncResult) msg.obj;
1513 request = (MainThreadRequest) ar.userObj;
1514 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1515 try {
1516 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001517 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001518 cb.onError(
1519 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1520 ar.exception.getClass().getName(),
1521 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001522 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001523 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001524 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001525 } else {
1526 // use the result as returned
1527 cb.onCellInfo((List<CellInfo>) ar.result);
1528 }
1529 } catch (RemoteException re) {
1530 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1531 }
1532 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001533 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001534 request = (MainThreadRequest) msg.obj;
1535 WorkSource ws = (WorkSource) request.argument;
1536 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001537 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001538 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001539 }
1540 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001541 ar = (AsyncResult) msg.obj;
1542 request = (MainThreadRequest) ar.userObj;
1543 if (ar.exception == null) {
1544 request.result = ar.result;
1545 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001546 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001547 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001548 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001549 }
1550
1551 synchronized (request) {
1552 request.notifyAll();
1553 }
1554 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001555 }
chen xu6dac5ab2018-10-26 17:39:23 -07001556 case CMD_MODEM_REBOOT:
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001559 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001560 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001561 case EVENT_CMD_MODEM_REBOOT_DONE:
1562 handleNullReturnEvent(msg, "rebootModem");
1563 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001564 case CMD_REQUEST_ENABLE_MODEM:
1565 request = (MainThreadRequest) msg.obj;
1566 boolean enable = (boolean) request.argument;
1567 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001568 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001569 PhoneConfigurationManager.getInstance()
1570 .enablePhone(request.phone, enable, onCompleted);
1571 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001572 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001576 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001577 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001578 if ((boolean) request.result) {
1579 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1580 updateModemStateMetrics();
1581 } else {
1582 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1583 + ar.exception);
1584 }
1585 notifyRequester(request);
1586 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001587 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001588 case CMD_GET_MODEM_STATUS:
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1591 PhoneConfigurationManager.getInstance()
1592 .getPhoneStatusFromModem(request.phone, onCompleted);
1593 break;
1594 case EVENT_GET_MODEM_STATUS_DONE:
1595 ar = (AsyncResult) msg.obj;
1596 request = (MainThreadRequest) ar.userObj;
1597 int id = request.phone.getPhoneId();
1598 if (ar.exception == null && ar.result != null) {
1599 request.result = ar.result;
1600 //update the cache as modem status has changed
1601 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1602 (boolean) request.result);
1603 } else {
1604 // Return true if modem status cannot be retrieved. For most cases,
1605 // modem status is on. And for older version modems, GET_MODEM_STATUS
1606 // and disable modem are not supported. Modem is always on.
1607 // TODO: this should be fixed in R to support a third
1608 // status UNKNOWN b/131631629
1609 request.result = true;
1610 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1611 + ar.exception);
1612 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001613 notifyRequester(request);
1614 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001615 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1616 request = (MainThreadRequest) msg.obj;
1617 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1618 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1619 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1620 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1621 break;
1622 }
1623 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1624 ar = (AsyncResult) msg.obj;
1625 request = (MainThreadRequest) ar.userObj;
1626 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1627 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1628 args.second.accept(ar.exception == null);
1629 notifyRequester(request);
1630 break;
1631 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001632 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1633 request = (MainThreadRequest) msg.obj;
1634 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1635 Phone phone = getPhoneFromRequest(request);
1636 if (phone != null) {
1637 phone.getSystemSelectionChannels(onCompleted);
1638 } else {
1639 loge("getSystemSelectionChannels: No phone object");
1640 request.result = new ArrayList<RadioAccessSpecifier>();
1641 notifyRequester(request);
1642 }
1643 break;
1644 }
1645 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
1648 if (ar.exception == null && ar.result != null) {
1649 request.result = ar.result;
1650 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001651 request.result = new IllegalStateException(
1652 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001653 if (ar.result == null) {
1654 loge("getSystemSelectionChannels: Empty response");
1655 } else {
1656 loge("getSystemSelectionChannels: Unknown exception");
1657 }
1658 }
1659 notifyRequester(request);
1660 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001661 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 if (ar.exception == null && ar.result != null) {
1665 request.result = ar.result;
1666 } else {
1667 request.result = -1;
1668 loge("Failed to set Forbidden Plmns");
1669 if (ar.result == null) {
1670 loge("setForbidenPlmns: Empty response");
1671 } else if (ar.exception != null) {
1672 loge("setForbiddenPlmns: Exception: " + ar.exception);
1673 request.result = -1;
1674 } else {
1675 loge("setForbiddenPlmns: Unknown exception");
1676 }
1677 }
1678 notifyRequester(request);
1679 break;
1680 case CMD_SET_FORBIDDEN_PLMNS:
1681 request = (MainThreadRequest) msg.obj;
1682 uiccCard = getUiccCardFromRequest(request);
1683 if (uiccCard == null) {
1684 loge("setForbiddenPlmns: UiccCard is null");
1685 request.result = -1;
1686 notifyRequester(request);
1687 break;
1688 }
1689 Pair<Integer, List<String>> setFplmnsArgs =
1690 (Pair<Integer, List<String>>) request.argument;
1691 appType = setFplmnsArgs.first;
1692 List<String> fplmns = setFplmnsArgs.second;
1693 uiccApp = uiccCard.getApplicationByType(appType);
1694 if (uiccApp == null) {
1695 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1696 request.result = -1;
1697 loge("Failed to get UICC App");
1698 notifyRequester(request);
1699 } else {
1700 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1701 ((SIMRecords) uiccApp.getIccRecords())
1702 .setForbiddenPlmns(onCompleted, fplmns);
1703 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001704 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001705 case CMD_ERASE_MODEM_CONFIG:
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1708 defaultPhone.eraseModemConfig(onCompleted);
1709 break;
1710 case EVENT_ERASE_MODEM_CONFIG_DONE:
1711 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001712 break;
zoey chene02881a2019-12-30 16:11:23 +08001713
Kai Shif70f46f2021-03-03 13:59:46 -08001714 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1715 request = (MainThreadRequest) msg.obj;
1716 request.result = defaultPhone.eraseDataInSharedPreferences();
1717 notifyRequester(request);
1718 break;
1719
zoey chene02881a2019-12-30 16:11:23 +08001720 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1723 Pair<String, String> changed = (Pair<String, String>) request.argument;
1724 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1725 changed.first, changed.second, onCompleted);
1726 break;
1727 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1728 ar = (AsyncResult) msg.obj;
1729 request = (MainThreadRequest) ar.userObj;
1730 if (ar.exception == null) {
1731 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001732 // If the operation is successful, update the PIN storage
1733 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1734 int phoneId = getPhoneFromRequest(request).getPhoneId();
1735 UiccController.getInstance().getPinStorage()
1736 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001737 } else {
1738 request.result = msg.arg1;
1739 }
1740 notifyRequester(request);
1741 break;
1742
Michele Berionne5e411512020-11-13 02:36:59 +00001743 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001744 request = (MainThreadRequest) msg.obj;
1745 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1746 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1747 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1748 enabled.first, enabled.second, onCompleted);
1749 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001750 }
zoey chene02881a2019-12-30 16:11:23 +08001751 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
1754 if (ar.exception == null) {
1755 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001756 // If the operation is successful, update the PIN storage
1757 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1758 int phoneId = getPhoneFromRequest(request).getPhoneId();
1759 if (enabled.first) {
1760 UiccController.getInstance().getPinStorage()
1761 .storePin(enabled.second, phoneId);
1762 } else {
1763 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1764 }
zoey chene02881a2019-12-30 16:11:23 +08001765 } else {
1766 request.result = msg.arg1;
1767 }
Michele Berionne5e411512020-11-13 02:36:59 +00001768
1769
zoey chene02881a2019-12-30 16:11:23 +08001770 notifyRequester(request);
1771 break;
1772
Peter Wangdafb9ac2020-01-15 14:13:38 -08001773 case MSG_NOTIFY_USER_ACTIVITY:
1774 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001775 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001776 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1777 getDefaultPhone().getContext().sendBroadcastAsUser(
1778 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1779 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001780
1781 case CMD_SET_DATA_THROTTLING: {
1782 request = (MainThreadRequest) msg.obj;
1783 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1784 DataThrottlingRequest dataThrottlingRequest =
1785 (DataThrottlingRequest) request.argument;
1786 Phone phone = getPhoneFromRequest(request);
1787 if (phone != null) {
1788 phone.setDataThrottling(onCompleted,
1789 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1790 dataThrottlingRequest.getCompletionDurationMillis());
1791 } else {
1792 loge("setDataThrottling: No phone object");
1793 request.result =
1794 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1795 notifyRequester(request);
1796 }
1797
1798 break;
1799 }
1800 case EVENT_SET_DATA_THROTTLING_DONE:
1801 ar = (AsyncResult) msg.obj;
1802 request = (MainThreadRequest) ar.userObj;
1803
1804 if (ar.exception == null) {
1805 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1806 } else if (ar.exception instanceof CommandException) {
1807 loge("setDataThrottling: CommandException: " + ar.exception);
1808 CommandException.Error error =
1809 ((CommandException) (ar.exception)).getCommandError();
1810
1811 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1812 request.result = TelephonyManager
1813 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1814 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1815 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001816 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1817 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001818 } else {
1819 request.result =
1820 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1821 }
1822 } else {
1823 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1824 }
1825 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1826 notifyRequester(request);
1827 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001828
1829 case CMD_SET_SIM_POWER: {
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1832 request = (MainThreadRequest) msg.obj;
1833 int stateToSet =
1834 ((Pair<Integer, IIntegerConsumer>)
1835 request.argument).first;
1836 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1837 break;
1838 }
1839 case EVENT_SET_SIM_POWER_DONE: {
1840 ar = (AsyncResult) msg.obj;
1841 request = (MainThreadRequest) ar.userObj;
1842 IIntegerConsumer callback =
1843 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1844 if (ar.exception != null) {
1845 loge("setSimPower exception: " + ar.exception);
1846 int errorCode = TelephonyManager.CallForwardingInfoCallback
1847 .RESULT_ERROR_UNKNOWN;
1848 if (ar.exception instanceof CommandException) {
1849 CommandException.Error error =
1850 ((CommandException) (ar.exception)).getCommandError();
1851 if (error == CommandException.Error.SIM_ERR) {
1852 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1853 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1854 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1855 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1856 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1857 } else {
1858 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1859 }
1860 }
1861 try {
1862 callback.accept(errorCode);
1863 } catch (RemoteException e) {
1864 // Ignore if the remote process is no longer available to call back.
1865 Log.w(LOG_TAG, "setSimPower: callback not available.");
1866 }
1867 } else {
1868 try {
1869 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1870 } catch (RemoteException e) {
1871 // Ignore if the remote process is no longer available to call back.
1872 Log.w(LOG_TAG, "setSimPower: callback not available.");
1873 }
1874 }
1875 break;
1876 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001877 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1878 request = (MainThreadRequest) msg.obj;
1879
1880 final Phone phone = getPhoneFromRequest(request);
1881 if (phone == null || phone.getServiceStateTracker() == null) {
1882 request.result = new IllegalStateException("Phone or SST is null");
1883 notifyRequester(request);
1884 break;
1885 }
1886
1887 Pair<Integer, SignalStrengthUpdateRequest> pair =
1888 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1889 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1890 request);
1891 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1892 request.subId, pair.first /*callingUid*/,
1893 pair.second /*request*/, onCompleted);
1894 break;
1895 }
1896 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
1899 // request.result will be the exception of ar if present, true otherwise.
1900 // Be cautious not to leave result null which will wait() forever
1901 request.result = ar.exception != null ? ar.exception : true;
1902 notifyRequester(request);
1903 break;
1904 }
1905 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1906 request = (MainThreadRequest) msg.obj;
1907
1908 Phone phone = getPhoneFromRequest(request);
1909 if (phone == null || phone.getServiceStateTracker() == null) {
1910 request.result = new IllegalStateException("Phone or SST is null");
1911 notifyRequester(request);
1912 break;
1913 }
1914
1915 Pair<Integer, SignalStrengthUpdateRequest> pair =
1916 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1917 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1918 request);
1919 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1920 request.subId, pair.first /*callingUid*/,
1921 pair.second /*request*/, onCompleted);
1922 break;
1923 }
1924 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1925 ar = (AsyncResult) msg.obj;
1926 request = (MainThreadRequest) ar.userObj;
1927 request.result = ar.exception != null ? ar.exception : true;
1928 notifyRequester(request);
1929 break;
1930 }
Jordan Liu109698e2020-11-24 14:50:34 -08001931
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001932 case CMD_GET_SLICING_CONFIG: {
1933 request = (MainThreadRequest) msg.obj;
1934 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1935 request.phone.getSlicingConfig(onCompleted);
1936 break;
1937 }
1938 case EVENT_GET_SLICING_CONFIG_DONE: {
1939 ar = (AsyncResult) msg.obj;
1940 request = (MainThreadRequest) ar.userObj;
1941 ResultReceiver result = (ResultReceiver) request.argument;
1942
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001943 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001944 Bundle bundle = new Bundle();
1945 int resultCode = 0;
1946 if (ar.exception != null) {
1947 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1948 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001949 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001950 } else if (ar.result == null) {
1951 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001952 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001953 } else {
1954 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001955 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1956 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001957 }
1958
1959 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001960 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001961 }
1962 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1963 result.send(resultCode, bundle);
1964 notifyRequester(request);
1965 break;
1966 }
1967
Michele Berionne5e411512020-11-13 02:36:59 +00001968 case CMD_PREPARE_UNATTENDED_REBOOT:
1969 request = (MainThreadRequest) msg.obj;
1970 request.result =
1971 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1972 notifyRequester(request);
1973 break;
1974
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 default:
1976 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1977 break;
1978 }
1979 }
Jake Hambye994d462014-02-03 13:10:13 -08001980
Pengquan Menga1bb6272018-09-06 09:59:22 -07001981 private void notifyRequester(MainThreadRequest request) {
1982 synchronized (request) {
1983 request.notifyAll();
1984 }
1985 }
1986
Jake Hambye994d462014-02-03 13:10:13 -08001987 private void handleNullReturnEvent(Message msg, String command) {
1988 AsyncResult ar = (AsyncResult) msg.obj;
1989 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1990 if (ar.exception == null) {
1991 request.result = true;
1992 } else {
1993 request.result = false;
1994 if (ar.exception instanceof CommandException) {
1995 loge(command + ": CommandException: " + ar.exception);
1996 } else {
1997 loge(command + ": Unknown exception");
1998 }
1999 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002000 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 }
2003
2004 /**
2005 * Posts the specified command to be executed on the main thread,
2006 * waits for the request to complete, and returns the result.
2007 * @see #sendRequestAsync
2008 */
2009 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002010 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2011 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002012 }
2013
2014 /**
2015 * Posts the specified command to be executed on the main thread,
2016 * waits for the request to complete, and returns the result.
2017 * @see #sendRequestAsync
2018 */
2019 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2020 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002021 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002022 }
2023
2024 /**
2025 * Posts the specified command to be executed on the main thread,
2026 * waits for the request to complete, and returns the result.
2027 * @see #sendRequestAsync
2028 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002029 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002030 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2031 }
2032
2033 /**
2034 * Posts the specified command to be executed on the main thread,
2035 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2036 * if not timeout or null otherwise.
2037 * @see #sendRequestAsync
2038 */
2039 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2040 long timeoutInMs) {
2041 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002042 }
2043
2044 /**
2045 * Posts the specified command to be executed on the main thread,
2046 * waits for the request to complete, and returns the result.
2047 * @see #sendRequestAsync
2048 */
Nathan Harold92bed182018-10-12 18:16:49 -07002049 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002050 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002051 }
2052
2053 /**
2054 * Posts the specified command to be executed on the main thread,
2055 * waits for the request to complete, and returns the result.
2056 * @see #sendRequestAsync
2057 */
2058 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002059 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2060 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002061 }
2062
2063 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002064 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2065 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2066 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002067 * @see #sendRequestAsync
2068 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002069 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2070 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2072 throw new RuntimeException("This method will deadlock if called from the main thread.");
2073 }
2074
Nathan Harold92bed182018-10-12 18:16:49 -07002075 MainThreadRequest request = null;
2076 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2077 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2078 } else if (phone != null) {
2079 request = new MainThreadRequest(argument, phone, workSource);
2080 } else {
2081 request = new MainThreadRequest(argument, subId, workSource);
2082 }
2083
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084 Message msg = mMainThreadHandler.obtainMessage(command, request);
2085 msg.sendToTarget();
2086
Rambo Wang0f050d82021-02-12 11:43:36 -08002087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002089 if (timeoutInMs >= 0) {
2090 // Wait for at least timeoutInMs before returning null request result
2091 long now = SystemClock.elapsedRealtime();
2092 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002093 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002094 try {
2095 request.wait(deadline - now);
2096 } catch (InterruptedException e) {
2097 // Do nothing, go back and check if request is completed or timeout
2098 } finally {
2099 now = SystemClock.elapsedRealtime();
2100 }
2101 }
2102 } else {
2103 // Wait for the request to complete
2104 while (request.result == null) {
2105 try {
2106 request.wait();
2107 } catch (InterruptedException e) {
2108 // Do nothing, go back and wait until the request is complete
2109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111 }
2112 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002113 if (request.result == null) {
2114 Log.wtf(LOG_TAG,
2115 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 return request.result;
2118 }
2119
2120 /**
2121 * Asynchronous ("fire and forget") version of sendRequest():
2122 * Posts the specified command to be executed on the main thread, and
2123 * returns immediately.
2124 * @see #sendRequest
2125 */
2126 private void sendRequestAsync(int command) {
2127 mMainThreadHandler.sendEmptyMessage(command);
2128 }
2129
2130 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002131 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002132 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002133 */
2134 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002135 sendRequestAsync(command, argument, null, null);
2136 }
2137
2138 /**
2139 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2140 * @see {@link #sendRequest(int,Object)}
2141 */
2142 private void sendRequestAsync(
2143 int command, Object argument, Phone phone, WorkSource workSource) {
2144 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002145 Message msg = mMainThreadHandler.obtainMessage(command, request);
2146 msg.sendToTarget();
2147 }
2148
2149 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 * Initialize the singleton PhoneInterfaceManager instance.
2151 * This is only done once, at startup, from PhoneApp.onCreate().
2152 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002153 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 synchronized (PhoneInterfaceManager.class) {
2155 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002156 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 } else {
2158 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2159 }
2160 return sInstance;
2161 }
2162 }
2163
2164 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002165 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002168 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002169 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002171 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002173 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002174 mTelephonySharedPreferences =
2175 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002176 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002177 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002178 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002179 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 publish();
2182 }
2183
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002184 private Phone getDefaultPhone() {
2185 Phone thePhone = getPhone(getDefaultSubscription());
2186 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2187 }
2188
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 private void publish() {
2190 if (DBG) log("publish: " + this);
2191
Peter Wangc035ce42020-01-08 21:00:22 -08002192 TelephonyFrameworkInitializer
2193 .getTelephonyServiceManager()
2194 .getTelephonyServiceRegisterer()
2195 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
Stuart Scott584921c2015-01-15 17:10:34 -08002198 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002199 if (request.phone != null) {
2200 return request.phone;
2201 } else {
2202 return getPhoneFromSubId(request.subId);
2203 }
2204 }
2205
2206 private Phone getPhoneFromSubId(int subId) {
2207 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2208 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002209 }
2210
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002211 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2212 Phone phone = getPhoneFromRequest(request);
2213 return phone == null ? null :
2214 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2215 }
2216
Wink Saville36469e72014-06-11 15:17:00 -07002217 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002218 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002219 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221
Kai Shif70f46f2021-03-03 13:59:46 -08002222 private void sendEraseModemConfig(@NonNull Phone phone) {
2223 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2224 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2225 }
2226
2227 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2228 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2229 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002230 }
2231
Peter Wang44b186e2020-01-13 23:33:09 -08002232 private boolean isImsAvailableOnDevice() {
2233 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2234 if (pm == null) {
2235 // For some reason package manger is not available.. This will fail internally anyway,
2236 // so do not throw error and allow.
2237 return true;
2238 }
2239 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2240 }
2241
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002243 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002244 }
2245
Wink Savilleb564aae2014-10-23 10:18:09 -07002246 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 if (DBG) log("dial: " + number);
2248 // No permission check needed here: This is just a wrapper around the
2249 // ACTION_DIAL intent, which is available to any app since it puts up
2250 // the UI before it does anything.
2251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 String url = createTelUrl(number);
2255 if (url == null) {
2256 return;
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 // PENDING: should we just silently fail if phone is offhook or ringing?
2260 PhoneConstants.State state = mCM.getState(subId);
2261 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2262 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2263 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2264 mApp.startActivity(intent);
2265 }
2266 } finally {
2267 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269 }
2270
2271 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002272 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002273 }
2274
Wink Savilleb564aae2014-10-23 10:18:09 -07002275 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 if (DBG) log("call: " + number);
2277
2278 // This is just a wrapper around the ACTION_CALL intent, but we still
2279 // need to do a permission check since we're calling startActivity()
2280 // from the context of the phone app.
2281 enforceCallPermission();
2282
Jordan Liu1617b712019-07-10 15:06:26 -07002283 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 != AppOpsManager.MODE_ALLOWED) {
2285 return;
2286 }
2287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 String url = createTelUrl(number);
2291 if (url == null) {
2292 return;
2293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 boolean isValid = false;
2296 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2297 if (slist != null) {
2298 for (SubscriptionInfo subInfoRecord : slist) {
2299 if (subInfoRecord.getSubscriptionId() == subId) {
2300 isValid = true;
2301 break;
2302 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002303 }
Wink Saville08874612014-08-31 19:19:58 -07002304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 if (!isValid) {
2306 return;
2307 }
Wink Saville08874612014-08-31 19:19:58 -07002308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2310 intent.putExtra(SUBSCRIPTION_KEY, subId);
2311 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2312 mApp.startActivity(intent);
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 }
2317
Wink Savilleb564aae2014-10-23 10:18:09 -07002318 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002319 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002320 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2321 }
2322
Wink Savilleb564aae2014-10-23 10:18:09 -07002323 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002324 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002325 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2326 }
2327
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002333 Phone phone = getPhone(subId);
2334 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002335 checkSimPin.start();
2336 return checkSimPin.unlockSim(null, pin);
2337 } finally {
2338 Binder.restoreCallingIdentity(identity);
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341
Wink Savilleb564aae2014-10-23 10:18:09 -07002342 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002347 Phone phone = getPhone(subId);
2348 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349 checkSimPuk.start();
2350 return checkSimPuk.unlockSim(puk, pin);
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
2353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 }
2355
2356 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002357 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 * a synchronous one.
2359 */
2360 private static class UnlockSim extends Thread {
2361
2362 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002363 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364
2365 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002366 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2367 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368
2369 // For replies from SimCard interface
2370 private Handler mHandler;
2371
2372 // For async handler to identify request type
2373 private static final int SUPPLY_PIN_COMPLETE = 100;
2374
Michele Berionne5e411512020-11-13 02:36:59 +00002375 UnlockSim(int phoneId, IccCard simCard) {
2376 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 mSimCard = simCard;
2378 }
2379
2380 @Override
2381 public void run() {
2382 Looper.prepare();
2383 synchronized (UnlockSim.this) {
2384 mHandler = new Handler() {
2385 @Override
2386 public void handleMessage(Message msg) {
2387 AsyncResult ar = (AsyncResult) msg.obj;
2388 switch (msg.what) {
2389 case SUPPLY_PIN_COMPLETE:
2390 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2391 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002392 mRetryCount = msg.arg1;
2393 if (ar.exception != null) {
2394 if (ar.exception instanceof CommandException &&
2395 ((CommandException)(ar.exception)).getCommandError()
2396 == CommandException.Error.PASSWORD_INCORRECT) {
2397 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002398 } //When UiccCardApp dispose,handle message and return exception
2399 else if (ar.exception instanceof CommandException &&
2400 ((CommandException) (ar.exception)).getCommandError()
2401 == CommandException.Error.ABORTED) {
2402 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002403 } else {
2404 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2405 }
2406 } else {
2407 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 mDone = true;
2410 UnlockSim.this.notifyAll();
2411 }
2412 break;
2413 }
2414 }
2415 };
2416 UnlockSim.this.notifyAll();
2417 }
2418 Looper.loop();
2419 }
2420
2421 /*
2422 * Use PIN or PUK to unlock SIM card
2423 *
2424 * If PUK is null, unlock SIM card with PIN
2425 *
2426 * If PUK is not null, unlock SIM card with PUK and set PIN code
2427 */
Wink Saville9de0f752013-10-22 19:04:03 -07002428 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429
2430 while (mHandler == null) {
2431 try {
2432 wait();
2433 } catch (InterruptedException e) {
2434 Thread.currentThread().interrupt();
2435 }
2436 }
2437 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2438
2439 if (puk == null) {
2440 mSimCard.supplyPin(pin, callback);
2441 } else {
2442 mSimCard.supplyPuk(puk, pin, callback);
2443 }
2444
2445 while (!mDone) {
2446 try {
2447 Log.d(LOG_TAG, "wait for done");
2448 wait();
2449 } catch (InterruptedException e) {
2450 // Restore the interrupted status
2451 Thread.currentThread().interrupt();
2452 }
2453 }
2454 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002455 int[] resultArray = new int[2];
2456 resultArray[0] = mResult;
2457 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002458
2459 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2460 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2461 }
2462
Wink Saville9de0f752013-10-22 19:04:03 -07002463 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465 }
2466
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002467 /**
2468 * This method has been removed due to privacy and stability concerns.
2469 */
2470 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002472 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2473 return;
Wink Saville36469e72014-06-11 15:17:00 -07002474 }
2475
Nathan Harold1f889d82020-06-04 17:05:26 -07002476 @Override
2477 public void updateServiceLocationWithPackageName(String callingPackage) {
2478 mApp.getSystemService(AppOpsManager.class)
2479 .checkPackage(Binder.getCallingUid(), callingPackage);
2480
Nathan Haroldf096d982020-11-18 17:18:06 -08002481 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002482 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2483 // Callers targeting S have no business invoking this method.
2484 return;
2485 }
2486
2487 LocationAccessPolicy.LocationPermissionResult locationResult =
2488 LocationAccessPolicy.checkLocationPermission(mApp,
2489 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2490 .setCallingPackage(callingPackage)
2491 .setCallingFeatureId(null)
2492 .setCallingPid(Binder.getCallingPid())
2493 .setCallingUid(Binder.getCallingUid())
2494 .setMethod("updateServiceLocation")
2495 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2496 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2497 .build());
2498 // Apps that lack location permission have no business calling this method;
2499 // however, because no permission was declared in the public API, denials must
2500 // all be "soft".
2501 switch (locationResult) {
2502 case DENIED_HARD: /* fall through */
2503 case DENIED_SOFT:
2504 return;
2505 }
2506
2507 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 final long identity = Binder.clearCallingIdentity();
2509 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002510 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002512 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002519 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002520 @Override
2521 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002522 return isRadioOnWithFeature(callingPackage, null);
2523 }
2524
2525
2526 @Override
2527 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2528 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2529 callingFeatureId);
2530 }
2531
2532 @Deprecated
2533 @Override
2534 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2535 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002536 }
2537
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002539 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2540 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002542 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002543 return false;
2544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 return isRadioOnForSubscriber(subId);
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002552 }
2553
2554 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 final Phone phone = getPhone(subId);
2558 if (phone != null) {
2559 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2560 } else {
2561 return false;
2562 }
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
2567
2568 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002569 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 }
Wink Saville36469e72014-06-11 15:17:00 -07002571
Wink Savilleb564aae2014-10-23 10:18:09 -07002572 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null) {
2579 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2580 }
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002583 }
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
2586 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002587 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
Wink Savilleb564aae2014-10-23 10:18:09 -07002590 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 final Phone phone = getPhone(subId);
2596 if (phone == null) {
2597 return false;
2598 }
2599 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2600 toggleRadioOnOffForSubscriber(subId);
2601 }
2602 return true;
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
Wink Saville36469e72014-06-11 15:17:00 -07002607
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002608 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002609 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002610 /*
2611 * If any of the Radios are available, it will need to be
2612 * shutdown. So return true if any Radio is available.
2613 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2617 Phone phone = PhoneFactory.getPhone(i);
2618 if (phone != null && phone.isRadioAvailable()) return true;
2619 }
2620 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2621 return false;
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002624 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002625 }
2626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002628 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 enforceModifyPermission();
2630
2631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2634 logv("Shutting down Phone " + i);
2635 shutdownRadioUsingPhoneId(i);
2636 }
2637 } finally {
2638 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002639 }
2640 }
2641
2642 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002643 Phone phone = PhoneFactory.getPhone(phoneId);
2644 if (phone != null && phone.isRadioAvailable()) {
2645 phone.shutdownRadio();
2646 }
2647 }
2648
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002650 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2655 if (defaultPhone != null) {
2656 defaultPhone.setRadioPower(turnOn);
2657 return true;
2658 } else {
2659 loge("There's no default phone.");
2660 return false;
2661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002664 }
Wink Saville36469e72014-06-11 15:17:00 -07002665 }
2666
Wink Savilleb564aae2014-10-23 10:18:09 -07002667 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669
2670 final long identity = Binder.clearCallingIdentity();
2671 try {
2672 final Phone phone = getPhone(subId);
2673 if (phone != null) {
2674 phone.setRadioPower(turnOn);
2675 return true;
2676 } else {
2677 return false;
2678 }
2679 } finally {
2680 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002681 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
2683
Wink Saville36469e72014-06-11 15:17:00 -07002684 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002685 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 public boolean enableDataConnectivity() {
2687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 int subId = mSubscriptionController.getDefaultDataSubId();
2692 final Phone phone = getPhone(subId);
2693 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002694 phone.getDataEnabledSettings().setDataEnabled(
2695 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 return true;
2697 } else {
2698 return false;
2699 }
2700 } finally {
2701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
Wink Saville36469e72014-06-11 15:17:00 -07002705 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002706 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 public boolean disableDataConnectivity() {
2708 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
2710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 int subId = mSubscriptionController.getDefaultDataSubId();
2713 final Phone phone = getPhone(subId);
2714 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002715 phone.getDataEnabledSettings().setDataEnabled(
2716 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 return true;
2718 } else {
2719 return false;
2720 }
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002727 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728 final long identity = Binder.clearCallingIdentity();
2729 try {
2730 final Phone phone = getPhone(subId);
2731 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002732 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 } else {
2734 return false;
2735 }
2736 } finally {
2737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 }
2740
2741 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002742 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002743 }
2744
pkanwarae03a6b2016-11-06 20:37:09 -08002745 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 enforceCallPermission();
2747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2751 return;
2752 }
2753 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2754 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
2757 }
pkanwar32d516d2016-10-14 19:37:38 -07002758 };
2759
Wink Savilleb564aae2014-10-23 10:18:09 -07002760 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2766 return false;
2767 }
2768 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 }
2773
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002774 /**
2775 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2776 * tag on getCallState Binder call.
2777 */
2778 @Deprecated
2779 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002781 if (CompatChanges.isChangeEnabled(
2782 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2783 Binder.getCallingUid())) {
2784 // Do not allow this API to be called on API version 31+, it should only be
2785 // called on old apps using this Binder call directly.
2786 throw new SecurityException("This method can only be used for applications "
2787 + "targeting API version 30 or less.");
2788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002791 Phone phone = getPhone(getDefaultSubscription());
2792 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2793 PhoneConstantConversions.convertCallState(phone.getState());
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
2796 }
2797 }
2798
2799 @Override
2800 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2801 if (CompatChanges.isChangeEnabled(
2802 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2803 Binder.getCallingUid())) {
2804 // Check READ_PHONE_STATE for API version 31+
2805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2806 featureId, "getCallStateForSubscription")) {
2807 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2808 + "targeting API level 31+.");
2809 }
2810 }
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2815 PhoneConstantConversions.convertCallState(phone.getState());
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002822 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002823 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2824 }
2825
2826 @Override
2827 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831 if (phone != null) {
2832 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2833 } else {
2834 return PhoneConstantConversions.convertDataState(
2835 PhoneConstants.DataState.DISCONNECTED);
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 }
2841
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002843 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002844 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2845 }
2846
2847 @Override
2848 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849 final long identity = Binder.clearCallingIdentity();
2850 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002851 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 if (phone != null) {
2853 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2854 } else {
2855 return TelephonyManager.DATA_ACTIVITY_NONE;
2856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
2862 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002863 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002865 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002866
2867 LocationAccessPolicy.LocationPermissionResult locationResult =
2868 LocationAccessPolicy.checkLocationPermission(mApp,
2869 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2870 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002871 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002872 .setCallingPid(Binder.getCallingPid())
2873 .setCallingUid(Binder.getCallingUid())
2874 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002875 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002876 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2877 .build());
2878 switch (locationResult) {
2879 case DENIED_HARD:
2880 throw new SecurityException("Not allowed to access cell location");
2881 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002882 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2883 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
2885
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002890 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002891 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 } finally {
2893 Binder.restoreCallingIdentity(identity);
2894 }
Svetoslav64fad262015-04-14 14:35:21 -07002895 }
2896
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002898 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002899 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2900 // registered cell info, so return a NULL country instead.
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002903 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2904 // Get default phone in this case.
2905 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2906 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002907 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002909 if (phone == null) return "";
2910 ServiceStateTracker sst = phone.getServiceStateTracker();
2911 if (sst == null) return "";
2912 LocaleTracker lt = sst.getLocaleTracker();
2913 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002914 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002915 } finally {
2916 Binder.restoreCallingIdentity(identity);
2917 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002918 }
2919
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002920 /**
2921 * This method was removed due to potential issues caused by performing partial
2922 * updates of service state, and lack of a credible use case.
2923 *
2924 * This has the ability to break the telephony implementation by disabling notification of
2925 * changes in device connectivity. DO NOT USE THIS!
2926 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002927 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 public void enableLocationUpdates() {
2929 mApp.enforceCallingOrSelfPermission(
2930 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002933 /**
2934 * This method was removed due to potential issues caused by performing partial
2935 * updates of service state, and lack of a credible use case.
2936 *
2937 * This has the ability to break the telephony implementation by disabling notification of
2938 * changes in device connectivity. DO NOT USE THIS!
2939 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 @Override
2941 public void disableLocationUpdates() {
2942 mApp.enforceCallingOrSelfPermission(
2943 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944 }
2945
2946 @Override
2947 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002948 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2949 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002950 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002951 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2952 throw new SecurityException(
2953 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2954 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002955
Jordan Liu1617b712019-07-10 15:06:26 -07002956 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2958 return null;
2959 }
Svetoslav64fad262015-04-14 14:35:21 -07002960
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002961 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002962
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002963 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002964 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965
Nathan Haroldf180aac2018-06-01 18:43:55 -07002966 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2967 for (CellInfo ci : info) {
2968 if (ci instanceof CellInfoGsm) {
2969 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2970 } else if (ci instanceof CellInfoWcdma) {
2971 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002974 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
2976
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002977 private List<CellInfo> getCachedCellInfo() {
2978 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2979 for (Phone phone : PhoneFactory.getPhones()) {
2980 List<CellInfo> info = phone.getAllCellInfo();
2981 if (info != null) cellInfos.addAll(info);
2982 }
2983 return cellInfos;
2984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002985
2986 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002987 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002988 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002989 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002990
2991 LocationAccessPolicy.LocationPermissionResult locationResult =
2992 LocationAccessPolicy.checkLocationPermission(mApp,
2993 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2994 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002995 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002996 .setCallingPid(Binder.getCallingPid())
2997 .setCallingUid(Binder.getCallingUid())
2998 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002999 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003000 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3001 .build());
3002 switch (locationResult) {
3003 case DENIED_HARD:
3004 throw new SecurityException("Not allowed to access cell info");
3005 case DENIED_SOFT:
3006 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 }
3008
Nathan Haroldf096d982020-11-18 17:18:06 -08003009 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003010 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3011 return getCachedCellInfo();
3012 }
3013
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003014 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003015 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3019 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003020 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003021 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 if (info != null) cellInfos.addAll(info);
3023 }
3024 return cellInfos;
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003027 }
3028 }
3029
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003030 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003031 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3032 String callingFeatureId) {
3033 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3034 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003035 }
3036
3037 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003038 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3039 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003040 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003041 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003042 }
3043
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003044 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3045 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003046 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003047 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003048
3049 LocationAccessPolicy.LocationPermissionResult locationResult =
3050 LocationAccessPolicy.checkLocationPermission(mApp,
3051 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3052 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003053 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003054 .setCallingPid(Binder.getCallingPid())
3055 .setCallingUid(Binder.getCallingUid())
3056 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003057 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3058 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003059 .build());
3060 switch (locationResult) {
3061 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003062 if (TelephonyPermissions
3063 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003064 // Safetynet logging for b/154934934
3065 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3066 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003067 throw new SecurityException("Not allowed to access cell info");
3068 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003069 if (TelephonyPermissions
3070 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003071 // Safetynet logging for b/154934934
3072 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3073 }
Nathan Harold5320c422019-05-09 10:26:08 -07003074 try {
3075 cb.onCellInfo(new ArrayList<CellInfo>());
3076 } catch (RemoteException re) {
3077 // Drop without consequences
3078 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003079 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003080 }
3081
Nathan Harolda939a962019-05-09 10:13:47 -07003082
3083 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003084 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3085
3086 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3087 }
3088
3089 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003090 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003091 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003096 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097 } finally {
3098 Binder.restoreCallingIdentity(identity);
3099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 }
3101
Shishir Agrawala9f32182016-04-12 12:00:16 -07003102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003103 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003104 Phone phone = PhoneFactory.getPhone(slotIndex);
3105 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003106 return null;
3107 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003108 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003109 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003110 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003111 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003112 return null;
3113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114
3115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 return phone.getImei();
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
3120 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003121 }
3122
3123 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003124 public String getTypeAllocationCodeForSlot(int slotIndex) {
3125 Phone phone = PhoneFactory.getPhone(slotIndex);
3126 String tac = null;
3127 if (phone != null) {
3128 String imei = phone.getImei();
3129 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3130 }
3131 return tac;
3132 }
3133
3134 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003135 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003136 Phone phone = PhoneFactory.getPhone(slotIndex);
3137 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003138 return null;
3139 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003140
Jeff Davidson913390f2018-02-23 17:11:49 -08003141 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003142 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003143 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003144 return null;
3145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146
3147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 return phone.getMeid();
3150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
Jack Yu2af8d712017-03-15 17:14:14 -07003153 }
3154
3155 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003156 public String getManufacturerCodeForSlot(int slotIndex) {
3157 Phone phone = PhoneFactory.getPhone(slotIndex);
3158 String manufacturerCode = null;
3159 if (phone != null) {
3160 String meid = phone.getMeid();
3161 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3162 }
3163 return manufacturerCode;
3164 }
3165
3166 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003167 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3168 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003169 Phone phone = PhoneFactory.getPhone(slotIndex);
3170 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003171 return null;
3172 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003173 int subId = phone.getSubId();
3174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003175 mApp, subId, callingPackage, callingFeatureId,
3176 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003177 return null;
3178 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003179
3180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 return phone.getDeviceSvn();
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003186 }
3187
fionaxu43304da2017-11-27 22:51:16 -08003188 @Override
3189 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190 final long identity = Binder.clearCallingIdentity();
3191 try {
3192 final Phone phone = getPhone(subId);
3193 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
fionaxu43304da2017-11-27 22:51:16 -08003197 }
3198
3199 @Override
3200 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 final Phone phone = getPhone(subId);
3204 return phone == null ? null : phone.getCarrierName();
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
fionaxu43304da2017-11-27 22:51:16 -08003208 }
3209
calvinpanffe225e2018-11-01 19:43:06 +08003210 @Override
chen xu0026ca62019-03-06 15:28:50 -08003211 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 final Phone phone = getPhone(subId);
3215 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003216 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003217 } finally {
3218 Binder.restoreCallingIdentity(identity);
3219 }
3220 }
3221
3222 @Override
chen xu0026ca62019-03-06 15:28:50 -08003223 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003227 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
3231 }
3232
chen xu651eec72018-11-11 19:03:44 -08003233 @Override
chen xu864e11c2018-12-06 22:10:03 -08003234 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3235 if (!isSubscriptionMccMnc) {
3236 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3237 }
chen xu651eec72018-11-11 19:03:44 -08003238 final Phone phone = PhoneFactory.getPhone(slotIndex);
3239 if (phone == null) {
3240 return TelephonyManager.UNKNOWN_CARRIER_ID;
3241 }
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
3248 }
3249
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003250 //
3251 // Internal helper methods.
3252 //
3253
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003254 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003255 * Make sure the caller is the calling package itself
3256 *
3257 * @throws SecurityException if the caller is not the calling package
3258 */
3259 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3260 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003261 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3262 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003263 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003264 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003265 } catch (PackageManager.NameNotFoundException e) {
3266 // packageUid is -1
3267 }
3268 if (packageUid != callingUid) {
3269 throw new SecurityException(message + ": Package " + callingPackage
3270 + " does not belong to " + callingUid);
3271 }
3272 }
3273
3274 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3276 *
3277 * @throws SecurityException if the caller does not have the required permission
3278 */
3279 private void enforceModifyPermission() {
3280 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3281 }
3282
Shuo Qiancd19c462020-01-16 20:51:11 -08003283 /**
3284 * Make sure the caller is system.
3285 *
3286 * @throws SecurityException if the caller is not system.
3287 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003288 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003289 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3290 throw new SecurityException("Caller must be system");
3291 }
3292 }
3293
Shuo Qian3b6ee772019-11-13 17:43:31 -08003294 private void enforceActiveEmergencySessionPermission() {
3295 mApp.enforceCallingOrSelfPermission(
3296 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3297 }
3298
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003299 /**
3300 * Make sure the caller has the CALL_PHONE permission.
3301 *
3302 * @throws SecurityException if the caller does not have the required permission
3303 */
3304 private void enforceCallPermission() {
3305 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3306 }
3307
paulhu5a773602019-08-23 19:17:33 +08003308 private void enforceSettingsPermission() {
3309 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003310 }
3311
Michele Berionne5e411512020-11-13 02:36:59 +00003312 private void enforceRebootPermission() {
3313 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3314 }
3315
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003316 private String createTelUrl(String number) {
3317 if (TextUtils.isEmpty(number)) {
3318 return null;
3319 }
3320
Jake Hambye994d462014-02-03 13:10:13 -08003321 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003322 }
3323
Ihab Awadf9e92732013-12-05 18:02:52 -08003324 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003325 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3326 }
3327
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003328 private static void logv(String msg) {
3329 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3330 }
3331
Ihab Awadf9e92732013-12-05 18:02:52 -08003332 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003333 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3334 }
3335
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003336 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003337 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003338 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003339 }
3340
Sanket Padawe356d7632015-06-22 14:03:32 -07003341 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003342 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 final Phone phone = PhoneFactory.getPhone(slotIndex);
3346 if (phone == null) {
3347 return PhoneConstants.PHONE_TYPE_NONE;
3348 } else {
3349 return phone.getPhoneType();
3350 }
3351 } finally {
3352 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003354 }
3355
3356 /**
3357 * Returns the CDMA ERI icon index to display
3358 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003359 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003360 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3361 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3362 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003363 }
3364
Sanket Padawe356d7632015-06-22 14:03:32 -07003365 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003366 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3367 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003369 mApp, subId, callingPackage, callingFeatureId,
3370 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003371 return -1;
3372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003373
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 final Phone phone = getPhone(subId);
3377 if (phone != null) {
3378 return phone.getCdmaEriIconIndex();
3379 } else {
3380 return -1;
3381 }
3382 } finally {
3383 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003385 }
3386
3387 /**
3388 * Returns the CDMA ERI icon mode,
3389 * 0 - ON
3390 * 1 - FLASHING
3391 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003392 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003393 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3394 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3395 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003396 }
3397
Sanket Padawe356d7632015-06-22 14:03:32 -07003398 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003399 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3400 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003401 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003402 mApp, subId, callingPackage, callingFeatureId,
3403 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003404 return -1;
3405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406
3407 final long identity = Binder.clearCallingIdentity();
3408 try {
3409 final Phone phone = getPhone(subId);
3410 if (phone != null) {
3411 return phone.getCdmaEriIconMode();
3412 } else {
3413 return -1;
3414 }
3415 } finally {
3416 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003418 }
3419
3420 /**
3421 * Returns the CDMA ERI text,
3422 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003423 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003424 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3425 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3426 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003427 }
3428
Sanket Padawe356d7632015-06-22 14:03:32 -07003429 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003430 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3431 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003433 mApp, subId, callingPackage, callingFeatureId,
3434 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003435 return null;
3436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 final Phone phone = getPhone(subId);
3441 if (phone != null) {
3442 return phone.getCdmaEriText();
3443 } else {
3444 return null;
3445 }
3446 } finally {
3447 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003449 }
3450
3451 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003452 * Returns the CDMA MDN.
3453 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003454 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003455 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3457 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003458
3459 final long identity = Binder.clearCallingIdentity();
3460 try {
3461 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003462 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463 return phone.getLine1Number();
3464 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003465 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466 return null;
3467 }
3468 } finally {
3469 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003470 }
3471 }
3472
3473 /**
3474 * Returns the CDMA MIN.
3475 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003476 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003477 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3479 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 final Phone phone = getPhone(subId);
3484 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3485 return phone.getCdmaMin();
3486 } else {
3487 return null;
3488 }
3489 } finally {
3490 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003491 }
3492 }
3493
Hall Liud892bec2018-11-30 14:51:45 -08003494 @Override
3495 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3496 INumberVerificationCallback callback, String callingPackage) {
3497 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3498 != PERMISSION_GRANTED) {
3499 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3500 }
3501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3502
3503 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3504 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003505 throw new SecurityException("Calling package must be configured in the device config: "
3506 + "calling package: " + callingPackage
3507 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003508 }
3509
3510 if (range == null) {
3511 throw new NullPointerException("Range must be non-null");
3512 }
3513
3514 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003515 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003516
3517 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3518 }
3519
Junda Liuca05d5d2014-08-14 22:36:34 -07003520 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 * Returns true if CDMA provisioning needs to run.
3522 */
3523 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003524 final long identity = Binder.clearCallingIdentity();
3525 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003526 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003530 }
3531
3532 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003533 * Sets the voice mail number of a given subId.
3534 */
3535 @Override
3536 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003537 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3538 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539
3540 final long identity = Binder.clearCallingIdentity();
3541 try {
3542 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3543 new Pair<String, String>(alphaTag, number), new Integer(subId));
3544 return success;
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003548 }
3549
Ta-wei Yen87c49842016-05-13 21:19:52 -07003550 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003551 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3552 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003553 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3554 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003555 if (!TextUtils.equals(callingPackage, systemDialer)) {
3556 throw new SecurityException("caller must be system dialer");
3557 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003558
3559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3562 if (phoneAccountHandle == null) {
3563 return null;
3564 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003565 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566 } finally {
3567 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003568 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003569 }
3570
3571 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003572 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3573 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003574 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003575 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003576 mApp, subId, callingPackage, callingFeatureId,
3577 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003578 return null;
3579 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003580
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003581 final long identity = Binder.clearCallingIdentity();
3582 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003583 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003584 } finally {
3585 Binder.restoreCallingIdentity(identity);
3586 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003587 }
3588
3589 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003590 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3591 VisualVoicemailSmsFilterSettings settings) {
3592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593
3594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003597 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598 } finally {
3599 Binder.restoreCallingIdentity(identity);
3600 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003601 }
3602
3603 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003604 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3605 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003606
3607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003610 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003611 } finally {
3612 Binder.restoreCallingIdentity(identity);
3613 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003614 }
3615
3616 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003617 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3618 String callingPackage, int subId) {
3619 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620
3621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003624 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003628 }
3629
3630 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003631 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003632 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633
3634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003637 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638 } finally {
3639 Binder.restoreCallingIdentity(identity);
3640 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003641 }
3642
3643 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003644 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3645 String callingAttributionTag, int subId, String number, int port, String text,
3646 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003648 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003649 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003650 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003651 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3652 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003653 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003654
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003655 /**
fionaxu0152e512016-11-14 13:36:14 -08003656 * Sets the voice activation state of a given subId.
3657 */
3658 @Override
3659 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3661 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662
3663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 final Phone phone = getPhone(subId);
3666 if (phone != null) {
3667 phone.setVoiceActivationState(activationState);
3668 } else {
3669 loge("setVoiceActivationState fails with invalid subId: " + subId);
3670 }
3671 } finally {
3672 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003673 }
3674 }
3675
3676 /**
3677 * Sets the data activation state of a given subId.
3678 */
3679 @Override
3680 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3682 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683
3684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 final Phone phone = getPhone(subId);
3687 if (phone != null) {
3688 phone.setDataActivationState(activationState);
3689 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003690 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003691 }
3692 } finally {
3693 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003694 }
3695 }
3696
3697 /**
3698 * Returns the voice activation state of a given subId.
3699 */
3700 @Override
3701 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003702 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703
fionaxu0152e512016-11-14 13:36:14 -08003704 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 if (phone != null) {
3708 return phone.getVoiceActivationState();
3709 } else {
3710 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3711 }
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003714 }
3715 }
3716
3717 /**
3718 * Returns the data activation state of a given subId.
3719 */
3720 @Override
3721 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
fionaxu0152e512016-11-14 13:36:14 -08003724 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 if (phone != null) {
3728 return phone.getDataActivationState();
3729 } else {
3730 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3731 }
3732 } finally {
3733 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003734 }
3735 }
3736
3737 /**
Wink Saville36469e72014-06-11 15:17:00 -07003738 * Returns the unread count of voicemails for a subId
3739 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003741 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3742 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003743 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003744 mApp, subId, callingPackage, callingFeatureId,
3745 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003746 return 0;
3747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 final Phone phone = getPhone(subId);
3751 if (phone != null) {
3752 return phone.getVoiceMessageCount();
3753 } else {
3754 return 0;
3755 }
3756 } finally {
3757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003759 }
3760
3761 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003762 * returns true, if the device is in a state where both voice and data
3763 * are supported simultaneously. This can change based on location or network condition.
3764 */
3765 @Override
3766 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767 final long identity = Binder.clearCallingIdentity();
3768 try {
3769 final Phone phone = getPhone(subId);
3770 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003774 }
3775
3776 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003777 * Send the dialer code if called from the current default dialer or the caller has
3778 * carrier privilege.
3779 * @param inputCode The dialer code to send
3780 */
3781 @Override
3782 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003783 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003784 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003785 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3786 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003787 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003788 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791
3792 final long identity = Binder.clearCallingIdentity();
3793 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003794 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003795 } finally {
3796 Binder.restoreCallingIdentity(identity);
3797 }
fionaxu235cc5e2017-03-06 22:25:57 -08003798 }
3799
Pengquan Menga1bb6272018-09-06 09:59:22 -07003800 @Override
3801 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003802 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003803 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003804 mApp, subId, "getNetworkSelectionMode");
3805 final long identity = Binder.clearCallingIdentity();
3806 try {
3807 if (!isActiveSubscription(subId)) {
3808 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3809 }
3810 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3811 } finally {
3812 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003813 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003814 }
3815
Brad Ebinger35c841c2018-10-01 10:40:55 -07003816 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003817 public boolean isInEmergencySmsMode() {
3818 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 for (Phone phone : PhoneFactory.getPhones()) {
3822 if (phone.isInEmergencySmsMode()) {
3823 return true;
3824 }
3825 }
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
3829 return false;
3830 }
3831
shilu366312e2019-12-17 09:28:10 -08003832 /**
3833 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3834 * @param subId The subscription to use to check the configuration.
3835 * @param c The callback that will be used to send the result.
3836 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003837 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003838 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3839 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003840 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003841 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003842
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003843 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3844 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3845 "IMS not available on device.");
3846 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 final long token = Binder.clearCallingIdentity();
3848 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003849 int slotId = getSlotIndexOrException(subId);
3850 verifyImsMmTelConfiguredOrThrow(slotId);
3851 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003852 } catch (ImsException e) {
3853 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 } finally {
3855 Binder.restoreCallingIdentity(token);
3856 }
3857 }
3858
shilu366312e2019-12-17 09:28:10 -08003859 /**
3860 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3861 * @param subId The subscription to use to check the configuration.
3862 * @param c The callback that will be used to send the result.
3863 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003865 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003866 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003867 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003868 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3869 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3870 }
Meng Wangafbc5852019-09-19 17:37:13 -07003871 final long token = Binder.clearCallingIdentity();
3872 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003873 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3874 .removeRegistrationCallbackForSubscription(c, subId);
3875 } catch (ImsException e) {
3876 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3877 + "is inactive, ignoring unregister.");
3878 // If the subscription is no longer active, just return, since the callback
3879 // will already have been removed internally.
3880 } finally {
3881 Binder.restoreCallingIdentity(token);
3882 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003883 }
3884
Brad Ebingera34a6c22019-10-22 17:36:18 -07003885 /**
3886 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3887 */
3888 @Override
3889 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3890 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3891 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3892 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3893 "IMS not available on device.");
3894 }
3895 final long token = Binder.clearCallingIdentity();
3896 try {
3897 Phone phone = getPhone(subId);
3898 if (phone == null) {
3899 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3900 + subId + "'");
3901 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3902 }
3903 phone.getImsRegistrationState(regState -> {
3904 try {
3905 consumer.accept((regState == null)
3906 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3907 } catch (RemoteException e) {
3908 // Ignore if the remote process is no longer available to call back.
3909 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3910 }
3911 });
3912 } finally {
3913 Binder.restoreCallingIdentity(token);
3914 }
3915 }
3916
3917 /**
3918 * Get the transport type for the IMS service registration state.
3919 */
3920 @Override
3921 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003922 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003923 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003924 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3925 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3926 "IMS not available on device.");
3927 }
3928 final long token = Binder.clearCallingIdentity();
3929 try {
3930 Phone phone = getPhone(subId);
3931 if (phone == null) {
3932 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3933 + subId + "'");
3934 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3935 }
3936 phone.getImsRegistrationTech(regTech -> {
3937 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3938 int regTechConverted = (regTech == null)
3939 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3940 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3941 regTechConverted);
3942 try {
3943 consumer.accept(regTechConverted);
3944 } catch (RemoteException e) {
3945 // Ignore if the remote process is no longer available to call back.
3946 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3947 }
3948 });
3949 } finally {
3950 Binder.restoreCallingIdentity(token);
3951 }
3952 }
3953
shilu366312e2019-12-17 09:28:10 -08003954 /**
3955 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3956 * @param subId The subscription to use to check the configuration.
3957 * @param c The callback that will be used to send the result.
3958 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003960 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3961 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003962 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003963 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003964 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3965 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3966 "IMS not available on device.");
3967 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 final long token = Binder.clearCallingIdentity();
3969 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003970 int slotId = getSlotIndexOrException(subId);
3971 verifyImsMmTelConfiguredOrThrow(slotId);
3972 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003973 } catch (ImsException e) {
3974 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 } finally {
3976 Binder.restoreCallingIdentity(token);
3977 }
3978 }
3979
shilu366312e2019-12-17 09:28:10 -08003980 /**
3981 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3982 * @param subId The subscription to use to check the configuration.
3983 * @param c The callback that will be used to send the result.
3984 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003986 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003987 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003988 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003989 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3990 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3991 }
Meng Wangafbc5852019-09-19 17:37:13 -07003992
3993 final long token = Binder.clearCallingIdentity();
3994 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003995 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003996 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003997 } catch (ImsException e) {
3998 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3999 + "is inactive, ignoring unregister.");
4000 // If the subscription is no longer active, just return, since the callback
4001 // will already have been removed internally.
4002 } finally {
4003 Binder.restoreCallingIdentity(token);
4004 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 }
4006
4007 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004008 public boolean isCapable(int subId, int capability, int regTech) {
4009 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 final long token = Binder.clearCallingIdentity();
4011 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004012 int slotId = getSlotIndexOrException(subId);
4013 verifyImsMmTelConfiguredOrThrow(slotId);
4014 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004015 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4017 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004018 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004019 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4020 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 } finally {
4022 Binder.restoreCallingIdentity(token);
4023 }
4024 }
4025
4026 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004027 public boolean isAvailable(int subId, int capability, int regTech) {
4028 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 final long token = Binder.clearCallingIdentity();
4030 try {
4031 Phone phone = getPhone(subId);
4032 if (phone == null) return false;
4033 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004034 } catch (com.android.ims.ImsException e) {
4035 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4036 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 } finally {
4038 Binder.restoreCallingIdentity(token);
4039 }
4040 }
4041
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004042 /**
4043 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4044 * subscription.
4045 * @param subId The subscription to use to check the configuration.
4046 * @param callback The callback that will be used to send the result.
4047 * @param capability The MmTelFeature capability that will be used to send the result.
4048 * @param transportType The transport type of the MmTelFeature capability.
4049 */
4050 @Override
4051 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4052 int transportType) {
4053 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4054 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4055 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4056 "IMS not available on device.");
4057 }
4058 final long token = Binder.clearCallingIdentity();
4059 try {
4060 int slotId = getSlotIndex(subId);
4061 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4062 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4063 + subId + "'");
4064 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4065 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004066 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004067 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4068 transportType, aBoolean -> {
4069 try {
4070 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4071 } catch (RemoteException e) {
4072 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4073 + "running. Ignore");
4074 }
4075 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004076 } catch (ImsException e) {
4077 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004078 } finally {
4079 Binder.restoreCallingIdentity(token);
4080 }
4081 }
4082
shilu366312e2019-12-17 09:28:10 -08004083 /**
4084 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4085 * @param subId The subscription to use to check the configuration.
4086 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 @Override
4088 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004089 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004090 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004091
Brad Ebinger35c841c2018-10-01 10:40:55 -07004092 final long token = Binder.clearCallingIdentity();
4093 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004094 int slotId = getSlotIndexOrException(subId);
4095 verifyImsMmTelConfiguredOrThrow(slotId);
4096 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004097 } catch (ImsException e) {
4098 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 } finally {
4100 Binder.restoreCallingIdentity(token);
4101 }
4102 }
4103
4104 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004105 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004107 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 final long identity = Binder.clearCallingIdentity();
4109 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004110 int slotId = getSlotIndexOrException(subId);
4111 verifyImsMmTelConfiguredOrThrow(slotId);
4112 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004113 } catch (ImsException e) {
4114 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 } finally {
4116 Binder.restoreCallingIdentity(identity);
4117 }
4118 }
4119
shilu366312e2019-12-17 09:28:10 -08004120 /**
4121 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4122 * @param subId The subscription to use to check the configuration.
4123 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004125 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004126 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004127 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 final long identity = Binder.clearCallingIdentity();
4129 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004130 int slotId = getSlotIndexOrException(subId);
4131 verifyImsMmTelConfiguredOrThrow(slotId);
4132 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004133 } catch (ImsException e) {
4134 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 } finally {
4136 Binder.restoreCallingIdentity(identity);
4137 }
4138 }
4139
4140 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004141 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004143 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 final long identity = Binder.clearCallingIdentity();
4145 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004146 int slotId = getSlotIndexOrException(subId);
4147 verifyImsMmTelConfiguredOrThrow(slotId);
4148 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004149 } catch (ImsException e) {
4150 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 } finally {
4152 Binder.restoreCallingIdentity(identity);
4153 }
4154 }
4155
shilu366312e2019-12-17 09:28:10 -08004156 /**
4157 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4158 * @param subId The subscription to use to check the configuration.
4159 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 @Override
4161 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004162 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004163 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 final long identity = Binder.clearCallingIdentity();
4165 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004166 int slotId = getSlotIndexOrException(subId);
4167 verifyImsMmTelConfiguredOrThrow(slotId);
4168 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004169 } catch (ImsException e) {
4170 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 } finally {
4172 Binder.restoreCallingIdentity(identity);
4173 }
4174 }
4175
4176 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004177 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004179 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 final long identity = Binder.clearCallingIdentity();
4181 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004182 int slotId = getSlotIndexOrException(subId);
4183 verifyImsMmTelConfiguredOrThrow(slotId);
4184 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004185 } catch (ImsException e) {
4186 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 } finally {
4188 Binder.restoreCallingIdentity(identity);
4189 }
4190 }
4191
shilu366312e2019-12-17 09:28:10 -08004192 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004193 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4194 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4195 * @param subId The subscription to use to check the configuration.
4196 */
4197 @Override
4198 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004199 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004200 mApp, subId, "isCrossSimCallingEnabledByUser");
4201 final long identity = Binder.clearCallingIdentity();
4202 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004203 int slotId = getSlotIndexOrException(subId);
4204 verifyImsMmTelConfiguredOrThrow(slotId);
4205 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004206 } catch (ImsException e) {
4207 throw new ServiceSpecificException(e.getCode());
4208 } finally {
4209 Binder.restoreCallingIdentity(identity);
4210 }
4211 }
4212
4213 /**
4214 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4215 * Requires MODIFY_PHONE_STATE permission.
4216 * @param subId The subscription to use to check the configuration.
4217 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4218 * false otherwise
4219 */
4220 @Override
4221 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4223 "setCrossSimCallingEnabled");
4224 final long identity = Binder.clearCallingIdentity();
4225 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004226 int slotId = getSlotIndexOrException(subId);
4227 verifyImsMmTelConfiguredOrThrow(slotId);
4228 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004229 } catch (ImsException e) {
4230 throw new ServiceSpecificException(e.getCode());
4231 } finally {
4232 Binder.restoreCallingIdentity(identity);
4233 }
4234 }
4235
4236 /**
shilu366312e2019-12-17 09:28:10 -08004237 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4238 * @param subId The subscription to use to check the configuration.
4239 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004241
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004243 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004244 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 final long identity = Binder.clearCallingIdentity();
4246 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004247 int slotId = getSlotIndexOrException(subId);
4248 verifyImsMmTelConfiguredOrThrow(slotId);
4249 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004250 } catch (ImsException e) {
4251 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 } finally {
4253 Binder.restoreCallingIdentity(identity);
4254 }
4255 }
4256
4257 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004258 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004260 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004261 final long identity = Binder.clearCallingIdentity();
4262 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004263 int slotId = getSlotIndexOrException(subId);
4264 verifyImsMmTelConfiguredOrThrow(slotId);
4265 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004266 } catch (ImsException e) {
4267 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 } finally {
4269 Binder.restoreCallingIdentity(identity);
4270 }
4271 }
4272
4273 @Override
4274 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4276 "setVoWiFiNonPersistent");
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004279 int slotId = getSlotIndexOrException(subId);
4280 verifyImsMmTelConfiguredOrThrow(slotId);
4281 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004282 } catch (ImsException e) {
4283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
4287 }
4288
shilu366312e2019-12-17 09:28:10 -08004289 /**
4290 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4291 * @param subId The subscription to use to check the configuration.
4292 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 @Override
4294 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004295 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004296 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 final long identity = Binder.clearCallingIdentity();
4298 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004299 int slotId = getSlotIndexOrException(subId);
4300 verifyImsMmTelConfiguredOrThrow(slotId);
4301 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004302 } catch (ImsException e) {
4303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307 }
4308
4309 @Override
4310 public void setVoWiFiModeSetting(int subId, int mode) {
4311 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4312 "setVoWiFiModeSetting");
4313 final long identity = Binder.clearCallingIdentity();
4314 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 int slotId = getSlotIndexOrException(subId);
4316 verifyImsMmTelConfiguredOrThrow(slotId);
4317 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004318 } catch (ImsException e) {
4319 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
4325 @Override
4326 public int getVoWiFiRoamingModeSetting(int subId) {
4327 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4328 final long identity = Binder.clearCallingIdentity();
4329 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004330 int slotId = getSlotIndexOrException(subId);
4331 verifyImsMmTelConfiguredOrThrow(slotId);
4332 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004333 } catch (ImsException e) {
4334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004335 } finally {
4336 Binder.restoreCallingIdentity(identity);
4337 }
4338 }
4339
4340 @Override
4341 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4343 "setVoWiFiRoamingModeSetting");
4344 final long identity = Binder.clearCallingIdentity();
4345 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004346 int slotId = getSlotIndexOrException(subId);
4347 verifyImsMmTelConfiguredOrThrow(slotId);
4348 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004349 } catch (ImsException e) {
4350 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 } finally {
4352 Binder.restoreCallingIdentity(identity);
4353 }
4354 }
4355
4356 @Override
4357 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4359 "setRttCapabilityEnabled");
4360 final long identity = Binder.clearCallingIdentity();
4361 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004362 int slotId = getSlotIndexOrException(subId);
4363 verifyImsMmTelConfiguredOrThrow(slotId);
4364 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004365 } catch (ImsException e) {
4366 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 } finally {
4368 Binder.restoreCallingIdentity(identity);
4369 }
4370 }
4371
shilu366312e2019-12-17 09:28:10 -08004372 /**
4373 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4374 * @param subId The subscription to use to check the configuration.
4375 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 @Override
4377 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004378 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004379 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 final long identity = Binder.clearCallingIdentity();
4381 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004382 int slotId = getSlotIndexOrException(subId);
4383 verifyImsMmTelConfiguredOrThrow(slotId);
4384 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004385 } catch (ImsException e) {
4386 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 } finally {
4388 Binder.restoreCallingIdentity(identity);
4389 }
4390 }
4391
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004392 @Override
4393 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4394 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4395 final long identity = Binder.clearCallingIdentity();
4396 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004397 if (!isImsAvailableOnDevice()) {
4398 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4399 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004400 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004401 int slotId = getSlotIndexOrException(subId);
4402 verifyImsMmTelConfiguredOrThrow(slotId);
4403 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004404 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004405 } catch (ImsException e) {
4406 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
4410 }
4411
4412 @Override
4413 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4414 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4415 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004416 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4417 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4418 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004419 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004420 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004421 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004422 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004423 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4424 + "is inactive, ignoring unregister.");
4425 // If the subscription is no longer active, just return, since the callback will already
4426 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
4430 }
4431
allenwtsu99c623b2020-01-03 18:24:23 +08004432
4433 private void checkModifyPhoneStatePermission(int subId, String message) {
4434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4435 message);
4436 }
4437
4438 private boolean isImsProvisioningRequired(int subId, int capability,
4439 boolean isMmtelCapability) {
4440 Phone phone = getPhone(subId);
4441 if (phone == null) {
4442 loge("phone instance null for subid " + subId);
4443 return false;
4444 }
4445 if (isMmtelCapability) {
4446 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4447 return false;
4448 }
4449 } else {
4450 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4451 return false;
4452 }
4453 }
4454 return true;
4455 }
4456
4457 @Override
4458 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4459 boolean isProvisioned) {
4460 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4461
4462 final long identity = Binder.clearCallingIdentity();
4463 try {
4464 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4465 if (!isImsProvisioningRequired(subId, capability, false)) {
4466 return;
4467 }
4468
4469 // this capability requires provisioning, route to the correct API.
4470 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4471 switch (capability) {
4472 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4473 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4474 ims.setEabProvisioned(isProvisioned);
4475 break;
4476 default: {
4477 throw new IllegalArgumentException("Tried to set provisioning for "
4478 + "rcs capability '" + capability + "', which does not require "
4479 + "provisioning.");
4480 }
4481 }
4482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485
4486 }
4487
4488
4489 @Override
4490 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4491 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4492 final long identity = Binder.clearCallingIdentity();
4493 try {
4494 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4495 if (!isImsProvisioningRequired(subId, capability, false)) {
4496 return true;
4497 }
4498
4499 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4500 switch (capability) {
4501 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4502 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4503 return ims.isEabProvisionedOnDevice();
4504
4505 default: {
4506 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4507 + "capability '" + capability + "', which does not require "
4508 + "provisioning.");
4509 }
4510 }
4511
4512 } finally {
4513 Binder.restoreCallingIdentity(identity);
4514 }
4515 }
4516
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004517 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004518 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4519 boolean isProvisioned) {
4520 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004521 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4522 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4523 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004524 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4525 }
allenwtsu99c623b2020-01-03 18:24:23 +08004526 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004527 final long identity = Binder.clearCallingIdentity();
4528 try {
4529 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004530 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004531 return;
4532 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004533 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4534 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4535 loge("setImsProvisioningStatusForCapability: called for technology that does "
4536 + "not support provisioning - " + tech);
4537 return;
4538 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004539
4540 // this capability requires provisioning, route to the correct API.
4541 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4542 switch (capability) {
4543 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4544 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4545 ims.setVolteProvisioned(isProvisioned);
4546 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4547 ims.setWfcProvisioned(isProvisioned);
4548 }
4549 break;
4550 }
4551 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4552 // There is currently no difference in VT provisioning type.
4553 ims.setVtProvisioned(isProvisioned);
4554 break;
4555 }
4556 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4557 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4558 // change the capability of the feature instead if needed.
4559 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4560 == isProvisioned) {
4561 // No change in provisioning.
4562 return;
4563 }
4564 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4565 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004566 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004567 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004568 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4569 + ", Exception" + e.getMessage());
4570 }
4571 break;
4572 }
4573 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004574 throw new IllegalArgumentException("Tried to set provisioning for "
4575 + "MmTel capability '" + capability + "', which does not require "
4576 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004577 }
4578 }
4579
4580 } finally {
4581 Binder.restoreCallingIdentity(identity);
4582 }
4583 }
4584
4585 @Override
4586 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4587 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004588 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4589 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4590 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004591 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4592 }
4593 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004597 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004598 return true;
4599 }
4600
Brad Ebinger0d79c572021-04-17 15:20:49 -07004601 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4602 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4603 loge("getImsProvisioningStatusForCapability: called for technology that does "
4604 + "not support provisioning - " + tech);
4605 return true;
4606 }
4607
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004608 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4609 switch (capability) {
4610 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4611 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4612 return ims.isVolteProvisionedOnDevice();
4613 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4614 return ims.isWfcProvisionedOnDevice();
4615 }
4616 // This should never happen, since we are checking tech above to make sure it
4617 // is either LTE or IWLAN.
4618 throw new IllegalArgumentException("Invalid radio technology for voice "
4619 + "capability.");
4620 }
4621 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4622 // There is currently no difference in VT provisioning type.
4623 return ims.isVtProvisionedOnDevice();
4624 }
4625 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4626 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4627 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4628 }
4629 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004630 throw new IllegalArgumentException(
4631 "Tried to get provisioning for MmTel capability '" + capability
4632 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004633 }
4634 }
4635
4636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
4639 }
4640
4641 @Override
4642 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4643 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4644 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4645 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4646 }
4647 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4648 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4649 return (provisionedBits & capability) > 0;
4650 }
4651
4652 @Override
4653 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4654 boolean isProvisioned) {
4655 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4656 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4657 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4658 }
4659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4660 "setProvisioningStatusForCapability");
4661 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4662 // If the current provisioning status for capability already matches isProvisioned,
4663 // do nothing.
4664 if (((provisionedBits & capability) > 0) == isProvisioned) {
4665 return;
4666 }
4667 if (isProvisioned) {
4668 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4669 } else {
4670 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4671 }
4672 }
4673
4674 /**
4675 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4676 * technology. The bitfield should mirror the bitfield defined by
4677 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4678 */
4679 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4680 String key = getMmTelProvisioningKey(subId, tech);
4681 // Default is no capabilities are provisioned.
4682 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4683 }
4684
4685 /**
4686 * Sets the MmTel capability provisioning bitfield (defined by
4687 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4688 * technology specified.
4689 *
4690 * Note: This is a synchronous command and should not be called on UI thread.
4691 */
4692 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4693 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4694 String key = getMmTelProvisioningKey(subId, tech);
4695 editor.putInt(key, newField);
4696 editor.commit();
4697 }
4698
4699 private static String getMmTelProvisioningKey(int subId, int tech) {
4700 // resulting key is provision_ims_mmtel_{subId}_{tech}
4701 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4702 }
4703
4704 /**
4705 * Query CarrierConfig to see if the specified capability requires provisioning for the
4706 * carrier associated with the subscription id.
4707 */
4708 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4709 int capability) {
4710 CarrierConfigManager configManager = new CarrierConfigManager(context);
4711 PersistableBundle c = configManager.getConfigForSubId(subId);
4712 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004713 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004714 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4715 false);
4716 boolean requireVoiceVtProvisioning = c.getBoolean(
4717 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4718
4719 // First check to make sure that the capability requires provisioning.
4720 switch (capability) {
4721 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4722 // intentional fallthrough
4723 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4724 if (requireVoiceVtProvisioning) {
4725 // Voice and Video requires provisioning
4726 return true;
4727 }
4728 break;
4729 }
4730 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4731 if (requireUtProvisioning) {
4732 // UT requires provisioning
4733 return true;
4734 }
4735 break;
4736 }
4737 }
4738 return false;
4739 }
4740
allenwtsu99c623b2020-01-03 18:24:23 +08004741 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4742 int capability) {
4743 CarrierConfigManager configManager = new CarrierConfigManager(context);
4744 PersistableBundle c = configManager.getConfigForSubId(subId);
4745
4746 boolean requireRcsProvisioning = c.getBoolean(
4747 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4748
4749 // First check to make sure that the capability requires provisioning.
4750 switch (capability) {
4751 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4752 // intentional fallthrough
4753 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4754 if (requireRcsProvisioning) {
4755 // OPTION or PRESENCE requires provisioning
4756 return true;
4757 }
4758 break;
4759 }
4760 }
4761 return false;
4762 }
4763
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004764 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004765 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004766 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4767 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4768 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004769 enforceReadPrivilegedPermission("getImsProvisioningInt");
4770 final long identity = Binder.clearCallingIdentity();
4771 try {
4772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004773 int slotId = getSlotIndex(subId);
4774 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4775 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4776 + subId + "' for key:" + key);
4777 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4778 }
calvinpanb5a34062021-02-08 19:59:36 +08004779 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004780 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004781 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4782 + subId + "' for key:" + key);
4783 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
4787 }
4788
4789 @Override
4790 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004791 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4792 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4793 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004794 enforceReadPrivilegedPermission("getImsProvisioningString");
4795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004798 int slotId = getSlotIndex(subId);
4799 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4800 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4801 + subId + "' for key:" + key);
4802 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4803 }
calvinpanb5a34062021-02-08 19:59:36 +08004804 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004805 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004806 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4807 + subId + "' for key:" + key);
4808 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004809 } finally {
4810 Binder.restoreCallingIdentity(identity);
4811 }
4812 }
4813
4814 @Override
4815 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004816 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4817 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4818 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4820 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004821 final long identity = Binder.clearCallingIdentity();
4822 try {
4823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004824 int slotId = getSlotIndex(subId);
4825 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4826 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4827 + subId + "' for key:" + key);
4828 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4829 }
calvinpanb5a34062021-02-08 19:59:36 +08004830 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4831 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004832 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004833 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004834 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004835 } finally {
4836 Binder.restoreCallingIdentity(identity);
4837 }
4838 }
4839
4840 @Override
4841 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004842 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4843 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4844 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4846 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004850 int slotId = getSlotIndex(subId);
4851 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4852 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4853 + subId + "' for key:" + key);
4854 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4855 }
calvinpanb5a34062021-02-08 19:59:36 +08004856 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4857 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004858 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004859 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004860 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
4864 }
4865
Brad Ebinger919631e2021-06-02 17:46:35 -07004866 /**
4867 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4868 * for the given slot ID or no ImsResolver instance has been created.
4869 * @param slotId The slot ID that the IMS service is created for.
4870 * @throws ImsException If there is no ImsService configured for this slot.
4871 */
4872 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4873 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4874 ImsFeature.FEATURE_MMTEL)) {
4875 throw new ImsException("This subscription does not support MMTEL over IMS",
4876 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4877 }
4878 }
4879
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004880 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004881 int slotId = SubscriptionManager.getSlotIndex(subId);
4882 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004883 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4884 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004885 }
4886 return slotId;
4887 }
4888
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004889 private int getSlotIndex(int subId) {
4890 int slotId = SubscriptionManager.getSlotIndex(subId);
4891 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4892 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4893 }
4894 return slotId;
4895 }
4896
Wink Saville36469e72014-06-11 15:17:00 -07004897 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004898 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004899 */
4900 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004901 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4902 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004903 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004904 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004905 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004906 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004907 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004908 mApp, subId, callingPackage, callingFeatureId,
4909 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004910 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4911 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004913 final long identity = Binder.clearCallingIdentity();
4914 try {
4915 final Phone phone = getPhone(subId);
4916 if (phone != null) {
4917 return phone.getServiceState().getDataNetworkType();
4918 } else {
4919 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4920 }
4921 } finally {
4922 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004924 }
4925
4926 /**
4927 * Returns the data network type
4928 */
4929 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004930 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004931 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4932 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004933 }
4934
4935 /**
4936 * Returns the data network type for a subId
4937 */
4938 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004939 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4940 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004942 mApp, subId, callingPackage, callingFeatureId,
4943 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004944 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4945 }
4946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 final long identity = Binder.clearCallingIdentity();
4948 try {
4949 final Phone phone = getPhone(subId);
4950 if (phone != null) {
4951 return phone.getServiceState().getDataNetworkType();
4952 } else {
4953 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4954 }
4955 } finally {
4956 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004957 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004958 }
4959
4960 /**
Wink Saville36469e72014-06-11 15:17:00 -07004961 * Returns the Voice network type for a subId
4962 */
4963 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004964 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4965 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004966 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004967 mApp, subId, callingPackage, callingFeatureId,
4968 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004969 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4970 }
4971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 final long identity = Binder.clearCallingIdentity();
4973 try {
4974 final Phone phone = getPhone(subId);
4975 if (phone != null) {
4976 return phone.getServiceState().getVoiceNetworkType();
4977 } else {
4978 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4979 }
4980 } finally {
4981 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004983 }
4984
4985 /**
4986 * @return true if a ICC card is present
4987 */
4988 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004989 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004990 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4991 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004992 }
4993
4994 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004995 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004996 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004997 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004998 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 final long identity = Binder.clearCallingIdentity();
5000 try {
5001 final Phone phone = PhoneFactory.getPhone(slotIndex);
5002 if (phone != null) {
5003 return phone.getIccCard().hasIccCard();
5004 } else {
5005 return false;
5006 }
5007 } finally {
5008 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005010 }
5011
5012 /**
5013 * Return if the current radio is LTE on CDMA. This
5014 * is a tri-state return value as for a period of time
5015 * the mode may be unknown.
5016 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005017 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005018 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005019 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005020 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005021 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005022 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5023 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5024 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005025 }
5026
Sanket Padawe356d7632015-06-22 14:03:32 -07005027 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005028 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5029 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005030 try {
5031 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5032 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005033 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5034 }
5035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 final long identity = Binder.clearCallingIdentity();
5037 try {
5038 final Phone phone = getPhone(subId);
5039 if (phone == null) {
5040 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5041 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005042 return TelephonyProperties.lte_on_cdma_device()
5043 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 }
5045 } finally {
5046 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005047 }
Wink Saville36469e72014-06-11 15:17:00 -07005048 }
5049
Wink Saville36469e72014-06-11 15:17:00 -07005050 /**
5051 * {@hide}
5052 * Returns Default subId, 0 in the case of single standby.
5053 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005054 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005055 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005056 }
5057
Shishir Agrawala9f32182016-04-12 12:00:16 -07005058 private int getSlotForDefaultSubscription() {
5059 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5060 }
5061
Wink Savilleb564aae2014-10-23 10:18:09 -07005062 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005063 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005064 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005065
Pengquan Menge92a50d2018-09-21 15:54:48 -07005066 private boolean isActiveSubscription(int subId) {
5067 return mSubscriptionController.isActiveSubId(subId);
5068 }
5069
Ihab Awadf2177b72013-11-25 13:33:23 -08005070 /**
5071 * @see android.telephony.TelephonyManager.WifiCallingChoices
5072 */
5073 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005076 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5078 getWhenToMakeWifiCallsDefaultPreference());
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005082 }
5083
5084 /**
5085 * @see android.telephony.TelephonyManager.WifiCallingChoices
5086 */
5087 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 final long identity = Binder.clearCallingIdentity();
5089 try {
5090 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005091 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
5095 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005096 }
5097
Sailesh Nepald1e68152013-12-12 19:08:02 -08005098 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005099 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005100 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005101 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005102
Jordan Liu4c733742019-02-28 12:03:40 -08005103 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5104 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5105 if (phoneId == -1) {
5106 throw new IllegalArgumentException("Given slot index: " + slotIndex
5107 + " does not correspond to an active phone");
5108 }
5109 return PhoneFactory.getPhone(phoneId);
5110 }
5111
Shishir Agrawal566b7612013-10-28 14:41:00 -07005112 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005113 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5114 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5116 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005118 if (DBG) {
5119 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5120 }
5121 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5122 p2);
5123 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005124
Jordan Liu4c733742019-02-28 12:03:40 -08005125
5126 @Override
5127 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5128 int slotIndex, String callingPackage, String aid, int p2) {
5129 enforceModifyPermission();
5130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5131 if (DBG) {
5132 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5133 }
5134 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5135 callingPackage, aid, p2);
5136 }
5137
5138 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5139 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 final long identity = Binder.clearCallingIdentity();
5141 try {
5142 if (TextUtils.equals(ISDR_AID, aid)) {
5143 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005144 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5145 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 if (bestComponent == null
5147 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5148 loge("The calling package is not allowed to access ISD-R.");
5149 throw new SecurityException(
5150 "The calling package is not allowed to access ISD-R.");
5151 }
Derek Tan740e1672017-06-27 14:56:27 -07005152 }
Derek Tan740e1672017-06-27 14:56:27 -07005153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005155 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5156 null /* workSource */);
5157 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 return response;
5159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005162 }
5163
5164 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005165 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5167 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005168 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5169 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5170 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005171
Jordan Liu4c733742019-02-28 12:03:40 -08005172 @Override
5173 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5174 enforceModifyPermission();
5175 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5176 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5177 channel);
5178 }
5179
5180 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 final long identity = Binder.clearCallingIdentity();
5182 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005183 if (channel < 0) {
5184 return false;
5185 }
Jordan Liu4c733742019-02-28 12:03:40 -08005186 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5187 null /* workSource */);
5188 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 return success;
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005192 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005193 }
5194
5195 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005196 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005197 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005198 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5199 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005200 if (DBG) {
5201 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5202 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5203 + p3 + " data=" + data);
5204 }
5205 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5206 command, p1, p2, p3, data);
5207 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005208
Jordan Liu4c733742019-02-28 12:03:40 -08005209 @Override
5210 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5211 int command, int p1, int p2, int p3, String data) {
5212 enforceModifyPermission();
5213 if (DBG) {
5214 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5215 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5216 + p3 + " data=" + data);
5217 }
5218 return iccTransmitApduLogicalChannelWithPermission(
5219 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5220 data);
5221 }
5222
5223 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5224 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005227 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 return "";
5229 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005232 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5233 null /* workSource */);
5234 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 // Append the returned status code to the end of the response payload.
5237 String s = Integer.toHexString(
5238 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5239 if (response.payload != null) {
5240 s = IccUtils.bytesToHexString(response.payload) + s;
5241 }
5242 return s;
5243 } finally {
5244 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005245 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005246 }
Jake Hambye994d462014-02-03 13:10:13 -08005247
Evan Charltonc66da362014-05-16 14:06:40 -07005248 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005249 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5250 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5252 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005253 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005254 if (DBG) {
5255 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5256 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5257 }
5258 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5259 cla, command, p1, p2, p3, data);
5260 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005261
Jordan Liu4c733742019-02-28 12:03:40 -08005262 @Override
5263 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5264 int command, int p1, int p2, int p3, String data) {
5265 enforceModifyPermission();
5266 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5267 if (DBG) {
5268 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5269 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5270 + " data=" + data);
5271 }
5272
5273 return iccTransmitApduBasicChannelWithPermission(
5274 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5275 p2, p3, data);
5276 }
5277
5278 // open APDU basic channel assuming the caller has sufficient permissions
5279 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5280 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 final long identity = Binder.clearCallingIdentity();
5282 try {
5283 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5284 && TextUtils.equals(ISDR_AID, data)) {
5285 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005286 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5287 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005288 if (bestComponent == null
5289 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5290 loge("The calling package is not allowed to select ISD-R.");
5291 throw new SecurityException(
5292 "The calling package is not allowed to select ISD-R.");
5293 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005294 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005297 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5298 null /* workSource */);
5299 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005300
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 // Append the returned status code to the end of the response payload.
5302 String s = Integer.toHexString(
5303 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5304 if (response.payload != null) {
5305 s = IccUtils.bytesToHexString(response.payload) + s;
5306 }
5307 return s;
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005310 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005311 }
5312
5313 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005314 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005315 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5317 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 final long identity = Binder.clearCallingIdentity();
5320 try {
5321 if (DBG) {
5322 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5323 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5324 }
5325
5326 IccIoResult response =
5327 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5328 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5329 subId);
5330
5331 if (DBG) {
5332 log("Exchange SIM_IO [R]" + response);
5333 }
5334
5335 byte[] result = null;
5336 int length = 2;
5337 if (response.payload != null) {
5338 length = 2 + response.payload.length;
5339 result = new byte[length];
5340 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5341 } else {
5342 result = new byte[length];
5343 }
5344
5345 result[length - 1] = (byte) response.sw2;
5346 result[length - 2] = (byte) response.sw1;
5347 return result;
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005350 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005351 }
5352
Nathan Haroldb3014052017-01-25 15:57:32 -08005353 /**
5354 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5355 * on a particular subscription
5356 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005357 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5358 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005360 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005361 return null;
5362 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363
5364 final long identity = Binder.clearCallingIdentity();
5365 try {
5366 if (appType != TelephonyManager.APPTYPE_USIM
5367 && appType != TelephonyManager.APPTYPE_SIM) {
5368 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5369 return null;
5370 }
5371 Object response = sendRequest(
5372 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5373 if (response instanceof String[]) {
5374 return (String[]) response;
5375 }
yincheng zhao2737e882019-09-06 17:06:54 -07005376 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005377 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005378 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 } finally {
5380 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005381 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005382 }
5383
yincheng zhao2737e882019-09-06 17:06:54 -07005384 /**
5385 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5386 * subscription.
5387 *
5388 * @param subId the id of the subscription.
5389 * @param appType the uicc app type, must be USIM or SIM.
5390 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5391 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005392 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005393 * @return number of fplmns that is successfully written to the SIM.
5394 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005395 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5396 String callingFeatureId) {
5397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5398 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005399 if (DBG) logv("no permissions for setForbiddenplmns");
5400 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5401 }
5402 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5403 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5404 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5405 }
5406 if (fplmns == null) {
5407 throw new IllegalArgumentException("Fplmn List provided is null");
5408 }
5409 for (String fplmn : fplmns) {
5410 if (!CellIdentity.isValidPlmn(fplmn)) {
5411 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5412 }
5413 }
5414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 Object response = sendRequest(
5417 CMD_SET_FORBIDDEN_PLMNS,
5418 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5419 subId);
5420 return (int) response;
5421 } finally {
5422 Binder.restoreCallingIdentity(identity);
5423 }
5424 }
5425
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005426 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005427 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5429 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005430
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 final long identity = Binder.clearCallingIdentity();
5432 try {
5433 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5434 if (response.payload == null) {
5435 return "";
5436 }
Evan Charltonc66da362014-05-16 14:06:40 -07005437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 // Append the returned status code to the end of the response payload.
5439 String s = Integer.toHexString(
5440 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5441 s = IccUtils.bytesToHexString(response.payload) + s;
5442 return s;
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
5445 }
Evan Charltonc66da362014-05-16 14:06:40 -07005446 }
5447
Jake Hambye994d462014-02-03 13:10:13 -08005448 /**
5449 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5450 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5451 *
5452 * @param itemID the ID of the item to read
5453 * @return the NV item as a String, or null on error.
5454 */
5455 @Override
5456 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005457 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5459 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460
5461 final long identity = Binder.clearCallingIdentity();
5462 try {
5463 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005464 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5466 return value;
5467 } finally {
5468 Binder.restoreCallingIdentity(identity);
5469 }
Jake Hambye994d462014-02-03 13:10:13 -08005470 }
5471
5472 /**
5473 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5474 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5475 *
5476 * @param itemID the ID of the item to read
5477 * @param itemValue the value to write, as a String
5478 * @return true on success; false on any failure
5479 */
5480 @Override
5481 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005482 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5484 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485
5486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5489 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005490 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5492 return success;
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
Jake Hambye994d462014-02-03 13:10:13 -08005496 }
5497
5498 /**
5499 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5500 * Used for device configuration by some CDMA operators.
5501 *
5502 * @param preferredRoamingList byte array containing the new PRL
5503 * @return true on success; false on any failure
5504 */
5505 @Override
5506 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5508 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509
5510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5513 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5514 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5515 return success;
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
5518 }
Jake Hambye994d462014-02-03 13:10:13 -08005519 }
5520
5521 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005522 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005523 * Used for device configuration by some CDMA operators.
5524 *
chen xu6dac5ab2018-10-26 17:39:23 -07005525 * @param slotIndex - device slot.
5526 *
Jake Hambye994d462014-02-03 13:10:13 -08005527 * @return true on success; false on any failure
5528 */
5529 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005530 public boolean resetModemConfig(int slotIndex) {
5531 Phone phone = PhoneFactory.getPhone(slotIndex);
5532 if (phone != null) {
5533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5534 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535
chen xu6dac5ab2018-10-26 17:39:23 -07005536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5539 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5540 return success;
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 }
chen xu6dac5ab2018-10-26 17:39:23 -07005545 return false;
5546 }
5547
5548 /**
5549 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5550 *
5551 * @param slotIndex - device slot.
5552 *
5553 * @return true on success; false on any failure
5554 */
5555 @Override
5556 public boolean rebootModem(int slotIndex) {
5557 Phone phone = PhoneFactory.getPhone(slotIndex);
5558 if (phone != null) {
5559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5560 mApp, phone.getSubId(), "rebootModem");
5561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5565 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5566 return success;
5567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
5570 }
5571 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005572 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005573
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005574 public String[] getPcscfAddress(String apnType, String callingPackage,
5575 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005576 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005577 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5578 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005579 return new String[0];
5580 }
5581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 final long identity = Binder.clearCallingIdentity();
5583 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005584 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
Wink Saville36469e72014-06-11 15:17:00 -07005588 }
5589
Brad Ebinger51f743a2017-01-23 13:50:20 -08005590 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005591 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5592 * {@link #disableIms(int)}.
5593 * @param slotIndex device slot.
5594 */
5595 public void resetIms(int slotIndex) {
5596 enforceModifyPermission();
5597
5598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 if (mImsResolver == null) {
5601 // may happen if the does not support IMS.
5602 return;
5603 }
5604 mImsResolver.disableIms(slotIndex);
5605 mImsResolver.enableIms(slotIndex);
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
5609 }
5610
5611 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005612 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5613 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005614 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005615 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005616 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617
5618 final long identity = Binder.clearCallingIdentity();
5619 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005620 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005621 // may happen if the device does not support IMS.
5622 return;
5623 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005624 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005628 }
5629
5630 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005631 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5632 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005633 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005634 public void disableIms(int slotId) {
5635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636
5637 final long identity = Binder.clearCallingIdentity();
5638 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005639 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005640 // may happen if the device does not support IMS.
5641 return;
5642 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005643 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005647 }
5648
5649 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005650 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5651 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005652 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005653 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005654 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005659 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005660 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5661 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005662 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005663 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005667 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005668 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005669 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5670 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005671 @Override
5672 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005673 enforceModifyPermission();
5674
5675 final long identity = Binder.clearCallingIdentity();
5676 try {
5677 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005678 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005679 } finally {
5680 Binder.restoreCallingIdentity(identity);
5681 }
5682 }
5683
5684 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005685 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005686 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005687 */
5688 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5689 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690
5691 final long identity = Binder.clearCallingIdentity();
5692 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005693 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005694 // may happen if the device does not support IMS.
5695 return null;
5696 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005697 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005701 }
5702
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005703 /**
5704 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005705 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005706 */
5707 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5708 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005712 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005713 // may happen if the device does not support IMS.
5714 return null;
5715 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005720 }
5721
Brad Ebinger884c07b2018-02-15 16:17:40 -08005722 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005723 * Sets the ImsService Package Name that Telephony will bind to.
5724 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005725 * @param slotIndex the slot ID that the ImsService should bind for.
5726 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005727 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005728 * @param featureTypes An integer array of feature types associated with a packageName.
5729 * @param packageName The name of the package that the current configuration will be replaced
5730 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005731 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005732 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005733 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5734 int[] featureTypes, String packageName) {
5735 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5736 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5738 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005739 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 final long identity = Binder.clearCallingIdentity();
5742 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005743 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005744 // may happen if the device does not support IMS.
5745 return false;
5746 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005747 Map<Integer, String> featureConfig = new HashMap<>();
5748 for (int featureType : featureTypes) {
5749 featureConfig.put(featureType, packageName);
5750 }
5751 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5752 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005756 }
5757
5758 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005759 * Clears any carrier ImsService overrides for the slot index specified that were previously
5760 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5761 *
5762 * This should only be used for testing.
5763 *
5764 * @param slotIndex the slot ID that the ImsService should bind for.
5765 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5766 */
5767 @Override
5768 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5769 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5770 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5771 "clearCarrierImsServiceOverride");
5772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5773 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5774 "clearCarrierImsServiceOverride");
5775
5776 final long identity = Binder.clearCallingIdentity();
5777 try {
5778 if (mImsResolver == null) {
5779 // may happen if the device does not support IMS.
5780 return false;
5781 }
5782 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
5785 }
5786 }
5787
5788 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005790 *
5791 * @param slotId The slot that the ImsService is associated with.
5792 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5793 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005794 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005795 * @return the package name of the ImsService configuration.
5796 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005797 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5798 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005799 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005800 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005801 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005802 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5803 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805 final long identity = Binder.clearCallingIdentity();
5806 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005807 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005808 // may happen if the device does not support IMS.
5809 return "";
5810 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005811 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005812 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5813 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005817 }
5818
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005819 /**
5820 * Get the MmTelFeature state associated with the requested subscription id.
5821 * @param subId The subscription that the MmTelFeature is associated with.
5822 * @param callback A callback with an integer containing the
5823 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5824 */
5825 @Override
5826 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5827 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5828 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5829 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5830 "IMS not available on device.");
5831 }
5832 final long token = Binder.clearCallingIdentity();
5833 try {
5834 int slotId = getSlotIndex(subId);
5835 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5836 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5837 + subId + "'");
5838 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5839 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005840 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005841 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5842 try {
5843 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5844 } catch (RemoteException e) {
5845 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5846 + "Ignore");
5847 }
5848 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005849 } catch (ImsException e) {
5850 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005851 } finally {
5852 Binder.restoreCallingIdentity(token);
5853 }
5854 }
5855
Daniel Brightbb5840b2021-01-12 15:48:18 -08005856 /**
5857 * Sets the ims registration state on all valid {@link Phone}s.
5858 */
5859 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005860 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861
5862 final long identity = Binder.clearCallingIdentity();
5863 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005864 // NOTE: Before S, this method only set the default phone.
5865 for (final Phone phone : PhoneFactory.getPhones()) {
5866 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5867 phone.setImsRegistrationState(registered);
5868 }
5869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
Wink Saville36469e72014-06-11 15:17:00 -07005873 }
5874
5875 /**
Stuart Scott54788802015-03-30 13:18:01 -07005876 * Set the network selection mode to automatic.
5877 *
5878 */
5879 @Override
5880 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5882 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883
5884 final long identity = Binder.clearCallingIdentity();
5885 try {
shilufc958392020-01-20 11:36:01 -08005886 if (!isActiveSubscription(subId)) {
5887 return;
5888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005890 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5891 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 } finally {
5893 Binder.restoreCallingIdentity(identity);
5894 }
Stuart Scott54788802015-03-30 13:18:01 -07005895 }
5896
Jack Yud10cdd42020-09-28 20:28:01 -07005897 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005898 * Ask the radio to connect to the input network and change selection mode to manual.
5899 *
5900 * @param subId the id of the subscription.
5901 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5902 * the operator to attach to.
5903 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5904 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5905 * normal network selection next time.
5906 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005907 */
5908 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005909 public boolean setNetworkSelectionModeManual(
5910 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5912 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005913
5914 if (!isActiveSubscription(subId)) {
5915 return false;
5916 }
5917
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005920 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005922 if (DBG) {
5923 log("setNetworkSelectionModeManual: subId: " + subId
5924 + " operator: " + operatorInfo);
5925 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5927 } finally {
5928 Binder.restoreCallingIdentity(identity);
5929 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005930 }
shilu84f6e8b2019-12-19 13:58:01 -08005931 /**
5932 * Get the manual network selection
5933 *
5934 * @param subId the id of the subscription.
5935 *
5936 * @return the previously saved user selected PLMN
5937 */
5938 @Override
5939 public String getManualNetworkSelectionPlmn(int subId) {
5940 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005941 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005942 mApp, subId, "getManualNetworkSelectionPlmn");
5943
5944 final long identity = Binder.clearCallingIdentity();
5945 try {
5946 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005947 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005948 }
5949
5950 final Phone phone = getPhone(subId);
5951 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005952 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005953 }
5954 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5955 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5956 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
5959 }
5960 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005961
5962 /**
5963 * Scans for available networks.
5964 */
5965 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005966 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5967 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5969 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005970 LocationAccessPolicy.LocationPermissionResult locationResult =
5971 LocationAccessPolicy.checkLocationPermission(mApp,
5972 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5973 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005974 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005975 .setCallingPid(Binder.getCallingPid())
5976 .setCallingUid(Binder.getCallingUid())
5977 .setMethod("getCellNetworkScanResults")
5978 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005979 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5980 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005981 .build());
5982 switch (locationResult) {
5983 case DENIED_HARD:
5984 throw new SecurityException("Not allowed to access scan results -- location");
5985 case DENIED_SOFT:
5986 return null;
5987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
Pengquan Menga1bb6272018-09-06 09:59:22 -07005989 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 try {
5991 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005992 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005997 }
5998
5999 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006000 * Get the call forwarding info, given the call forwarding reason.
6001 */
6002 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006003 public void getCallForwarding(int subId, int callForwardingReason,
6004 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006005 enforceReadPrivilegedPermission("getCallForwarding");
6006 long identity = Binder.clearCallingIdentity();
6007 try {
6008 if (DBG) {
6009 log("getCallForwarding: subId " + subId
6010 + " callForwardingReason" + callForwardingReason);
6011 }
Hall Liu27d24262020-09-18 19:04:59 -07006012
6013 Phone phone = getPhone(subId);
6014 if (phone == null) {
6015 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006016 callback.onError(
6017 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006018 } catch (RemoteException e) {
6019 // ignore
6020 }
6021 return;
6022 }
6023
6024 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6025 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6026 @Override
6027 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6028 try {
6029 callback.onCallForwardingInfoAvailable(info);
6030 } catch (RemoteException e) {
6031 // ignore
6032 }
6033 }
6034
6035 @Override
6036 public void onError(int error) {
6037 try {
6038 callback.onError(error);
6039 } catch (RemoteException e) {
6040 // ignore
6041 }
6042 }
6043 });
6044 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006045 } finally {
6046 Binder.restoreCallingIdentity(identity);
6047 }
6048 }
6049
6050 /**
6051 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6052 * reason, the number to forward, and the timeout before the forwarding is attempted.
6053 */
6054 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006055 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6056 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006057 enforceModifyPermission();
6058 long identity = Binder.clearCallingIdentity();
6059 try {
6060 if (DBG) {
6061 log("setCallForwarding: subId " + subId
6062 + " callForwardingInfo" + callForwardingInfo);
6063 }
Hall Liu27d24262020-09-18 19:04:59 -07006064
6065 Phone phone = getPhone(subId);
6066 if (phone == null) {
6067 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006068 callback.accept(
6069 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006070 } catch (RemoteException e) {
6071 // ignore
6072 }
6073 return;
6074 }
6075
6076 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6077 FunctionalUtils.ignoreRemoteException(callback::accept));
6078
6079 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006080 } finally {
6081 Binder.restoreCallingIdentity(identity);
6082 }
6083 }
6084
6085 /**
Hall Liu27d24262020-09-18 19:04:59 -07006086 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006087 */
6088 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006089 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006090 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006091 long identity = Binder.clearCallingIdentity();
6092 try {
Hall Liu27d24262020-09-18 19:04:59 -07006093 Phone phone = getPhone(subId);
6094 if (phone == null) {
6095 try {
6096 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6097 } catch (RemoteException e) {
6098 // ignore
6099 }
6100 return;
6101 }
SongFerngWang0e767992021-03-31 22:08:45 +08006102 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6103 PersistableBundle c = configManager.getConfigForSubId(subId);
6104 boolean requireUssd = c.getBoolean(
6105 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006106
Shuo Qian4a594052020-01-23 11:59:30 -08006107 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006108 if (requireUssd) {
6109 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6110 getSubscriptionCarrierId(subId));
6111 String newUssdCommand = "";
6112 try {
6113 newUssdCommand = carrierXmlParser.getFeature(
6114 CarrierXmlParser.FEATURE_CALL_WAITING)
6115 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6116 } catch (NullPointerException e) {
6117 loge("Failed to generate USSD number" + e);
6118 }
6119 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6120 mMainThreadHandler, callback, carrierXmlParser,
6121 CarrierXmlParser.SsEntry.SSAction.QUERY);
6122 final String ussdCommand = newUssdCommand;
6123 Executors.newSingleThreadExecutor().execute(() -> {
6124 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6125 });
6126 } else {
6127 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6128 callback::accept);
6129 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6130 }
Shuo Qian4a594052020-01-23 11:59:30 -08006131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
6134 }
6135
6136 /**
Hall Liu27d24262020-09-18 19:04:59 -07006137 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006138 */
6139 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006140 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006141 enforceModifyPermission();
6142 long identity = Binder.clearCallingIdentity();
6143 try {
Hall Liu27d24262020-09-18 19:04:59 -07006144 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6145
6146 Phone phone = getPhone(subId);
6147 if (phone == null) {
6148 try {
6149 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6150 } catch (RemoteException e) {
6151 // ignore
6152 }
6153 return;
6154 }
6155
SongFerngWang0e767992021-03-31 22:08:45 +08006156 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6157 PersistableBundle c = configManager.getConfigForSubId(subId);
6158 boolean requireUssd = c.getBoolean(
6159 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006160
SongFerngWang0e767992021-03-31 22:08:45 +08006161 if (DBG) log("getCallWaitingStatus: subId " + subId);
6162 if (requireUssd) {
6163 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6164 getSubscriptionCarrierId(subId));
6165 CarrierXmlParser.SsEntry.SSAction ssAction =
6166 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6167 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6168 String newUssdCommand = "";
6169 try {
6170 newUssdCommand = carrierXmlParser.getFeature(
6171 CarrierXmlParser.FEATURE_CALL_WAITING)
6172 .makeCommand(ssAction, null);
6173 } catch (NullPointerException e) {
6174 loge("Failed to generate USSD number" + e);
6175 }
6176 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6177 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6178 final String ussdCommand = newUssdCommand;
6179 Executors.newSingleThreadExecutor().execute(() -> {
6180 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6181 });
6182 } else {
6183 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6184 FunctionalUtils.ignoreRemoteException(callback::accept));
6185
6186 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6187 }
Shuo Qian4a594052020-01-23 11:59:30 -08006188 } finally {
6189 Binder.restoreCallingIdentity(identity);
6190 }
6191 }
6192
6193 /**
yinxub1bed742017-04-17 11:45:04 -07006194 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006195 *
yinxub1bed742017-04-17 11:45:04 -07006196 * @param subId id of the subscription
6197 * @param request contains the radio access networks with bands/channels to scan
6198 * @param messenger callback messenger for scan results or errors
6199 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006200 * @return the id of the requested scan which can be used to stop the scan.
6201 */
6202 @Override
6203 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006204 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6206 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006207 LocationAccessPolicy.LocationPermissionResult locationResult =
6208 LocationAccessPolicy.checkLocationPermission(mApp,
6209 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6210 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006211 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006212 .setCallingPid(Binder.getCallingPid())
6213 .setCallingUid(Binder.getCallingUid())
6214 .setMethod("requestNetworkScan")
6215 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006216 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6217 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006218 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006219 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006220 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6221 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006222 if (e != null) {
6223 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6224 throw e;
6225 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006226 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006227 return TelephonyScanManager.INVALID_SCAN_ID;
6228 }
6229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 }
Hall Liu912dfd32019-04-25 14:02:26 -07006231 int callingUid = Binder.getCallingUid();
6232 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006233 final long identity = Binder.clearCallingIdentity();
6234 try {
6235 return mNetworkScanRequestTracker.startNetworkScan(
6236 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006237 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
yinxu504e1392017-04-12 16:03:22 -07006241 }
6242
Hall Liub2ac8ef2019-02-28 15:56:23 -08006243 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006244 NetworkScanRequest request, int subId, String callingPackage) {
6245 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006246 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6247 boolean hasNetworkScanPermission =
6248 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6249 == PERMISSION_GRANTED;
6250
6251 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6252 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6253 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006254 }
6255
6256 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6257 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006258 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6259 return new SecurityException("Specific channels must not be"
6260 + " scanned without location access.");
6261 }
6262 }
6263 }
6264
Hall Liub2ac8ef2019-02-28 15:56:23 -08006265 return null;
6266 }
6267
yinxu504e1392017-04-12 16:03:22 -07006268 /**
6269 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006270 *
6271 * @param subId id of the subscription
6272 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006273 */
6274 @Override
6275 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6277 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278
Hall Liu912dfd32019-04-25 14:02:26 -07006279 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 final long identity = Binder.clearCallingIdentity();
6281 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006282 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 } finally {
6284 Binder.restoreCallingIdentity(identity);
6285 }
yinxu504e1392017-04-12 16:03:22 -07006286 }
6287
6288 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006289 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006290 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006291 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006292 */
6293 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006294 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006295 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006296 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006297 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298
6299 final long identity = Binder.clearCallingIdentity();
6300 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006301 if (DBG) log("getAllowedNetworkTypesBitmask");
6302 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6303 int networkTypesBitmask = (result != null ? result[0] : -1);
6304 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6305 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006309 }
6310
6311 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006312 * Get the allowed network types for certain reason.
6313 *
6314 * @param subId the id of the subscription.
6315 * @param reason the reason the allowed network type change is taking place
6316 * @return the allowed network types.
6317 */
6318 @Override
6319 public long getAllowedNetworkTypesForReason(int subId,
6320 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006321 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006322 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006323 final long identity = Binder.clearCallingIdentity();
6324 try {
6325 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6326 } finally {
6327 Binder.restoreCallingIdentity(identity);
6328 }
6329 }
6330
6331 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006332 * Enable/Disable E-UTRA-NR Dual Connectivity
6333 * @param subId subscription id of the sim card
6334 * @param nrDualConnectivityState expected NR dual connectivity state
6335 * This can be passed following states
6336 * <ol>
6337 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6338 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6339 * <li>Disable NR dual connectivity and force secondary cell to be released
6340 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6341 * </ol>
6342 * @return operation result.
6343 */
6344 @Override
6345 public int setNrDualConnectivityState(int subId,
6346 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6347 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6348 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006349 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006350 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6351 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6352 }
6353
Sooraj Sasindran37444802020-08-11 10:40:43 -07006354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6358 nrDualConnectivityState, subId,
6359 workSource);
6360 if (DBG) log("enableNRDualConnectivity result: " + result);
6361 return result;
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
6364 }
6365 }
6366
6367 /**
6368 * Is E-UTRA-NR Dual Connectivity enabled
6369 * @return true if dual connectivity is enabled else false
6370 */
6371 @Override
6372 public boolean isNrDualConnectivityEnabled(int subId) {
6373 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006374 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006375 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006376 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006377 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6378 return false;
6379 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006380 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6381 final long identity = Binder.clearCallingIdentity();
6382 try {
6383 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6384 null, subId, workSource);
6385 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6386 return isEnabled;
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
6390 }
6391
6392 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006393 * Set the allowed network types of the device and
6394 * provide the reason triggering the allowed network change.
6395 *
6396 * @param subId the id of the subscription.
6397 * @param reason the reason the allowed network type change is taking place
6398 * @param allowedNetworkTypes the allowed network types.
6399 * @return true on success; false on any failure.
6400 */
6401 @Override
6402 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006403 @TelephonyManager.AllowedNetworkTypesReason int reason,
6404 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6406 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006407 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006408 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6409 return false;
6410 }
6411 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6412 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006413 return false;
6414 }
6415
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006416 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6417 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6418
6419
6420 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6421 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6422 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006423 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006424
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006425 final long identity = Binder.clearCallingIdentity();
6426 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006427 Boolean success = (Boolean) sendRequest(
6428 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6429 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6430
6431 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6432 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
6436 }
6437
6438 /**
Miaoa84611c2019-03-15 09:21:10 +08006439 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006440 *
Miaoa84611c2019-03-15 09:21:10 +08006441 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006442 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006443 * @hide
6444 */
6445 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006446 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006447 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006449 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006450 try {
Miaoa84611c2019-03-15 09:21:10 +08006451 if (phone != null) {
6452 return phone.hasMatchedTetherApnSetting();
6453 } else {
6454 return false;
6455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 } finally {
6457 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006458 }
Junda Liu475951f2014-11-07 16:45:03 -08006459 }
6460
6461 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006462 * Enable or disable always reporting signal strength changes from radio.
6463 *
6464 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6465 */
6466 @Override
6467 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6468 enforceModifyPermission();
6469 enforceSystemCaller();
6470
6471 final long identity = Binder.clearCallingIdentity();
6472 final Phone phone = getPhone(subId);
6473 try {
6474 if (phone != null) {
6475 if (DBG) {
6476 log("setAlwaysReportSignalStrength: subId=" + subId
6477 + " isEnable=" + isEnable);
6478 }
6479 phone.setAlwaysReportSignalStrength(isEnable);
6480 } else {
6481 loge("setAlwaysReportSignalStrength: no phone found for subId="
6482 + subId);
6483 }
6484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
6487 }
6488
6489 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006490 * Get the user enabled state of Mobile Data.
6491 *
6492 * TODO: remove and use isUserDataEnabled.
6493 * This can't be removed now because some vendor codes
6494 * calls through ITelephony directly while they should
6495 * use TelephonyManager.
6496 *
6497 * @return true on enabled
6498 */
6499 @Override
6500 public boolean getDataEnabled(int subId) {
6501 return isUserDataEnabled(subId);
6502 }
6503
6504 /**
6505 * Get whether mobile data is enabled per user setting.
6506 *
6507 * There are other factors deciding whether mobile data is actually enabled, but they are
6508 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006509 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006510 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006511 *
6512 * @return {@code true} if data is enabled else {@code false}
6513 */
6514 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006515 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006516 try {
6517 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6518 null);
6519 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6521 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523
6524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 int phoneId = mSubscriptionController.getPhoneId(subId);
6527 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6528 Phone phone = PhoneFactory.getPhone(phoneId);
6529 if (phone != null) {
6530 boolean retVal = phone.isUserDataEnabled();
6531 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6532 return retVal;
6533 } else {
6534 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6535 return false;
6536 }
6537 } finally {
6538 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006539 }
6540 }
6541
6542 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006543 * Checks if the device is capable of mobile data by considering whether whether the
6544 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6545 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006546 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006547 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006548 */
6549 @Override
6550 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006551 try {
6552 try {
6553 mApp.enforceCallingOrSelfPermission(
6554 android.Manifest.permission.ACCESS_NETWORK_STATE,
6555 null);
6556 } catch (Exception e) {
6557 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6558 "isDataEnabled");
6559 }
6560 } catch (Exception e) {
6561 enforceReadPrivilegedPermission("isDataEnabled");
6562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006563
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 int phoneId = mSubscriptionController.getPhoneId(subId);
6567 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6568 Phone phone = PhoneFactory.getPhone(phoneId);
6569 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006570 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6572 return retVal;
6573 } else {
6574 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6575 return false;
6576 }
6577 } finally {
6578 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006579 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006580 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006581
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006582 /**
6583 * Check if data is enabled for a specific reason
6584 * @param subId Subscription index
6585 * @param reason the reason the data enable change is taking place
6586 * @return {@code true} if the overall data is enabled; {@code false} if not.
6587 */
6588 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006589 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006590 @TelephonyManager.DataEnabledReason int reason) {
6591 try {
6592 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6593 null);
6594 } catch (Exception e) {
6595 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006596 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006597 }
6598
6599
6600 final long identity = Binder.clearCallingIdentity();
6601 try {
6602 int phoneId = mSubscriptionController.getPhoneId(subId);
6603 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006604 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006605 + " reason=" + reason);
6606 }
6607 Phone phone = PhoneFactory.getPhone(phoneId);
6608 if (phone != null) {
6609 boolean retVal;
6610 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6611 retVal = phone.isUserDataEnabled();
6612 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006613 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006614 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006615 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006616 return retVal;
6617 } else {
6618 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006619 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006620 + subId + " retVal=false");
6621 }
6622 return false;
6623 }
6624 } finally {
6625 Binder.restoreCallingIdentity(identity);
6626 }
6627 }
6628
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006629 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006630 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006631 if (uid == Process.PHONE_UID) {
6632 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6633 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006634 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6635 }
6636
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006637 //load access rules from carrier configs, and check those as well: b/139133814
6638 SubscriptionController subController = SubscriptionController.getInstance();
6639 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6640 || subController == null) return privilegeFromSim;
6641
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006642 PackageManager pkgMgr = phone.getContext().getPackageManager();
6643 String[] packages = pkgMgr.getPackagesForUid(uid);
6644
6645 final long identity = Binder.clearCallingIdentity();
6646 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006647 int subId = phone.getSubId();
6648 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6649 // A test override is in place for the privileges for this subId, so don't try to
6650 // read the subscription privileges.
6651 return privilegeFromSim;
6652 }
6653 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006654 SubscriptionManager subManager = (SubscriptionManager)
6655 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6656 for (String pkg : packages) {
6657 if (subManager.canManageSubscription(subInfo, pkg)) {
6658 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6659 }
6660 }
6661 return privilegeFromSim;
6662 } finally {
6663 Binder.restoreCallingIdentity(identity);
6664 }
6665 }
6666
6667 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6668 String pkgName) {
6669 //load access rules from carrier configs, and check those as well: b/139133814
6670 SubscriptionController subController = SubscriptionController.getInstance();
6671 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6672 || subController == null) return privilegeFromSim;
6673
6674 final long identity = Binder.clearCallingIdentity();
6675 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006676 int subId = phone.getSubId();
6677 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6678 // A test override is in place for the privileges for this subId, so don't try to
6679 // read the subscription privileges.
6680 return privilegeFromSim;
6681 }
6682 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006683 SubscriptionManager subManager = (SubscriptionManager)
6684 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6685 return subManager.canManageSubscription(subInfo, pkgName)
6686 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6687 } finally {
6688 Binder.restoreCallingIdentity(identity);
6689 }
6690 }
6691
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006692 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006693 public int getCarrierPrivilegeStatus(int subId) {
6694 final Phone phone = getPhone(subId);
6695 if (phone == null) {
6696 loge("getCarrierPrivilegeStatus: Invalid subId");
6697 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6698 }
6699 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006700 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006701 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006702 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6703 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006704
6705 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6706 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006707 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006708 }
Junda Liu29340342014-07-10 15:23:27 -07006709
6710 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006711 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006712 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006713 final Phone phone = getPhone(subId);
6714 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006715 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006716 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6717 }
6718 UiccProfile profile =
6719 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6720 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006721 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006722 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6723 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006724 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006725 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006726 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006727 }
6728
6729 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006730 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006731 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006732 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006733 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006734 }
6735
6736 int phoneId = SubscriptionManager.getPhoneId(subId);
6737 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006738 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006739 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006740 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6741 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006742 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6743 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6744 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006745 }
6746
6747 @Override
6748 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006749 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006750 if (TextUtils.isEmpty(pkgName))
6751 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006752 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6753 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6754 UiccCard card = UiccController.getInstance().getUiccCard(i);
6755 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006756 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006757 continue;
6758 }
6759
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006760 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6761 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6762 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006763 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6764 break;
6765 }
6766 }
6767
6768 return result;
Junda Liu29340342014-07-10 15:23:27 -07006769 }
Derek Tan89e89d42014-07-08 17:00:10 -07006770
6771 @Override
Junda Liue64de782015-04-16 17:19:16 -07006772 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006773 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006774 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6775 loge("phoneId " + phoneId + " is not valid.");
6776 return null;
6777 }
6778 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006779 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006780 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006781 return null ;
6782 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006783 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006784 }
6785
Amith Yamasani6e118872016-02-19 12:53:51 -08006786 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006787 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006788 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006789 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006790 List<String> privilegedPackages = new ArrayList<>();
6791 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006792 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6793 // has UICC in that slot.
6794 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006795 if (card.hasCarrierPrivilegeRules()) {
6796 if (packages == null) {
6797 // Only check packages in user 0 for now
6798 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006799 PackageManager.MATCH_DISABLED_COMPONENTS
6800 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006801 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006802 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006803 }
6804 for (int p = packages.size() - 1; p >= 0; p--) {
6805 PackageInfo pkgInfo = packages.get(p);
6806 if (pkgInfo != null && pkgInfo.packageName != null
6807 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006808 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006809 privilegedPackages.add(pkgInfo.packageName);
6810 }
6811 }
6812 }
6813 }
6814 return privilegedPackages;
6815 }
6816
chen xuf7e9fe82019-05-09 19:31:02 -07006817 @Override
6818 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006819 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6820
6821 final long identity = Binder.clearCallingIdentity();
6822
chen xuf7e9fe82019-05-09 19:31:02 -07006823 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006824 try {
6825 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6826 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6827 }
6828 } finally {
6829 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006830 }
6831 return privilegedPackages;
6832 }
6833
Wink Savilleb564aae2014-10-23 10:18:09 -07006834 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006835 final Phone phone = getPhone(subId);
6836 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006837 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006838 return null;
6839 }
6840 String iccId = card.getIccId();
6841 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006842 return null;
6843 }
6844 return iccId;
6845 }
6846
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006847 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006848 public void setCallComposerStatus(int subId, int status) {
6849 enforceModifyPermission();
6850
6851 final long identity = Binder.clearCallingIdentity();
6852 try {
6853 Phone phone = getPhone(subId);
6854 if (phone != null) {
6855 Phone defaultPhone = phone.getImsPhone();
6856 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6857 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6858 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006859 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6860 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006861 }
6862 }
Shuo Qian284ae752020-12-22 19:10:14 -08006863 } catch (ImsException e) {
6864 throw new ServiceSpecificException(e.getCode());
6865 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006866 Binder.restoreCallingIdentity(identity);
6867 }
6868 }
6869
6870 @Override
6871 public int getCallComposerStatus(int subId) {
6872 enforceReadPrivilegedPermission("getCallComposerStatus");
6873
6874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 Phone phone = getPhone(subId);
6877 if (phone != null) {
6878 Phone defaultPhone = phone.getImsPhone();
6879 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6880 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6881 return imsPhone.getCallComposerStatus();
6882 }
6883 }
6884 } finally {
6885 Binder.restoreCallingIdentity(identity);
6886 }
6887 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6888 }
6889
6890 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006891 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6892 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006893 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006894 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896 final long identity = Binder.clearCallingIdentity();
6897 try {
6898 final String iccId = getIccId(subId);
6899 final Phone phone = getPhone(subId);
6900 if (phone == null) {
6901 return false;
6902 }
6903 final String subscriberId = phone.getSubscriberId();
6904
6905 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006906 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 + subscriberId + " to " + number);
6908 }
6909
6910 if (TextUtils.isEmpty(iccId)) {
6911 return false;
6912 }
6913
6914 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6915
6916 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6917 if (alphaTag == null) {
6918 editor.remove(alphaTagPrefKey);
6919 } else {
6920 editor.putString(alphaTagPrefKey, alphaTag);
6921 }
6922
6923 // Record both the line number and IMSI for this ICCID, since we need to
6924 // track all merged IMSIs based on line number
6925 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6926 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6927 if (number == null) {
6928 editor.remove(numberPrefKey);
6929 editor.remove(subscriberPrefKey);
6930 } else {
6931 editor.putString(numberPrefKey, number);
6932 editor.putString(subscriberPrefKey, subscriberId);
6933 }
6934
6935 editor.commit();
6936 return true;
6937 } finally {
6938 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006939 }
Derek Tan7226c842014-07-02 17:42:23 -07006940 }
6941
6942 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006943 public String getLine1NumberForDisplay(int subId, String callingPackage,
6944 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006945 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006947 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006948 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006949 return null;
6950 }
Derek Tan97ebb422014-09-05 16:55:38 -07006951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 final long identity = Binder.clearCallingIdentity();
6953 try {
6954 String iccId = getIccId(subId);
6955 if (iccId != null) {
6956 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6957 if (DBG_MERGE) {
6958 log("getLine1NumberForDisplay returning "
6959 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6960 }
6961 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6964 return null;
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006967 }
Derek Tan7226c842014-07-02 17:42:23 -07006968 }
6969
6970 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006971 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6972 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006974 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006975 return null;
6976 }
Derek Tan97ebb422014-09-05 16:55:38 -07006977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 final long identity = Binder.clearCallingIdentity();
6979 try {
6980 String iccId = getIccId(subId);
6981 if (iccId != null) {
6982 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6983 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6984 }
6985 return null;
6986 } finally {
6987 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006988 }
Derek Tan7226c842014-07-02 17:42:23 -07006989 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006990
6991 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006992 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6993 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006994 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6995 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006997 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006998 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006999 return null;
7000 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007001
Jordan Liub49b04b2019-05-06 14:45:15 -07007002 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7003 // the process, where TelephonyManager was instantiated.
7004 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007005 final long identity = Binder.clearCallingIdentity();
7006 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007007 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 final TelephonyManager tele = TelephonyManager.from(context);
7009 final SubscriptionManager sub = SubscriptionManager.from(context);
7010
7011 // Figure out what subscribers are currently active
7012 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013
Jordan Liub49b04b2019-05-06 14:45:15 -07007014 // Only consider subs which match the current subId
7015 // This logic can be simplified. See b/131189269 for progress.
7016 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007017 activeSubscriberIds.add(tele.getSubscriberId(subId));
7018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019
7020 // First pass, find a number override for an active subscriber
7021 String mergeNumber = null;
7022 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7023 for (String key : prefs.keySet()) {
7024 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7025 final String subscriberId = (String) prefs.get(key);
7026 if (activeSubscriberIds.contains(subscriberId)) {
7027 final String iccId = key.substring(
7028 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7029 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7030 mergeNumber = (String) prefs.get(numberKey);
7031 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007032 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 + " for active subscriber " + subscriberId);
7034 }
7035 if (!TextUtils.isEmpty(mergeNumber)) {
7036 break;
7037 }
7038 }
7039 }
7040 }
7041
7042 // Shortcut when no active merged subscribers
7043 if (TextUtils.isEmpty(mergeNumber)) {
7044 return null;
7045 }
7046
7047 // Second pass, find all subscribers under that line override
7048 final ArraySet<String> result = new ArraySet<>();
7049 for (String key : prefs.keySet()) {
7050 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7051 final String number = (String) prefs.get(key);
7052 if (mergeNumber.equals(number)) {
7053 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7054 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7055 final String subscriberId = (String) prefs.get(subscriberKey);
7056 if (!TextUtils.isEmpty(subscriberId)) {
7057 result.add(subscriberId);
7058 }
7059 }
7060 }
7061 }
7062
7063 final String[] resultArray = result.toArray(new String[result.size()]);
7064 Arrays.sort(resultArray);
7065 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007066 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7068 }
7069 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007070 } finally {
7071 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007072 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007073 }
7074
7075 @Override
zoey chen38003472019-12-13 17:16:31 +08007076 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7077 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007078
7079 final long identity = Binder.clearCallingIdentity();
7080 try {
7081 final TelephonyManager telephonyManager = mApp.getSystemService(
7082 TelephonyManager.class);
7083 String subscriberId = telephonyManager.getSubscriberId(subId);
7084 if (subscriberId == null) {
7085 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007086 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007087 + subId);
7088 }
7089 return null;
7090 }
7091
7092 final SubscriptionInfo info = SubscriptionController.getInstance()
7093 .getSubscriptionInfo(subId);
7094 final ParcelUuid groupUuid = info.getGroupUuid();
7095 // If it doesn't belong to any group, return just subscriberId of itself.
7096 if (groupUuid == null) {
7097 return new String[]{subscriberId};
7098 }
7099
7100 // Get all subscriberIds from the group.
7101 final List<String> mergedSubscriberIds = new ArrayList<>();
7102 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007103 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007104 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007105 for (SubscriptionInfo subInfo : groupInfos) {
7106 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7107 if (subscriberId != null) {
7108 mergedSubscriberIds.add(subscriberId);
7109 }
7110 }
7111
7112 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115
7116 }
7117 }
7118
7119 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007120 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007121 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007122 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 final Phone phone = getPhone(subId);
7127 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007131 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007132
7133 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007134 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007135 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7136 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007137 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7138 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
7142 final Phone phone = getPhone(subId);
7143 if (phone == null) {
7144 return false;
7145 }
7146 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7147 cdmaNonRoamingList);
7148 } finally {
7149 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007150 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007151 }
7152
7153 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007154 @Deprecated
7155 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7156 enforceModifyPermission();
7157
7158 int returnValue = 0;
7159 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007160 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007161 if(result.exception == null) {
7162 if (result.result != null) {
7163 byte[] responseData = (byte[])(result.result);
7164 if(responseData.length > oemResp.length) {
7165 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7166 responseData.length + "bytes. Buffer Size is " +
7167 oemResp.length + "bytes.");
7168 }
7169 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7170 returnValue = responseData.length;
7171 }
7172 } else {
7173 CommandException ex = (CommandException) result.exception;
7174 returnValue = ex.getCommandError().ordinal();
7175 if(returnValue > 0) returnValue *= -1;
7176 }
7177 } catch (RuntimeException e) {
7178 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7179 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7180 if(returnValue > 0) returnValue *= -1;
7181 }
7182
7183 return returnValue;
7184 }
7185
7186 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007187 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007188 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007189 try {
7190 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007191 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007192 mApp, phone.getSubId(), "getRadioAccessFamily");
7193 } catch (SecurityException e) {
7194 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7195 throw e;
7196 }
chen xub97461a2018-10-26 14:17:57 -07007197 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007198 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007199 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007200 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 final long identity = Binder.clearCallingIdentity();
7202 try {
chen xub97461a2018-10-26 14:17:57 -07007203 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007204 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007205 mApp, phone.getSubId(), "getRadioAccessFamily");
7206 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 } finally {
7208 Binder.restoreCallingIdentity(identity);
7209 }
chen xub97461a2018-10-26 14:17:57 -07007210 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007211 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007212
7213 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007214 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007215 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007216 try {
7217 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7218 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007219 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007220 }
7221 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007222 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007223 }
7224 RoleManager rm = mApp.getSystemService(RoleManager.class);
7225 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7226 if (!dialerRoleHolders.contains(callingPackage)) {
7227 throw new SecurityException("App must be the dialer role holder to"
7228 + " upload a call composer pic");
7229 }
7230
7231 Executors.newSingleThreadExecutor().execute(() -> {
7232 ByteArrayOutputStream output = new ByteArrayOutputStream(
7233 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7234 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7235 boolean readUntilEnd = false;
7236 int totalBytesRead = 0;
7237 byte[] buffer = new byte[16 * 1024];
7238 while (true) {
7239 int numRead;
7240 try {
7241 numRead = input.read(buffer);
7242 } catch (IOException e) {
7243 try {
7244 fd.checkError();
7245 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7246 null);
7247 } catch (IOException e1) {
7248 // This means that the other side closed explicitly with an error. If this
7249 // happens, log and ignore.
7250 loge("Remote end of call composer picture pipe closed: " + e1);
7251 }
7252 break;
7253 }
7254 if (numRead == -1) {
7255 readUntilEnd = true;
7256 break;
7257 }
7258 totalBytesRead += numRead;
7259 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7260 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7261 try {
7262 input.close();
7263 } catch (IOException e) {
7264 // ignore
7265 }
7266 break;
7267 }
7268 output.write(buffer, 0, numRead);
7269 }
7270 // Generally, the remote end will close the file descriptors. The only case where we
7271 // close is above, where the picture size is too big.
7272
7273 try {
7274 fd.checkError();
7275 } catch (IOException e) {
7276 loge("Remote end for call composer closed with an error: " + e);
7277 return;
7278 }
7279
Hall Liuaa4211e2021-01-20 15:43:39 -08007280 if (!readUntilEnd) {
7281 loge("Did not finish reading entire image; aborting");
7282 return;
7283 }
Hall Liu82694d52020-12-11 18:22:04 -08007284
Hall Liuaa4211e2021-01-20 15:43:39 -08007285 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7286 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7287 new CallComposerPictureTransfer.Factory() {},
7288 imageData,
7289 (result) -> {
7290 if (result.first != null) {
7291 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7292 Bundle outputResult = new Bundle();
7293 outputResult.putParcelable(
7294 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7295 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7296 outputResult);
7297 } else {
7298 callback.send(result.second, null);
7299 }
7300 }
7301 );
Hall Liu82694d52020-12-11 18:22:04 -08007302 });
7303 }
7304
7305 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007306 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007307 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007308 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309
7310 final long identity = Binder.clearCallingIdentity();
7311 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007312 ImsManager.getInstance(defaultPhone.getContext(),
7313 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007317 }
7318
7319 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007320 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007321 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7323 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007324 return false;
7325 }
Svet Ganovb320e182015-04-16 12:30:10 -07007326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 final long identity = Binder.clearCallingIdentity();
7328 try {
7329 // Check the user preference and the system-level IMS setting. Even if the user has
7330 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7331 // In the long run, we may instead need to check if there exists a connection service
7332 // which can support video calling.
7333 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007334 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 return imsManager.isVtEnabledByPlatform()
7336 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7337 && imsManager.isVtEnabledByUser();
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007341 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007342
Andrew Leea1239f22015-03-02 17:44:07 -08007343 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007344 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7345 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007347 mApp, subId, callingPackage, callingFeatureId,
7348 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007349 return false;
7350 }
7351
7352 final long identity = Binder.clearCallingIdentity();
7353 try {
7354 CarrierConfigManager configManager =
7355 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007356 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7358 } finally {
7359 Binder.restoreCallingIdentity(identity);
7360 }
Andrew Leea1239f22015-03-02 17:44:07 -08007361 }
7362
7363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007364 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007366 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 return false;
7368 }
7369
7370 final long identity = Binder.clearCallingIdentity();
7371 try {
7372 CarrierConfigManager configManager =
7373 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007374 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
7378 }
Andrew Leea1239f22015-03-02 17:44:07 -08007379 }
7380
Andrew Lee9431b832015-03-09 18:46:45 -07007381 @Override
7382 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007383 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007384 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007385 }
7386
7387 @Override
7388 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 final long identity = Binder.clearCallingIdentity();
7390 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007391 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
Andrew Lee9431b832015-03-09 18:46:45 -07007395 }
7396
Hall Liuf6668912018-10-31 17:05:23 -07007397 /**
7398 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7399 * support for the feature and device firmware support.
7400 *
7401 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7402 */
7403 @Override
7404 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007405 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007406 final Phone phone = getPhone(subscriptionId);
7407 if (phone == null) {
7408 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7409 return false;
7410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007412 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7414 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007415 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 return isCarrierSupported && isDeviceSupported;
7417 } finally {
7418 Binder.restoreCallingIdentity(identity);
7419 }
Hall Liu98187582018-01-22 19:15:32 -08007420 }
7421
Hall Liuf6668912018-10-31 17:05:23 -07007422 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007423 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7424 * RTT setting, will return true if the device and carrier both support RTT.
7425 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007426 */
7427 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 final long identity = Binder.clearCallingIdentity();
7429 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007430 boolean isRttSupported = isRttSupported(subscriptionId);
7431 boolean isUserRttSettingOn = Settings.Secure.getInt(
7432 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7433 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7434 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7435 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007439 }
7440
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007441 @Deprecated
7442 @Override
7443 public String getDeviceId(String callingPackage) {
7444 return getDeviceIdWithFeature(callingPackage, null);
7445 }
7446
Sanket Padawe7310cc72015-01-14 09:53:20 -08007447 /**
7448 * Returns the unique device ID of phone, for example, the IMEI for
7449 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7450 *
7451 * <p>Requires Permission:
7452 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7453 */
7454 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007455 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007456 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007457 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007458 return null;
7459 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007460 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007461 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007462 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007463 return null;
7464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465
7466 final long identity = Binder.clearCallingIdentity();
7467 try {
7468 return phone.getDeviceId();
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007472 }
7473
Ping Sunc67b7c22016-03-02 19:16:45 +08007474 /**
7475 * {@hide}
7476 * Returns the IMS Registration Status on a particular subid
7477 *
7478 * @param subId
7479 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007480 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007481 Phone phone = getPhone(subId);
7482 if (phone != null) {
7483 return phone.isImsRegistered();
7484 } else {
7485 return false;
7486 }
7487 }
7488
Santos Cordon7a1885b2015-02-03 11:15:19 -08007489 @Override
7490 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491 final long identity = Binder.clearCallingIdentity();
7492 try {
7493 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007497 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007498
Tyler Gunnf70ed162019-04-03 15:28:53 -07007499 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007500 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007501 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007503 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007504 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7505 }
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
7512 }
7513
7514 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007515 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007516 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007517 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007518 mApp,
7519 subscriptionId,
7520 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 Phone phone = getPhone(subscriptionId);
7524 if (phone == null) {
7525 return null;
7526 }
7527 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
7531 }
7532
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007533 /**
7534 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007535 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007536 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 Phone phone = getPhone(subId);
7540 if (phone != null) {
7541 return phone.isWifiCallingEnabled();
7542 } else {
7543 return false;
7544 }
7545 } finally {
7546 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007547 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007548 }
7549
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007550 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007551 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007552 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007553 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 final long identity = Binder.clearCallingIdentity();
7555 try {
7556 Phone phone = getPhone(subId);
7557 if (phone != null) {
7558 return phone.isVideoEnabled();
7559 } else {
7560 return false;
7561 }
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007564 }
7565 }
7566
7567 /**
7568 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7569 * defined in {@link ImsRegistrationImplBase}.
7570 */
7571 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 final long identity = Binder.clearCallingIdentity();
7573 try {
7574 Phone phone = getPhone(subId);
7575 if (phone != null) {
7576 return phone.getImsRegistrationTech();
7577 } else {
7578 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7579 }
7580 } finally {
7581 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007582 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007583 }
7584
Stuart Scott8eef64f2015-04-08 15:13:54 -07007585 @Override
7586 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007587 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007588 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7589 return;
7590 }
Kai Shif70f46f2021-03-03 13:59:46 -08007591 Phone defaultPhone = getDefaultPhone();
7592 if (defaultPhone != null) {
7593 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7594 mApp, getDefaultPhone().getSubId(), "factoryReset");
7595 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007596 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007597
Svet Ganovcc087f82015-05-12 20:35:54 -07007598 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007599 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7600 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007601 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007602 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007603 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007604 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007605 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007606 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007607 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007608 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007609 // There has been issues when Sms raw table somehow stores orphan
7610 // fragments. They lead to garbled message when new fragments come
7611 // in and combined with those stale ones. In case this happens again,
7612 // user can reset all network settings which will clean up this table.
7613 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007614 // Clean up IMS settings as well here.
7615 int slotId = getSlotIndex(subId);
7616 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7617 ImsManager.getInstance(mApp, slotId).factoryReset();
7618 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007619
Kai Shif70f46f2021-03-03 13:59:46 -08007620 if (defaultPhone == null) {
7621 return;
7622 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007623 // Erase modem config if erase modem on network setting is enabled.
7624 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7625 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7626 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007627 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007628 }
Kai Shif70f46f2021-03-03 13:59:46 -08007629
7630 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007631 } finally {
7632 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007633 }
7634 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007635
SongFerngWangfd89b102021-05-27 22:44:54 +08007636 @VisibleForTesting
7637 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7638 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7639 return;
7640 }
7641 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7642 RILConstants.PREFERRED_NETWORK_MODE);
7643 SubscriptionManager.setSubscriptionProperty(subId,
7644 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7645 "user=" + defaultNetworkType);
7646 phone.loadAllowedNetworksFromSubscriptionDatabase();
7647 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7648 defaultNetworkType, null);
7649 }
7650
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007651 private void cleanUpSmsRawTable(Context context) {
7652 ContentResolver resolver = context.getContentResolver();
7653 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7654 resolver.delete(uri, null, null);
7655 }
7656
Narayan Kamath1c496c22015-04-16 14:40:19 +01007657 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007658 public String getSimLocaleForSubscriber(int subId) {
7659 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7660 final Phone phone = getPhone(subId);
7661 if (phone == null) {
7662 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007663 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 final long identity = Binder.clearCallingIdentity();
7666 try {
chen xu5d3637b2019-01-21 23:31:38 -08007667 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007668 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007669 if (info == null) {
7670 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7671 return null;
7672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673 // Try and fetch the locale from the carrier properties or from the SIM language
7674 // preferences (EF-PL and EF-LI)...
7675 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007677 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7678 if (localeFromDefaultSim != null) {
7679 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7680 if (DBG) log("Using locale from subId: " + subId + " locale: "
7681 + localeFromDefaultSim);
7682 return localeFromDefaultSim.toLanguageTag();
7683 } else {
7684 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 }
7686 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 // The SIM language preferences only store a language (e.g. fr = French), not an
7689 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7690 // the SIM and carrier preferences does not include a country we add the country
7691 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007692 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007693 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007694 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 return mccLocale.toLanguageTag();
7696 }
7697
7698 if (DBG) log("No locale found - returning null");
7699 return null;
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007703 }
7704
7705 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007706 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007707 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007708 }
7709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 /**
7711 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7712 */
7713 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007714 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007715 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007716 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007717
Chenjie Yu1ba97252018-01-11 18:16:20 -08007718 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007719 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007720
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007721 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007722 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7723 * representing the state of the modem.
7724 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007725 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7726 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007727 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007728 */
7729 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007730 public void requestModemActivityInfo(ResultReceiver result) {
7731 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007732 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007733
7734 final long identity = Binder.clearCallingIdentity();
7735 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007736 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 } finally {
7738 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007739 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007740 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007741
Siddharth Rayb8114062018-06-17 15:02:38 -07007742 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7743 // less than total activity duration.
7744 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7745 if (info == null) {
7746 return false;
7747 }
7748 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007749 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7750 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7751
Siddharth Rayb8114062018-06-17 15:02:38 -07007752 return (info.isValid()
7753 && (info.getSleepTimeMillis() <= activityDurationMs)
7754 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007755 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007756 && (totalTxTimeMs <= activityDurationMs));
7757 }
7758
Jack Yu85bd38a2015-11-09 11:34:32 -08007759 /**
7760 * {@hide}
7761 * Returns the service state information on specified subscription.
7762 */
7763 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007764 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7765 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007766 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007767 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007768 return null;
7769 }
7770
Hall Liuf19c44f2018-11-27 14:38:17 -08007771 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7772 LocationAccessPolicy.checkLocationPermission(mApp,
7773 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7774 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007775 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007776 .setCallingPid(Binder.getCallingPid())
7777 .setCallingUid(Binder.getCallingUid())
7778 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007779 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007780 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007781 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7782 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007783 .build());
7784
7785 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7786 LocationAccessPolicy.checkLocationPermission(mApp,
7787 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7788 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007789 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007790 .setCallingPid(Binder.getCallingPid())
7791 .setCallingUid(Binder.getCallingUid())
7792 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007793 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007794 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007795 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7796 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007797 .build());
7798 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7799 boolean hasFinePermission =
7800 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7801 boolean hasCoarsePermission =
7802 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7803
Jack Yu479f40e2020-10-27 21:29:25 -07007804 final Phone phone = getPhone(subId);
7805 if (phone == null) {
7806 return null;
7807 }
7808
Jordan Liu0f2bc442020-11-18 16:47:37 -08007809 final long identity = Binder.clearCallingIdentity();
7810
Jack Yu479f40e2020-10-27 21:29:25 -07007811 boolean isCallingPackageDataService = phone.getDataServicePackages()
7812 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007814 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7815 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7816 Rlog.d(LOG_TAG,
7817 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7818 return null;
7819 }
7820
Hall Liuf19c44f2018-11-27 14:38:17 -08007821 ServiceState ss = phone.getServiceState();
7822
7823 // Scrub out the location info in ServiceState depending on what level of access
7824 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007825 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007826 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7827 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 } finally {
7829 Binder.restoreCallingIdentity(identity);
7830 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007831 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007832
7833 /**
7834 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7835 *
7836 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7837 * voicemail ringtone.
7838 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7839 * PhoneAccount.
7840 */
7841 @Override
7842 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007843 final long identity = Binder.clearCallingIdentity();
7844 try {
7845 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7846 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007847 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007854 }
7855
7856 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007857 * Sets the per-account voicemail ringtone.
7858 *
7859 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7860 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7861 *
7862 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7863 * voicemail ringtone.
7864 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7865 * PhoneAccount.
7866 */
7867 @Override
7868 public void setVoicemailRingtoneUri(String callingPackage,
7869 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007870 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007871 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007872 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7873 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7875 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7876 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878
7879 final long identity = Binder.clearCallingIdentity();
7880 try {
7881 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7882 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007883 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007884 }
7885 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7886 } finally {
7887 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007888 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007889 }
7890
7891 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007892 * Returns whether vibration is set for voicemail notification in Phone settings.
7893 *
7894 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7895 * voicemail vibration setting.
7896 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7897 */
7898 @Override
7899 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007900 final long identity = Binder.clearCallingIdentity();
7901 try {
7902 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7903 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007904 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7908 } finally {
7909 Binder.restoreCallingIdentity(identity);
7910 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007911 }
7912
Youhan Wange64578a2016-05-02 15:32:42 -07007913 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007914 * Sets the per-account voicemail vibration.
7915 *
7916 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7917 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7918 *
7919 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7920 * voicemail vibration setting.
7921 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7922 * specific PhoneAccount.
7923 */
7924 @Override
7925 public void setVoicemailVibrationEnabled(String callingPackage,
7926 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007927 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007928 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007929 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7930 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7932 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7933 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007934 }
7935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007936 final long identity = Binder.clearCallingIdentity();
7937 try {
7938 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7939 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007940 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941 }
7942 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7943 } finally {
7944 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007945 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007946 }
7947
7948 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007949 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7950 *
7951 * @throws SecurityException if the caller does not have the required permission
7952 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007953 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007954 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007955 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007956 }
7957
7958 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007959 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7960 * permission.
7961 *
7962 * @throws SecurityException if the caller does not have the required permission
7963 */
7964 private void enforceSendSmsPermission() {
7965 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7966 }
7967
7968 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007969 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007970 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007971 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007972 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007973 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974 final long identity = Binder.clearCallingIdentity();
7975 try {
7976 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007977 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 if (componentName == null) {
7979 throw new SecurityException(
7980 "Caller not current active visual voicemail package[null]");
7981 }
7982 String vvmPackage = componentName.getPackageName();
7983 if (!callingPackage.equals(vvmPackage)) {
7984 throw new SecurityException("Caller not current active visual voicemail package["
7985 + vvmPackage + "]");
7986 }
7987 } finally {
7988 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007989 }
7990 }
7991
7992 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007993 * Return the application ID for the app type.
7994 *
7995 * @param subId the subscription ID that this request applies to.
7996 * @param appType the uicc app type.
7997 * @return Application ID for specificied app type, or null if no uicc.
7998 */
7999 @Override
8000 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008001 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008002 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003
8004 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008005 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008006 if (phone == null) {
8007 return null;
8008 }
8009 String aid = null;
8010 try {
8011 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8012 .getApplicationByType(appType).getAid();
8013 } catch (Exception e) {
8014 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8015 }
8016 return aid;
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008019 }
Youhan Wange64578a2016-05-02 15:32:42 -07008020 }
8021
Youhan Wang4001d252016-05-11 10:29:41 -07008022 /**
8023 * Return the Electronic Serial Number.
8024 *
8025 * @param subId the subscription ID that this request applies to.
8026 * @return ESN or null if error.
8027 */
8028 @Override
8029 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008030 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008031 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032
8033 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008034 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 if (phone == null) {
8036 return null;
8037 }
8038 String esn = null;
8039 try {
8040 esn = phone.getEsn();
8041 } catch (Exception e) {
8042 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8043 }
8044 return esn;
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008047 }
Youhan Wang4001d252016-05-11 10:29:41 -07008048 }
8049
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008050 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008051 * Return the Preferred Roaming List Version.
8052 *
8053 * @param subId the subscription ID that this request applies to.
8054 * @return PRLVersion or null if error.
8055 */
8056 @Override
8057 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008058 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008059 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060
8061 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008062 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008063 if (phone == null) {
8064 return null;
8065 }
8066 String cdmaPrlVersion = null;
8067 try {
8068 cdmaPrlVersion = phone.getCdmaPrlVersion();
8069 } catch (Exception e) {
8070 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8071 }
8072 return cdmaPrlVersion;
8073 } finally {
8074 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008075 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008076 }
8077
8078 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008079 * Get snapshot of Telephony histograms
8080 * @return List of Telephony histograms
8081 * @hide
8082 */
8083 @Override
8084 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8086 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087
8088 final long identity = Binder.clearCallingIdentity();
8089 try {
8090 return RIL.getTelephonyRILTimingHistograms();
8091 } finally {
8092 Binder.restoreCallingIdentity(identity);
8093 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008094 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008095
8096 /**
8097 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008098 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8099 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008100 * Require system privileges. In the future we may add this to carrier APIs.
8101 *
Michele Berionne482f8202018-11-27 18:57:59 -08008102 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008103 */
8104 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008105 @TelephonyManager.SetCarrierRestrictionResult
8106 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008107 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008108 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008109
Michele Berionne482f8202018-11-27 18:57:59 -08008110 if (carrierRestrictionRules == null) {
8111 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008112 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114 final long identity = Binder.clearCallingIdentity();
8115 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008116 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008117 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118 } finally {
8119 Binder.restoreCallingIdentity(identity);
8120 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008121 }
8122
8123 /**
8124 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008125 * Get the allowed carrier list and the excluded carrier list, including the priority between
8126 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008127 * Require system privileges. In the future we may add this to carrier APIs.
8128 *
Michele Berionne482f8202018-11-27 18:57:59 -08008129 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008130 */
8131 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008132 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008133 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008134 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135
8136 final long identity = Binder.clearCallingIdentity();
8137 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008138 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8139 if (response instanceof CarrierRestrictionRules) {
8140 return (CarrierRestrictionRules) response;
8141 }
8142 // Response is an Exception of some kind,
8143 // which is signalled to the user as a NULL retval
8144 return null;
8145 } catch (Exception e) {
8146 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8147 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008148 } finally {
8149 Binder.restoreCallingIdentity(identity);
8150 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008151 }
8152
fionaxu59545b42016-05-25 15:53:37 -07008153 /**
fionaxu59545b42016-05-25 15:53:37 -07008154 * Action set from carrier signalling broadcast receivers to enable/disable radio
8155 * @param subId the subscription ID that this action applies to.
8156 * @param enabled control enable or disable radio.
8157 * {@hide}
8158 */
8159 @Override
8160 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8161 enforceModifyPermission();
8162 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008163
8164 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008165 if (phone == null) {
8166 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8167 return;
8168 }
8169 try {
8170 phone.carrierActionSetRadioEnabled(enabled);
8171 } catch (Exception e) {
8172 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 } finally {
8174 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008175 }
8176 }
8177
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008178 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008179 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8180 * network status based on which carrier apps could apply actions accordingly,
8181 * enable/disable default url handler for example.
8182 *
8183 * @param subId the subscription ID that this action applies to.
8184 * @param report control start/stop reporting the default network status.
8185 * {@hide}
8186 */
8187 @Override
8188 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8189 enforceModifyPermission();
8190 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008191
8192 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008193 if (phone == null) {
8194 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8195 return;
8196 }
8197 try {
8198 phone.carrierActionReportDefaultNetworkStatus(report);
8199 } catch (Exception e) {
8200 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 } finally {
8202 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008203 }
8204 }
8205
8206 /**
fionaxud9622282017-07-17 17:51:30 -07008207 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8208 * @param subId the subscription ID that this action applies to.
8209 * {@hide}
8210 */
8211 @Override
8212 public void carrierActionResetAll(int subId) {
8213 enforceModifyPermission();
8214 final Phone phone = getPhone(subId);
8215 if (phone == null) {
8216 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8217 return;
8218 }
8219 try {
8220 phone.carrierActionResetAll();
8221 } catch (Exception e) {
8222 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8223 }
8224 }
8225
8226 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008227 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8228 * bug report is being generated.
8229 */
8230 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008231 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008232 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8233 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008234 writer.println("Permission Denial: can't dump Phone from pid="
8235 + Binder.getCallingPid()
8236 + ", uid=" + Binder.getCallingUid()
8237 + "without permission "
8238 + android.Manifest.permission.DUMP);
8239 return;
8240 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008241 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008242 }
Jack Yueb89b242016-06-22 13:27:47 -07008243
Brad Ebingerdac2f002018-04-03 15:17:52 -07008244 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008245 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8246 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8247 @NonNull String[] args) {
8248 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8249 this, in.getFileDescriptor(), out.getFileDescriptor(),
8250 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008251 }
8252
Jack Yueb89b242016-06-22 13:27:47 -07008253 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008254 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008255 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008256 * @param reason the reason the data enable change is taking place
8257 * @param enabled True if enabling the data, otherwise disabling.
8258 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008259 */
8260 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008261 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008262 boolean enabled) {
8263 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8264 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8265 try {
8266 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008267 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008268 } catch (SecurityException se) {
8269 enforceModifyPermission();
8270 }
8271 } else {
8272 enforceModifyPermission();
8273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 Phone phone = getPhone(subId);
8278 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008279 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8280 phone.carrierActionSetMeteredApnsEnabled(enabled);
8281 } else {
8282 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8283 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008284 }
8285 } finally {
8286 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008287 }
8288 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008289
8290 /**
8291 * Get Client request stats
8292 * @return List of Client Request Stats
8293 * @hide
8294 */
8295 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008296 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8297 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008299 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008300 return null;
8301 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008302 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 final long identity = Binder.clearCallingIdentity();
8305 try {
8306 if (phone != null) {
8307 return phone.getClientRequestStats();
8308 }
8309
8310 return null;
8311 } finally {
8312 Binder.restoreCallingIdentity(identity);
8313 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008314 }
8315
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008316 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008317 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008318 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008319 }
Jack Yueb4124c2017-02-16 15:32:43 -08008320
8321 /**
Grace Chen70990072017-03-24 17:21:30 -07008322 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008323 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008324 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008325 * @param state State of SIM (power down, power up, pass through)
8326 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8327 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8328 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008329 *
8330 **/
8331 @Override
Grace Chen70990072017-03-24 17:21:30 -07008332 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008333 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008334 Phone phone = PhoneFactory.getPhone(slotIndex);
8335
vagdeviaf9a5b92018-08-15 16:01:53 -07008336 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 final long identity = Binder.clearCallingIdentity();
8339 try {
8340 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008341 phone.setSimPowerState(state, null, workSource);
8342 }
8343 } finally {
8344 Binder.restoreCallingIdentity(identity);
8345 }
8346 }
8347
8348 /**
8349 * Set SIM card power state.
8350 *
8351 * @param slotIndex SIM slot id.
8352 * @param state State of SIM (power down, power up, pass through)
8353 * @param callback callback to trigger after success or failure
8354 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8355 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8356 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8357 *
8358 **/
8359 @Override
8360 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8361 IIntegerConsumer callback) {
8362 enforceModifyPermission();
8363 Phone phone = PhoneFactory.getPhone(slotIndex);
8364
8365 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8366
8367 final long identity = Binder.clearCallingIdentity();
8368 try {
8369 if (phone != null) {
8370 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8371 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008372 }
8373 } finally {
8374 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008375 }
8376 }
Shuo Qiandd210312017-04-12 22:11:33 +00008377
Tyler Gunn65d45c22017-06-05 11:22:26 -07008378 private boolean isUssdApiAllowed(int subId) {
8379 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008380 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008381 if (configManager == null) {
8382 return false;
8383 }
8384 PersistableBundle pb = configManager.getConfigForSubId(subId);
8385 if (pb == null) {
8386 return false;
8387 }
8388 return pb.getBoolean(
8389 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8390 }
8391
Shuo Qiandd210312017-04-12 22:11:33 +00008392 /**
8393 * Check if phone is in emergency callback mode
8394 * @return true if phone is in emergency callback mode
8395 * @param subId sub id
8396 */
goneil9c5f4872017-12-05 14:07:56 -08008397 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008398 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008399 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008400 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008401
8402 final long identity = Binder.clearCallingIdentity();
8403 try {
8404 if (phone != null) {
8405 return phone.isInEcm();
8406 } else {
8407 return false;
8408 }
8409 } finally {
8410 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008411 }
8412 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008413
8414 /**
8415 * Get the current signal strength information for the given subscription.
8416 * Because this information is not updated when the device is in a low power state
8417 * it should not be relied-upon to be current.
8418 * @param subId Subscription index
8419 * @return the most recent cached signal strength info from the modem
8420 */
8421 @Override
8422 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008423 final long identity = Binder.clearCallingIdentity();
8424 try {
8425 Phone p = getPhone(subId);
8426 if (p == null) {
8427 return null;
8428 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 return p.getSignalStrength();
8431 } finally {
8432 Binder.restoreCallingIdentity(identity);
8433 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008434 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008435
Pengquan Meng77b7f132018-08-22 14:49:57 -07008436 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008437 * Get the current modem radio state for the given slot.
8438 * @param slotIndex slot index.
8439 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008440 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008441 * @return the current radio power state from the modem
8442 */
8443 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008444 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008445 Phone phone = PhoneFactory.getPhone(slotIndex);
8446 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8448 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008449 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8450 }
8451
8452 final long identity = Binder.clearCallingIdentity();
8453 try {
8454 return phone.getRadioPowerState();
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
8457 }
8458 }
8459 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8460 }
8461
8462 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008463 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8464 *
8465 * <p>Requires one of the following permissions:
8466 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8467 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8468 * privileges.
8469 *
8470 * @param subId subscription id
8471 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8472 * {@code false}.
8473 */
8474 @Override
8475 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008476 try {
8477 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8478 null);
8479 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008480 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008481 mApp, subId, "isDataRoamingEnabled");
8482 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008483
Pengquan Menga1bb6272018-09-06 09:59:22 -07008484 boolean isEnabled = false;
8485 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008486 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008487 Phone phone = getPhone(subId);
8488 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008489 } finally {
8490 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008492 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008493 }
8494
8495
8496 /**
8497 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8498 *
8499 * <p> Requires permission:
8500 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8501 * privileges.
8502 *
8503 * @param subId subscription id
8504 * @param isEnabled {@code true} means enable, {@code false} means disable.
8505 */
8506 @Override
8507 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8509 mApp, subId, "setDataRoamingEnabled");
8510
Pengquan Menga1bb6272018-09-06 09:59:22 -07008511 final long identity = Binder.clearCallingIdentity();
8512 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008513 Phone phone = getPhone(subId);
8514 if (phone != null) {
8515 phone.setDataRoamingEnabled(isEnabled);
8516 }
8517 } finally {
8518 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008519 }
8520 }
8521
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008522 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008523 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008524 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008525 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008526 mApp, subId, "isManualNetworkSelectionAllowed");
8527
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008528 boolean isAllowed = true;
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008531 Phone phone = getPhone(subId);
8532 if (phone != null) {
8533 isAllowed = phone.isCspPlmnEnabled();
8534 }
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
8538 return isAllowed;
8539 }
8540
8541 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008542 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008543 // Verify that tha callingPackage belongs to the calling UID
8544 mApp.getSystemService(AppOpsManager.class)
8545 .checkPackage(Binder.getCallingUid(), callingPackage);
8546
Jordan Liu1e142fc2019-04-22 15:10:43 -07008547 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008548 try {
8549 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008550 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008551 } catch (SecurityException e) {
8552 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8553 // has carrier privileges on an active UICC
8554 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8555 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008556 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008557 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008558 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008559
8560 final long identity = Binder.clearCallingIdentity();
8561 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008562 UiccController uiccController = UiccController.getInstance();
8563 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008564 if (hasReadPermission) {
8565 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008566 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008567
8568 // Remove private info if the caller doesn't have access
8569 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8570 for (UiccCardInfo cardInfo : cardInfos) {
8571 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8572 // is available
8573 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8574 if (card == null || card.getUiccProfile() == null) {
8575 // assume no access if the card or profile is unavailable
8576 filteredInfos.add(cardInfo.getUnprivileged());
8577 continue;
8578 }
8579 UiccProfile profile = card.getUiccProfile();
8580 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8581 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8582 filteredInfos.add(cardInfo);
8583 } else {
8584 filteredInfos.add(cardInfo.getUnprivileged());
8585 }
8586 }
8587 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008588 } finally {
8589 Binder.restoreCallingIdentity(identity);
8590 }
8591 }
8592
8593 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008594 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008595 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008596
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008597 final long identity = Binder.clearCallingIdentity();
8598 try {
8599 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8600 if (slots == null) {
8601 Rlog.i(LOG_TAG, "slots is null.");
8602 return null;
8603 }
8604
8605 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8606 for (int i = 0; i < slots.length; i++) {
8607 UiccSlot slot = slots[i];
8608 if (slot == null) {
8609 continue;
8610 }
8611
Jordan Liu7be7e652019-05-06 18:55:02 +00008612 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008613 UiccCard card = slot.getUiccCard();
8614 if (card != null) {
8615 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008616 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008617 cardId = slot.getEid();
8618 if (TextUtils.isEmpty(cardId)) {
8619 cardId = slot.getIccId();
8620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008621 }
8622
Jordan Liu857451f2019-05-09 16:35:35 -07008623 if (cardId != null) {
8624 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8625 // if cardId is an EID, it's all digits so this is fine
8626 cardId = IccUtils.stripTrailingFs(cardId);
8627 }
8628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008629 int cardState = 0;
8630 switch (slot.getCardState()) {
8631 case CARDSTATE_ABSENT:
8632 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8633 break;
8634 case CARDSTATE_PRESENT:
8635 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8636 break;
8637 case CARDSTATE_ERROR:
8638 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8639 break;
8640 case CARDSTATE_RESTRICTED:
8641 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8642 break;
8643 default:
8644 break;
8645
8646 }
8647
8648 infos[i] = new UiccSlotInfo(
8649 slot.isActive(),
8650 slot.isEuicc(),
8651 cardId,
8652 cardState,
8653 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008654 slot.isExtendedApduSupported(),
8655 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008656 }
8657 return infos;
8658 } finally {
8659 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008660 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008661 }
8662
8663 @Override
8664 public boolean switchSlots(int[] physicalSlots) {
8665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008666
8667 final long identity = Binder.clearCallingIdentity();
8668 try {
8669 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8670 } finally {
8671 Binder.restoreCallingIdentity(identity);
8672 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008673 }
Jack Yu4c988042018-02-27 15:30:01 -08008674
8675 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008676 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008677 final long identity = Binder.clearCallingIdentity();
8678 try {
8679 return UiccController.getInstance().getCardIdForDefaultEuicc();
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
8684
Pengquan Meng85728fb2018-03-12 16:31:21 -07008685 /**
goneil47ffb6e2018-04-06 15:40:58 -07008686 * A test API to reload the UICC profile.
8687 *
8688 * <p>Requires that the calling app has permission
8689 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8690 * @hide
8691 */
8692 @Override
8693 public void refreshUiccProfile(int subId) {
8694 enforceModifyPermission();
8695
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
8698 Phone phone = getPhone(subId);
8699 if (phone == null) {
8700 return;
8701 }
8702 UiccCard uiccCard = phone.getUiccCard();
8703 if (uiccCard == null) {
8704 return;
8705 }
8706 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8707 if (uiccProfile == null) {
8708 return;
8709 }
8710 uiccProfile.refresh();
8711 } finally {
8712 Binder.restoreCallingIdentity(identity);
8713 }
8714 }
8715
8716 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008717 * Returns false if the mobile data is disabled by default, otherwise return true.
8718 */
8719 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008720 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008721 }
8722
8723 /**
8724 * Returns true if the data roaming is enabled by default, i.e the system property
8725 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8726 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8727 */
8728 private boolean getDefaultDataRoamingEnabled(int subId) {
8729 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008730 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008731 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008732 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8733 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8734 return isDataRoamingEnabled;
8735 }
8736
8737 /**
8738 * Returns the default network type for the given {@code subId}, if the default network type is
8739 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8740 */
8741 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008742 List<Integer> list = TelephonyProperties.default_network();
8743 int phoneId = mSubscriptionController.getPhoneId(subId);
8744 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8745 return list.get(phoneId);
8746 }
8747 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008748 }
fionaxua13278b2018-03-21 00:08:13 -07008749
8750 @Override
8751 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008752 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008754
8755 final long identity = Binder.clearCallingIdentity();
8756 try {
8757 final Phone phone = getPhone(subId);
8758 if (phone == null) {
8759 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8760 return;
8761 }
chen xueaba88a2019-03-15 13:15:10 -07008762 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8763 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008764 if (carrierPrivilegeRules == null) {
8765 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8766 } else {
8767 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008769 } finally {
8770 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008771 }
fionaxua13278b2018-03-21 00:08:13 -07008772 }
8773
8774 @Override
8775 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008776 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008777
8778 final long identity = Binder.clearCallingIdentity();
8779 try {
8780 final Phone phone = getPhone(subId);
8781 if (phone == null) {
8782 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8783 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8784 }
8785 return phone.getCarrierIdListVersion();
8786 } finally {
8787 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008788 }
fionaxua13278b2018-03-21 00:08:13 -07008789 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008790
8791 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008792 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8793 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008795 mApp, subId, callingPackage, callingFeatureId,
8796 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008797 return -1;
8798 }
8799
8800 final long identity = Binder.clearCallingIdentity();
8801 try {
8802 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8803 } finally {
8804 Binder.restoreCallingIdentity(identity);
8805 }
8806 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008807
8808 @Override
8809 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008810 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008811 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008812 mApp, subId, "getCdmaRoamingMode");
8813
8814 final long identity = Binder.clearCallingIdentity();
8815 try {
8816 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8817 } finally {
8818 Binder.restoreCallingIdentity(identity);
8819 }
8820 }
8821
8822 @Override
8823 public boolean setCdmaRoamingMode(int subId, int mode) {
8824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8825 mApp, subId, "setCdmaRoamingMode");
8826
8827 final long identity = Binder.clearCallingIdentity();
8828 try {
8829 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8830 } finally {
8831 Binder.restoreCallingIdentity(identity);
8832 }
8833 }
8834
8835 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008836 public int getCdmaSubscriptionMode(int subId) {
8837 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008838 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008839 mApp, subId, "getCdmaSubscriptionMode");
8840
8841 final long identity = Binder.clearCallingIdentity();
8842 try {
8843 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8844 } finally {
8845 Binder.restoreCallingIdentity(identity);
8846 }
8847 }
8848
8849 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008850 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8852 mApp, subId, "setCdmaSubscriptionMode");
8853
8854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8857 } finally {
8858 Binder.restoreCallingIdentity(identity);
8859 }
8860 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008861
sqianc5eccab2018-10-19 18:46:41 -07008862 @Override
sqian8c685422019-02-22 15:55:18 -08008863 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008864 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008866 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8867 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008868 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8869 }
8870 final long identity = Binder.clearCallingIdentity();
8871 try {
sqian854d44b2018-12-12 16:48:18 -08008872 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8873 for (Phone phone: PhoneFactory.getPhones()) {
8874 if (phone.getEmergencyNumberTracker() != null
8875 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8876 emergencyNumberListInternal.put(
8877 phone.getSubId(),
8878 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8879 }
sqian11b7a0e2018-12-05 18:48:28 -08008880 }
sqian854d44b2018-12-12 16:48:18 -08008881 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008882 } finally {
8883 Binder.restoreCallingIdentity(identity);
8884 }
sqianc5eccab2018-10-19 18:46:41 -07008885 }
8886
8887 @Override
sqian8c685422019-02-22 15:55:18 -08008888 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008889 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008890 if (!exactMatch) {
8891 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008892 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008893 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008894 }
8895 final long identity = Binder.clearCallingIdentity();
8896 try {
sqian854d44b2018-12-12 16:48:18 -08008897 for (Phone phone: PhoneFactory.getPhones()) {
8898 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008899 && phone.getEmergencyNumberTracker()
8900 .isEmergencyNumber(number, exactMatch)) {
8901 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008902 }
sqian11b7a0e2018-12-05 18:48:28 -08008903 }
8904 return false;
8905 } finally {
8906 Binder.restoreCallingIdentity(identity);
8907 }
8908 }
8909
sqianf4ca7ed2019-01-15 18:32:07 -08008910 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008911 * Start emergency callback mode for GsmCdmaPhone for testing.
8912 */
8913 @Override
8914 public void startEmergencyCallbackMode() {
8915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8916 "startEmergencyCallbackMode");
8917 enforceModifyPermission();
8918 final long identity = Binder.clearCallingIdentity();
8919 try {
8920 for (Phone phone : PhoneFactory.getPhones()) {
8921 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8922 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8923 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8924 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8925 gsmCdmaPhone.obtainMessage(
8926 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8927 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8928 }
8929 }
8930 } finally {
8931 Binder.restoreCallingIdentity(identity);
8932 }
8933 }
8934
8935 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008936 * Update emergency number list for test mode.
8937 */
8938 @Override
8939 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8941 "updateEmergencyNumberListTestMode");
8942
8943 final long identity = Binder.clearCallingIdentity();
8944 try {
8945 for (Phone phone: PhoneFactory.getPhones()) {
8946 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8947 if (tracker != null) {
8948 tracker.executeEmergencyNumberTestModeCommand(action, num);
8949 }
8950 }
8951 } finally {
8952 Binder.restoreCallingIdentity(identity);
8953 }
8954 }
8955
8956 /**
8957 * Get the full emergency number list for test mode.
8958 */
8959 @Override
8960 public List<String> getEmergencyNumberListTestMode() {
8961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8962 "getEmergencyNumberListTestMode");
8963
8964 final long identity = Binder.clearCallingIdentity();
8965 try {
8966 Set<String> emergencyNumbers = new HashSet<>();
8967 for (Phone phone: PhoneFactory.getPhones()) {
8968 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8969 if (tracker != null) {
8970 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8971 emergencyNumbers.add(num.getNumber());
8972 }
8973 }
8974 }
8975 return new ArrayList<>(emergencyNumbers);
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
8978 }
8979 }
8980
chen xud6b45bd2018-10-30 22:27:10 -07008981 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008982 public int getEmergencyNumberDbVersion(int subId) {
8983 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8984
8985 final long identity = Binder.clearCallingIdentity();
8986 try {
8987 final Phone phone = getPhone(subId);
8988 if (phone == null) {
8989 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8990 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8991 }
8992 return phone.getEmergencyNumberDbVersion();
8993 } finally {
8994 Binder.restoreCallingIdentity(identity);
8995 }
8996 }
8997
8998 @Override
8999 public void notifyOtaEmergencyNumberDbInstalled() {
9000 enforceModifyPermission();
9001
9002 final long identity = Binder.clearCallingIdentity();
9003 try {
9004 for (Phone phone: PhoneFactory.getPhones()) {
9005 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9006 if (tracker != null) {
9007 tracker.updateOtaEmergencyNumberDatabase();
9008 }
9009 }
9010 } finally {
9011 Binder.restoreCallingIdentity(identity);
9012 }
9013 }
9014
9015 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009016 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009017 enforceActiveEmergencySessionPermission();
9018
9019 final long identity = Binder.clearCallingIdentity();
9020 try {
9021 for (Phone phone: PhoneFactory.getPhones()) {
9022 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9023 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009024 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9025 }
9026 }
9027 } finally {
9028 Binder.restoreCallingIdentity(identity);
9029 }
9030 }
9031
9032 @Override
9033 public void resetOtaEmergencyNumberDbFilePath() {
9034 enforceActiveEmergencySessionPermission();
9035
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
9038 for (Phone phone: PhoneFactory.getPhones()) {
9039 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9040 if (tracker != null) {
9041 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009042 }
9043 }
9044 } finally {
9045 Binder.restoreCallingIdentity(identity);
9046 }
9047 }
9048
9049 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009050 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9051 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9052 Phone phone = getPhone(subId);
9053 if (phone == null) {
9054 return null;
9055 }
9056 final long identity = Binder.clearCallingIdentity();
9057 try {
9058 UiccProfile profile = UiccController.getInstance()
9059 .getUiccProfileForPhone(phone.getPhoneId());
9060 if (profile != null) {
9061 return profile.getCertsFromCarrierPrivilegeAccessRules();
9062 }
9063 } finally {
9064 Binder.restoreCallingIdentity(identity);
9065 }
9066 return null;
9067 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009068
9069 /**
9070 * Enable or disable a modem stack.
9071 */
9072 @Override
9073 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9074 enforceModifyPermission();
9075
9076 final long identity = Binder.clearCallingIdentity();
9077 try {
9078 Phone phone = PhoneFactory.getPhone(slotIndex);
9079 if (phone == null) {
9080 return false;
9081 } else {
9082 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9083 }
9084 } finally {
9085 Binder.restoreCallingIdentity(identity);
9086 }
9087 }
Michelecea4cf22018-12-21 15:00:11 -08009088
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009089 /**
9090 * Whether a modem stack is enabled or not.
9091 */
9092 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009093 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9094 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009095 Phone phone = PhoneFactory.getPhone(slotIndex);
9096 if (phone == null) return false;
9097
9098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009099 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9100 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009101 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9102 }
9103
9104 final long identity = Binder.clearCallingIdentity();
9105 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009106 try {
9107 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9108 } catch (NoSuchElementException ex) {
9109 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9110 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009111 } finally {
9112 Binder.restoreCallingIdentity(identity);
9113 }
9114 }
9115
Michelecea4cf22018-12-21 15:00:11 -08009116 @Override
Michele0ea7d782019-03-19 14:58:42 -07009117 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009118 enforceModifyPermission();
9119
9120 final long identity = Binder.clearCallingIdentity();
9121 try {
9122 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009123 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009124 .commit();
9125 } finally {
9126 Binder.restoreCallingIdentity(identity);
9127 }
9128 }
9129
9130 @Override
Michele0ea7d782019-03-19 14:58:42 -07009131 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009132 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009134 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9135 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009136 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009137 }
Michelecea4cf22018-12-21 15:00:11 -08009138
9139 final long identity = Binder.clearCallingIdentity();
9140 try {
Michele0ea7d782019-03-19 14:58:42 -07009141 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009142 } finally {
9143 Binder.restoreCallingIdentity(identity);
9144 }
9145 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009146
Michele0ea7d782019-03-19 14:58:42 -07009147 @TelephonyManager.IsMultiSimSupportedResult
9148 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009149 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9150 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9151 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009152 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9153 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009154 }
9155 // Check if the hardware supports multisim functionality. If usage of multisim is not
9156 // supported by the modem, indicate that it is restricted.
9157 PhoneCapability staticCapability =
9158 mPhoneConfigurationManager.getStaticPhoneCapability();
9159 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009160 loge("isMultiSimSupportedInternal: no static configuration available");
9161 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009162 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009163 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009164 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9165 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009166 }
9167 // Check if support of multiple SIMs is restricted by carrier
9168 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009169 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009170 }
9171
Michele0ea7d782019-03-19 14:58:42 -07009172 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009173 }
9174
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009175 /**
9176 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009177 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9178 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9179 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009180 * @param numOfSims number of active sims we want to switch to
9181 */
9182 @Override
9183 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009184 if (numOfSims == 1) {
9185 enforceModifyPermission();
9186 } else {
9187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9188 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9189 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009190 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009191
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009192 try {
Michele30b57b22019-03-01 12:01:14 -08009193 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009194 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009195 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9196 return;
9197 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009198 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9199 } finally {
9200 Binder.restoreCallingIdentity(identity);
9201 }
9202 }
9203
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009204 @Override
9205 public boolean isApplicationOnUicc(int subId, int appType) {
9206 enforceReadPrivilegedPermission("isApplicationOnUicc");
9207 Phone phone = getPhone(subId);
9208 if (phone == null) {
9209 return false;
9210 }
9211 final long identity = Binder.clearCallingIdentity();
9212 try {
9213 UiccCard uiccCard = phone.getUiccCard();
9214 if (uiccCard == null) {
9215 return false;
9216 }
9217 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9218 if (uiccProfile == null) {
9219 return false;
9220 }
9221 if (TelephonyManager.APPTYPE_SIM <= appType
9222 && appType <= TelephonyManager.APPTYPE_ISIM) {
9223 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9224 }
9225 return false;
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
9228 }
9229 }
9230
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009231 /**
chen xub4baa772019-04-03 10:23:41 -07009232 * Get whether making changes to modem configurations will trigger reboot.
9233 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009234 */
9235 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009236 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9237 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009239 mApp, subId, callingPackage, callingFeatureId,
9240 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009241 return false;
9242 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009243 final long identity = Binder.clearCallingIdentity();
9244 try {
9245 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9246 } finally {
9247 Binder.restoreCallingIdentity(identity);
9248 }
9249 }
9250
Nathan Harold29f5f052019-02-15 13:41:57 -08009251 private void updateModemStateMetrics() {
9252 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9253 // TODO: check the state for each modem if the api is ready.
9254 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9255 }
9256
Pengquan Meng3889a572019-01-23 11:16:29 -08009257 @Override
9258 public int[] getSlotsMapping() {
9259 enforceReadPrivilegedPermission("getSlotsMapping");
9260
9261 final long identity = Binder.clearCallingIdentity();
9262 try {
9263 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9264 // All logical slots should have a mapping to a physical slot.
9265 int[] logicalSlotsMapping = new int[phoneCount];
9266 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9267 for (int i = 0; i < slotInfos.length; i++) {
9268 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9269 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9270 }
9271 }
9272 return logicalSlotsMapping;
9273 } finally {
9274 Binder.restoreCallingIdentity(identity);
9275 }
9276 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009277
9278 /**
9279 * Get the IRadio HAL Version
9280 */
9281 @Override
9282 public int getRadioHalVersion() {
9283 Phone phone = getDefaultPhone();
9284 if (phone == null) return -1;
9285 HalVersion hv = phone.getHalVersion();
9286 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9287 return hv.major * 100 + hv.minor;
9288 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009289
9290 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009291 * Get the current calling package name.
9292 * @return the current calling package name
9293 */
9294 @Override
9295 public String getCurrentPackageName() {
9296 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9297 }
9298
9299 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009300 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9301 * corresponding network requests on a subId.
9302 *
9303 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009304 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009305 * 2) APN is un-metered for this subscription, or
9306 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009307 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009308 *
9309 * @return whether data is allowed for a apn type.
9310 *
9311 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009312 */
9313 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009314 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009315 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9316 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009317
9318 // Now that all security checks passes, perform the operation as ourselves.
9319 final long identity = Binder.clearCallingIdentity();
9320 try {
9321 Phone phone = getPhone(subId);
9322 if (phone == null) return false;
9323
Jack Yu41407ee2019-05-13 16:54:09 -07009324 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009325 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9326 } finally {
9327 Binder.restoreCallingIdentity(identity);
9328 }
9329 }
9330
9331 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009332 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009333 enforceReadPrivilegedPermission("isApnMetered");
9334
9335 // Now that all security checks passes, perform the operation as ourselves.
9336 final long identity = Binder.clearCallingIdentity();
9337 try {
9338 Phone phone = getPhone(subId);
9339 if (phone == null) return true; // By default return true.
9340
Jack Yu41407ee2019-05-13 16:54:09 -07009341 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009342 } finally {
9343 Binder.restoreCallingIdentity(identity);
9344 }
9345 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009346
9347 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009348 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9349 int subscriptionId, IBooleanConsumer resultCallback) {
9350 enforceModifyPermission();
9351 long token = Binder.clearCallingIdentity();
9352 try {
9353 Phone phone = getPhone(subscriptionId);
9354 if (phone == null) {
9355 try {
9356 if (resultCallback != null) {
9357 resultCallback.accept(false);
9358 }
9359 } catch (RemoteException e) {
9360 // ignore
9361 }
9362 return;
9363 }
9364 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9365 Pair.create(specifiers, (x) -> {
9366 try {
9367 if (resultCallback != null) {
9368 resultCallback.accept(x);
9369 }
9370 } catch (RemoteException e) {
9371 // ignore
9372 }
9373 });
9374 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9375 } finally {
9376 Binder.restoreCallingIdentity(token);
9377 }
9378 }
9379
9380 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009381 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9382 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009383 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009384 mApp, subId, "getSystemSelectionChannels");
9385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9386 final long identity = Binder.clearCallingIdentity();
9387 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009388 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9389 if (result instanceof IllegalStateException) {
9390 throw (IllegalStateException) result;
9391 }
9392 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009393 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9394 return specifiers;
9395 } finally {
9396 Binder.restoreCallingIdentity(identity);
9397 }
9398 }
9399
9400 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009401 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009402 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009403 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9404 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9405 if (iccRecords == null) {
9406 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9407 return false;
9408 }
9409 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9410 }
9411
9412 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009413 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9414 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009415 if (callingPackage == null) {
9416 callingPackage = getCurrentPackageName();
9417 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009418 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9419 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009420 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9421 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009422 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9423 }
9424 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9425 Intent intent = new Intent();
9426 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9427 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9428 // Bring up choose default SMS subscription dialog right now
9429 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9430 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9431 mApp.startActivity(intent);
9432 }
chen xud5ca2d52019-05-28 15:20:57 -07009433
9434 @Override
9435 public String getMmsUAProfUrl(int subId) {
9436 //TODO investigate if this API should require proper permission check in R b/133791609
9437 final long identity = Binder.clearCallingIdentity();
9438 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009439 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9440 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9441 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9442 return carrierUAProfUrl;
9443 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009444 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9445 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009446 } finally {
9447 Binder.restoreCallingIdentity(identity);
9448 }
9449 }
9450
9451 @Override
9452 public String getMmsUserAgent(int subId) {
9453 //TODO investigate if this API should require proper permission check in R b/133791609
9454 final long identity = Binder.clearCallingIdentity();
9455 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009456 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9457 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9458 if (!TextUtils.isEmpty(carrierUserAgent)) {
9459 return carrierUserAgent;
9460 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009461 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9462 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009463 } finally {
9464 Binder.restoreCallingIdentity(identity);
9465 }
9466 }
Jack Yub07d4972019-05-28 16:12:25 -07009467
9468 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009469 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9470 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009471
Jack Yub07d4972019-05-28 16:12:25 -07009472 final long identity = Binder.clearCallingIdentity();
9473 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009474 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009475 if (phone == null) return false;
9476
Hall Liua62f5da2020-09-25 10:42:19 -07009477 switch (policy) {
9478 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9479 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9480 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9481 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9482 default:
9483 throw new IllegalArgumentException(policy + " is not a valid policy");
9484 }
Jack Yub07d4972019-05-28 16:12:25 -07009485 } finally {
9486 Binder.restoreCallingIdentity(identity);
9487 }
9488 }
9489
9490 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009491 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009492 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009493 enforceModifyPermission();
9494
changbettyd5c246e2019-12-24 15:40:37 +08009495 final long identity = Binder.clearCallingIdentity();
9496 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009497 Phone phone = getPhone(subscriptionId);
9498 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009499
Hall Liua62f5da2020-09-25 10:42:19 -07009500 switch (policy) {
9501 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9502 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9503 break;
9504 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9505 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9506 break;
9507 default:
9508 throw new IllegalArgumentException(policy + " is not a valid policy");
9509 }
changbettyd5c246e2019-12-24 15:40:37 +08009510 } finally {
9511 Binder.restoreCallingIdentity(identity);
9512 }
9513 }
9514
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009515 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009516 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009517 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9518 * otherwise.
9519 */
9520 @Override
9521 public void setCepEnabled(boolean isCepEnabled) {
9522 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9523
9524 final long identity = Binder.clearCallingIdentity();
9525 try {
9526 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9527 for (Phone phone : PhoneFactory.getPhones()) {
9528 Phone defaultPhone = phone.getImsPhone();
9529 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9530 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9531 ImsPhoneCallTracker imsPhoneCallTracker =
9532 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9533 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9534 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9535 + imsPhone.getMsisdn());
9536 }
9537 }
9538 } finally {
9539 Binder.restoreCallingIdentity(identity);
9540 }
9541 }
allenwtsu46dcc572020-01-08 18:24:03 +08009542
9543 /**
9544 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9545 *
9546 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9547 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9548 * before being read.
9549 */
9550 @Override
9551 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9552 isCompressed) {
9553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9554 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009555 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9556 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9557 }
9558 if (!isImsAvailableOnDevice()) {
9559 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9560 "IMS not available on device.");
9561 }
9562
9563 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009564 try {
Hui Wang761a6682020-10-31 05:12:53 +00009565 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9566 } finally {
9567 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009568 }
9569 }
zoey chene02881a2019-12-30 16:11:23 +08009570
9571 @Override
9572 public boolean isIccLockEnabled(int subId) {
9573 enforceReadPrivilegedPermission("isIccLockEnabled");
9574
9575 // Now that all security checks passes, perform the operation as ourselves.
9576 final long identity = Binder.clearCallingIdentity();
9577 try {
9578 Phone phone = getPhone(subId);
9579 if (phone != null && phone.getIccCard() != null) {
9580 return phone.getIccCard().getIccLockEnabled();
9581 } else {
9582 return false;
9583 }
9584 } finally {
9585 Binder.restoreCallingIdentity(identity);
9586 }
9587 }
9588
9589 /**
9590 * Set the ICC pin lock enabled or disabled.
9591 *
9592 * @return an integer representing the status of IccLock enabled or disabled in the following
9593 * three cases:
9594 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9595 * successfully.
9596 * - Positive number and zero for remaining password attempts.
9597 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9598 *
9599 */
9600 @Override
9601 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9602 enforceModifyPermission();
9603
9604 Phone phone = getPhone(subId);
9605 if (phone == null) {
9606 return 0;
9607 }
9608 // Now that all security checks passes, perform the operation as ourselves.
9609 final long identity = Binder.clearCallingIdentity();
9610 try {
9611 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9612 new Pair<Boolean, String>(enabled, password), phone, null);
9613 return attemptsRemaining;
9614
9615 } catch (Exception e) {
9616 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9617 } finally {
9618 Binder.restoreCallingIdentity(identity);
9619 }
9620 return 0;
9621 }
9622
9623 /**
9624 * Change the ICC password used in ICC pin lock.
9625 *
9626 * @return an integer representing the status of IccLock changed in the following three cases:
9627 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9628 * - Positive number and zero for remaining password attempts.
9629 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9630 *
9631 */
9632 @Override
9633 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9634 enforceModifyPermission();
9635
9636 Phone phone = getPhone(subId);
9637 if (phone == null) {
9638 return 0;
9639 }
9640 // Now that all security checks passes, perform the operation as ourselves.
9641 final long identity = Binder.clearCallingIdentity();
9642 try {
9643 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9644 new Pair<String, String>(oldPassword, newPassword), phone, null);
9645 return attemptsRemaining;
9646
9647 } catch (Exception e) {
9648 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9649 } finally {
9650 Binder.restoreCallingIdentity(identity);
9651 }
9652 return 0;
9653 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009654
9655 /**
9656 * Request for receiving user activity notification
9657 */
9658 @Override
9659 public void requestUserActivityNotification() {
9660 if (!mNotifyUserActivity.get()
9661 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9662 mNotifyUserActivity.set(true);
9663 }
9664 }
9665
9666 /**
9667 * Called when userActivity is signalled in the power manager.
9668 * This is safe to call from any thread, with any window manager locks held or not.
9669 */
9670 @Override
9671 public void userActivity() {
9672 // ***************************************
9673 // * Inherited from PhoneWindowManager *
9674 // ***************************************
9675 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9676 // WITH ITS LOCKS HELD.
9677 //
9678 // This code must be VERY careful about the locks
9679 // it acquires.
9680 // In fact, the current code acquires way too many,
9681 // and probably has lurking deadlocks.
9682
9683 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9684 throw new SecurityException("Only the OS may call notifyUserActivity()");
9685 }
9686
9687 if (mNotifyUserActivity.getAndSet(false)) {
9688 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9689 USER_ACTIVITY_NOTIFICATION_DELAY);
9690 }
9691 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009692
9693 @Override
9694 public boolean canConnectTo5GInDsdsMode() {
9695 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9696 }
Jack Yud10cdd42020-09-28 20:28:01 -07009697
9698 @Override
9699 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9700 String callingFeatureId) {
9701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9702 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9703 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9704 }
9705
9706 Phone phone = getPhone(subId);
9707 if (phone == null) {
9708 throw new RuntimeException("phone is not available");
9709 }
9710 // Now that all security checks passes, perform the operation as ourselves.
9711 final long identity = Binder.clearCallingIdentity();
9712 try {
9713 return phone.getEquivalentHomePlmns();
9714 } finally {
9715 Binder.restoreCallingIdentity(identity);
9716 }
9717 }
Daniel Bright59e67312020-11-13 11:49:37 -08009718
9719 @Override
9720 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009721 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9722 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009723 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009724 if (radioInterfaceCapabilities == null) {
9725 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009726 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009727 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009728 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009729
Hui Wang641e81c2020-10-12 12:14:23 -07009730 @Override
9731 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9732 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009733 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9734 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9735 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9736 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9737 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009738 if (DBG) {
9739 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9740 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9741 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9742 }
9743
9744 if (!SubscriptionManager.isValidSubscriptionId(subId)
9745 || appType < TelephonyManager.APPTYPE_UNKNOWN
9746 || appType > TelephonyManager.APPTYPE_ISIM
9747 || nafUrl == null || securityProtocol == null || callback == null) {
9748 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9749 if (callback != null) {
9750 try {
9751 callback.onAuthenticationFailure(
9752 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9753 } catch (RemoteException exception) {
9754 log("Fail to notify onAuthenticationFailure due to " + exception);
9755 }
9756 return;
9757 }
9758 }
9759
9760 final long token = Binder.clearCallingIdentity();
9761 try {
9762 getGbaManager(subId).bootstrapAuthenticationRequest(
9763 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9764 forceBootStrapping, callback));
9765 } finally {
9766 Binder.restoreCallingIdentity(token);
9767 }
9768 }
9769
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009770 /**
9771 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9772 * requested radio power state will actually be set. See {@link
9773 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9774 *
9775 * @param subId the subscription ID of the phone requesting to set the radio power state.
9776 * @param enable {@code true} if trying to turn radio on.
9777 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9778 * false}.
9779 */
9780 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9781 Phone phone = getPhone(subId);
9782 if (phone != null) {
9783 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9784 return true;
9785 }
9786 return false;
9787 }
9788
9789 private int handleDataThrottlingRequest(int subId,
9790 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009791 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9792 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9793 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9794 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9795 throw new IllegalArgumentException("modem does not support data throttling");
9796 }
9797
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009798 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9799 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9800 if (!setRadioPowerForThermal(subId, true)) {
9801 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9802 }
9803
9804 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9805
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009806 if (isDataThrottlingSupported) {
9807 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009808 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009809 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9810 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9811 } else if (thermalMitigationResult
9812 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009813 log("Modem likely does not support data throttling on secondary carrier. Data " +
9814 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9815 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009816 }
9817 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009818 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009819
9820 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009821 }
9822
Jack Nudelman644b91a2021-03-12 14:09:48 -08009823 private static List<String> getThermalMitigationAllowlist(Context context) {
9824 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9825 for (String pckg : context.getResources()
9826 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9827 sThermalMitigationAllowlistedPackages.add(pckg);
9828 }
9829 }
9830
9831 return sThermalMitigationAllowlistedPackages;
9832 }
9833
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009834 private boolean isAnyPhoneInEmergencyState() {
9835 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9836 if (tm.isInEmergencyCall()) {
9837 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9838 return true;
9839 }
9840 for (Phone phone : PhoneFactory.getPhones()) {
9841 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9842 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9843 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9844 + phone.isInEcm());
9845 return true;
9846 }
9847 }
9848
9849 return false;
9850 }
9851
Jack Nudelman644b91a2021-03-12 14:09:48 -08009852 /**
9853 * Used by shell commands to add an authorized package name for thermal mitigation.
9854 * @param packageName name of package to be allowlisted
9855 * @param context
9856 */
9857 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9858 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9859 sThermalMitigationAllowlistedPackages.add(packageName);
9860 }
9861
9862 /**
9863 * Used by shell commands to remove an authorized package name for thermal mitigation.
9864 * @param packageName name of package to remove from allowlist
9865 * @param context
9866 */
9867 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9868 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9869 sThermalMitigationAllowlistedPackages.remove(packageName);
9870 }
9871
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009872 /**
9873 * Thermal mitigation request to control functionalities at modem.
9874 *
9875 * @param subId the id of the subscription.
9876 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009877 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009878 *
9879 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9880 */
9881 @Override
9882 @ThermalMitigationResult
9883 public int sendThermalMitigationRequest(
9884 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009885 ThermalMitigationRequest thermalMitigationRequest,
9886 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009887 enforceModifyPermission();
9888
Jack Nudelman644b91a2021-03-12 14:09:48 -08009889 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9890 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9891 .contains(callingPackage)) {
9892 throw new SecurityException("Calling package must be configured in the device config. "
9893 + "calling package: " + callingPackage);
9894 }
9895
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009896 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9897 final long identity = Binder.clearCallingIdentity();
9898
9899 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9900 try {
9901 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9902 switch (thermalMitigationAction) {
9903 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9904 thermalMitigationResult =
9905 handleDataThrottlingRequest(subId,
9906 thermalMitigationRequest.getDataThrottlingRequest());
9907 break;
9908 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9909 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9910 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9911 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9912 }
9913
9914 // Ensure that radio is on. If not able to power on due to phone being
9915 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9916 if (!setRadioPowerForThermal(subId, true)) {
9917 thermalMitigationResult =
9918 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9919 break;
9920 }
9921
9922 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9923 false);
9924 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9925 break;
9926 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9927 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9928 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9929 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9930 }
9931
9932 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9933 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009934 Phone phone = getPhone(subId);
9935 if (phone == null) {
9936 thermalMitigationResult =
9937 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9938 break;
9939 }
9940
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009941 TelephonyConnectionService service =
9942 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -07009943 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009944 Log.e(LOG_TAG, "An emergency call is pending");
9945 thermalMitigationResult =
9946 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9947 break;
9948 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009949 thermalMitigationResult =
9950 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9951 break;
9952 }
9953 } else {
9954 thermalMitigationResult =
9955 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9956 break;
9957 }
9958
9959 // Turn radio off. If not able to power off due to phone being unavailable,
9960 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9961 if (!setRadioPowerForThermal(subId, false)) {
9962 thermalMitigationResult =
9963 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9964 break;
9965 }
9966 thermalMitigationResult =
9967 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9968 break;
9969 default:
9970 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9971 + "not exist. Requested action: " + thermalMitigationAction);
9972 }
9973 } catch (IllegalArgumentException e) {
9974 throw e;
9975 } catch (Exception e) {
9976 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9977 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9978 } finally {
9979 Binder.restoreCallingIdentity(identity);
9980 }
9981
9982 if (DBG) {
9983 log("thermalMitigationRequest returning with thermalMitigationResult: "
9984 + thermalMitigationResult);
9985 }
9986
9987 return thermalMitigationResult;
9988 }
Hui Wang641e81c2020-10-12 12:14:23 -07009989
9990 /**
9991 * Set the GbaService Package Name that Telephony will bind to.
9992 *
9993 * @param subId The sim that the GbaService is associated with.
9994 * @param packageName The name of the package to be replaced with.
9995 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9996 */
9997 @Override
9998 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9999 enforceModifyPermission();
10000
10001 final long identity = Binder.clearCallingIdentity();
10002 try {
10003 return getGbaManager(subId).overrideServicePackage(packageName);
10004 } finally {
10005 Binder.restoreCallingIdentity(identity);
10006 }
10007 }
10008
10009 /**
10010 * Return the package name of the currently bound GbaService.
10011 *
10012 * @param subId The sim that the GbaService is associated with.
10013 * @return the package name of the GbaService configuration, null if GBA is not supported.
10014 */
10015 @Override
10016 public String getBoundGbaService(int subId) {
10017 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10018
10019 final long identity = Binder.clearCallingIdentity();
10020 try {
10021 return getGbaManager(subId).getServicePackage();
10022 } finally {
10023 Binder.restoreCallingIdentity(identity);
10024 }
10025 }
10026
10027 /**
10028 * Set the release time for telephony to unbind GbaService.
10029 *
10030 * @param subId The sim that the GbaService is associated with.
10031 * @param interval The release time to unbind GbaService by millisecond.
10032 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10033 */
10034 @Override
10035 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10036 enforceModifyPermission();
10037
10038 final long identity = Binder.clearCallingIdentity();
10039 try {
10040 return getGbaManager(subId).overrideReleaseTime(interval);
10041 } finally {
10042 Binder.restoreCallingIdentity(identity);
10043 }
10044 }
10045
10046 /**
10047 * Return the release time for telephony to unbind GbaService.
10048 *
10049 * @param subId The sim that the GbaService is associated with.
10050 * @return The release time to unbind GbaService by millisecond.
10051 */
10052 @Override
10053 public int getGbaReleaseTime(int subId) {
10054 enforceReadPrivilegedPermission("getGbaReleaseTime");
10055
10056 final long identity = Binder.clearCallingIdentity();
10057 try {
10058 return getGbaManager(subId).getReleaseTime();
10059 } finally {
10060 Binder.restoreCallingIdentity(identity);
10061 }
10062 }
10063
10064 private GbaManager getGbaManager(int subId) {
10065 GbaManager instance = GbaManager.getInstance(subId);
10066 if (instance == null) {
10067 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10068 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10069 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10070 }
10071 return instance;
10072 }
Hui Wang761a6682020-10-31 05:12:53 +000010073
10074 /**
10075 * indicate whether the device and the carrier can support
10076 * RCS VoLTE single registration.
10077 */
10078 @Override
10079 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010080 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10081 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10082 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10083 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010084
10085 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10086 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10087 }
10088
10089 final long identity = Binder.clearCallingIdentity();
10090 try {
10091 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10092 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010093 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10094 if (isCapable != null) {
10095 return isCapable;
10096 }
Hui Wang761a6682020-10-31 05:12:53 +000010097 }
Hui Wang67af90e2021-06-04 16:57:15 -070010098 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10099 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010100 } finally {
10101 Binder.restoreCallingIdentity(identity);
10102 }
10103 }
10104
10105 /**
10106 * Register RCS provisioning callback.
10107 */
10108 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010109 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010110 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010111 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010112 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010113 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10114 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010115
10116 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10117 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10118 }
10119 if (!isImsAvailableOnDevice()) {
10120 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10121 "IMS not available on device.");
10122 }
10123
10124 final long identity = Binder.clearCallingIdentity();
10125 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010126 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010127 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010128 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10129 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010130 }
Hui Wang761a6682020-10-31 05:12:53 +000010131 } finally {
10132 Binder.restoreCallingIdentity(identity);
10133 }
10134 }
10135
10136 /**
10137 * Unregister RCS provisioning callback.
10138 */
10139 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010140 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010141 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010142 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010143 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010144 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10145 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010146
10147 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10148 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10149 }
10150 if (!isImsAvailableOnDevice()) {
10151 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10152 "IMS not available on device.");
10153 }
10154
10155 final long identity = Binder.clearCallingIdentity();
10156 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010157 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010158 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010159 } finally {
10160 Binder.restoreCallingIdentity(identity);
10161 }
10162 }
10163
10164 /**
10165 * trigger RCS reconfiguration.
10166 */
10167 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010168 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10169 "triggerRcsReconfiguration",
10170 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010171
10172 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10173 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10174 }
10175 if (!isImsAvailableOnDevice()) {
10176 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10177 "IMS not available on device.");
10178 }
10179
10180 final long identity = Binder.clearCallingIdentity();
10181 try {
10182 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10183 } finally {
10184 Binder.restoreCallingIdentity(identity);
10185 }
10186 }
10187
10188 /**
10189 * Provide the client configuration parameters of the RCS application.
10190 */
10191 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010192 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10193 "setRcsClientConfiguration",
10194 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010195
10196 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10197 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10198 }
10199 if (!isImsAvailableOnDevice()) {
10200 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10201 "IMS not available on device.");
10202 }
10203
10204 final long identity = Binder.clearCallingIdentity();
10205
10206 try {
10207 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10208 if (configBinder == null) {
10209 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010210 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10211 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010212 } else {
10213 configBinder.setRcsClientConfiguration(rcc);
10214 }
10215 } catch (RemoteException e) {
10216 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010217 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10218 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010219 } finally {
10220 Binder.restoreCallingIdentity(identity);
10221 }
10222 }
10223
10224 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010225 * Enables or disables the test mode for RCS VoLTE single registration.
10226 */
10227 @Override
10228 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10229 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10230 "setRcsSingleRegistrationTestModeEnabled");
10231
10232 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10233 }
10234
10235 /**
10236 * Gets the test mode for RCS VoLTE single registration.
10237 */
10238 @Override
10239 public boolean getRcsSingleRegistrationTestModeEnabled() {
10240 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10241 "getRcsSingleRegistrationTestModeEnabled");
10242
10243 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10244 }
10245
10246 /**
Hui Wang761a6682020-10-31 05:12:53 +000010247 * Overrides the config of RCS VoLTE single registration enabled for the device.
10248 */
10249 @Override
10250 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10252 "setDeviceSingleRegistrationEnabledOverride");
10253 enforceModifyPermission();
10254
10255 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10256 : Boolean.parseBoolean(enabledStr);
10257 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010258 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010259 }
10260
10261 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010262 * Sends a device to device communication message. Only usable via shell.
10263 * @param message message to send.
10264 * @param value message value.
10265 */
10266 @Override
10267 public void sendDeviceToDeviceMessage(int message, int value) {
10268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010269 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010270 enforceModifyPermission();
10271
10272 final long identity = Binder.clearCallingIdentity();
10273 try {
10274 TelephonyConnectionService service =
10275 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10276 if (service == null) {
10277 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10278 return;
10279 }
10280 service.sendTestDeviceToDeviceMessage(message, value);
10281 } finally {
10282 Binder.restoreCallingIdentity(identity);
10283 }
10284 }
10285
Tyler Gunnbabbda02021-02-10 11:05:02 -080010286 /**
10287 * Sets the specified device to device transport active.
10288 * @param transport The transport to set active.
10289 */
10290 @Override
10291 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10292 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10293 "setActiveDeviceToDeviceTransport");
10294 enforceModifyPermission();
10295
10296 final long identity = Binder.clearCallingIdentity();
10297 try {
10298 TelephonyConnectionService service =
10299 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10300 if (service == null) {
10301 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10302 return;
10303 }
10304 service.setActiveDeviceToDeviceTransport(transport);
10305 } finally {
10306 Binder.restoreCallingIdentity(identity);
10307 }
10308 }
Tyler Gunn92479152021-01-20 16:30:10 -080010309
Tyler Gunnd4575212021-05-03 14:46:49 -070010310 @Override
10311 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10312 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10313 "setDeviceToDeviceForceEnabled");
10314
10315 final long identity = Binder.clearCallingIdentity();
10316 try {
10317 Arrays.stream(PhoneFactory.getPhones()).forEach(
10318 p -> {
10319 Phone thePhone = p.getImsPhone();
10320 if (thePhone != null && thePhone instanceof ImsPhone) {
10321 ImsPhone imsPhone = (ImsPhone) thePhone;
10322 CallTracker tracker = imsPhone.getCallTracker();
10323 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10324 ImsPhoneCallTracker imsPhoneCallTracker =
10325 (ImsPhoneCallTracker) tracker;
10326 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10327 }
10328 }
10329 }
10330 );
10331 } finally {
10332 Binder.restoreCallingIdentity(identity);
10333 }
10334 }
10335
Tyler Gunn92479152021-01-20 16:30:10 -080010336 /**
Hui Wang761a6682020-10-31 05:12:53 +000010337 * Gets the config of RCS VoLTE single registration enabled for the device.
10338 */
10339 @Override
10340 public boolean getDeviceSingleRegistrationEnabled() {
10341 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10342 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10343 }
10344
10345 /**
10346 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10347 */
10348 @Override
10349 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10350 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10351 "setCarrierSingleRegistrationEnabledOverride");
10352 enforceModifyPermission();
10353
10354 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10355 : Boolean.parseBoolean(enabledStr);
10356 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10357 subId, enabled);
10358 }
10359
10360 /**
10361 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10362 */
10363 @Override
10364 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10365 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10366 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10367 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010368
10369 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010370 * Overrides the ims feature validation result
10371 */
10372 @Override
10373 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10374 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10375 "setImsFeatureValidationOverride");
10376
10377 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10378 : Boolean.parseBoolean(enabledStr);
10379 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10380 subId, enabled);
10381 }
10382
10383 /**
10384 * Gets the ims feature validation override value
10385 */
10386 @Override
10387 public boolean getImsFeatureValidationOverride(int subId) {
10388 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10389 "getImsFeatureValidationOverride");
10390 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10391 }
10392
10393 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010394 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10395 * their mobile plan.
10396 */
10397 @Override
10398 public String getMobileProvisioningUrl() {
10399 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10400 final long identity = Binder.clearCallingIdentity();
10401 try {
10402 return getDefaultPhone().getMobileProvisioningUrl();
10403 } finally {
10404 Binder.restoreCallingIdentity(identity);
10405 }
10406 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010407
James.cf Linbcdf8b32021-01-14 16:44:13 +080010408 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010409 * Get the EAB contact from the EAB database.
10410 */
10411 @Override
10412 public String getContactFromEab(String contact) {
10413 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10414 enforceModifyPermission();
10415 final long identity = Binder.clearCallingIdentity();
10416 try {
10417 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10418 } finally {
10419 Binder.restoreCallingIdentity(identity);
10420 }
10421 }
10422
10423 /**
Calvin Pana1434322021-07-01 19:27:01 +080010424 * Get the EAB capability from the EAB database.
10425 */
10426 @Override
10427 public String getCapabilityFromEab(String contact) {
10428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10429 enforceModifyPermission();
10430 final long identity = Binder.clearCallingIdentity();
10431 try {
10432 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10433 } finally {
10434 Binder.restoreCallingIdentity(identity);
10435 }
10436 }
10437
10438 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010439 * Remove the EAB contacts from the EAB database.
10440 */
10441 @Override
10442 public int removeContactFromEab(int subId, String contacts) {
10443 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10444 enforceModifyPermission();
10445 final long identity = Binder.clearCallingIdentity();
10446 try {
10447 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10448 } finally {
10449 Binder.restoreCallingIdentity(identity);
10450 }
10451 }
10452
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010453 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010454 public boolean getDeviceUceEnabled() {
10455 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10456 final long identity = Binder.clearCallingIdentity();
10457 try {
10458 return mApp.getDeviceUceEnabled();
10459 } finally {
10460 Binder.restoreCallingIdentity(identity);
10461 }
10462 }
10463
10464 @Override
10465 public void setDeviceUceEnabled(boolean isEnabled) {
10466 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10467 final long identity = Binder.clearCallingIdentity();
10468 try {
10469 mApp.setDeviceUceEnabled(isEnabled);
10470 } finally {
10471 Binder.restoreCallingIdentity(identity);
10472 }
10473 }
10474
Brad Ebinger14d467f2021-02-12 06:18:28 +000010475 /**
10476 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10477 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10478 */
10479 // Used for SHELL command only right now.
10480 @Override
10481 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10482 List<String> featureTags) {
10483 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10484 "addUceRegistrationOverrideShell");
10485 final long identity = Binder.clearCallingIdentity();
10486 try {
10487 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10488 new ArraySet<>(featureTags));
10489 } catch (ImsException e) {
10490 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10491 } finally {
10492 Binder.restoreCallingIdentity(identity);
10493 }
10494 }
10495
10496 /**
10497 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10498 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10499 */
10500 // Used for SHELL command only right now.
10501 @Override
10502 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10503 List<String> featureTags) {
10504 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10505 "removeUceRegistrationOverrideShell");
10506 final long identity = Binder.clearCallingIdentity();
10507 try {
10508 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10509 new ArraySet<>(featureTags));
10510 } catch (ImsException e) {
10511 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10512 } finally {
10513 Binder.restoreCallingIdentity(identity);
10514 }
10515 }
10516
10517 /**
10518 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10519 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10520 */
10521 // Used for SHELL command only right now.
10522 @Override
10523 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10524 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10525 "clearUceRegistrationOverrideShell");
10526 final long identity = Binder.clearCallingIdentity();
10527 try {
10528 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10529 } catch (ImsException e) {
10530 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10531 } finally {
10532 Binder.restoreCallingIdentity(identity);
10533 }
10534 }
10535
10536 /**
10537 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10538 */
10539 // Used for SHELL command only right now.
10540 @Override
10541 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10542 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10543 "getLatestRcsContactUceCapabilityShell");
10544 final long identity = Binder.clearCallingIdentity();
10545 try {
10546 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10547 } catch (ImsException e) {
10548 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10549 } finally {
10550 Binder.restoreCallingIdentity(identity);
10551 }
10552 }
10553
10554 /**
10555 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10556 * device does not have an active PUBLISH.
10557 */
10558 // Used for SHELL command only right now.
10559 @Override
10560 public String getLastUcePidfXmlShell(int subId) {
10561 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10562 final long identity = Binder.clearCallingIdentity();
10563 try {
10564 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10565 } catch (ImsException e) {
10566 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10567 } finally {
10568 Binder.restoreCallingIdentity(identity);
10569 }
10570 }
10571
James.cf Line8713a42021-04-29 16:04:26 +080010572 /**
10573 * Remove UCE requests cannot be sent to the network status.
10574 */
10575 // Used for SHELL command only right now.
10576 @Override
10577 public boolean removeUceRequestDisallowedStatus(int subId) {
10578 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10579 final long identity = Binder.clearCallingIdentity();
10580 try {
10581 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10582 } catch (ImsException e) {
10583 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10584 } finally {
10585 Binder.restoreCallingIdentity(identity);
10586 }
10587 }
10588
James.cf Lin0fc71b02021-05-25 01:37:38 +080010589 /**
10590 * Remove UCE requests cannot be sent to the network status.
10591 */
10592 // Used for SHELL command only.
10593 @Override
10594 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10595 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10596 final long identity = Binder.clearCallingIdentity();
10597 try {
10598 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10599 } catch (ImsException e) {
10600 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10601 } finally {
10602 Binder.restoreCallingIdentity(identity);
10603 }
10604 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010605
James.cf Lin4b784aa2021-01-31 03:25:15 +080010606 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010607 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10608 String callingPackage) {
10609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10610 mApp, subId, "setSignalStrengthUpdateRequest");
10611
10612 final int callingUid = Binder.getCallingUid();
10613 // Verify that tha callingPackage belongs to the calling UID
10614 mApp.getSystemService(AppOpsManager.class)
10615 .checkPackage(callingUid, callingPackage);
10616
10617 validateSignalStrengthUpdateRequest(request, callingUid);
10618
10619 final long identity = Binder.clearCallingIdentity();
10620 try {
10621 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10622 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10623
10624 if (result instanceof IllegalStateException) {
10625 throw (IllegalStateException) result;
10626 }
10627 } finally {
10628 Binder.restoreCallingIdentity(identity);
10629 }
10630 }
10631
10632 @Override
10633 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10634 String callingPackage) {
10635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10636 mApp, subId, "clearSignalStrengthUpdateRequest");
10637
10638 final int callingUid = Binder.getCallingUid();
10639 // Verify that tha callingPackage belongs to the calling UID
10640 mApp.getSystemService(AppOpsManager.class)
10641 .checkPackage(callingUid, callingPackage);
10642
10643 final long identity = Binder.clearCallingIdentity();
10644 try {
10645 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10646 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10647
10648 if (result instanceof IllegalStateException) {
10649 throw (IllegalStateException) result;
10650 }
10651 } finally {
10652 Binder.restoreCallingIdentity(identity);
10653 }
10654 }
10655
10656 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10657 int callingUid) {
10658 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10659 // phone/system process do not have further restriction on request
10660 return;
10661 }
10662
10663 // Applications has restrictions on how to use the request:
10664 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10665 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10666 // This is not system caller which has been checked above
10667 throw new IllegalArgumentException(
10668 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10669 }
10670
10671 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10672 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10673 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10674 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10675 || info.isEnabled()) {
10676 throw new IllegalArgumentException(
10677 "Only system can set hide fields in SignalThresholdInfo");
10678 }
10679
10680 // Thresholds length for each RAN need in range. This has been validated in
10681 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10682 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10683 final int[] thresholds = info.getThresholds();
10684 Objects.requireNonNull(thresholds);
10685 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10686 || thresholds.length
10687 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10688 throw new IllegalArgumentException(
10689 "thresholds length is out of range: " + thresholds.length);
10690 }
10691 }
10692 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010693
10694 /**
10695 * Gets the current phone capability.
10696 *
10697 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10698 * @return the PhoneCapability which describes the data connection capability of modem.
10699 * It's used to evaluate possible phone config change, for example from single
10700 * SIM device to multi-SIM device.
10701 */
10702 @Override
10703 public PhoneCapability getPhoneCapability() {
10704 enforceReadPrivilegedPermission("getPhoneCapability");
10705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10708 } finally {
10709 Binder.restoreCallingIdentity(identity);
10710 }
10711 }
Michele Berionne5e411512020-11-13 02:36:59 +000010712
10713 /**
10714 * Prepare TelephonyManager for an unattended reboot. The reboot is
10715 * required to be done shortly after the API is invoked.
10716 */
10717 @Override
10718 @TelephonyManager.PrepareUnattendedRebootResult
10719 public int prepareForUnattendedReboot() {
10720 enforceRebootPermission();
10721
10722 final long identity = Binder.clearCallingIdentity();
10723 try {
10724 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10725 } finally {
10726 Binder.restoreCallingIdentity(identity);
10727 }
10728 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010729
10730 /**
10731 * Request to get the current slicing configuration including URSP rules and
10732 * NSSAIs (configured, allowed and rejected).
10733 *
10734 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10735 */
10736 @Override
10737 public void getSlicingConfig(ResultReceiver callback) {
10738 enforceReadPrivilegedPermission("getSlicingConfig");
10739
10740 final long identity = Binder.clearCallingIdentity();
10741 try {
10742 Phone phone = getDefaultPhone();
10743 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10744 } finally {
10745 Binder.restoreCallingIdentity(identity);
10746 }
10747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010748}