blob: 9262084c7c27868cca6e6c615241ff9d4c8a5aca [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;
Shuo Qian4a594052020-01-23 11:59:30 -0800140import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700142import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700143import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800144import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700145import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700146import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800147import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700148import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700149import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800150import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800151import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800152import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700153import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700154import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800155import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700156import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800157import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700158import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700159import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700160import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700162import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800163import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700164import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700165import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700166import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700167import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800168import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800169import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700170import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700171import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700172import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800173import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800174import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800175import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700176import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800177import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700178import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800179import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700180import com.android.internal.telephony.imsphone.ImsPhone;
181import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800182import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700183import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800185import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800187import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700188import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700190import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800191import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000192import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800193import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700194import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700195import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800196import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800197import com.android.phone.callcomposer.CallComposerPictureManager;
198import com.android.phone.callcomposer.CallComposerPictureTransfer;
199import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700200import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700201import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800202import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700203import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700204import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800205import com.android.services.telephony.TelecomAccountRegistry;
206import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800207import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800208
Hall Liu82694d52020-12-11 18:22:04 -0800209import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700210import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.io.IOException;
212import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700213import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700214import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800215import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800216import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800217import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800218import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100219import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800220import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700221import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800223import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800225import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800226import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700227
228/**
229 * Implementation of the ITelephony interface.
230 */
Santos Cordon117fee72014-05-16 17:56:12 -0700231public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700232 private static final String LOG_TAG = "PhoneInterfaceManager";
233 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
234 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800235 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700236
237 // Message codes used with mMainThreadHandler
238 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700239 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
240 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700241 private static final int CMD_OPEN_CHANNEL = 9;
242 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
243 private static final int CMD_CLOSE_CHANNEL = 11;
244 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800245 private static final int CMD_NV_READ_ITEM = 13;
246 private static final int EVENT_NV_READ_ITEM_DONE = 14;
247 private static final int CMD_NV_WRITE_ITEM = 15;
248 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
249 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
250 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700251 private static final int CMD_RESET_MODEM_CONFIG = 19;
252 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800253 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
254 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800255 private static final int CMD_SEND_ENVELOPE = 25;
256 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000257 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
258 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700259 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
260 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
261 private static final int CMD_EXCHANGE_SIM_IO = 31;
262 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800263 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
264 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700265 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
266 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700267 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
268 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700269 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
270 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
271 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
272 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700273 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
274 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
275 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
276 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700277 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800278 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
279 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000280 private static final int CMD_SWITCH_SLOTS = 50;
281 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700282 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
283 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
284 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
285 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
286 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
287 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
288 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
289 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700290 private static final int CMD_GET_ALL_CELL_INFO = 60;
291 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
292 private static final int CMD_GET_CELL_LOCATION = 62;
293 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700294 private static final int CMD_MODEM_REBOOT = 64;
295 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700296 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
297 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800298 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
299 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700300 private static final int CMD_GET_MODEM_STATUS = 70;
301 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700302 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
303 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700304 private static final int CMD_ERASE_MODEM_CONFIG = 74;
305 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800306 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
307 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
308 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
309 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800310 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
311 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800313 private static final int CMD_GET_CALL_FORWARDING = 83;
314 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
315 private static final int CMD_SET_CALL_FORWARDING = 85;
316 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
317 private static final int CMD_GET_CALL_WAITING = 87;
318 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
319 private static final int CMD_SET_CALL_WAITING = 89;
320 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700321 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
322 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
323 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
324 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700325 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
326 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800327 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
328 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800329 private static final int CMD_SET_DATA_THROTTLING = 99;
330 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800331 private static final int CMD_SET_SIM_POWER = 101;
332 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800333 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
334 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
335 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
336 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800337 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
338 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000339 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800340 private static final int CMD_GET_SLICING_CONFIG = 110;
341 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800342 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800344 // Parameters of select command.
345 private static final int SELECT_COMMAND = 0xA4;
346 private static final int SELECT_P1 = 0x04;
347 private static final int SELECT_P2 = 0;
348 private static final int SELECT_P3 = 0x10;
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 /** The singleton instance. */
351 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800352 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Wink Saville3ab207e2014-11-20 13:07:20 -0800354 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800355 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800356 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700357 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800358 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700359 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800361 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800362 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700363 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800364 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
Peter Wangdafb9ac2020-01-15 14:13:38 -0800366 /** User Activity */
367 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800368 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
369
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700370 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
371
Derek Tan97ebb422014-09-05 16:55:38 -0700372 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
373 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800374 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800375 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700376
Michelecea4cf22018-12-21 15:00:11 -0800377 // String to store multi SIM allowed
378 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
379
Derek Tan740e1672017-06-27 14:56:27 -0700380 // The AID of ISD-R.
381 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
382
yinxub1bed742017-04-17 11:45:04 -0700383 private NetworkScanRequestTracker mNetworkScanRequestTracker;
384
David Kelly5e06a7f2018-03-12 14:10:59 +0000385 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
386 private static final int MANUFACTURER_CODE_LENGTH = 8;
387
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800388 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800389 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800390
Derek Tan89e89d42014-07-08 17:00:10 -0700391 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700392 * Experiment flag to enable erase modem config on reset network, default value is false
393 */
394 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
395 "reset_network_erase_modem_config_enabled";
396
Rambo Wang0f050d82021-02-12 11:43:36 -0800397 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
398
Naina Nallurid63128d2019-09-17 14:10:30 -0700399 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700400 * A request object to use for transmitting data to an ICC.
401 */
402 private static final class IccAPDUArgument {
403 public int channel, cla, command, p1, p2, p3;
404 public String data;
405
406 public IccAPDUArgument(int channel, int cla, int command,
407 int p1, int p2, int p3, String data) {
408 this.channel = channel;
409 this.cla = cla;
410 this.command = command;
411 this.p1 = p1;
412 this.p2 = p2;
413 this.p3 = p3;
414 this.data = data;
415 }
416 }
417
418 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700419 * A request object to use for transmitting data to an ICC.
420 */
421 private static final class ManualNetworkSelectionArgument {
422 public OperatorInfo operatorInfo;
423 public boolean persistSelection;
424
425 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
426 this.operatorInfo = operatorInfo;
427 this.persistSelection = persistSelection;
428 }
429 }
430
431 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
433 * request after sending. The main thread will notify the request when it is complete.
434 */
435 private static final class MainThreadRequest {
436 /** The argument to use for the request */
437 public Object argument;
438 /** The result of the request that is run on the main thread */
439 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800440 // The subscriber id that this request applies to. Defaults to
441 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
442 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
Nathan Harold92bed182018-10-12 18:16:49 -0700444 // In cases where subId is unavailable, the caller needs to specify the phone.
445 public Phone phone;
446
vagdeviaf9a5b92018-08-15 16:01:53 -0700447 public WorkSource workSource;
448
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 public MainThreadRequest(Object argument) {
450 this.argument = argument;
451 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800452
Nathan Harold92bed182018-10-12 18:16:49 -0700453 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
454 this.argument = argument;
455 if (phone != null) {
456 this.phone = phone;
457 }
458 this.workSource = workSource;
459 }
460
vagdeviaf9a5b92018-08-15 16:01:53 -0700461 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800462 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800463 if (subId != null) {
464 this.subId = subId;
465 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700466 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700468 }
469
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800470 private static final class IncomingThirdPartyCallArgs {
471 public final ComponentName component;
472 public final String callId;
473 public final String callerDisplayName;
474
475 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
476 String callerDisplayName) {
477 this.component = component;
478 this.callId = callId;
479 this.callerDisplayName = callerDisplayName;
480 }
481 }
482
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700483 /**
484 * A handler that processes messages on the main thread in the phone process. Since many
485 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
486 * inbound binder threads to the main thread in the phone process. The Binder thread
487 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
488 * on, which will be notified when the operation completes and will contain the result of the
489 * request.
490 *
491 * <p>If a MainThreadRequest object is provided in the msg.obj field,
492 * note that request.result must be set to something non-null for the calling thread to
493 * unblock.
494 */
495 private final class MainThreadHandler extends Handler {
496 @Override
497 public void handleMessage(Message msg) {
498 MainThreadRequest request;
499 Message onCompleted;
500 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800503 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504
505 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700506 case CMD_HANDLE_USSD_REQUEST: {
507 request = (MainThreadRequest) msg.obj;
508 final Phone phone = getPhoneFromRequest(request);
509 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
510 String ussdRequest = ussdObject.first;
511 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700512
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 if (!isUssdApiAllowed(request.subId)) {
514 // Carrier does not support use of this API, return failure.
515 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
516 UssdResponse response = new UssdResponse(ussdRequest, null);
517 Bundle returnData = new Bundle();
518 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
519 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700520
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 request.result = true;
522 notifyRequester(request);
523 return;
524 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700525
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 try {
527 request.result = phone != null
528 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
529 } catch (CallStateException cse) {
530 request.result = false;
531 }
532 // Wake up the requesting thread
533 notifyRequester(request);
534 break;
pkanwar32d516d2016-10-14 19:37:38 -0700535 }
536
Yorke Lee716f67e2015-06-17 15:39:16 -0700537 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700539 final Phone phone = getPhoneFromRequest(request);
540 request.result = phone != null ?
541 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
542 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700547
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 if (uiccCard == null) {
553 loge("iccTransmitApduLogicalChannel: No UICC");
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
558 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 iccArgument.channel, iccArgument.cla, iccArgument.command,
561 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 break;
565
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 ar = (AsyncResult) msg.obj;
568 request = (MainThreadRequest) ar.userObj;
569 if (ar.exception == null && ar.result != null) {
570 request.result = ar.result;
571 } else {
572 request.result = new IccIoResult(0x6F, 0, (byte[])null);
573 if (ar.result == null) {
574 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800575 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800577 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 } else {
579 loge("iccTransmitApduLogicalChannel: Unknown exception");
580 }
581 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 break;
584
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
586 request = (MainThreadRequest) msg.obj;
587 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800588 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 if (uiccCard == null) {
590 loge("iccTransmitApduBasicChannel: No UICC");
591 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700593 } else {
594 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
595 request);
596 uiccCard.iccTransmitApduBasicChannel(
597 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
598 iccArgument.p3, iccArgument.data, onCompleted);
599 }
600 break;
601
602 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
605 if (ar.exception == null && ar.result != null) {
606 request.result = ar.result;
607 } else {
608 request.result = new IccIoResult(0x6F, 0, (byte[])null);
609 if (ar.result == null) {
610 loge("iccTransmitApduBasicChannel: Empty response");
611 } else if (ar.exception instanceof CommandException) {
612 loge("iccTransmitApduBasicChannel: CommandException: " +
613 ar.exception);
614 } else {
615 loge("iccTransmitApduBasicChannel: Unknown exception");
616 }
617 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700618 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 break;
620
621 case CMD_EXCHANGE_SIM_IO:
622 request = (MainThreadRequest) msg.obj;
623 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 if (uiccCard == null) {
626 loge("iccExchangeSimIO: No UICC");
627 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
631 request);
632 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
633 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
634 iccArgument.data, onCompleted);
635 }
636 break;
637
638 case EVENT_EXCHANGE_SIM_IO_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
641 if (ar.exception == null && ar.result != null) {
642 request.result = ar.result;
643 } else {
644 request.result = new IccIoResult(0x6f, 0, (byte[])null);
645 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700647 break;
648
Derek Tan4d5e5c12014-02-04 11:54:58 -0800649 case CMD_SEND_ENVELOPE:
650 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800651 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 if (uiccCard == null) {
653 loge("sendEnvelopeWithStatus: No UICC");
654 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
658 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
659 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800660 break;
661
662 case EVENT_SEND_ENVELOPE_DONE:
663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800667 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700668 request.result = new IccIoResult(0x6F, 0, (byte[])null);
669 if (ar.result == null) {
670 loge("sendEnvelopeWithStatus: Empty response");
671 } else if (ar.exception instanceof CommandException) {
672 loge("sendEnvelopeWithStatus: CommandException: " +
673 ar.exception);
674 } else {
675 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
676 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800679 break;
680
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 case CMD_OPEN_CHANNEL:
682 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800683 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800684 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 if (uiccCard == null) {
686 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800687 request.result = new IccOpenLogicalChannelResponse(-1,
688 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 } else {
691 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800692 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
693 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700694 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700695 break;
696
697 case EVENT_OPEN_CHANNEL_DONE:
698 ar = (AsyncResult) msg.obj;
699 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700702 int[] result = (int[]) ar.result;
703 int channelId = result[0];
704 byte[] selectResponse = null;
705 if (result.length > 1) {
706 selectResponse = new byte[result.length - 1];
707 for (int i = 1; i < result.length; ++i) {
708 selectResponse[i - 1] = (byte) result[i];
709 }
710 }
711 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700712 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 if (ar.result == null) {
715 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700717 if (ar.exception != null) {
718 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
719 }
720
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700721 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700722 if (ar.exception instanceof CommandException) {
723 CommandException.Error error =
724 ((CommandException) (ar.exception)).getCommandError();
725 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700726 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700727 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700728 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700729 }
730 }
731 openChannelResp = new IccOpenLogicalChannelResponse(
732 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700734 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700736 break;
737
738 case CMD_CLOSE_CHANNEL:
739 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800740 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700741 if (uiccCard == null) {
742 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900743 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700745 } else {
746 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
747 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
748 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700749 break;
750
751 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800752 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
753 break;
754
755 case CMD_NV_READ_ITEM:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800758 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
759 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800760 break;
761
762 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 ar = (AsyncResult) msg.obj;
764 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800765 if (ar.exception == null && ar.result != null) {
766 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700767 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800768 request.result = "";
769 if (ar.result == null) {
770 loge("nvReadItem: Empty response");
771 } else if (ar.exception instanceof CommandException) {
772 loge("nvReadItem: CommandException: " +
773 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800775 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 }
777 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700778 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 break;
780
Jake Hambye994d462014-02-03 13:10:13 -0800781 case CMD_NV_WRITE_ITEM:
782 request = (MainThreadRequest) msg.obj;
783 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
784 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800785 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700786 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800787 break;
788
789 case EVENT_NV_WRITE_ITEM_DONE:
790 handleNullReturnEvent(msg, "nvWriteItem");
791 break;
792
793 case CMD_NV_WRITE_CDMA_PRL:
794 request = (MainThreadRequest) msg.obj;
795 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800796 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800797 break;
798
799 case EVENT_NV_WRITE_CDMA_PRL_DONE:
800 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
801 break;
802
chen xu6dac5ab2018-10-26 17:39:23 -0700803 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800804 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700805 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800806 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800807 break;
808
chen xu6dac5ab2018-10-26 17:39:23 -0700809 case EVENT_RESET_MODEM_CONFIG_DONE:
810 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800811 break;
812
Sooraj Sasindran37444802020-08-11 10:40:43 -0700813 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
816 request);
817 Phone phone = getPhoneFromRequest(request);
818 if (phone != null) {
819 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
820 } else {
821 loge("isNRDualConnectivityEnabled: No phone object");
822 request.result = false;
823 notifyRequester(request);
824 }
825 break;
826 }
827
828 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
829 ar = (AsyncResult) msg.obj;
830 request = (MainThreadRequest) ar.userObj;
831 if (ar.exception == null && ar.result != null) {
832 request.result = ar.result;
833 } else {
834 // request.result must be set to something non-null
835 // for the calling thread to unblock
836 if (request.result != null) {
837 request.result = ar.result;
838 } else {
839 request.result = false;
840 }
841 if (ar.result == null) {
842 loge("isNRDualConnectivityEnabled: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("isNRDualConnectivityEnabled: CommandException: "
845 + ar.exception);
846 } else {
847 loge("isNRDualConnectivityEnabled: Unknown exception");
848 }
849 }
850 notifyRequester(request);
851 break;
852
853 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
854 request = (MainThreadRequest) msg.obj;
855 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
856 Phone phone = getPhoneFromRequest(request);
857 if (phone != null) {
858 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
859 request.workSource);
860 } else {
861 loge("enableNrDualConnectivity: No phone object");
862 request.result =
863 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
864 notifyRequester(request);
865 }
866 break;
867 }
868
869 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null) {
873 request.result =
874 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
875 } else {
876 request.result =
877 TelephonyManager
878 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
879 if (ar.exception instanceof CommandException) {
880 CommandException.Error error =
881 ((CommandException) (ar.exception)).getCommandError();
882 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
883 request.result =
884 TelephonyManager
885 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000886 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
887 request.result =
888 TelephonyManager
889 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700890 }
891 loge("enableNrDualConnectivity" + ": CommandException: "
892 + ar.exception);
893 } else {
894 loge("enableNrDualConnectivity" + ": Unknown exception");
895 }
896 }
897 notifyRequester(request);
898 break;
899 }
900
SongFerngWang3ef3e072020-12-21 16:41:52 +0800901 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800903 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
904 request);
905 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 break;
907
SongFerngWang3ef3e072020-12-21 16:41:52 +0800908 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result; // Integer
913 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530914 // request.result must be set to something non-null
915 // for the calling thread to unblock
916 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800918 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800920 loge("getAllowedNetworkTypesBitmask: CommandException: "
921 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800922 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800923 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800924 }
925 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800927 break;
928
SongFerngWang3ef3e072020-12-21 16:41:52 +0800929 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800930 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800931 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
932 request);
933 Pair<Integer, Long> reasonWithNetworkTypes =
934 (Pair<Integer, Long>) request.argument;
935 getPhoneFromRequest(request).setAllowedNetworkTypes(
936 reasonWithNetworkTypes.first,
937 reasonWithNetworkTypes.second,
938 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800939 break;
940
SongFerngWang3ef3e072020-12-21 16:41:52 +0800941 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
942 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800943 break;
944
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000945 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
946 request = (MainThreadRequest)msg.obj;
947 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800948 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000949 break;
950
951 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
952 ar = (AsyncResult)msg.obj;
953 request = (MainThreadRequest)ar.userObj;
954 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000956 break;
957
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800958 case CMD_SET_VOICEMAIL_NUMBER:
959 request = (MainThreadRequest) msg.obj;
960 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
961 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800962 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
963 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800964 break;
965
966 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
967 handleNullReturnEvent(msg, "setVoicemailNumber");
968 break;
969
Stuart Scott54788802015-03-30 13:18:01 -0700970 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
973 request);
974 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
975 break;
976
977 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
978 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
979 break;
980
Shishir Agrawal302c8692015-06-19 13:49:39 -0700981 case CMD_PERFORM_NETWORK_SCAN:
982 request = (MainThreadRequest) msg.obj;
983 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
984 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
985 break;
986
Hall Liu27d24262020-09-18 19:04:59 -0700987 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700990 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
991 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
992 request.argument;
993 int callForwardingReason = args.first;
994 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800995 break;
Hall Liu27d24262020-09-18 19:04:59 -0700996 }
997 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001000 TelephonyManager.CallForwardingInfoCallback callback =
1001 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1002 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001003 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001004 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001005 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1006 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1007 // Service Class is a bit mask per 3gpp 27.007. Search for
1008 // any service for voice call.
1009 if ((callForwardInfo.serviceClass
1010 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001011 callForwardingInfo = new CallForwardingInfo(true,
1012 callForwardInfo.reason,
1013 callForwardInfo.number,
1014 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001015 break;
1016 }
1017 }
1018 // Didn't find a call forward info for voice call.
1019 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001020 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1021 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001022 }
Hall Liu27d24262020-09-18 19:04:59 -07001023 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001024 } else {
1025 if (ar.result == null) {
1026 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1027 }
1028 if (ar.exception != null) {
1029 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1030 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001031 int errorCode = TelephonyManager
1032 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001033 if (ar.exception instanceof CommandException) {
1034 CommandException.Error error =
1035 ((CommandException) (ar.exception)).getCommandError();
1036 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001037 errorCode = TelephonyManager
1038 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001039 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001040 errorCode = TelephonyManager
1041 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001042 }
1043 }
Hall Liu27d24262020-09-18 19:04:59 -07001044 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001045 }
Shuo Qian4a594052020-01-23 11:59:30 -08001046 break;
Hall Liu27d24262020-09-18 19:04:59 -07001047 }
Shuo Qian4a594052020-01-23 11:59:30 -08001048
Hall Liu27d24262020-09-18 19:04:59 -07001049 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001050 request = (MainThreadRequest) msg.obj;
1051 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001052 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001053 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001054 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1055 request.argument).first;
1056 request.phone.setCallForwardingOption(
1057 callForwardingInfoToSet.isEnabled()
1058 ? CommandsInterface.CF_ACTION_ENABLE
1059 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001060 callForwardingInfoToSet.getReason(),
1061 callForwardingInfoToSet.getNumber(),
1062 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1063 break;
Hall Liu27d24262020-09-18 19:04:59 -07001064 }
Shuo Qian4a594052020-01-23 11:59:30 -08001065
Hall Liu27d24262020-09-18 19:04:59 -07001066 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001069 Consumer<Integer> callback =
1070 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1071 request.argument).second;
1072 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001073 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001074 int errorCode = TelephonyManager.CallForwardingInfoCallback
1075 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001076 if (ar.exception instanceof CommandException) {
1077 CommandException.Error error =
1078 ((CommandException) (ar.exception)).getCommandError();
1079 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001080 errorCode = TelephonyManager.CallForwardingInfoCallback
1081 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001082 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001083 errorCode = TelephonyManager.CallForwardingInfoCallback
1084 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001085 }
1086 }
1087 callback.accept(errorCode);
1088 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001089 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001090 }
Shuo Qian4a594052020-01-23 11:59:30 -08001091 break;
Hall Liu27d24262020-09-18 19:04:59 -07001092 }
Shuo Qian4a594052020-01-23 11:59:30 -08001093
Hall Liu27d24262020-09-18 19:04:59 -07001094 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1097 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1098 break;
Hall Liu27d24262020-09-18 19:04:59 -07001099 }
Shuo Qian4a594052020-01-23 11:59:30 -08001100
Hall Liu27d24262020-09-18 19:04:59 -07001101 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001102 ar = (AsyncResult) msg.obj;
1103 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001104 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001105 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1106 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001107 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001108 // Service Class is a bit mask per 3gpp 27.007.
1109 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001110 if (callForwardResults.length > 1
1111 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001112 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001113 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001114 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1115 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001116 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001117 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001118 }
1119 } else {
1120 if (ar.result == null) {
1121 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1122 }
1123 if (ar.exception != null) {
1124 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1125 }
1126 if (ar.exception instanceof CommandException) {
1127 CommandException.Error error =
1128 ((CommandException) (ar.exception)).getCommandError();
1129 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1130 callForwardingStatus =
1131 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1132 }
1133 }
1134 }
Hall Liu27d24262020-09-18 19:04:59 -07001135 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001136 break;
Hall Liu27d24262020-09-18 19:04:59 -07001137 }
Shuo Qian4a594052020-01-23 11:59:30 -08001138
Hall Liu27d24262020-09-18 19:04:59 -07001139 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001142 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1143 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001144 break;
Hall Liu27d24262020-09-18 19:04:59 -07001145 }
Shuo Qian4a594052020-01-23 11:59:30 -08001146
Hall Liu27d24262020-09-18 19:04:59 -07001147 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001150 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1151 Consumer<Integer> callback =
1152 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1153 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001154 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001155 if (ar.exception instanceof CommandException) {
1156 CommandException.Error error =
1157 ((CommandException) (ar.exception)).getCommandError();
1158 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1159 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1160 } else {
1161 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1162 }
1163 } else {
1164 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1165 }
1166 } else {
1167 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1168 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001169 }
Shuo Qian4a594052020-01-23 11:59:30 -08001170 break;
Hall Liu27d24262020-09-18 19:04:59 -07001171 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001172 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1173 ar = (AsyncResult) msg.obj;
1174 request = (MainThreadRequest) ar.userObj;
1175 CellNetworkScanResult cellScanResult;
1176 if (ar.exception == null && ar.result != null) {
1177 cellScanResult = new CellNetworkScanResult(
1178 CellNetworkScanResult.STATUS_SUCCESS,
1179 (List<OperatorInfo>) ar.result);
1180 } else {
1181 if (ar.result == null) {
1182 loge("getCellNetworkScanResults: Empty response");
1183 }
1184 if (ar.exception != null) {
1185 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1186 }
1187 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1188 if (ar.exception instanceof CommandException) {
1189 CommandException.Error error =
1190 ((CommandException) (ar.exception)).getCommandError();
1191 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1192 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1193 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1194 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1195 }
1196 }
1197 cellScanResult = new CellNetworkScanResult(errorCode, null);
1198 }
1199 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001200 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001201 break;
1202
1203 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1204 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001205 ManualNetworkSelectionArgument selArg =
1206 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001207 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1208 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001209 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1210 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001211 break;
1212
1213 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001214 ar = (AsyncResult) msg.obj;
1215 request = (MainThreadRequest) ar.userObj;
1216 if (ar.exception == null) {
1217 request.result = true;
1218 } else {
1219 request.result = false;
1220 loge("setNetworkSelectionModeManual " + ar.exception);
1221 }
1222 notifyRequester(request);
1223 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001224 break;
1225
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001226 case CMD_GET_MODEM_ACTIVITY_INFO:
1227 request = (MainThreadRequest) msg.obj;
1228 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001229 if (defaultPhone != null) {
1230 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001231 } else {
1232 ResultReceiver result = (ResultReceiver) request.argument;
1233 Bundle bundle = new Bundle();
1234 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001235 new ModemActivityInfo(0, 0, 0,
1236 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001237 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001238 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239 break;
1240
Hall Liud0f208c2020-10-14 16:54:44 -07001241 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001242 ar = (AsyncResult) msg.obj;
1243 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001244 ResultReceiver result = (ResultReceiver) request.argument;
1245
Hall Liud0f208c2020-10-14 16:54:44 -07001246 ModemActivityInfo ret = null;
1247 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001248 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001249 // Update the last modem activity info and the result of the request.
1250 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1251 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001252 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001253 int[] txTimeMs = info.getTransmitTimeMillis();
1254 int[] lastModemTxTimeMs = mLastModemActivityInfo
1255 .getTransmitTimeMillis();
1256 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1257 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1258 }
Hall Liu49656c02020-10-09 19:00:11 -07001259 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001260 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1261 + mLastModemActivityInfo.getSleepTimeMillis());
1262 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1263 + mLastModemActivityInfo.getIdleTimeMillis());
1264 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1265 mLastModemActivityInfo.setReceiveTimeMillis(
1266 info.getReceiveTimeMillis()
1267 + mLastModemActivityInfo.getReceiveTimeMillis());
1268 }
Hall Liu49656c02020-10-09 19:00:11 -07001269 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001270 mLastModemActivityInfo.getSleepTimeMillis(),
1271 mLastModemActivityInfo.getIdleTimeMillis(),
1272 mLastModemActivityInfo.getTransmitTimeMillis(),
1273 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001274 } else {
1275 if (ar.result == null) {
1276 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001277 error = TelephonyManager.ModemActivityInfoException
1278 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001279 } else if (ar.exception instanceof CommandException) {
1280 loge("queryModemActivityInfo: CommandException: " +
1281 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001282 error = TelephonyManager.ModemActivityInfoException
1283 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001284 } else {
1285 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001286 error = TelephonyManager.ModemActivityInfoException
1287 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001288 }
1289 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001290 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001291 if (ret != null) {
1292 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1293 } else {
1294 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1295 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001296 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001297 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001298 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001299 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001300
Meng Wang1a7c35a2016-05-05 20:56:15 -07001301 case CMD_SET_ALLOWED_CARRIERS:
1302 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001303 CarrierRestrictionRules argument =
1304 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001305 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001306 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001307 break;
1308
1309 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
1312 if (ar.exception == null && ar.result != null) {
1313 request.result = ar.result;
1314 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001315 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1316 if (ar.exception instanceof CommandException) {
1317 loge("setAllowedCarriers: CommandException: " + ar.exception);
1318 CommandException.Error error =
1319 ((CommandException) (ar.exception)).getCommandError();
1320 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1321 request.result =
1322 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1323 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001324 } else {
1325 loge("setAllowedCarriers: Unknown exception");
1326 }
1327 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001328 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001329 break;
1330
1331 case CMD_GET_ALLOWED_CARRIERS:
1332 request = (MainThreadRequest) msg.obj;
1333 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001334 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001335 break;
1336
1337 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1338 ar = (AsyncResult) msg.obj;
1339 request = (MainThreadRequest) ar.userObj;
1340 if (ar.exception == null && ar.result != null) {
1341 request.result = ar.result;
1342 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001343 request.result = new IllegalStateException(
1344 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001345 if (ar.result == null) {
1346 loge("getAllowedCarriers: Empty response");
1347 } else if (ar.exception instanceof CommandException) {
1348 loge("getAllowedCarriers: CommandException: " +
1349 ar.exception);
1350 } else {
1351 loge("getAllowedCarriers: Unknown exception");
1352 }
1353 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001354 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001355 break;
1356
Nathan Haroldb3014052017-01-25 15:57:32 -08001357 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 if (ar.exception == null && ar.result != null) {
1361 request.result = ar.result;
1362 } else {
1363 request.result = new IllegalArgumentException(
1364 "Failed to retrieve Forbidden Plmns");
1365 if (ar.result == null) {
1366 loge("getForbiddenPlmns: Empty response");
1367 } else {
1368 loge("getForbiddenPlmns: Unknown exception");
1369 }
1370 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001371 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001372 break;
1373
1374 case CMD_GET_FORBIDDEN_PLMNS:
1375 request = (MainThreadRequest) msg.obj;
1376 uiccCard = getUiccCardFromRequest(request);
1377 if (uiccCard == null) {
1378 loge("getForbiddenPlmns() UiccCard is null");
1379 request.result = new IllegalArgumentException(
1380 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001381 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001382 break;
1383 }
1384 Integer appType = (Integer) request.argument;
1385 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1386 if (uiccApp == null) {
1387 loge("getForbiddenPlmns() no app with specified type -- "
1388 + appType);
1389 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001390 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001391 break;
1392 } else {
1393 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1394 + " specified type -- " + appType);
1395 }
1396 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1397 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1398 onCompleted);
1399 break;
1400
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001401 case CMD_SWITCH_SLOTS:
1402 request = (MainThreadRequest) msg.obj;
1403 int[] physicalSlots = (int[]) request.argument;
1404 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1405 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1406 break;
1407
1408 case EVENT_SWITCH_SLOTS_DONE:
1409 ar = (AsyncResult) msg.obj;
1410 request = (MainThreadRequest) ar.userObj;
1411 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001412 notifyRequester(request);
1413 break;
1414 case CMD_GET_NETWORK_SELECTION_MODE:
1415 request = (MainThreadRequest) msg.obj;
1416 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1417 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1418 break;
1419
1420 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1421 ar = (AsyncResult) msg.obj;
1422 request = (MainThreadRequest) ar.userObj;
1423 if (ar.exception != null) {
1424 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1425 } else {
1426 int mode = ((int[]) ar.result)[0];
1427 if (mode == 0) {
1428 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1429 } else {
1430 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1431 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001432 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001433 notifyRequester(request);
1434 break;
1435 case CMD_GET_CDMA_ROAMING_MODE:
1436 request = (MainThreadRequest) msg.obj;
1437 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1438 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1439 break;
1440 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1441 ar = (AsyncResult) msg.obj;
1442 request = (MainThreadRequest) ar.userObj;
1443 if (ar.exception != null) {
1444 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1445 } else {
1446 request.result = ((int[]) ar.result)[0];
1447 }
1448 notifyRequester(request);
1449 break;
1450 case CMD_SET_CDMA_ROAMING_MODE:
1451 request = (MainThreadRequest) msg.obj;
1452 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1453 int mode = (int) request.argument;
1454 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1455 break;
1456 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1457 ar = (AsyncResult) msg.obj;
1458 request = (MainThreadRequest) ar.userObj;
1459 request.result = ar.exception == null;
1460 notifyRequester(request);
1461 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001462 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1463 request = (MainThreadRequest) msg.obj;
1464 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1465 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1466 break;
1467 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1468 ar = (AsyncResult) msg.obj;
1469 request = (MainThreadRequest) ar.userObj;
1470 if (ar.exception != null) {
1471 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1472 } else {
1473 request.result = ((int[]) ar.result)[0];
1474 }
1475 notifyRequester(request);
1476 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001477 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1478 request = (MainThreadRequest) msg.obj;
1479 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1480 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001481 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1482 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001483 break;
1484 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1485 ar = (AsyncResult) msg.obj;
1486 request = (MainThreadRequest) ar.userObj;
1487 request.result = ar.exception == null;
1488 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001489 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 case CMD_GET_ALL_CELL_INFO:
1491 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001493 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 case EVENT_GET_ALL_CELL_INFO_DONE:
1496 ar = (AsyncResult) msg.obj;
1497 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001498 // If a timeout occurs, the response will be null
1499 request.result = (ar.exception == null && ar.result != null)
1500 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001501 synchronized (request) {
1502 request.notifyAll();
1503 }
1504 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001505 case CMD_REQUEST_CELL_INFO_UPDATE:
1506 request = (MainThreadRequest) msg.obj;
1507 request.phone.requestCellInfoUpdate(request.workSource,
1508 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1509 break;
1510 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1511 ar = (AsyncResult) msg.obj;
1512 request = (MainThreadRequest) ar.userObj;
1513 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1514 try {
1515 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001516 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001517 cb.onError(
1518 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1519 ar.exception.getClass().getName(),
1520 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001521 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001522 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001523 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001524 } else {
1525 // use the result as returned
1526 cb.onCellInfo((List<CellInfo>) ar.result);
1527 }
1528 } catch (RemoteException re) {
1529 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1530 }
1531 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001532 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001533 request = (MainThreadRequest) msg.obj;
1534 WorkSource ws = (WorkSource) request.argument;
1535 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001536 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001537 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001538 }
1539 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001540 ar = (AsyncResult) msg.obj;
1541 request = (MainThreadRequest) ar.userObj;
1542 if (ar.exception == null) {
1543 request.result = ar.result;
1544 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001545 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001546 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001547 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001548 }
1549
1550 synchronized (request) {
1551 request.notifyAll();
1552 }
1553 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001554 }
chen xu6dac5ab2018-10-26 17:39:23 -07001555 case CMD_MODEM_REBOOT:
1556 request = (MainThreadRequest) msg.obj;
1557 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001558 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001559 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001560 case EVENT_CMD_MODEM_REBOOT_DONE:
1561 handleNullReturnEvent(msg, "rebootModem");
1562 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001563 case CMD_REQUEST_ENABLE_MODEM:
1564 request = (MainThreadRequest) msg.obj;
1565 boolean enable = (boolean) request.argument;
1566 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001567 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001568 PhoneConfigurationManager.getInstance()
1569 .enablePhone(request.phone, enable, onCompleted);
1570 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001571 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001572 ar = (AsyncResult) msg.obj;
1573 request = (MainThreadRequest) ar.userObj;
1574 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001575 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001576 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001577 if ((boolean) request.result) {
1578 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1579 updateModemStateMetrics();
1580 } else {
1581 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1582 + ar.exception);
1583 }
1584 notifyRequester(request);
1585 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001586 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001587 case CMD_GET_MODEM_STATUS:
1588 request = (MainThreadRequest) msg.obj;
1589 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1590 PhoneConfigurationManager.getInstance()
1591 .getPhoneStatusFromModem(request.phone, onCompleted);
1592 break;
1593 case EVENT_GET_MODEM_STATUS_DONE:
1594 ar = (AsyncResult) msg.obj;
1595 request = (MainThreadRequest) ar.userObj;
1596 int id = request.phone.getPhoneId();
1597 if (ar.exception == null && ar.result != null) {
1598 request.result = ar.result;
1599 //update the cache as modem status has changed
1600 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1601 (boolean) request.result);
1602 } else {
1603 // Return true if modem status cannot be retrieved. For most cases,
1604 // modem status is on. And for older version modems, GET_MODEM_STATUS
1605 // and disable modem are not supported. Modem is always on.
1606 // TODO: this should be fixed in R to support a third
1607 // status UNKNOWN b/131631629
1608 request.result = true;
1609 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1610 + ar.exception);
1611 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001612 notifyRequester(request);
1613 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001614 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1615 request = (MainThreadRequest) msg.obj;
1616 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1617 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1618 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1619 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1620 break;
1621 }
1622 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1626 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1627 args.second.accept(ar.exception == null);
1628 notifyRequester(request);
1629 break;
1630 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001631 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1632 request = (MainThreadRequest) msg.obj;
1633 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1634 Phone phone = getPhoneFromRequest(request);
1635 if (phone != null) {
1636 phone.getSystemSelectionChannels(onCompleted);
1637 } else {
1638 loge("getSystemSelectionChannels: No phone object");
1639 request.result = new ArrayList<RadioAccessSpecifier>();
1640 notifyRequester(request);
1641 }
1642 break;
1643 }
1644 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1645 ar = (AsyncResult) msg.obj;
1646 request = (MainThreadRequest) ar.userObj;
1647 if (ar.exception == null && ar.result != null) {
1648 request.result = ar.result;
1649 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001650 request.result = new IllegalStateException(
1651 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001652 if (ar.result == null) {
1653 loge("getSystemSelectionChannels: Empty response");
1654 } else {
1655 loge("getSystemSelectionChannels: Unknown exception");
1656 }
1657 }
1658 notifyRequester(request);
1659 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001660 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 if (ar.exception == null && ar.result != null) {
1664 request.result = ar.result;
1665 } else {
1666 request.result = -1;
1667 loge("Failed to set Forbidden Plmns");
1668 if (ar.result == null) {
1669 loge("setForbidenPlmns: Empty response");
1670 } else if (ar.exception != null) {
1671 loge("setForbiddenPlmns: Exception: " + ar.exception);
1672 request.result = -1;
1673 } else {
1674 loge("setForbiddenPlmns: Unknown exception");
1675 }
1676 }
1677 notifyRequester(request);
1678 break;
1679 case CMD_SET_FORBIDDEN_PLMNS:
1680 request = (MainThreadRequest) msg.obj;
1681 uiccCard = getUiccCardFromRequest(request);
1682 if (uiccCard == null) {
1683 loge("setForbiddenPlmns: UiccCard is null");
1684 request.result = -1;
1685 notifyRequester(request);
1686 break;
1687 }
1688 Pair<Integer, List<String>> setFplmnsArgs =
1689 (Pair<Integer, List<String>>) request.argument;
1690 appType = setFplmnsArgs.first;
1691 List<String> fplmns = setFplmnsArgs.second;
1692 uiccApp = uiccCard.getApplicationByType(appType);
1693 if (uiccApp == null) {
1694 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1695 request.result = -1;
1696 loge("Failed to get UICC App");
1697 notifyRequester(request);
1698 } else {
1699 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1700 ((SIMRecords) uiccApp.getIccRecords())
1701 .setForbiddenPlmns(onCompleted, fplmns);
1702 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001703 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001704 case CMD_ERASE_MODEM_CONFIG:
1705 request = (MainThreadRequest) msg.obj;
1706 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1707 defaultPhone.eraseModemConfig(onCompleted);
1708 break;
1709 case EVENT_ERASE_MODEM_CONFIG_DONE:
1710 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001711 break;
zoey chene02881a2019-12-30 16:11:23 +08001712
Kai Shif70f46f2021-03-03 13:59:46 -08001713 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1714 request = (MainThreadRequest) msg.obj;
1715 request.result = defaultPhone.eraseDataInSharedPreferences();
1716 notifyRequester(request);
1717 break;
1718
zoey chene02881a2019-12-30 16:11:23 +08001719 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1722 Pair<String, String> changed = (Pair<String, String>) request.argument;
1723 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1724 changed.first, changed.second, onCompleted);
1725 break;
1726 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1727 ar = (AsyncResult) msg.obj;
1728 request = (MainThreadRequest) ar.userObj;
1729 if (ar.exception == null) {
1730 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001731 // If the operation is successful, update the PIN storage
1732 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1733 int phoneId = getPhoneFromRequest(request).getPhoneId();
1734 UiccController.getInstance().getPinStorage()
1735 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001736 } else {
1737 request.result = msg.arg1;
1738 }
1739 notifyRequester(request);
1740 break;
1741
Michele Berionne5e411512020-11-13 02:36:59 +00001742 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001743 request = (MainThreadRequest) msg.obj;
1744 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1745 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1746 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1747 enabled.first, enabled.second, onCompleted);
1748 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001749 }
zoey chene02881a2019-12-30 16:11:23 +08001750 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1751 ar = (AsyncResult) msg.obj;
1752 request = (MainThreadRequest) ar.userObj;
1753 if (ar.exception == null) {
1754 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001755 // If the operation is successful, update the PIN storage
1756 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1757 int phoneId = getPhoneFromRequest(request).getPhoneId();
1758 if (enabled.first) {
1759 UiccController.getInstance().getPinStorage()
1760 .storePin(enabled.second, phoneId);
1761 } else {
1762 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1763 }
zoey chene02881a2019-12-30 16:11:23 +08001764 } else {
1765 request.result = msg.arg1;
1766 }
Michele Berionne5e411512020-11-13 02:36:59 +00001767
1768
zoey chene02881a2019-12-30 16:11:23 +08001769 notifyRequester(request);
1770 break;
1771
Peter Wangdafb9ac2020-01-15 14:13:38 -08001772 case MSG_NOTIFY_USER_ACTIVITY:
1773 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001774 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001775 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1776 getDefaultPhone().getContext().sendBroadcastAsUser(
1777 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1778 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001779
1780 case CMD_SET_DATA_THROTTLING: {
1781 request = (MainThreadRequest) msg.obj;
1782 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1783 DataThrottlingRequest dataThrottlingRequest =
1784 (DataThrottlingRequest) request.argument;
1785 Phone phone = getPhoneFromRequest(request);
1786 if (phone != null) {
1787 phone.setDataThrottling(onCompleted,
1788 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1789 dataThrottlingRequest.getCompletionDurationMillis());
1790 } else {
1791 loge("setDataThrottling: No phone object");
1792 request.result =
1793 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1794 notifyRequester(request);
1795 }
1796
1797 break;
1798 }
1799 case EVENT_SET_DATA_THROTTLING_DONE:
1800 ar = (AsyncResult) msg.obj;
1801 request = (MainThreadRequest) ar.userObj;
1802
1803 if (ar.exception == null) {
1804 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1805 } else if (ar.exception instanceof CommandException) {
1806 loge("setDataThrottling: CommandException: " + ar.exception);
1807 CommandException.Error error =
1808 ((CommandException) (ar.exception)).getCommandError();
1809
1810 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1811 request.result = TelephonyManager
1812 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1813 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1814 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001815 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1816 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001817 } else {
1818 request.result =
1819 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1820 }
1821 } else {
1822 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1823 }
1824 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1825 notifyRequester(request);
1826 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001827
1828 case CMD_SET_SIM_POWER: {
1829 request = (MainThreadRequest) msg.obj;
1830 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1831 request = (MainThreadRequest) msg.obj;
1832 int stateToSet =
1833 ((Pair<Integer, IIntegerConsumer>)
1834 request.argument).first;
1835 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1836 break;
1837 }
1838 case EVENT_SET_SIM_POWER_DONE: {
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 IIntegerConsumer callback =
1842 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1843 if (ar.exception != null) {
1844 loge("setSimPower exception: " + ar.exception);
1845 int errorCode = TelephonyManager.CallForwardingInfoCallback
1846 .RESULT_ERROR_UNKNOWN;
1847 if (ar.exception instanceof CommandException) {
1848 CommandException.Error error =
1849 ((CommandException) (ar.exception)).getCommandError();
1850 if (error == CommandException.Error.SIM_ERR) {
1851 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1852 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1853 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1854 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1855 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1856 } else {
1857 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1858 }
1859 }
1860 try {
1861 callback.accept(errorCode);
1862 } catch (RemoteException e) {
1863 // Ignore if the remote process is no longer available to call back.
1864 Log.w(LOG_TAG, "setSimPower: callback not available.");
1865 }
1866 } else {
1867 try {
1868 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1869 } catch (RemoteException e) {
1870 // Ignore if the remote process is no longer available to call back.
1871 Log.w(LOG_TAG, "setSimPower: callback not available.");
1872 }
1873 }
1874 break;
1875 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001876 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1877 request = (MainThreadRequest) msg.obj;
1878
1879 final Phone phone = getPhoneFromRequest(request);
1880 if (phone == null || phone.getServiceStateTracker() == null) {
1881 request.result = new IllegalStateException("Phone or SST is null");
1882 notifyRequester(request);
1883 break;
1884 }
1885
1886 Pair<Integer, SignalStrengthUpdateRequest> pair =
1887 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1888 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1889 request);
1890 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1891 request.subId, pair.first /*callingUid*/,
1892 pair.second /*request*/, onCompleted);
1893 break;
1894 }
1895 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1896 ar = (AsyncResult) msg.obj;
1897 request = (MainThreadRequest) ar.userObj;
1898 // request.result will be the exception of ar if present, true otherwise.
1899 // Be cautious not to leave result null which will wait() forever
1900 request.result = ar.exception != null ? ar.exception : true;
1901 notifyRequester(request);
1902 break;
1903 }
1904 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1905 request = (MainThreadRequest) msg.obj;
1906
1907 Phone phone = getPhoneFromRequest(request);
1908 if (phone == null || phone.getServiceStateTracker() == null) {
1909 request.result = new IllegalStateException("Phone or SST is null");
1910 notifyRequester(request);
1911 break;
1912 }
1913
1914 Pair<Integer, SignalStrengthUpdateRequest> pair =
1915 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1916 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1917 request);
1918 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1919 request.subId, pair.first /*callingUid*/,
1920 pair.second /*request*/, onCompleted);
1921 break;
1922 }
1923 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1924 ar = (AsyncResult) msg.obj;
1925 request = (MainThreadRequest) ar.userObj;
1926 request.result = ar.exception != null ? ar.exception : true;
1927 notifyRequester(request);
1928 break;
1929 }
Jordan Liu109698e2020-11-24 14:50:34 -08001930
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001931 case CMD_GET_SLICING_CONFIG: {
1932 request = (MainThreadRequest) msg.obj;
1933 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1934 request.phone.getSlicingConfig(onCompleted);
1935 break;
1936 }
1937 case EVENT_GET_SLICING_CONFIG_DONE: {
1938 ar = (AsyncResult) msg.obj;
1939 request = (MainThreadRequest) ar.userObj;
1940 ResultReceiver result = (ResultReceiver) request.argument;
1941
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001942 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001943 Bundle bundle = new Bundle();
1944 int resultCode = 0;
1945 if (ar.exception != null) {
1946 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1947 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001948 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001949 } else if (ar.result == null) {
1950 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001951 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001952 } else {
1953 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001954 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1955 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001956 }
1957
1958 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001959 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001960 }
1961 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1962 result.send(resultCode, bundle);
1963 notifyRequester(request);
1964 break;
1965 }
1966
Michele Berionne5e411512020-11-13 02:36:59 +00001967 case CMD_PREPARE_UNATTENDED_REBOOT:
1968 request = (MainThreadRequest) msg.obj;
1969 request.result =
1970 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1971 notifyRequester(request);
1972 break;
1973
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 default:
1975 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1976 break;
1977 }
1978 }
Jake Hambye994d462014-02-03 13:10:13 -08001979
Pengquan Menga1bb6272018-09-06 09:59:22 -07001980 private void notifyRequester(MainThreadRequest request) {
1981 synchronized (request) {
1982 request.notifyAll();
1983 }
1984 }
1985
Jake Hambye994d462014-02-03 13:10:13 -08001986 private void handleNullReturnEvent(Message msg, String command) {
1987 AsyncResult ar = (AsyncResult) msg.obj;
1988 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1989 if (ar.exception == null) {
1990 request.result = true;
1991 } else {
1992 request.result = false;
1993 if (ar.exception instanceof CommandException) {
1994 loge(command + ": CommandException: " + ar.exception);
1995 } else {
1996 loge(command + ": Unknown exception");
1997 }
1998 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001999 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002000 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 }
2002
2003 /**
2004 * Posts the specified command to be executed on the main thread,
2005 * waits for the request to complete, and returns the result.
2006 * @see #sendRequestAsync
2007 */
2008 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002009 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2010 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002011 }
2012
2013 /**
2014 * Posts the specified command to be executed on the main thread,
2015 * waits for the request to complete, and returns the result.
2016 * @see #sendRequestAsync
2017 */
2018 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2019 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002020 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002021 }
2022
2023 /**
2024 * Posts the specified command to be executed on the main thread,
2025 * waits for the request to complete, and returns the result.
2026 * @see #sendRequestAsync
2027 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002028 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002029 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2030 }
2031
2032 /**
2033 * Posts the specified command to be executed on the main thread,
2034 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2035 * if not timeout or null otherwise.
2036 * @see #sendRequestAsync
2037 */
2038 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2039 long timeoutInMs) {
2040 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002041 }
2042
2043 /**
2044 * Posts the specified command to be executed on the main thread,
2045 * waits for the request to complete, and returns the result.
2046 * @see #sendRequestAsync
2047 */
Nathan Harold92bed182018-10-12 18:16:49 -07002048 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002049 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002050 }
2051
2052 /**
2053 * Posts the specified command to be executed on the main thread,
2054 * waits for the request to complete, and returns the result.
2055 * @see #sendRequestAsync
2056 */
2057 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002058 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2059 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002060 }
2061
2062 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002063 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2064 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2065 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002066 * @see #sendRequestAsync
2067 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002068 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2069 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2071 throw new RuntimeException("This method will deadlock if called from the main thread.");
2072 }
2073
Nathan Harold92bed182018-10-12 18:16:49 -07002074 MainThreadRequest request = null;
2075 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2076 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2077 } else if (phone != null) {
2078 request = new MainThreadRequest(argument, phone, workSource);
2079 } else {
2080 request = new MainThreadRequest(argument, subId, workSource);
2081 }
2082
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 Message msg = mMainThreadHandler.obtainMessage(command, request);
2084 msg.sendToTarget();
2085
Rambo Wang0f050d82021-02-12 11:43:36 -08002086
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002088 if (timeoutInMs >= 0) {
2089 // Wait for at least timeoutInMs before returning null request result
2090 long now = SystemClock.elapsedRealtime();
2091 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002092 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002093 try {
2094 request.wait(deadline - now);
2095 } catch (InterruptedException e) {
2096 // Do nothing, go back and check if request is completed or timeout
2097 } finally {
2098 now = SystemClock.elapsedRealtime();
2099 }
2100 }
2101 } else {
2102 // Wait for the request to complete
2103 while (request.result == null) {
2104 try {
2105 request.wait();
2106 } catch (InterruptedException e) {
2107 // Do nothing, go back and wait until the request is complete
2108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002109 }
2110 }
2111 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002112 if (request.result == null) {
2113 Log.wtf(LOG_TAG,
2114 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 return request.result;
2117 }
2118
2119 /**
2120 * Asynchronous ("fire and forget") version of sendRequest():
2121 * Posts the specified command to be executed on the main thread, and
2122 * returns immediately.
2123 * @see #sendRequest
2124 */
2125 private void sendRequestAsync(int command) {
2126 mMainThreadHandler.sendEmptyMessage(command);
2127 }
2128
2129 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002130 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002131 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002132 */
2133 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002134 sendRequestAsync(command, argument, null, null);
2135 }
2136
2137 /**
2138 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2139 * @see {@link #sendRequest(int,Object)}
2140 */
2141 private void sendRequestAsync(
2142 int command, Object argument, Phone phone, WorkSource workSource) {
2143 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002144 Message msg = mMainThreadHandler.obtainMessage(command, request);
2145 msg.sendToTarget();
2146 }
2147
2148 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 * Initialize the singleton PhoneInterfaceManager instance.
2150 * This is only done once, at startup, from PhoneApp.onCreate().
2151 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002152 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 synchronized (PhoneInterfaceManager.class) {
2154 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002155 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 } else {
2157 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2158 }
2159 return sInstance;
2160 }
2161 }
2162
2163 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002164 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002167 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002168 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002170 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002172 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002173 mTelephonySharedPreferences =
2174 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002175 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002176 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002177 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002178 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002179
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 publish();
2181 }
2182
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002183 private Phone getDefaultPhone() {
2184 Phone thePhone = getPhone(getDefaultSubscription());
2185 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2186 }
2187
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 private void publish() {
2189 if (DBG) log("publish: " + this);
2190
Peter Wangc035ce42020-01-08 21:00:22 -08002191 TelephonyFrameworkInitializer
2192 .getTelephonyServiceManager()
2193 .getTelephonyServiceRegisterer()
2194 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 }
2196
Stuart Scott584921c2015-01-15 17:10:34 -08002197 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002198 if (request.phone != null) {
2199 return request.phone;
2200 } else {
2201 return getPhoneFromSubId(request.subId);
2202 }
2203 }
2204
2205 private Phone getPhoneFromSubId(int subId) {
2206 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2207 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002208 }
2209
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002210 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2211 Phone phone = getPhoneFromRequest(request);
2212 return phone == null ? null :
2213 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2214 }
2215
Wink Saville36469e72014-06-11 15:17:00 -07002216 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002217 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002218 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220
Kai Shif70f46f2021-03-03 13:59:46 -08002221 private void sendEraseModemConfig(@NonNull Phone phone) {
2222 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2223 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2224 }
2225
2226 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2227 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2228 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002229 }
2230
Peter Wang44b186e2020-01-13 23:33:09 -08002231 private boolean isImsAvailableOnDevice() {
2232 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2233 if (pm == null) {
2234 // For some reason package manger is not available.. This will fail internally anyway,
2235 // so do not throw error and allow.
2236 return true;
2237 }
2238 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2239 }
2240
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002242 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002243 }
2244
Wink Savilleb564aae2014-10-23 10:18:09 -07002245 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 if (DBG) log("dial: " + number);
2247 // No permission check needed here: This is just a wrapper around the
2248 // ACTION_DIAL intent, which is available to any app since it puts up
2249 // the UI before it does anything.
2250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002251 final long identity = Binder.clearCallingIdentity();
2252 try {
2253 String url = createTelUrl(number);
2254 if (url == null) {
2255 return;
2256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 // PENDING: should we just silently fail if phone is offhook or ringing?
2259 PhoneConstants.State state = mCM.getState(subId);
2260 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2261 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2262 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2263 mApp.startActivity(intent);
2264 }
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268 }
2269
2270 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002271 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002272 }
2273
Wink Savilleb564aae2014-10-23 10:18:09 -07002274 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 if (DBG) log("call: " + number);
2276
2277 // This is just a wrapper around the ACTION_CALL intent, but we still
2278 // need to do a permission check since we're calling startActivity()
2279 // from the context of the phone app.
2280 enforceCallPermission();
2281
Jordan Liu1617b712019-07-10 15:06:26 -07002282 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 != AppOpsManager.MODE_ALLOWED) {
2284 return;
2285 }
2286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 String url = createTelUrl(number);
2290 if (url == null) {
2291 return;
2292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294 boolean isValid = false;
2295 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2296 if (slist != null) {
2297 for (SubscriptionInfo subInfoRecord : slist) {
2298 if (subInfoRecord.getSubscriptionId() == subId) {
2299 isValid = true;
2300 break;
2301 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002302 }
Wink Saville08874612014-08-31 19:19:58 -07002303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002304 if (!isValid) {
2305 return;
2306 }
Wink Saville08874612014-08-31 19:19:58 -07002307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002308 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2309 intent.putExtra(SUBSCRIPTION_KEY, subId);
2310 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2311 mApp.startActivity(intent);
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
2314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 }
2316
Wink Savilleb564aae2014-10-23 10:18:09 -07002317 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002318 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002319 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2320 }
2321
Wink Savilleb564aae2014-10-23 10:18:09 -07002322 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002323 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002324 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2325 }
2326
Wink Savilleb564aae2014-10-23 10:18:09 -07002327 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002329
2330 final long identity = Binder.clearCallingIdentity();
2331 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002332 Phone phone = getPhone(subId);
2333 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334 checkSimPin.start();
2335 return checkSimPin.unlockSim(null, pin);
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
2338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
2340
Wink Savilleb564aae2014-10-23 10:18:09 -07002341 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002346 Phone phone = getPhone(subId);
2347 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348 checkSimPuk.start();
2349 return checkSimPuk.unlockSim(puk, pin);
2350 } finally {
2351 Binder.restoreCallingIdentity(identity);
2352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 }
2354
2355 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002356 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357 * a synchronous one.
2358 */
2359 private static class UnlockSim extends Thread {
2360
2361 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002362 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363
2364 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002365 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2366 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367
2368 // For replies from SimCard interface
2369 private Handler mHandler;
2370
2371 // For async handler to identify request type
2372 private static final int SUPPLY_PIN_COMPLETE = 100;
2373
Michele Berionne5e411512020-11-13 02:36:59 +00002374 UnlockSim(int phoneId, IccCard simCard) {
2375 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 mSimCard = simCard;
2377 }
2378
2379 @Override
2380 public void run() {
2381 Looper.prepare();
2382 synchronized (UnlockSim.this) {
2383 mHandler = new Handler() {
2384 @Override
2385 public void handleMessage(Message msg) {
2386 AsyncResult ar = (AsyncResult) msg.obj;
2387 switch (msg.what) {
2388 case SUPPLY_PIN_COMPLETE:
2389 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2390 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002391 mRetryCount = msg.arg1;
2392 if (ar.exception != null) {
2393 if (ar.exception instanceof CommandException &&
2394 ((CommandException)(ar.exception)).getCommandError()
2395 == CommandException.Error.PASSWORD_INCORRECT) {
2396 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002397 } //When UiccCardApp dispose,handle message and return exception
2398 else if (ar.exception instanceof CommandException &&
2399 ((CommandException) (ar.exception)).getCommandError()
2400 == CommandException.Error.ABORTED) {
2401 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002402 } else {
2403 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2404 }
2405 } else {
2406 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2407 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002408 mDone = true;
2409 UnlockSim.this.notifyAll();
2410 }
2411 break;
2412 }
2413 }
2414 };
2415 UnlockSim.this.notifyAll();
2416 }
2417 Looper.loop();
2418 }
2419
2420 /*
2421 * Use PIN or PUK to unlock SIM card
2422 *
2423 * If PUK is null, unlock SIM card with PIN
2424 *
2425 * If PUK is not null, unlock SIM card with PUK and set PIN code
2426 */
Wink Saville9de0f752013-10-22 19:04:03 -07002427 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428
2429 while (mHandler == null) {
2430 try {
2431 wait();
2432 } catch (InterruptedException e) {
2433 Thread.currentThread().interrupt();
2434 }
2435 }
2436 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2437
2438 if (puk == null) {
2439 mSimCard.supplyPin(pin, callback);
2440 } else {
2441 mSimCard.supplyPuk(puk, pin, callback);
2442 }
2443
2444 while (!mDone) {
2445 try {
2446 Log.d(LOG_TAG, "wait for done");
2447 wait();
2448 } catch (InterruptedException e) {
2449 // Restore the interrupted status
2450 Thread.currentThread().interrupt();
2451 }
2452 }
2453 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002454 int[] resultArray = new int[2];
2455 resultArray[0] = mResult;
2456 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002457
2458 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2459 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2460 }
2461
Wink Saville9de0f752013-10-22 19:04:03 -07002462 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464 }
2465
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002466 /**
2467 * This method has been removed due to privacy and stability concerns.
2468 */
2469 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002470 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002471 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2472 return;
Wink Saville36469e72014-06-11 15:17:00 -07002473 }
2474
Nathan Harold1f889d82020-06-04 17:05:26 -07002475 @Override
2476 public void updateServiceLocationWithPackageName(String callingPackage) {
2477 mApp.getSystemService(AppOpsManager.class)
2478 .checkPackage(Binder.getCallingUid(), callingPackage);
2479
Nathan Haroldf096d982020-11-18 17:18:06 -08002480 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002481 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2482 // Callers targeting S have no business invoking this method.
2483 return;
2484 }
2485
2486 LocationAccessPolicy.LocationPermissionResult locationResult =
2487 LocationAccessPolicy.checkLocationPermission(mApp,
2488 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2489 .setCallingPackage(callingPackage)
2490 .setCallingFeatureId(null)
2491 .setCallingPid(Binder.getCallingPid())
2492 .setCallingUid(Binder.getCallingUid())
2493 .setMethod("updateServiceLocation")
2494 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2495 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2496 .build());
2497 // Apps that lack location permission have no business calling this method;
2498 // however, because no permission was declared in the public API, denials must
2499 // all be "soft".
2500 switch (locationResult) {
2501 case DENIED_HARD: /* fall through */
2502 case DENIED_SOFT:
2503 return;
2504 }
2505
2506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 final long identity = Binder.clearCallingIdentity();
2508 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002509 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002511 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 }
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 }
2517
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002518 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002519 @Override
2520 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002521 return isRadioOnWithFeature(callingPackage, null);
2522 }
2523
2524
2525 @Override
2526 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2527 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2528 callingFeatureId);
2529 }
2530
2531 @Deprecated
2532 @Override
2533 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2534 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002535 }
2536
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002538 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2539 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002541 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002542 return false;
2543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 return isRadioOnForSubscriber(subId);
2548 } finally {
2549 Binder.restoreCallingIdentity(identity);
2550 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002551 }
2552
2553 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 final Phone phone = getPhone(subId);
2557 if (phone != null) {
2558 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2559 } else {
2560 return false;
2561 }
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 }
2566
2567 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002568 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 }
Wink Saville36469e72014-06-11 15:17:00 -07002570
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002573
2574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 if (phone != null) {
2578 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002582 }
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
2585 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002586 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002587 }
2588
Wink Savilleb564aae2014-10-23 10:18:09 -07002589 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002590 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591
2592 final long identity = Binder.clearCallingIdentity();
2593 try {
2594 final Phone phone = getPhone(subId);
2595 if (phone == null) {
2596 return false;
2597 }
2598 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2599 toggleRadioOnOffForSubscriber(subId);
2600 }
2601 return true;
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 }
Wink Saville36469e72014-06-11 15:17:00 -07002606
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002607 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002608 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002609 /*
2610 * If any of the Radios are available, it will need to be
2611 * shutdown. So return true if any Radio is available.
2612 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2616 Phone phone = PhoneFactory.getPhone(i);
2617 if (phone != null && phone.isRadioAvailable()) return true;
2618 }
2619 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2620 return false;
2621 } finally {
2622 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002623 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002624 }
2625
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002627 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 enforceModifyPermission();
2629
2630 final long identity = Binder.clearCallingIdentity();
2631 try {
2632 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2633 logv("Shutting down Phone " + i);
2634 shutdownRadioUsingPhoneId(i);
2635 }
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002638 }
2639 }
2640
2641 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002642 Phone phone = PhoneFactory.getPhone(phoneId);
2643 if (phone != null && phone.isRadioAvailable()) {
2644 phone.shutdownRadio();
2645 }
2646 }
2647
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002648 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002649 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650
2651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2654 if (defaultPhone != null) {
2655 defaultPhone.setRadioPower(turnOn);
2656 return true;
2657 } else {
2658 loge("There's no default phone.");
2659 return false;
2660 }
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002663 }
Wink Saville36469e72014-06-11 15:17:00 -07002664 }
2665
Wink Savilleb564aae2014-10-23 10:18:09 -07002666 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002667 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
2669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 final Phone phone = getPhone(subId);
2672 if (phone != null) {
2673 phone.setRadioPower(turnOn);
2674 return true;
2675 } else {
2676 return false;
2677 }
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 }
2682
Wink Saville36469e72014-06-11 15:17:00 -07002683 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002684 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 public boolean enableDataConnectivity() {
2686 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 int subId = mSubscriptionController.getDefaultDataSubId();
2691 final Phone phone = getPhone(subId);
2692 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002693 phone.getDataEnabledSettings().setDataEnabled(
2694 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002695 return true;
2696 } else {
2697 return false;
2698 }
2699 } finally {
2700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 }
2703
Wink Saville36469e72014-06-11 15:17:00 -07002704 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002705 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 public boolean disableDataConnectivity() {
2707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 int subId = mSubscriptionController.getDefaultDataSubId();
2712 final Phone phone = getPhone(subId);
2713 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002714 phone.getDataEnabledSettings().setDataEnabled(
2715 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 return true;
2717 } else {
2718 return false;
2719 }
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002726 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 final Phone phone = getPhone(subId);
2730 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002731 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 } else {
2733 return false;
2734 }
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
2739
2740 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002741 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002742 }
2743
pkanwarae03a6b2016-11-06 20:37:09 -08002744 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745 enforceCallPermission();
2746
2747 final long identity = Binder.clearCallingIdentity();
2748 try {
2749 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2750 return;
2751 }
2752 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2753 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
pkanwar32d516d2016-10-14 19:37:38 -07002757 };
2758
Wink Savilleb564aae2014-10-23 10:18:09 -07002759 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2765 return false;
2766 }
2767 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002773 /**
2774 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2775 * tag on getCallState Binder call.
2776 */
2777 @Deprecated
2778 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002780 if (CompatChanges.isChangeEnabled(
2781 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2782 Binder.getCallingUid())) {
2783 // Do not allow this API to be called on API version 31+, it should only be
2784 // called on old apps using this Binder call directly.
2785 throw new SecurityException("This method can only be used for applications "
2786 + "targeting API version 30 or less.");
2787 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 final long identity = Binder.clearCallingIdentity();
2789 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002790 Phone phone = getPhone(getDefaultSubscription());
2791 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2792 PhoneConstantConversions.convertCallState(phone.getState());
2793 } finally {
2794 Binder.restoreCallingIdentity(identity);
2795 }
2796 }
2797
2798 @Override
2799 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2800 if (CompatChanges.isChangeEnabled(
2801 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2802 Binder.getCallingUid())) {
2803 // Check READ_PHONE_STATE for API version 31+
2804 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2805 featureId, "getCallStateForSubscription")) {
2806 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2807 + "targeting API level 31+.");
2808 }
2809 }
2810 final long identity = Binder.clearCallingIdentity();
2811 try {
2812 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2814 PhoneConstantConversions.convertCallState(phone.getState());
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
2817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
2819
Sanket Padawe356d7632015-06-22 14:03:32 -07002820 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002821 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002822 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2823 }
2824
2825 @Override
2826 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 final long identity = Binder.clearCallingIdentity();
2828 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002829 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 if (phone != null) {
2831 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2832 } else {
2833 return PhoneConstantConversions.convertDataState(
2834 PhoneConstants.DataState.DISCONNECTED);
2835 }
2836 } finally {
2837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002839 }
2840
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002842 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002843 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2844 }
2845
2846 @Override
2847 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002850 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 if (phone != null) {
2852 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2853 } else {
2854 return TelephonyManager.DATA_ACTIVITY_NONE;
2855 }
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
2861 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002862 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002864 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002865
2866 LocationAccessPolicy.LocationPermissionResult locationResult =
2867 LocationAccessPolicy.checkLocationPermission(mApp,
2868 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2869 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002870 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002871 .setCallingPid(Binder.getCallingPid())
2872 .setCallingUid(Binder.getCallingUid())
2873 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002874 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002875 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2876 .build());
2877 switch (locationResult) {
2878 case DENIED_HARD:
2879 throw new SecurityException("Not allowed to access cell location");
2880 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002881 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2882 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002883 }
2884
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002885 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002889 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002890 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002891 } finally {
2892 Binder.restoreCallingIdentity(identity);
2893 }
Svetoslav64fad262015-04-14 14:35:21 -07002894 }
2895
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002897 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002898 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2899 // registered cell info, so return a NULL country instead.
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002902 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2903 // Get default phone in this case.
2904 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2905 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002906 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002908 if (phone == null) return "";
2909 ServiceStateTracker sst = phone.getServiceStateTracker();
2910 if (sst == null) return "";
2911 LocaleTracker lt = sst.getLocaleTracker();
2912 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002913 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002917 }
2918
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002919 /**
2920 * This method was removed due to potential issues caused by performing partial
2921 * updates of service state, and lack of a credible use case.
2922 *
2923 * This has the ability to break the telephony implementation by disabling notification of
2924 * changes in device connectivity. DO NOT USE THIS!
2925 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002926 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 public void enableLocationUpdates() {
2928 mApp.enforceCallingOrSelfPermission(
2929 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002930 }
2931
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002932 /**
2933 * This method was removed due to potential issues caused by performing partial
2934 * updates of service state, and lack of a credible use case.
2935 *
2936 * This has the ability to break the telephony implementation by disabling notification of
2937 * changes in device connectivity. DO NOT USE THIS!
2938 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 @Override
2940 public void disableLocationUpdates() {
2941 mApp.enforceCallingOrSelfPermission(
2942 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943 }
2944
2945 @Override
2946 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002947 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2948 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002949 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002950 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2951 throw new SecurityException(
2952 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2953 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002954
Jordan Liu1617b712019-07-10 15:06:26 -07002955 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002956 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2957 return null;
2958 }
Svetoslav64fad262015-04-14 14:35:21 -07002959
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002960 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002961
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002962 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002963 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002964
Nathan Haroldf180aac2018-06-01 18:43:55 -07002965 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2966 for (CellInfo ci : info) {
2967 if (ci instanceof CellInfoGsm) {
2968 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2969 } else if (ci instanceof CellInfoWcdma) {
2970 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2971 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002972 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002973 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002974 }
2975
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002976 private List<CellInfo> getCachedCellInfo() {
2977 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2978 for (Phone phone : PhoneFactory.getPhones()) {
2979 List<CellInfo> info = phone.getAllCellInfo();
2980 if (info != null) cellInfos.addAll(info);
2981 }
2982 return cellInfos;
2983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984
2985 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002986 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002987 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002988 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002989
2990 LocationAccessPolicy.LocationPermissionResult locationResult =
2991 LocationAccessPolicy.checkLocationPermission(mApp,
2992 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2993 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002994 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002995 .setCallingPid(Binder.getCallingPid())
2996 .setCallingUid(Binder.getCallingUid())
2997 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002998 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002999 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3000 .build());
3001 switch (locationResult) {
3002 case DENIED_HARD:
3003 throw new SecurityException("Not allowed to access cell info");
3004 case DENIED_SOFT:
3005 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003006 }
3007
Nathan Haroldf096d982020-11-18 17:18:06 -08003008 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003009 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3010 return getCachedCellInfo();
3011 }
3012
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003013 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003014 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3018 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003019 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003020 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021 if (info != null) cellInfos.addAll(info);
3022 }
3023 return cellInfos;
3024 } finally {
3025 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003026 }
3027 }
3028
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003029 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003030 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3031 String callingFeatureId) {
3032 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3033 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003034 }
3035
3036 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003037 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3038 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003039 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003040 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003041 }
3042
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003043 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3044 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003045 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003046 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003047
3048 LocationAccessPolicy.LocationPermissionResult locationResult =
3049 LocationAccessPolicy.checkLocationPermission(mApp,
3050 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3051 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003052 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003053 .setCallingPid(Binder.getCallingPid())
3054 .setCallingUid(Binder.getCallingUid())
3055 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003056 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3057 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003058 .build());
3059 switch (locationResult) {
3060 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003061 if (TelephonyPermissions
3062 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003063 // Safetynet logging for b/154934934
3064 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3065 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003066 throw new SecurityException("Not allowed to access cell info");
3067 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003068 if (TelephonyPermissions
3069 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003070 // Safetynet logging for b/154934934
3071 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3072 }
Nathan Harold5320c422019-05-09 10:26:08 -07003073 try {
3074 cb.onCellInfo(new ArrayList<CellInfo>());
3075 } catch (RemoteException re) {
3076 // Drop without consequences
3077 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003078 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003079 }
3080
Nathan Harolda939a962019-05-09 10:13:47 -07003081
3082 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003083 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3084
3085 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3086 }
3087
3088 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003089 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003090 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003091 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003092
3093 final long identity = Binder.clearCallingIdentity();
3094 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003095 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003099 }
3100
Shishir Agrawala9f32182016-04-12 12:00:16 -07003101 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003102 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003103 Phone phone = PhoneFactory.getPhone(slotIndex);
3104 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003105 return null;
3106 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003107 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003108 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003109 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003110 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003111 return null;
3112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 return phone.getImei();
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003120 }
3121
3122 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003123 public String getTypeAllocationCodeForSlot(int slotIndex) {
3124 Phone phone = PhoneFactory.getPhone(slotIndex);
3125 String tac = null;
3126 if (phone != null) {
3127 String imei = phone.getImei();
3128 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3129 }
3130 return tac;
3131 }
3132
3133 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003134 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003135 Phone phone = PhoneFactory.getPhone(slotIndex);
3136 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003137 return null;
3138 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139
Jeff Davidson913390f2018-02-23 17:11:49 -08003140 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003141 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003143 return null;
3144 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003145
3146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 return phone.getMeid();
3149 } finally {
3150 Binder.restoreCallingIdentity(identity);
3151 }
Jack Yu2af8d712017-03-15 17:14:14 -07003152 }
3153
3154 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003155 public String getManufacturerCodeForSlot(int slotIndex) {
3156 Phone phone = PhoneFactory.getPhone(slotIndex);
3157 String manufacturerCode = null;
3158 if (phone != null) {
3159 String meid = phone.getMeid();
3160 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3161 }
3162 return manufacturerCode;
3163 }
3164
3165 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003166 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3167 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003168 Phone phone = PhoneFactory.getPhone(slotIndex);
3169 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003170 return null;
3171 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003172 int subId = phone.getSubId();
3173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003174 mApp, subId, callingPackage, callingFeatureId,
3175 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003176 return null;
3177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003178
3179 final long identity = Binder.clearCallingIdentity();
3180 try {
3181 return phone.getDeviceSvn();
3182 } finally {
3183 Binder.restoreCallingIdentity(identity);
3184 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003185 }
3186
fionaxu43304da2017-11-27 22:51:16 -08003187 @Override
3188 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 final Phone phone = getPhone(subId);
3192 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
fionaxu43304da2017-11-27 22:51:16 -08003196 }
3197
3198 @Override
3199 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 final Phone phone = getPhone(subId);
3203 return phone == null ? null : phone.getCarrierName();
3204 } finally {
3205 Binder.restoreCallingIdentity(identity);
3206 }
fionaxu43304da2017-11-27 22:51:16 -08003207 }
3208
calvinpanffe225e2018-11-01 19:43:06 +08003209 @Override
chen xu0026ca62019-03-06 15:28:50 -08003210 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 final Phone phone = getPhone(subId);
3214 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003215 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
3219 }
3220
3221 @Override
chen xu0026ca62019-03-06 15:28:50 -08003222 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003226 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003227 } finally {
3228 Binder.restoreCallingIdentity(identity);
3229 }
3230 }
3231
chen xu651eec72018-11-11 19:03:44 -08003232 @Override
chen xu864e11c2018-12-06 22:10:03 -08003233 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3234 if (!isSubscriptionMccMnc) {
3235 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3236 }
chen xu651eec72018-11-11 19:03:44 -08003237 final Phone phone = PhoneFactory.getPhone(slotIndex);
3238 if (phone == null) {
3239 return TelephonyManager.UNKNOWN_CARRIER_ID;
3240 }
3241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 }
3248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003249 //
3250 // Internal helper methods.
3251 //
3252
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003253 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003254 * Make sure the caller is the calling package itself
3255 *
3256 * @throws SecurityException if the caller is not the calling package
3257 */
3258 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3259 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003260 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3261 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003262 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003263 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003264 } catch (PackageManager.NameNotFoundException e) {
3265 // packageUid is -1
3266 }
3267 if (packageUid != callingUid) {
3268 throw new SecurityException(message + ": Package " + callingPackage
3269 + " does not belong to " + callingUid);
3270 }
3271 }
3272
3273 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3275 *
3276 * @throws SecurityException if the caller does not have the required permission
3277 */
3278 private void enforceModifyPermission() {
3279 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3280 }
3281
Shuo Qiancd19c462020-01-16 20:51:11 -08003282 /**
3283 * Make sure the caller is system.
3284 *
3285 * @throws SecurityException if the caller is not system.
3286 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003287 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003288 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3289 throw new SecurityException("Caller must be system");
3290 }
3291 }
3292
Shuo Qian3b6ee772019-11-13 17:43:31 -08003293 private void enforceActiveEmergencySessionPermission() {
3294 mApp.enforceCallingOrSelfPermission(
3295 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3296 }
3297
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003298 /**
3299 * Make sure the caller has the CALL_PHONE permission.
3300 *
3301 * @throws SecurityException if the caller does not have the required permission
3302 */
3303 private void enforceCallPermission() {
3304 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3305 }
3306
paulhu5a773602019-08-23 19:17:33 +08003307 private void enforceSettingsPermission() {
3308 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003309 }
3310
Michele Berionne5e411512020-11-13 02:36:59 +00003311 private void enforceRebootPermission() {
3312 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3313 }
3314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315 private String createTelUrl(String number) {
3316 if (TextUtils.isEmpty(number)) {
3317 return null;
3318 }
3319
Jake Hambye994d462014-02-03 13:10:13 -08003320 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 }
3322
Ihab Awadf9e92732013-12-05 18:02:52 -08003323 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003324 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3325 }
3326
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003327 private static void logv(String msg) {
3328 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3329 }
3330
Ihab Awadf9e92732013-12-05 18:02:52 -08003331 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003332 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3333 }
3334
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003335 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003337 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003338 }
3339
Sanket Padawe356d7632015-06-22 14:03:32 -07003340 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003341 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 final Phone phone = PhoneFactory.getPhone(slotIndex);
3345 if (phone == null) {
3346 return PhoneConstants.PHONE_TYPE_NONE;
3347 } else {
3348 return phone.getPhoneType();
3349 }
3350 } finally {
3351 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003353 }
3354
3355 /**
3356 * Returns the CDMA ERI icon index to display
3357 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003358 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003359 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3360 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3361 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003362 }
3363
Sanket Padawe356d7632015-06-22 14:03:32 -07003364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003365 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3366 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003368 mApp, subId, callingPackage, callingFeatureId,
3369 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003370 return -1;
3371 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003372
3373 final long identity = Binder.clearCallingIdentity();
3374 try {
3375 final Phone phone = getPhone(subId);
3376 if (phone != null) {
3377 return phone.getCdmaEriIconIndex();
3378 } else {
3379 return -1;
3380 }
3381 } finally {
3382 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003383 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003384 }
3385
3386 /**
3387 * Returns the CDMA ERI icon mode,
3388 * 0 - ON
3389 * 1 - FLASHING
3390 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003391 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003392 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3393 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3394 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003395 }
3396
Sanket Padawe356d7632015-06-22 14:03:32 -07003397 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003398 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3399 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003401 mApp, subId, callingPackage, callingFeatureId,
3402 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003403 return -1;
3404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 final Phone phone = getPhone(subId);
3409 if (phone != null) {
3410 return phone.getCdmaEriIconMode();
3411 } else {
3412 return -1;
3413 }
3414 } finally {
3415 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003417 }
3418
3419 /**
3420 * Returns the CDMA ERI text,
3421 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003422 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003423 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3424 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3425 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003426 }
3427
Sanket Padawe356d7632015-06-22 14:03:32 -07003428 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003429 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3430 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003432 mApp, subId, callingPackage, callingFeatureId,
3433 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003434 return null;
3435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003436
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 final Phone phone = getPhone(subId);
3440 if (phone != null) {
3441 return phone.getCdmaEriText();
3442 } else {
3443 return null;
3444 }
3445 } finally {
3446 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003448 }
3449
3450 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003451 * Returns the CDMA MDN.
3452 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003453 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003454 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3456 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003457
3458 final long identity = Binder.clearCallingIdentity();
3459 try {
3460 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003461 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462 return phone.getLine1Number();
3463 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 return null;
3466 }
3467 } finally {
3468 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003469 }
3470 }
3471
3472 /**
3473 * Returns the CDMA MIN.
3474 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003475 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003476 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3478 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 final Phone phone = getPhone(subId);
3483 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3484 return phone.getCdmaMin();
3485 } else {
3486 return null;
3487 }
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003490 }
3491 }
3492
Hall Liud892bec2018-11-30 14:51:45 -08003493 @Override
3494 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3495 INumberVerificationCallback callback, String callingPackage) {
3496 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3497 != PERMISSION_GRANTED) {
3498 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3499 }
3500 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3501
3502 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3503 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003504 throw new SecurityException("Calling package must be configured in the device config: "
3505 + "calling package: " + callingPackage
3506 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003507 }
3508
3509 if (range == null) {
3510 throw new NullPointerException("Range must be non-null");
3511 }
3512
3513 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003514 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003515
3516 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3517 }
3518
Junda Liuca05d5d2014-08-14 22:36:34 -07003519 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 * Returns true if CDMA provisioning needs to run.
3521 */
3522 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523 final long identity = Binder.clearCallingIdentity();
3524 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003525 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003526 } finally {
3527 Binder.restoreCallingIdentity(identity);
3528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003529 }
3530
3531 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003532 * Sets the voice mail number of a given subId.
3533 */
3534 @Override
3535 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003536 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3537 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538
3539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3542 new Pair<String, String>(alphaTag, number), new Integer(subId));
3543 return success;
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003547 }
3548
Ta-wei Yen87c49842016-05-13 21:19:52 -07003549 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003550 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3551 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003552 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3553 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003554 if (!TextUtils.equals(callingPackage, systemDialer)) {
3555 throw new SecurityException("caller must be system dialer");
3556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3561 if (phoneAccountHandle == null) {
3562 return null;
3563 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003564 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 } finally {
3566 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003567 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003568 }
3569
3570 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003571 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3572 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003573 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003575 mApp, subId, callingPackage, callingFeatureId,
3576 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003577 return null;
3578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003580 final long identity = Binder.clearCallingIdentity();
3581 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003582 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003583 } finally {
3584 Binder.restoreCallingIdentity(identity);
3585 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003586 }
3587
3588 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003589 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3590 VisualVoicemailSmsFilterSettings settings) {
3591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592
3593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003596 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597 } finally {
3598 Binder.restoreCallingIdentity(identity);
3599 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003600 }
3601
3602 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003603 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003609 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003613 }
3614
3615 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003616 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3617 String callingPackage, int subId) {
3618 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003623 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003627 }
3628
3629 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003630 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003636 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003640 }
3641
3642 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003643 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3644 String callingAttributionTag, int subId, String number, int port, String text,
3645 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003647 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003648 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003649 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003650 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3651 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003652 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003653
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003654 /**
fionaxu0152e512016-11-14 13:36:14 -08003655 * Sets the voice activation state of a given subId.
3656 */
3657 @Override
3658 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3660 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661
3662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = getPhone(subId);
3665 if (phone != null) {
3666 phone.setVoiceActivationState(activationState);
3667 } else {
3668 loge("setVoiceActivationState fails with invalid subId: " + subId);
3669 }
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003672 }
3673 }
3674
3675 /**
3676 * Sets the data activation state of a given subId.
3677 */
3678 @Override
3679 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003680 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3681 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003682
3683 final long identity = Binder.clearCallingIdentity();
3684 try {
3685 final Phone phone = getPhone(subId);
3686 if (phone != null) {
3687 phone.setDataActivationState(activationState);
3688 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003689 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 }
3691 } finally {
3692 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003693 }
3694 }
3695
3696 /**
3697 * Returns the voice activation state of a given subId.
3698 */
3699 @Override
3700 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702
fionaxu0152e512016-11-14 13:36:14 -08003703 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 if (phone != null) {
3707 return phone.getVoiceActivationState();
3708 } else {
3709 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3710 }
3711 } finally {
3712 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003713 }
3714 }
3715
3716 /**
3717 * Returns the data activation state of a given subId.
3718 */
3719 @Override
3720 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003722
fionaxu0152e512016-11-14 13:36:14 -08003723 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 if (phone != null) {
3727 return phone.getDataActivationState();
3728 } else {
3729 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3730 }
3731 } finally {
3732 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003733 }
3734 }
3735
3736 /**
Wink Saville36469e72014-06-11 15:17:00 -07003737 * Returns the unread count of voicemails for a subId
3738 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003739 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003740 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3741 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003742 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003743 mApp, subId, callingPackage, callingFeatureId,
3744 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003745 return 0;
3746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 final Phone phone = getPhone(subId);
3750 if (phone != null) {
3751 return phone.getVoiceMessageCount();
3752 } else {
3753 return 0;
3754 }
3755 } finally {
3756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003758 }
3759
3760 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003761 * returns true, if the device is in a state where both voice and data
3762 * are supported simultaneously. This can change based on location or network condition.
3763 */
3764 @Override
3765 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 final Phone phone = getPhone(subId);
3769 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3770 } finally {
3771 Binder.restoreCallingIdentity(identity);
3772 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003773 }
3774
3775 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003776 * Send the dialer code if called from the current default dialer or the caller has
3777 * carrier privilege.
3778 * @param inputCode The dialer code to send
3779 */
3780 @Override
3781 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003782 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003783 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003784 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3785 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003786 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003787 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003788 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790
3791 final long identity = Binder.clearCallingIdentity();
3792 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003793 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 } finally {
3795 Binder.restoreCallingIdentity(identity);
3796 }
fionaxu235cc5e2017-03-06 22:25:57 -08003797 }
3798
Pengquan Menga1bb6272018-09-06 09:59:22 -07003799 @Override
3800 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003801 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003802 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003803 mApp, subId, "getNetworkSelectionMode");
3804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 if (!isActiveSubscription(subId)) {
3807 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3808 }
3809 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003812 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003813 }
3814
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003816 public boolean isInEmergencySmsMode() {
3817 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 for (Phone phone : PhoneFactory.getPhones()) {
3821 if (phone.isInEmergencySmsMode()) {
3822 return true;
3823 }
3824 }
3825 } finally {
3826 Binder.restoreCallingIdentity(identity);
3827 }
3828 return false;
3829 }
3830
shilu366312e2019-12-17 09:28:10 -08003831 /**
3832 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3833 * @param subId The subscription to use to check the configuration.
3834 * @param c The callback that will be used to send the result.
3835 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003836 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003837 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3838 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003839 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003840 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003841
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003842 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3843 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3844 "IMS not available on device.");
3845 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003846 final long token = Binder.clearCallingIdentity();
3847 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003848 int slotId = getSlotIndexOrException(subId);
3849 verifyImsMmTelConfiguredOrThrow(slotId);
3850 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003851 } catch (ImsException e) {
3852 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003853 } finally {
3854 Binder.restoreCallingIdentity(token);
3855 }
3856 }
3857
shilu366312e2019-12-17 09:28:10 -08003858 /**
3859 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3860 * @param subId The subscription to use to check the configuration.
3861 * @param c The callback that will be used to send the result.
3862 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003864 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003865 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003866 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003867 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3868 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3869 }
Meng Wangafbc5852019-09-19 17:37:13 -07003870 final long token = Binder.clearCallingIdentity();
3871 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003872 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3873 .removeRegistrationCallbackForSubscription(c, subId);
3874 } catch (ImsException e) {
3875 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3876 + "is inactive, ignoring unregister.");
3877 // If the subscription is no longer active, just return, since the callback
3878 // will already have been removed internally.
3879 } finally {
3880 Binder.restoreCallingIdentity(token);
3881 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003882 }
3883
Brad Ebingera34a6c22019-10-22 17:36:18 -07003884 /**
3885 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3886 */
3887 @Override
3888 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3889 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3890 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3891 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3892 "IMS not available on device.");
3893 }
3894 final long token = Binder.clearCallingIdentity();
3895 try {
3896 Phone phone = getPhone(subId);
3897 if (phone == null) {
3898 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3899 + subId + "'");
3900 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3901 }
3902 phone.getImsRegistrationState(regState -> {
3903 try {
3904 consumer.accept((regState == null)
3905 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3906 } catch (RemoteException e) {
3907 // Ignore if the remote process is no longer available to call back.
3908 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3909 }
3910 });
3911 } finally {
3912 Binder.restoreCallingIdentity(token);
3913 }
3914 }
3915
3916 /**
3917 * Get the transport type for the IMS service registration state.
3918 */
3919 @Override
3920 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003921 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003922 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003923 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3924 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3925 "IMS not available on device.");
3926 }
3927 final long token = Binder.clearCallingIdentity();
3928 try {
3929 Phone phone = getPhone(subId);
3930 if (phone == null) {
3931 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3932 + subId + "'");
3933 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3934 }
3935 phone.getImsRegistrationTech(regTech -> {
3936 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3937 int regTechConverted = (regTech == null)
3938 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3939 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3940 regTechConverted);
3941 try {
3942 consumer.accept(regTechConverted);
3943 } catch (RemoteException e) {
3944 // Ignore if the remote process is no longer available to call back.
3945 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3946 }
3947 });
3948 } finally {
3949 Binder.restoreCallingIdentity(token);
3950 }
3951 }
3952
shilu366312e2019-12-17 09:28:10 -08003953 /**
3954 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3955 * @param subId The subscription to use to check the configuration.
3956 * @param c The callback that will be used to send the result.
3957 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003958 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003959 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3960 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003961 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003962 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003963 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3964 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3965 "IMS not available on device.");
3966 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 final long token = Binder.clearCallingIdentity();
3968 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003969 int slotId = getSlotIndexOrException(subId);
3970 verifyImsMmTelConfiguredOrThrow(slotId);
3971 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003972 } catch (ImsException e) {
3973 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 } finally {
3975 Binder.restoreCallingIdentity(token);
3976 }
3977 }
3978
shilu366312e2019-12-17 09:28:10 -08003979 /**
3980 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3981 * @param subId The subscription to use to check the configuration.
3982 * @param c The callback that will be used to send the result.
3983 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003985 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003986 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003987 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003988 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3989 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3990 }
Meng Wangafbc5852019-09-19 17:37:13 -07003991
3992 final long token = Binder.clearCallingIdentity();
3993 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003994 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003995 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003996 } catch (ImsException e) {
3997 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3998 + "is inactive, ignoring unregister.");
3999 // If the subscription is no longer active, just return, since the callback
4000 // will already have been removed internally.
4001 } finally {
4002 Binder.restoreCallingIdentity(token);
4003 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004004 }
4005
4006 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004007 public boolean isCapable(int subId, int capability, int regTech) {
4008 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 final long token = Binder.clearCallingIdentity();
4010 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004011 int slotId = getSlotIndexOrException(subId);
4012 verifyImsMmTelConfiguredOrThrow(slotId);
4013 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004014 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4016 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004017 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004018 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4019 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 } finally {
4021 Binder.restoreCallingIdentity(token);
4022 }
4023 }
4024
4025 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004026 public boolean isAvailable(int subId, int capability, int regTech) {
4027 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 final long token = Binder.clearCallingIdentity();
4029 try {
4030 Phone phone = getPhone(subId);
4031 if (phone == null) return false;
4032 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004033 } catch (com.android.ims.ImsException e) {
4034 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4035 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 } finally {
4037 Binder.restoreCallingIdentity(token);
4038 }
4039 }
4040
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004041 /**
4042 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4043 * subscription.
4044 * @param subId The subscription to use to check the configuration.
4045 * @param callback The callback that will be used to send the result.
4046 * @param capability The MmTelFeature capability that will be used to send the result.
4047 * @param transportType The transport type of the MmTelFeature capability.
4048 */
4049 @Override
4050 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4051 int transportType) {
4052 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4053 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4054 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4055 "IMS not available on device.");
4056 }
4057 final long token = Binder.clearCallingIdentity();
4058 try {
4059 int slotId = getSlotIndex(subId);
4060 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4061 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4062 + subId + "'");
4063 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4064 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004065 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004066 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4067 transportType, aBoolean -> {
4068 try {
4069 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4070 } catch (RemoteException e) {
4071 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4072 + "running. Ignore");
4073 }
4074 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004075 } catch (ImsException e) {
4076 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004077 } finally {
4078 Binder.restoreCallingIdentity(token);
4079 }
4080 }
4081
shilu366312e2019-12-17 09:28:10 -08004082 /**
4083 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4084 * @param subId The subscription to use to check the configuration.
4085 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 @Override
4087 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004088 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004089 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004090
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 final long token = Binder.clearCallingIdentity();
4092 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004093 int slotId = getSlotIndexOrException(subId);
4094 verifyImsMmTelConfiguredOrThrow(slotId);
4095 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
4097 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 } finally {
4099 Binder.restoreCallingIdentity(token);
4100 }
4101 }
4102
4103 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004104 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004106 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 final long identity = Binder.clearCallingIdentity();
4108 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004109 int slotId = getSlotIndexOrException(subId);
4110 verifyImsMmTelConfiguredOrThrow(slotId);
4111 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004112 } catch (ImsException e) {
4113 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
4117 }
4118
shilu366312e2019-12-17 09:28:10 -08004119 /**
4120 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4121 * @param subId The subscription to use to check the configuration.
4122 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004124 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004125 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004126 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 final long identity = Binder.clearCallingIdentity();
4128 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004129 int slotId = getSlotIndexOrException(subId);
4130 verifyImsMmTelConfiguredOrThrow(slotId);
4131 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004132 } catch (ImsException e) {
4133 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 } finally {
4135 Binder.restoreCallingIdentity(identity);
4136 }
4137 }
4138
4139 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004140 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004142 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 final long identity = Binder.clearCallingIdentity();
4144 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004145 int slotId = getSlotIndexOrException(subId);
4146 verifyImsMmTelConfiguredOrThrow(slotId);
4147 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004148 } catch (ImsException e) {
4149 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 } finally {
4151 Binder.restoreCallingIdentity(identity);
4152 }
4153 }
4154
shilu366312e2019-12-17 09:28:10 -08004155 /**
4156 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4157 * @param subId The subscription to use to check the configuration.
4158 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 @Override
4160 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004161 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004162 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004163 final long identity = Binder.clearCallingIdentity();
4164 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004165 int slotId = getSlotIndexOrException(subId);
4166 verifyImsMmTelConfiguredOrThrow(slotId);
4167 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004168 } catch (ImsException e) {
4169 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
4173 }
4174
4175 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004176 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004178 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004179 final long identity = Binder.clearCallingIdentity();
4180 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004181 int slotId = getSlotIndexOrException(subId);
4182 verifyImsMmTelConfiguredOrThrow(slotId);
4183 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004184 } catch (ImsException e) {
4185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
4189 }
4190
shilu366312e2019-12-17 09:28:10 -08004191 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004192 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4193 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4194 * @param subId The subscription to use to check the configuration.
4195 */
4196 @Override
4197 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004198 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004199 mApp, subId, "isCrossSimCallingEnabledByUser");
4200 final long identity = Binder.clearCallingIdentity();
4201 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004202 int slotId = getSlotIndexOrException(subId);
4203 verifyImsMmTelConfiguredOrThrow(slotId);
4204 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004205 } catch (ImsException e) {
4206 throw new ServiceSpecificException(e.getCode());
4207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
4210 }
4211
4212 /**
4213 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4214 * Requires MODIFY_PHONE_STATE permission.
4215 * @param subId The subscription to use to check the configuration.
4216 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4217 * false otherwise
4218 */
4219 @Override
4220 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4222 "setCrossSimCallingEnabled");
4223 final long identity = Binder.clearCallingIdentity();
4224 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004225 int slotId = getSlotIndexOrException(subId);
4226 verifyImsMmTelConfiguredOrThrow(slotId);
4227 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004228 } catch (ImsException e) {
4229 throw new ServiceSpecificException(e.getCode());
4230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
4233 }
4234
4235 /**
shilu366312e2019-12-17 09:28:10 -08004236 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4237 * @param subId The subscription to use to check the configuration.
4238 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004240
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004242 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004243 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 final long identity = Binder.clearCallingIdentity();
4245 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004246 int slotId = getSlotIndexOrException(subId);
4247 verifyImsMmTelConfiguredOrThrow(slotId);
4248 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004249 } catch (ImsException e) {
4250 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
4256 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004257 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004259 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 final long identity = Binder.clearCallingIdentity();
4261 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 int slotId = getSlotIndexOrException(subId);
4263 verifyImsMmTelConfiguredOrThrow(slotId);
4264 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004265 } catch (ImsException e) {
4266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
4270 }
4271
4272 @Override
4273 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4275 "setVoWiFiNonPersistent");
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 int slotId = getSlotIndexOrException(subId);
4279 verifyImsMmTelConfiguredOrThrow(slotId);
4280 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004281 } catch (ImsException e) {
4282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286 }
4287
shilu366312e2019-12-17 09:28:10 -08004288 /**
4289 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4290 * @param subId The subscription to use to check the configuration.
4291 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 @Override
4293 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004294 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004295 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 final long identity = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 int slotId = getSlotIndexOrException(subId);
4299 verifyImsMmTelConfiguredOrThrow(slotId);
4300 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004301 } catch (ImsException e) {
4302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
4306 }
4307
4308 @Override
4309 public void setVoWiFiModeSetting(int subId, int mode) {
4310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4311 "setVoWiFiModeSetting");
4312 final long identity = Binder.clearCallingIdentity();
4313 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004314 int slotId = getSlotIndexOrException(subId);
4315 verifyImsMmTelConfiguredOrThrow(slotId);
4316 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004317 } catch (ImsException e) {
4318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
4324 @Override
4325 public int getVoWiFiRoamingModeSetting(int subId) {
4326 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4327 final long identity = Binder.clearCallingIdentity();
4328 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004329 int slotId = getSlotIndexOrException(subId);
4330 verifyImsMmTelConfiguredOrThrow(slotId);
4331 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004332 } catch (ImsException e) {
4333 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
4337 }
4338
4339 @Override
4340 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4342 "setVoWiFiRoamingModeSetting");
4343 final long identity = Binder.clearCallingIdentity();
4344 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004345 int slotId = getSlotIndexOrException(subId);
4346 verifyImsMmTelConfiguredOrThrow(slotId);
4347 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004348 } catch (ImsException e) {
4349 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
4353 }
4354
4355 @Override
4356 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4358 "setRttCapabilityEnabled");
4359 final long identity = Binder.clearCallingIdentity();
4360 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004361 int slotId = getSlotIndexOrException(subId);
4362 verifyImsMmTelConfiguredOrThrow(slotId);
4363 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004364 } catch (ImsException e) {
4365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 } finally {
4367 Binder.restoreCallingIdentity(identity);
4368 }
4369 }
4370
shilu366312e2019-12-17 09:28:10 -08004371 /**
4372 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4373 * @param subId The subscription to use to check the configuration.
4374 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 @Override
4376 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004377 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004378 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 final long identity = Binder.clearCallingIdentity();
4380 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004381 int slotId = getSlotIndexOrException(subId);
4382 verifyImsMmTelConfiguredOrThrow(slotId);
4383 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004384 } catch (ImsException e) {
4385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
4389 }
4390
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004391 @Override
4392 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4393 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4394 final long identity = Binder.clearCallingIdentity();
4395 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004396 if (!isImsAvailableOnDevice()) {
4397 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4398 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004399 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004400 int slotId = getSlotIndexOrException(subId);
4401 verifyImsMmTelConfiguredOrThrow(slotId);
4402 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004403 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004404 } catch (ImsException e) {
4405 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
4409 }
4410
4411 @Override
4412 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4413 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4414 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004415 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4416 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4417 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004418 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004419 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004420 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004421 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004422 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4423 + "is inactive, ignoring unregister.");
4424 // If the subscription is no longer active, just return, since the callback will already
4425 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
4429 }
4430
allenwtsu99c623b2020-01-03 18:24:23 +08004431
4432 private void checkModifyPhoneStatePermission(int subId, String message) {
4433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4434 message);
4435 }
4436
4437 private boolean isImsProvisioningRequired(int subId, int capability,
4438 boolean isMmtelCapability) {
4439 Phone phone = getPhone(subId);
4440 if (phone == null) {
4441 loge("phone instance null for subid " + subId);
4442 return false;
4443 }
4444 if (isMmtelCapability) {
4445 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4446 return false;
4447 }
4448 } else {
4449 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4450 return false;
4451 }
4452 }
4453 return true;
4454 }
4455
4456 @Override
4457 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4458 boolean isProvisioned) {
4459 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4460
4461 final long identity = Binder.clearCallingIdentity();
4462 try {
4463 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4464 if (!isImsProvisioningRequired(subId, capability, false)) {
4465 return;
4466 }
4467
4468 // this capability requires provisioning, route to the correct API.
4469 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4470 switch (capability) {
4471 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4472 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4473 ims.setEabProvisioned(isProvisioned);
4474 break;
4475 default: {
4476 throw new IllegalArgumentException("Tried to set provisioning for "
4477 + "rcs capability '" + capability + "', which does not require "
4478 + "provisioning.");
4479 }
4480 }
4481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
4484
4485 }
4486
4487
4488 @Override
4489 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4490 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4494 if (!isImsProvisioningRequired(subId, capability, false)) {
4495 return true;
4496 }
4497
4498 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4499 switch (capability) {
4500 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4501 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4502 return ims.isEabProvisionedOnDevice();
4503
4504 default: {
4505 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4506 + "capability '" + capability + "', which does not require "
4507 + "provisioning.");
4508 }
4509 }
4510
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
4514 }
4515
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004516 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004517 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4518 boolean isProvisioned) {
4519 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004520 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4521 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4522 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004523 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4524 }
allenwtsu99c623b2020-01-03 18:24:23 +08004525 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004526 final long identity = Binder.clearCallingIdentity();
4527 try {
4528 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004529 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004530 return;
4531 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004532 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4533 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4534 loge("setImsProvisioningStatusForCapability: called for technology that does "
4535 + "not support provisioning - " + tech);
4536 return;
4537 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004538
4539 // this capability requires provisioning, route to the correct API.
4540 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4541 switch (capability) {
4542 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4543 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4544 ims.setVolteProvisioned(isProvisioned);
4545 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4546 ims.setWfcProvisioned(isProvisioned);
4547 }
4548 break;
4549 }
4550 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4551 // There is currently no difference in VT provisioning type.
4552 ims.setVtProvisioned(isProvisioned);
4553 break;
4554 }
4555 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4556 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4557 // change the capability of the feature instead if needed.
4558 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4559 == isProvisioned) {
4560 // No change in provisioning.
4561 return;
4562 }
4563 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4564 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004565 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004566 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004567 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4568 + ", Exception" + e.getMessage());
4569 }
4570 break;
4571 }
4572 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004573 throw new IllegalArgumentException("Tried to set provisioning for "
4574 + "MmTel capability '" + capability + "', which does not require "
4575 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004576 }
4577 }
4578
4579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
4582 }
4583
4584 @Override
4585 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4586 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004587 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4588 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4589 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004590 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4591 }
4592 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004596 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 return true;
4598 }
4599
Brad Ebinger0d79c572021-04-17 15:20:49 -07004600 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4601 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4602 loge("getImsProvisioningStatusForCapability: called for technology that does "
4603 + "not support provisioning - " + tech);
4604 return true;
4605 }
4606
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004607 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4608 switch (capability) {
4609 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4610 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4611 return ims.isVolteProvisionedOnDevice();
4612 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4613 return ims.isWfcProvisionedOnDevice();
4614 }
4615 // This should never happen, since we are checking tech above to make sure it
4616 // is either LTE or IWLAN.
4617 throw new IllegalArgumentException("Invalid radio technology for voice "
4618 + "capability.");
4619 }
4620 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4621 // There is currently no difference in VT provisioning type.
4622 return ims.isVtProvisionedOnDevice();
4623 }
4624 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4625 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4626 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4627 }
4628 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004629 throw new IllegalArgumentException(
4630 "Tried to get provisioning for MmTel capability '" + capability
4631 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004632 }
4633 }
4634
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639
4640 @Override
4641 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4642 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4643 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4644 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4645 }
4646 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4647 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4648 return (provisionedBits & capability) > 0;
4649 }
4650
4651 @Override
4652 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4653 boolean isProvisioned) {
4654 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4655 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4656 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4657 }
4658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4659 "setProvisioningStatusForCapability");
4660 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4661 // If the current provisioning status for capability already matches isProvisioned,
4662 // do nothing.
4663 if (((provisionedBits & capability) > 0) == isProvisioned) {
4664 return;
4665 }
4666 if (isProvisioned) {
4667 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4668 } else {
4669 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4670 }
4671 }
4672
4673 /**
4674 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4675 * technology. The bitfield should mirror the bitfield defined by
4676 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4677 */
4678 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4679 String key = getMmTelProvisioningKey(subId, tech);
4680 // Default is no capabilities are provisioned.
4681 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4682 }
4683
4684 /**
4685 * Sets the MmTel capability provisioning bitfield (defined by
4686 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4687 * technology specified.
4688 *
4689 * Note: This is a synchronous command and should not be called on UI thread.
4690 */
4691 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4692 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4693 String key = getMmTelProvisioningKey(subId, tech);
4694 editor.putInt(key, newField);
4695 editor.commit();
4696 }
4697
4698 private static String getMmTelProvisioningKey(int subId, int tech) {
4699 // resulting key is provision_ims_mmtel_{subId}_{tech}
4700 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4701 }
4702
4703 /**
4704 * Query CarrierConfig to see if the specified capability requires provisioning for the
4705 * carrier associated with the subscription id.
4706 */
4707 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4708 int capability) {
4709 CarrierConfigManager configManager = new CarrierConfigManager(context);
4710 PersistableBundle c = configManager.getConfigForSubId(subId);
4711 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004712 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4714 false);
4715 boolean requireVoiceVtProvisioning = c.getBoolean(
4716 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4717
4718 // First check to make sure that the capability requires provisioning.
4719 switch (capability) {
4720 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4721 // intentional fallthrough
4722 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4723 if (requireVoiceVtProvisioning) {
4724 // Voice and Video requires provisioning
4725 return true;
4726 }
4727 break;
4728 }
4729 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4730 if (requireUtProvisioning) {
4731 // UT requires provisioning
4732 return true;
4733 }
4734 break;
4735 }
4736 }
4737 return false;
4738 }
4739
allenwtsu99c623b2020-01-03 18:24:23 +08004740 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4741 int capability) {
4742 CarrierConfigManager configManager = new CarrierConfigManager(context);
4743 PersistableBundle c = configManager.getConfigForSubId(subId);
4744
4745 boolean requireRcsProvisioning = c.getBoolean(
4746 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4747
4748 // First check to make sure that the capability requires provisioning.
4749 switch (capability) {
4750 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4751 // intentional fallthrough
4752 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4753 if (requireRcsProvisioning) {
4754 // OPTION or PRESENCE requires provisioning
4755 return true;
4756 }
4757 break;
4758 }
4759 }
4760 return false;
4761 }
4762
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004763 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004764 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004765 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4766 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4767 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004768 enforceReadPrivilegedPermission("getImsProvisioningInt");
4769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004772 int slotId = getSlotIndex(subId);
4773 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4774 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4775 + subId + "' for key:" + key);
4776 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4777 }
calvinpanb5a34062021-02-08 19:59:36 +08004778 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004779 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004780 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4781 + subId + "' for key:" + key);
4782 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004783 } finally {
4784 Binder.restoreCallingIdentity(identity);
4785 }
4786 }
4787
4788 @Override
4789 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4791 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4792 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004793 enforceReadPrivilegedPermission("getImsProvisioningString");
4794 final long identity = Binder.clearCallingIdentity();
4795 try {
4796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004797 int slotId = getSlotIndex(subId);
4798 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4799 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4800 + subId + "' for key:" + key);
4801 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4802 }
calvinpanb5a34062021-02-08 19:59:36 +08004803 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004804 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004805 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4806 + subId + "' for key:" + key);
4807 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004808 } finally {
4809 Binder.restoreCallingIdentity(identity);
4810 }
4811 }
4812
4813 @Override
4814 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004815 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4816 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4817 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4819 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004820 final long identity = Binder.clearCallingIdentity();
4821 try {
4822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004823 int slotId = getSlotIndex(subId);
4824 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4825 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4826 + subId + "' for key:" + key);
4827 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4828 }
calvinpanb5a34062021-02-08 19:59:36 +08004829 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4830 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004831 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004832 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004833 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
4837 }
4838
4839 @Override
4840 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004841 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4842 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4843 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4845 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004849 int slotId = getSlotIndex(subId);
4850 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4851 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4852 + subId + "' for key:" + key);
4853 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4854 }
calvinpanb5a34062021-02-08 19:59:36 +08004855 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4856 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004857 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004858 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004859 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
4863 }
4864
Brad Ebinger919631e2021-06-02 17:46:35 -07004865 /**
4866 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4867 * for the given slot ID or no ImsResolver instance has been created.
4868 * @param slotId The slot ID that the IMS service is created for.
4869 * @throws ImsException If there is no ImsService configured for this slot.
4870 */
4871 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4872 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4873 ImsFeature.FEATURE_MMTEL)) {
4874 throw new ImsException("This subscription does not support MMTEL over IMS",
4875 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4876 }
4877 }
4878
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004879 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004880 int slotId = SubscriptionManager.getSlotIndex(subId);
4881 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004882 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4883 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004884 }
4885 return slotId;
4886 }
4887
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 private int getSlotIndex(int subId) {
4889 int slotId = SubscriptionManager.getSlotIndex(subId);
4890 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4891 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4892 }
4893 return slotId;
4894 }
4895
Wink Saville36469e72014-06-11 15:17:00 -07004896 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004897 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004898 */
4899 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004900 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4901 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004902 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004903 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004904 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004905 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004906 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004907 mApp, subId, callingPackage, callingFeatureId,
4908 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004909 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4910 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 final Phone phone = getPhone(subId);
4915 if (phone != null) {
4916 return phone.getServiceState().getDataNetworkType();
4917 } else {
4918 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4919 }
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004923 }
4924
4925 /**
4926 * Returns the data network type
4927 */
4928 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004929 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004930 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4931 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004932 }
4933
4934 /**
4935 * Returns the data network type for a subId
4936 */
4937 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004938 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4939 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004940 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004941 mApp, subId, callingPackage, callingFeatureId,
4942 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004943 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4944 }
4945
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 final long identity = Binder.clearCallingIdentity();
4947 try {
4948 final Phone phone = getPhone(subId);
4949 if (phone != null) {
4950 return phone.getServiceState().getDataNetworkType();
4951 } else {
4952 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4953 }
4954 } finally {
4955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004957 }
4958
4959 /**
Wink Saville36469e72014-06-11 15:17:00 -07004960 * Returns the Voice network type for a subId
4961 */
4962 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004963 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4964 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004966 mApp, subId, callingPackage, callingFeatureId,
4967 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004968 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4969 }
4970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 final long identity = Binder.clearCallingIdentity();
4972 try {
4973 final Phone phone = getPhone(subId);
4974 if (phone != null) {
4975 return phone.getServiceState().getVoiceNetworkType();
4976 } else {
4977 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4978 }
4979 } finally {
4980 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004982 }
4983
4984 /**
4985 * @return true if a ICC card is present
4986 */
4987 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004988 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004989 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4990 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004991 }
4992
4993 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004994 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004995 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004996 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004997 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 final long identity = Binder.clearCallingIdentity();
4999 try {
5000 final Phone phone = PhoneFactory.getPhone(slotIndex);
5001 if (phone != null) {
5002 return phone.getIccCard().hasIccCard();
5003 } else {
5004 return false;
5005 }
5006 } finally {
5007 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005009 }
5010
5011 /**
5012 * Return if the current radio is LTE on CDMA. This
5013 * is a tri-state return value as for a period of time
5014 * the mode may be unknown.
5015 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005016 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005017 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005018 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005019 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005020 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005021 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5022 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5023 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005024 }
5025
Sanket Padawe356d7632015-06-22 14:03:32 -07005026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005027 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5028 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005029 try {
5030 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5031 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005032 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5033 }
5034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 final Phone phone = getPhone(subId);
5038 if (phone == null) {
5039 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5040 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005041 return TelephonyProperties.lte_on_cdma_device()
5042 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 }
5044 } finally {
5045 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005046 }
Wink Saville36469e72014-06-11 15:17:00 -07005047 }
5048
Wink Saville36469e72014-06-11 15:17:00 -07005049 /**
5050 * {@hide}
5051 * Returns Default subId, 0 in the case of single standby.
5052 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005053 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005054 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005055 }
5056
Shishir Agrawala9f32182016-04-12 12:00:16 -07005057 private int getSlotForDefaultSubscription() {
5058 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5059 }
5060
Wink Savilleb564aae2014-10-23 10:18:09 -07005061 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005062 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005063 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005064
Pengquan Menge92a50d2018-09-21 15:54:48 -07005065 private boolean isActiveSubscription(int subId) {
5066 return mSubscriptionController.isActiveSubId(subId);
5067 }
5068
Ihab Awadf2177b72013-11-25 13:33:23 -08005069 /**
5070 * @see android.telephony.TelephonyManager.WifiCallingChoices
5071 */
5072 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005075 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5077 getWhenToMakeWifiCallsDefaultPreference());
5078 } finally {
5079 Binder.restoreCallingIdentity(identity);
5080 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005081 }
5082
5083 /**
5084 * @see android.telephony.TelephonyManager.WifiCallingChoices
5085 */
5086 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005090 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005091 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5092 } finally {
5093 Binder.restoreCallingIdentity(identity);
5094 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005095 }
5096
Sailesh Nepald1e68152013-12-12 19:08:02 -08005097 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005098 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005099 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005100 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005101
Jordan Liu4c733742019-02-28 12:03:40 -08005102 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5103 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5104 if (phoneId == -1) {
5105 throw new IllegalArgumentException("Given slot index: " + slotIndex
5106 + " does not correspond to an active phone");
5107 }
5108 return PhoneFactory.getPhone(phoneId);
5109 }
5110
Shishir Agrawal566b7612013-10-28 14:41:00 -07005111 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005112 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5113 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5115 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005117 if (DBG) {
5118 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5119 }
5120 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5121 p2);
5122 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005123
Jordan Liu4c733742019-02-28 12:03:40 -08005124
5125 @Override
5126 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5127 int slotIndex, String callingPackage, String aid, int p2) {
5128 enforceModifyPermission();
5129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5130 if (DBG) {
5131 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5132 }
5133 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5134 callingPackage, aid, p2);
5135 }
5136
5137 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5138 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 final long identity = Binder.clearCallingIdentity();
5140 try {
5141 if (TextUtils.equals(ISDR_AID, aid)) {
5142 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005143 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5144 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 if (bestComponent == null
5146 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5147 loge("The calling package is not allowed to access ISD-R.");
5148 throw new SecurityException(
5149 "The calling package is not allowed to access ISD-R.");
5150 }
Derek Tan740e1672017-06-27 14:56:27 -07005151 }
Derek Tan740e1672017-06-27 14:56:27 -07005152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005154 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5155 null /* workSource */);
5156 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157 return response;
5158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005161 }
5162
5163 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005164 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5166 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005167 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5168 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5169 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005170
Jordan Liu4c733742019-02-28 12:03:40 -08005171 @Override
5172 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5173 enforceModifyPermission();
5174 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5175 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5176 channel);
5177 }
5178
5179 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 final long identity = Binder.clearCallingIdentity();
5181 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182 if (channel < 0) {
5183 return false;
5184 }
Jordan Liu4c733742019-02-28 12:03:40 -08005185 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5186 null /* workSource */);
5187 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 return success;
5189 } finally {
5190 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005191 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005192 }
5193
5194 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005195 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005196 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5198 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005199 if (DBG) {
5200 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5201 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5202 + p3 + " data=" + data);
5203 }
5204 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5205 command, p1, p2, p3, data);
5206 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005207
Jordan Liu4c733742019-02-28 12:03:40 -08005208 @Override
5209 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5210 int command, int p1, int p2, int p3, String data) {
5211 enforceModifyPermission();
5212 if (DBG) {
5213 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5214 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5215 + p3 + " data=" + data);
5216 }
5217 return iccTransmitApduLogicalChannelWithPermission(
5218 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5219 data);
5220 }
5221
5222 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5223 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005226 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 return "";
5228 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005231 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5232 null /* workSource */);
5233 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 // Append the returned status code to the end of the response payload.
5236 String s = Integer.toHexString(
5237 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5238 if (response.payload != null) {
5239 s = IccUtils.bytesToHexString(response.payload) + s;
5240 }
5241 return s;
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005244 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005245 }
Jake Hambye994d462014-02-03 13:10:13 -08005246
Evan Charltonc66da362014-05-16 14:06:40 -07005247 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005248 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5249 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5251 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005253 if (DBG) {
5254 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5255 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5256 }
5257 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5258 cla, command, p1, p2, p3, data);
5259 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005260
Jordan Liu4c733742019-02-28 12:03:40 -08005261 @Override
5262 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5263 int command, int p1, int p2, int p3, String data) {
5264 enforceModifyPermission();
5265 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5266 if (DBG) {
5267 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5268 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5269 + " data=" + data);
5270 }
5271
5272 return iccTransmitApduBasicChannelWithPermission(
5273 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5274 p2, p3, data);
5275 }
5276
5277 // open APDU basic channel assuming the caller has sufficient permissions
5278 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5279 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 final long identity = Binder.clearCallingIdentity();
5281 try {
5282 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5283 && TextUtils.equals(ISDR_AID, data)) {
5284 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005285 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5286 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 if (bestComponent == null
5288 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5289 loge("The calling package is not allowed to select ISD-R.");
5290 throw new SecurityException(
5291 "The calling package is not allowed to select ISD-R.");
5292 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005293 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005296 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5297 null /* workSource */);
5298 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005299
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 // Append the returned status code to the end of the response payload.
5301 String s = Integer.toHexString(
5302 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5303 if (response.payload != null) {
5304 s = IccUtils.bytesToHexString(response.payload) + s;
5305 }
5306 return s;
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005309 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005310 }
5311
5312 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005313 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005314 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5316 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318 final long identity = Binder.clearCallingIdentity();
5319 try {
5320 if (DBG) {
5321 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5322 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5323 }
5324
5325 IccIoResult response =
5326 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5327 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5328 subId);
5329
5330 if (DBG) {
5331 log("Exchange SIM_IO [R]" + response);
5332 }
5333
5334 byte[] result = null;
5335 int length = 2;
5336 if (response.payload != null) {
5337 length = 2 + response.payload.length;
5338 result = new byte[length];
5339 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5340 } else {
5341 result = new byte[length];
5342 }
5343
5344 result[length - 1] = (byte) response.sw2;
5345 result[length - 2] = (byte) response.sw1;
5346 return result;
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005349 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005350 }
5351
Nathan Haroldb3014052017-01-25 15:57:32 -08005352 /**
5353 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5354 * on a particular subscription
5355 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005356 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5357 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005358 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005359 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005360 return null;
5361 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362
5363 final long identity = Binder.clearCallingIdentity();
5364 try {
5365 if (appType != TelephonyManager.APPTYPE_USIM
5366 && appType != TelephonyManager.APPTYPE_SIM) {
5367 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5368 return null;
5369 }
5370 Object response = sendRequest(
5371 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5372 if (response instanceof String[]) {
5373 return (String[]) response;
5374 }
yincheng zhao2737e882019-09-06 17:06:54 -07005375 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005377 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 } finally {
5379 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005380 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005381 }
5382
yincheng zhao2737e882019-09-06 17:06:54 -07005383 /**
5384 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5385 * subscription.
5386 *
5387 * @param subId the id of the subscription.
5388 * @param appType the uicc app type, must be USIM or SIM.
5389 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5390 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005391 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005392 * @return number of fplmns that is successfully written to the SIM.
5393 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005394 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5395 String callingFeatureId) {
5396 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5397 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005398 if (DBG) logv("no permissions for setForbiddenplmns");
5399 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5400 }
5401 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5402 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5403 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5404 }
5405 if (fplmns == null) {
5406 throw new IllegalArgumentException("Fplmn List provided is null");
5407 }
5408 for (String fplmn : fplmns) {
5409 if (!CellIdentity.isValidPlmn(fplmn)) {
5410 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5411 }
5412 }
5413 final long identity = Binder.clearCallingIdentity();
5414 try {
5415 Object response = sendRequest(
5416 CMD_SET_FORBIDDEN_PLMNS,
5417 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5418 subId);
5419 return (int) response;
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
5423 }
5424
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005425 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005426 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5428 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 final long identity = Binder.clearCallingIdentity();
5431 try {
5432 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5433 if (response.payload == null) {
5434 return "";
5435 }
Evan Charltonc66da362014-05-16 14:06:40 -07005436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 // Append the returned status code to the end of the response payload.
5438 String s = Integer.toHexString(
5439 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5440 s = IccUtils.bytesToHexString(response.payload) + s;
5441 return s;
5442 } finally {
5443 Binder.restoreCallingIdentity(identity);
5444 }
Evan Charltonc66da362014-05-16 14:06:40 -07005445 }
5446
Jake Hambye994d462014-02-03 13:10:13 -08005447 /**
5448 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5449 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5450 *
5451 * @param itemID the ID of the item to read
5452 * @return the NV item as a String, or null on error.
5453 */
5454 @Override
5455 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005456 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5458 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459
5460 final long identity = Binder.clearCallingIdentity();
5461 try {
5462 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005463 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5465 return value;
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
Jake Hambye994d462014-02-03 13:10:13 -08005469 }
5470
5471 /**
5472 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5473 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5474 *
5475 * @param itemID the ID of the item to read
5476 * @param itemValue the value to write, as a String
5477 * @return true on success; false on any failure
5478 */
5479 @Override
5480 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005481 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5483 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484
5485 final long identity = Binder.clearCallingIdentity();
5486 try {
5487 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5488 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005489 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5491 return success;
5492 } finally {
5493 Binder.restoreCallingIdentity(identity);
5494 }
Jake Hambye994d462014-02-03 13:10:13 -08005495 }
5496
5497 /**
5498 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5499 * Used for device configuration by some CDMA operators.
5500 *
5501 * @param preferredRoamingList byte array containing the new PRL
5502 * @return true on success; false on any failure
5503 */
5504 @Override
5505 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5507 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508
5509 final long identity = Binder.clearCallingIdentity();
5510 try {
5511 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5512 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5513 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5514 return success;
5515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
Jake Hambye994d462014-02-03 13:10:13 -08005518 }
5519
5520 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005521 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005522 * Used for device configuration by some CDMA operators.
5523 *
chen xu6dac5ab2018-10-26 17:39:23 -07005524 * @param slotIndex - device slot.
5525 *
Jake Hambye994d462014-02-03 13:10:13 -08005526 * @return true on success; false on any failure
5527 */
5528 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005529 public boolean resetModemConfig(int slotIndex) {
5530 Phone phone = PhoneFactory.getPhone(slotIndex);
5531 if (phone != null) {
5532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5533 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534
chen xu6dac5ab2018-10-26 17:39:23 -07005535 final long identity = Binder.clearCallingIdentity();
5536 try {
5537 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5538 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5539 return success;
5540 } finally {
5541 Binder.restoreCallingIdentity(identity);
5542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 }
chen xu6dac5ab2018-10-26 17:39:23 -07005544 return false;
5545 }
5546
5547 /**
5548 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5549 *
5550 * @param slotIndex - device slot.
5551 *
5552 * @return true on success; false on any failure
5553 */
5554 @Override
5555 public boolean rebootModem(int slotIndex) {
5556 Phone phone = PhoneFactory.getPhone(slotIndex);
5557 if (phone != null) {
5558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5559 mApp, phone.getSubId(), "rebootModem");
5560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5564 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5565 return success;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
5569 }
5570 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005571 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005572
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005573 public String[] getPcscfAddress(String apnType, String callingPackage,
5574 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005575 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005576 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5577 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005578 return new String[0];
5579 }
5580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581 final long identity = Binder.clearCallingIdentity();
5582 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005583 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
Wink Saville36469e72014-06-11 15:17:00 -07005587 }
5588
Brad Ebinger51f743a2017-01-23 13:50:20 -08005589 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005590 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5591 * {@link #disableIms(int)}.
5592 * @param slotIndex device slot.
5593 */
5594 public void resetIms(int slotIndex) {
5595 enforceModifyPermission();
5596
5597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 if (mImsResolver == null) {
5600 // may happen if the does not support IMS.
5601 return;
5602 }
5603 mImsResolver.disableIms(slotIndex);
5604 mImsResolver.enableIms(slotIndex);
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
5608 }
5609
5610 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005611 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5612 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005613 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005614 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616
5617 final long identity = Binder.clearCallingIdentity();
5618 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005619 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005620 // may happen if the device does not support IMS.
5621 return;
5622 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005623 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005627 }
5628
5629 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005630 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5631 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005632 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005633 public void disableIms(int slotId) {
5634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005638 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005639 // may happen if the device does not support IMS.
5640 return;
5641 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005642 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 } finally {
5644 Binder.restoreCallingIdentity(identity);
5645 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005646 }
5647
5648 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005649 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5650 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005651 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005652 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005653 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005658 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005659 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5660 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005661 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005662 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005666 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005667 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005668 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5669 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005670 @Override
5671 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005672 enforceModifyPermission();
5673
5674 final long identity = Binder.clearCallingIdentity();
5675 try {
5676 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005677 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005678 } finally {
5679 Binder.restoreCallingIdentity(identity);
5680 }
5681 }
5682
5683 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005684 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005685 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005686 */
5687 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5688 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689
5690 final long identity = Binder.clearCallingIdentity();
5691 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005692 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005693 // may happen if the device does not support IMS.
5694 return null;
5695 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005696 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005700 }
5701
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005702 /**
5703 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005704 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005705 */
5706 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5707 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708
5709 final long identity = Binder.clearCallingIdentity();
5710 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005711 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005712 // may happen if the device does not support IMS.
5713 return null;
5714 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005715 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 } finally {
5717 Binder.restoreCallingIdentity(identity);
5718 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005719 }
5720
Brad Ebinger884c07b2018-02-15 16:17:40 -08005721 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005722 * Sets the ImsService Package Name that Telephony will bind to.
5723 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005724 * @param slotIndex the slot ID that the ImsService should bind for.
5725 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005726 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005727 * @param featureTypes An integer array of feature types associated with a packageName.
5728 * @param packageName The name of the package that the current configuration will be replaced
5729 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005730 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005731 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005732 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5733 int[] featureTypes, String packageName) {
5734 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5735 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5737 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005739
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 final long identity = Binder.clearCallingIdentity();
5741 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005743 // may happen if the device does not support IMS.
5744 return false;
5745 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005746 Map<Integer, String> featureConfig = new HashMap<>();
5747 for (int featureType : featureTypes) {
5748 featureConfig.put(featureType, packageName);
5749 }
5750 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5751 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005755 }
5756
5757 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005758 * Clears any carrier ImsService overrides for the slot index specified that were previously
5759 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5760 *
5761 * This should only be used for testing.
5762 *
5763 * @param slotIndex the slot ID that the ImsService should bind for.
5764 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5765 */
5766 @Override
5767 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5768 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5769 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5770 "clearCarrierImsServiceOverride");
5771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5772 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5773 "clearCarrierImsServiceOverride");
5774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 if (mImsResolver == null) {
5778 // may happen if the device does not support IMS.
5779 return false;
5780 }
5781 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
5785 }
5786
5787 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005788 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005789 *
5790 * @param slotId The slot that the ImsService is associated with.
5791 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5792 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005793 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005794 * @return the package name of the ImsService configuration.
5795 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005796 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5797 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005798 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005799 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005800 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005801 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5802 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 final long identity = Binder.clearCallingIdentity();
5805 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005806 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005807 // may happen if the device does not support IMS.
5808 return "";
5809 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005810 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005811 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5812 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005816 }
5817
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005818 /**
5819 * Get the MmTelFeature state associated with the requested subscription id.
5820 * @param subId The subscription that the MmTelFeature is associated with.
5821 * @param callback A callback with an integer containing the
5822 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5823 */
5824 @Override
5825 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5826 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5827 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5828 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5829 "IMS not available on device.");
5830 }
5831 final long token = Binder.clearCallingIdentity();
5832 try {
5833 int slotId = getSlotIndex(subId);
5834 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5835 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5836 + subId + "'");
5837 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5838 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005839 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005840 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5841 try {
5842 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5843 } catch (RemoteException e) {
5844 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5845 + "Ignore");
5846 }
5847 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005848 } catch (ImsException e) {
5849 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005850 } finally {
5851 Binder.restoreCallingIdentity(token);
5852 }
5853 }
5854
Daniel Brightbb5840b2021-01-12 15:48:18 -08005855 /**
5856 * Sets the ims registration state on all valid {@link Phone}s.
5857 */
5858 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005859 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005863 // NOTE: Before S, this method only set the default phone.
5864 for (final Phone phone : PhoneFactory.getPhones()) {
5865 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5866 phone.setImsRegistrationState(registered);
5867 }
5868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
Wink Saville36469e72014-06-11 15:17:00 -07005872 }
5873
5874 /**
Stuart Scott54788802015-03-30 13:18:01 -07005875 * Set the network selection mode to automatic.
5876 *
5877 */
5878 @Override
5879 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5881 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882
5883 final long identity = Binder.clearCallingIdentity();
5884 try {
shilufc958392020-01-20 11:36:01 -08005885 if (!isActiveSubscription(subId)) {
5886 return;
5887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005889 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5890 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
Stuart Scott54788802015-03-30 13:18:01 -07005894 }
5895
Jack Yud10cdd42020-09-28 20:28:01 -07005896 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005897 * Ask the radio to connect to the input network and change selection mode to manual.
5898 *
5899 * @param subId the id of the subscription.
5900 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5901 * the operator to attach to.
5902 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5903 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5904 * normal network selection next time.
5905 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005906 */
5907 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005908 public boolean setNetworkSelectionModeManual(
5909 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5911 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005912
5913 if (!isActiveSubscription(subId)) {
5914 return false;
5915 }
5916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 final long identity = Binder.clearCallingIdentity();
5918 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005919 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005921 if (DBG) {
5922 log("setNetworkSelectionModeManual: subId: " + subId
5923 + " operator: " + operatorInfo);
5924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5926 } finally {
5927 Binder.restoreCallingIdentity(identity);
5928 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005929 }
shilu84f6e8b2019-12-19 13:58:01 -08005930 /**
5931 * Get the manual network selection
5932 *
5933 * @param subId the id of the subscription.
5934 *
5935 * @return the previously saved user selected PLMN
5936 */
5937 @Override
5938 public String getManualNetworkSelectionPlmn(int subId) {
5939 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005940 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005941 mApp, subId, "getManualNetworkSelectionPlmn");
5942
5943 final long identity = Binder.clearCallingIdentity();
5944 try {
5945 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005946 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005947 }
5948
5949 final Phone phone = getPhone(subId);
5950 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005951 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005952 }
5953 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5954 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5955 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5956 } finally {
5957 Binder.restoreCallingIdentity(identity);
5958 }
5959 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005960
5961 /**
5962 * Scans for available networks.
5963 */
5964 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005965 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5966 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5968 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005969 LocationAccessPolicy.LocationPermissionResult locationResult =
5970 LocationAccessPolicy.checkLocationPermission(mApp,
5971 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5972 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005973 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005974 .setCallingPid(Binder.getCallingPid())
5975 .setCallingUid(Binder.getCallingUid())
5976 .setMethod("getCellNetworkScanResults")
5977 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005978 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5979 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005980 .build());
5981 switch (locationResult) {
5982 case DENIED_HARD:
5983 throw new SecurityException("Not allowed to access scan results -- location");
5984 case DENIED_SOFT:
5985 return null;
5986 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987
Pengquan Menga1bb6272018-09-06 09:59:22 -07005988 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 try {
5990 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005991 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
5995 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005996 }
5997
5998 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005999 * Get the call forwarding info, given the call forwarding reason.
6000 */
6001 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006002 public void getCallForwarding(int subId, int callForwardingReason,
6003 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006004 enforceReadPrivilegedPermission("getCallForwarding");
6005 long identity = Binder.clearCallingIdentity();
6006 try {
6007 if (DBG) {
6008 log("getCallForwarding: subId " + subId
6009 + " callForwardingReason" + callForwardingReason);
6010 }
Hall Liu27d24262020-09-18 19:04:59 -07006011
6012 Phone phone = getPhone(subId);
6013 if (phone == null) {
6014 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006015 callback.onError(
6016 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006017 } catch (RemoteException e) {
6018 // ignore
6019 }
6020 return;
6021 }
6022
6023 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6024 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6025 @Override
6026 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6027 try {
6028 callback.onCallForwardingInfoAvailable(info);
6029 } catch (RemoteException e) {
6030 // ignore
6031 }
6032 }
6033
6034 @Override
6035 public void onError(int error) {
6036 try {
6037 callback.onError(error);
6038 } catch (RemoteException e) {
6039 // ignore
6040 }
6041 }
6042 });
6043 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006044 } finally {
6045 Binder.restoreCallingIdentity(identity);
6046 }
6047 }
6048
6049 /**
6050 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6051 * reason, the number to forward, and the timeout before the forwarding is attempted.
6052 */
6053 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006054 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6055 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006056 enforceModifyPermission();
6057 long identity = Binder.clearCallingIdentity();
6058 try {
6059 if (DBG) {
6060 log("setCallForwarding: subId " + subId
6061 + " callForwardingInfo" + callForwardingInfo);
6062 }
Hall Liu27d24262020-09-18 19:04:59 -07006063
6064 Phone phone = getPhone(subId);
6065 if (phone == null) {
6066 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006067 callback.accept(
6068 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006069 } catch (RemoteException e) {
6070 // ignore
6071 }
6072 return;
6073 }
6074
6075 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6076 FunctionalUtils.ignoreRemoteException(callback::accept));
6077
6078 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006079 } finally {
6080 Binder.restoreCallingIdentity(identity);
6081 }
6082 }
6083
6084 /**
Hall Liu27d24262020-09-18 19:04:59 -07006085 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006086 */
6087 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006088 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006089 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006090 long identity = Binder.clearCallingIdentity();
6091 try {
Hall Liu27d24262020-09-18 19:04:59 -07006092 Phone phone = getPhone(subId);
6093 if (phone == null) {
6094 try {
6095 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6096 } catch (RemoteException e) {
6097 // ignore
6098 }
6099 return;
6100 }
SongFerngWang0e767992021-03-31 22:08:45 +08006101 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6102 PersistableBundle c = configManager.getConfigForSubId(subId);
6103 boolean requireUssd = c.getBoolean(
6104 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006105
Shuo Qian4a594052020-01-23 11:59:30 -08006106 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006107 if (requireUssd) {
6108 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6109 getSubscriptionCarrierId(subId));
6110 String newUssdCommand = "";
6111 try {
6112 newUssdCommand = carrierXmlParser.getFeature(
6113 CarrierXmlParser.FEATURE_CALL_WAITING)
6114 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6115 } catch (NullPointerException e) {
6116 loge("Failed to generate USSD number" + e);
6117 }
6118 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6119 mMainThreadHandler, callback, carrierXmlParser,
6120 CarrierXmlParser.SsEntry.SSAction.QUERY);
6121 final String ussdCommand = newUssdCommand;
6122 Executors.newSingleThreadExecutor().execute(() -> {
6123 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6124 });
6125 } else {
6126 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6127 callback::accept);
6128 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6129 }
Shuo Qian4a594052020-01-23 11:59:30 -08006130 } finally {
6131 Binder.restoreCallingIdentity(identity);
6132 }
6133 }
6134
6135 /**
Hall Liu27d24262020-09-18 19:04:59 -07006136 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006137 */
6138 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006139 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006140 enforceModifyPermission();
6141 long identity = Binder.clearCallingIdentity();
6142 try {
Hall Liu27d24262020-09-18 19:04:59 -07006143 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6144
6145 Phone phone = getPhone(subId);
6146 if (phone == null) {
6147 try {
6148 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6149 } catch (RemoteException e) {
6150 // ignore
6151 }
6152 return;
6153 }
6154
SongFerngWang0e767992021-03-31 22:08:45 +08006155 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6156 PersistableBundle c = configManager.getConfigForSubId(subId);
6157 boolean requireUssd = c.getBoolean(
6158 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006159
SongFerngWang0e767992021-03-31 22:08:45 +08006160 if (DBG) log("getCallWaitingStatus: subId " + subId);
6161 if (requireUssd) {
6162 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6163 getSubscriptionCarrierId(subId));
6164 CarrierXmlParser.SsEntry.SSAction ssAction =
6165 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6166 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6167 String newUssdCommand = "";
6168 try {
6169 newUssdCommand = carrierXmlParser.getFeature(
6170 CarrierXmlParser.FEATURE_CALL_WAITING)
6171 .makeCommand(ssAction, null);
6172 } catch (NullPointerException e) {
6173 loge("Failed to generate USSD number" + e);
6174 }
6175 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6176 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6177 final String ussdCommand = newUssdCommand;
6178 Executors.newSingleThreadExecutor().execute(() -> {
6179 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6180 });
6181 } else {
6182 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6183 FunctionalUtils.ignoreRemoteException(callback::accept));
6184
6185 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6186 }
Shuo Qian4a594052020-01-23 11:59:30 -08006187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
yinxub1bed742017-04-17 11:45:04 -07006193 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006194 *
yinxub1bed742017-04-17 11:45:04 -07006195 * @param subId id of the subscription
6196 * @param request contains the radio access networks with bands/channels to scan
6197 * @param messenger callback messenger for scan results or errors
6198 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006199 * @return the id of the requested scan which can be used to stop the scan.
6200 */
6201 @Override
6202 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006203 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6205 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006206 LocationAccessPolicy.LocationPermissionResult locationResult =
6207 LocationAccessPolicy.checkLocationPermission(mApp,
6208 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6209 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006210 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006211 .setCallingPid(Binder.getCallingPid())
6212 .setCallingUid(Binder.getCallingUid())
6213 .setMethod("requestNetworkScan")
6214 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006215 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6216 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006217 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006218 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006219 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6220 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006221 if (e != null) {
6222 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6223 throw e;
6224 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006225 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006226 return TelephonyScanManager.INVALID_SCAN_ID;
6227 }
6228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 }
Hall Liu912dfd32019-04-25 14:02:26 -07006230 int callingUid = Binder.getCallingUid();
6231 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006232 final long identity = Binder.clearCallingIdentity();
6233 try {
6234 return mNetworkScanRequestTracker.startNetworkScan(
6235 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006236 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
yinxu504e1392017-04-12 16:03:22 -07006240 }
6241
Hall Liub2ac8ef2019-02-28 15:56:23 -08006242 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006243 NetworkScanRequest request, int subId, String callingPackage) {
6244 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006245 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6246 boolean hasNetworkScanPermission =
6247 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6248 == PERMISSION_GRANTED;
6249
6250 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6251 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6252 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006253 }
6254
6255 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6256 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006257 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6258 return new SecurityException("Specific channels must not be"
6259 + " scanned without location access.");
6260 }
6261 }
6262 }
6263
Hall Liub2ac8ef2019-02-28 15:56:23 -08006264 return null;
6265 }
6266
yinxu504e1392017-04-12 16:03:22 -07006267 /**
6268 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006269 *
6270 * @param subId id of the subscription
6271 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006272 */
6273 @Override
6274 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6276 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006277
Hall Liu912dfd32019-04-25 14:02:26 -07006278 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279 final long identity = Binder.clearCallingIdentity();
6280 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006281 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284 }
yinxu504e1392017-04-12 16:03:22 -07006285 }
6286
6287 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006288 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006289 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006290 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006291 */
6292 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006293 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006294 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006295 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006296 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297
6298 final long identity = Binder.clearCallingIdentity();
6299 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006300 if (DBG) log("getAllowedNetworkTypesBitmask");
6301 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6302 int networkTypesBitmask = (result != null ? result[0] : -1);
6303 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6304 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 } finally {
6306 Binder.restoreCallingIdentity(identity);
6307 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006308 }
6309
6310 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006311 * Get the allowed network types for certain reason.
6312 *
6313 * @param subId the id of the subscription.
6314 * @param reason the reason the allowed network type change is taking place
6315 * @return the allowed network types.
6316 */
6317 @Override
6318 public long getAllowedNetworkTypesForReason(int subId,
6319 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006320 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006321 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006322 final long identity = Binder.clearCallingIdentity();
6323 try {
6324 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
6328 }
6329
6330 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006331 * Enable/Disable E-UTRA-NR Dual Connectivity
6332 * @param subId subscription id of the sim card
6333 * @param nrDualConnectivityState expected NR dual connectivity state
6334 * This can be passed following states
6335 * <ol>
6336 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6337 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6338 * <li>Disable NR dual connectivity and force secondary cell to be released
6339 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6340 * </ol>
6341 * @return operation result.
6342 */
6343 @Override
6344 public int setNrDualConnectivityState(int subId,
6345 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6347 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006348 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006349 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6350 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6351 }
6352
Sooraj Sasindran37444802020-08-11 10:40:43 -07006353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6354 final long identity = Binder.clearCallingIdentity();
6355 try {
6356 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6357 nrDualConnectivityState, subId,
6358 workSource);
6359 if (DBG) log("enableNRDualConnectivity result: " + result);
6360 return result;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
6364 }
6365
6366 /**
6367 * Is E-UTRA-NR Dual Connectivity enabled
6368 * @return true if dual connectivity is enabled else false
6369 */
6370 @Override
6371 public boolean isNrDualConnectivityEnabled(int subId) {
6372 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006373 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006374 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006375 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006376 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6377 return false;
6378 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006379 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6383 null, subId, workSource);
6384 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6385 return isEnabled;
6386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
6389 }
6390
6391 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006392 * Set the allowed network types of the device and
6393 * provide the reason triggering the allowed network change.
6394 *
6395 * @param subId the id of the subscription.
6396 * @param reason the reason the allowed network type change is taking place
6397 * @param allowedNetworkTypes the allowed network types.
6398 * @return true on success; false on any failure.
6399 */
6400 @Override
6401 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006402 @TelephonyManager.AllowedNetworkTypesReason int reason,
6403 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6405 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006406 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006407 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6408 return false;
6409 }
6410 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6411 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006412 return false;
6413 }
6414
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006415 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6416 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6417
6418
6419 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6420 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6421 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006422 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006423
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006424 final long identity = Binder.clearCallingIdentity();
6425 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006426 Boolean success = (Boolean) sendRequest(
6427 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6428 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6429
6430 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6431 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
6435 }
6436
6437 /**
Miaoa84611c2019-03-15 09:21:10 +08006438 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006439 *
Miaoa84611c2019-03-15 09:21:10 +08006440 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006441 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006442 * @hide
6443 */
6444 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006445 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006448 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449 try {
Miaoa84611c2019-03-15 09:21:10 +08006450 if (phone != null) {
6451 return phone.hasMatchedTetherApnSetting();
6452 } else {
6453 return false;
6454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 } finally {
6456 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006457 }
Junda Liu475951f2014-11-07 16:45:03 -08006458 }
6459
6460 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006461 * Enable or disable always reporting signal strength changes from radio.
6462 *
6463 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6464 */
6465 @Override
6466 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6467 enforceModifyPermission();
6468 enforceSystemCaller();
6469
6470 final long identity = Binder.clearCallingIdentity();
6471 final Phone phone = getPhone(subId);
6472 try {
6473 if (phone != null) {
6474 if (DBG) {
6475 log("setAlwaysReportSignalStrength: subId=" + subId
6476 + " isEnable=" + isEnable);
6477 }
6478 phone.setAlwaysReportSignalStrength(isEnable);
6479 } else {
6480 loge("setAlwaysReportSignalStrength: no phone found for subId="
6481 + subId);
6482 }
6483 } finally {
6484 Binder.restoreCallingIdentity(identity);
6485 }
6486 }
6487
6488 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006489 * Get the user enabled state of Mobile Data.
6490 *
6491 * TODO: remove and use isUserDataEnabled.
6492 * This can't be removed now because some vendor codes
6493 * calls through ITelephony directly while they should
6494 * use TelephonyManager.
6495 *
6496 * @return true on enabled
6497 */
6498 @Override
6499 public boolean getDataEnabled(int subId) {
6500 return isUserDataEnabled(subId);
6501 }
6502
6503 /**
6504 * Get whether mobile data is enabled per user setting.
6505 *
6506 * There are other factors deciding whether mobile data is actually enabled, but they are
6507 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006508 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006509 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006510 *
6511 * @return {@code true} if data is enabled else {@code false}
6512 */
6513 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006514 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006515 try {
6516 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6517 null);
6518 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6520 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006521 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006522
6523 final long identity = Binder.clearCallingIdentity();
6524 try {
6525 int phoneId = mSubscriptionController.getPhoneId(subId);
6526 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6527 Phone phone = PhoneFactory.getPhone(phoneId);
6528 if (phone != null) {
6529 boolean retVal = phone.isUserDataEnabled();
6530 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6531 return retVal;
6532 } else {
6533 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6534 return false;
6535 }
6536 } finally {
6537 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006538 }
6539 }
6540
6541 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006542 * Checks if the device is capable of mobile data by considering whether whether the
6543 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6544 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006545 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006546 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006547 */
6548 @Override
6549 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006550 try {
6551 try {
6552 mApp.enforceCallingOrSelfPermission(
6553 android.Manifest.permission.ACCESS_NETWORK_STATE,
6554 null);
6555 } catch (Exception e) {
6556 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6557 "isDataEnabled");
6558 }
6559 } catch (Exception e) {
6560 enforceReadPrivilegedPermission("isDataEnabled");
6561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562
6563 final long identity = Binder.clearCallingIdentity();
6564 try {
6565 int phoneId = mSubscriptionController.getPhoneId(subId);
6566 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6567 Phone phone = PhoneFactory.getPhone(phoneId);
6568 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006569 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6571 return retVal;
6572 } else {
6573 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6574 return false;
6575 }
6576 } finally {
6577 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006578 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006579 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006580
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006581 /**
6582 * Check if data is enabled for a specific reason
6583 * @param subId Subscription index
6584 * @param reason the reason the data enable change is taking place
6585 * @return {@code true} if the overall data is enabled; {@code false} if not.
6586 */
6587 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006588 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006589 @TelephonyManager.DataEnabledReason int reason) {
6590 try {
6591 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6592 null);
6593 } catch (Exception e) {
6594 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006595 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006596 }
6597
6598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 int phoneId = mSubscriptionController.getPhoneId(subId);
6602 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006603 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006604 + " reason=" + reason);
6605 }
6606 Phone phone = PhoneFactory.getPhone(phoneId);
6607 if (phone != null) {
6608 boolean retVal;
6609 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6610 retVal = phone.isUserDataEnabled();
6611 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006612 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006613 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006614 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006615 return retVal;
6616 } else {
6617 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006618 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006619 + subId + " retVal=false");
6620 }
6621 return false;
6622 }
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
6626 }
6627
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006628 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006629 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006630 if (uid == Process.PHONE_UID) {
6631 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6632 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006633 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6634 }
6635
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006636 //load access rules from carrier configs, and check those as well: b/139133814
6637 SubscriptionController subController = SubscriptionController.getInstance();
6638 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6639 || subController == null) return privilegeFromSim;
6640
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006641 PackageManager pkgMgr = phone.getContext().getPackageManager();
6642 String[] packages = pkgMgr.getPackagesForUid(uid);
6643
6644 final long identity = Binder.clearCallingIdentity();
6645 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006646 int subId = phone.getSubId();
6647 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6648 // A test override is in place for the privileges for this subId, so don't try to
6649 // read the subscription privileges.
6650 return privilegeFromSim;
6651 }
6652 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006653 SubscriptionManager subManager = (SubscriptionManager)
6654 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6655 for (String pkg : packages) {
6656 if (subManager.canManageSubscription(subInfo, pkg)) {
6657 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6658 }
6659 }
6660 return privilegeFromSim;
6661 } finally {
6662 Binder.restoreCallingIdentity(identity);
6663 }
6664 }
6665
6666 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6667 String pkgName) {
6668 //load access rules from carrier configs, and check those as well: b/139133814
6669 SubscriptionController subController = SubscriptionController.getInstance();
6670 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6671 || subController == null) return privilegeFromSim;
6672
6673 final long identity = Binder.clearCallingIdentity();
6674 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006675 int subId = phone.getSubId();
6676 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6677 // A test override is in place for the privileges for this subId, so don't try to
6678 // read the subscription privileges.
6679 return privilegeFromSim;
6680 }
6681 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006682 SubscriptionManager subManager = (SubscriptionManager)
6683 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6684 return subManager.canManageSubscription(subInfo, pkgName)
6685 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
6688 }
6689 }
6690
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006691 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006692 public int getCarrierPrivilegeStatus(int subId) {
6693 final Phone phone = getPhone(subId);
6694 if (phone == null) {
6695 loge("getCarrierPrivilegeStatus: Invalid subId");
6696 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6697 }
6698 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006699 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006700 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006701 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6702 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006703
6704 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6705 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006706 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006707 }
Junda Liu29340342014-07-10 15:23:27 -07006708
6709 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006710 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006711 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006712 final Phone phone = getPhone(subId);
6713 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006714 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006715 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6716 }
6717 UiccProfile profile =
6718 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6719 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006720 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006721 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6722 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006723 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006724 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006725 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006726 }
6727
6728 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006729 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006730 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006731 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006732 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006733 }
6734
6735 int phoneId = SubscriptionManager.getPhoneId(subId);
6736 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006737 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006738 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006739 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6740 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006741 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6742 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6743 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006744 }
6745
6746 @Override
6747 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006748 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006749 if (TextUtils.isEmpty(pkgName))
6750 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006751 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6752 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6753 UiccCard card = UiccController.getInstance().getUiccCard(i);
6754 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006755 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006756 continue;
6757 }
6758
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006759 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6760 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6761 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006762 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6763 break;
6764 }
6765 }
6766
6767 return result;
Junda Liu29340342014-07-10 15:23:27 -07006768 }
Derek Tan89e89d42014-07-08 17:00:10 -07006769
6770 @Override
Junda Liue64de782015-04-16 17:19:16 -07006771 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006772 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006773 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6774 loge("phoneId " + phoneId + " is not valid.");
6775 return null;
6776 }
6777 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006778 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006779 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006780 return null ;
6781 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006782 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006783 }
6784
Amith Yamasani6e118872016-02-19 12:53:51 -08006785 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006786 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006787 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006788 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006789 List<String> privilegedPackages = new ArrayList<>();
6790 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006791 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6792 // has UICC in that slot.
6793 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006794 if (card.hasCarrierPrivilegeRules()) {
6795 if (packages == null) {
6796 // Only check packages in user 0 for now
6797 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006798 PackageManager.MATCH_DISABLED_COMPONENTS
6799 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006800 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006801 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006802 }
6803 for (int p = packages.size() - 1; p >= 0; p--) {
6804 PackageInfo pkgInfo = packages.get(p);
6805 if (pkgInfo != null && pkgInfo.packageName != null
6806 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006807 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006808 privilegedPackages.add(pkgInfo.packageName);
6809 }
6810 }
6811 }
6812 }
6813 return privilegedPackages;
6814 }
6815
chen xuf7e9fe82019-05-09 19:31:02 -07006816 @Override
6817 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006818 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6819
6820 final long identity = Binder.clearCallingIdentity();
6821
chen xuf7e9fe82019-05-09 19:31:02 -07006822 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006823 try {
6824 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6825 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6826 }
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006829 }
6830 return privilegedPackages;
6831 }
6832
Wink Savilleb564aae2014-10-23 10:18:09 -07006833 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006834 final Phone phone = getPhone(subId);
6835 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006836 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006837 return null;
6838 }
6839 String iccId = card.getIccId();
6840 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006841 return null;
6842 }
6843 return iccId;
6844 }
6845
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006846 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006847 public void setCallComposerStatus(int subId, int status) {
6848 enforceModifyPermission();
6849
6850 final long identity = Binder.clearCallingIdentity();
6851 try {
6852 Phone phone = getPhone(subId);
6853 if (phone != null) {
6854 Phone defaultPhone = phone.getImsPhone();
6855 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6856 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6857 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006858 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6859 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006860 }
6861 }
Shuo Qian284ae752020-12-22 19:10:14 -08006862 } catch (ImsException e) {
6863 throw new ServiceSpecificException(e.getCode());
6864 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006865 Binder.restoreCallingIdentity(identity);
6866 }
6867 }
6868
6869 @Override
6870 public int getCallComposerStatus(int subId) {
6871 enforceReadPrivilegedPermission("getCallComposerStatus");
6872
6873 final long identity = Binder.clearCallingIdentity();
6874 try {
6875 Phone phone = getPhone(subId);
6876 if (phone != null) {
6877 Phone defaultPhone = phone.getImsPhone();
6878 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6879 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6880 return imsPhone.getCallComposerStatus();
6881 }
6882 }
6883 } finally {
6884 Binder.restoreCallingIdentity(identity);
6885 }
6886 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6887 }
6888
6889 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006890 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6891 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006892 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006893 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006895 final long identity = Binder.clearCallingIdentity();
6896 try {
6897 final String iccId = getIccId(subId);
6898 final Phone phone = getPhone(subId);
6899 if (phone == null) {
6900 return false;
6901 }
6902 final String subscriberId = phone.getSubscriberId();
6903
6904 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006905 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006906 + subscriberId + " to " + number);
6907 }
6908
6909 if (TextUtils.isEmpty(iccId)) {
6910 return false;
6911 }
6912
6913 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6914
6915 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6916 if (alphaTag == null) {
6917 editor.remove(alphaTagPrefKey);
6918 } else {
6919 editor.putString(alphaTagPrefKey, alphaTag);
6920 }
6921
6922 // Record both the line number and IMSI for this ICCID, since we need to
6923 // track all merged IMSIs based on line number
6924 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6925 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6926 if (number == null) {
6927 editor.remove(numberPrefKey);
6928 editor.remove(subscriberPrefKey);
6929 } else {
6930 editor.putString(numberPrefKey, number);
6931 editor.putString(subscriberPrefKey, subscriberId);
6932 }
6933
6934 editor.commit();
6935 return true;
6936 } finally {
6937 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006938 }
Derek Tan7226c842014-07-02 17:42:23 -07006939 }
6940
6941 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006942 public String getLine1NumberForDisplay(int subId, String callingPackage,
6943 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006944 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006946 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006947 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006948 return null;
6949 }
Derek Tan97ebb422014-09-05 16:55:38 -07006950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006951 final long identity = Binder.clearCallingIdentity();
6952 try {
6953 String iccId = getIccId(subId);
6954 if (iccId != null) {
6955 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6956 if (DBG_MERGE) {
6957 log("getLine1NumberForDisplay returning "
6958 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6959 }
6960 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6963 return null;
6964 } finally {
6965 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006966 }
Derek Tan7226c842014-07-02 17:42:23 -07006967 }
6968
6969 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006970 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6971 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006973 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006974 return null;
6975 }
Derek Tan97ebb422014-09-05 16:55:38 -07006976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 String iccId = getIccId(subId);
6980 if (iccId != null) {
6981 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6982 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6983 }
6984 return null;
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006987 }
Derek Tan7226c842014-07-02 17:42:23 -07006988 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006989
6990 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006991 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6992 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006993 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6994 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006995 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006996 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006997 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006998 return null;
6999 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007000
Jordan Liub49b04b2019-05-06 14:45:15 -07007001 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7002 // the process, where TelephonyManager was instantiated.
7003 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007004 final long identity = Binder.clearCallingIdentity();
7005 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007006 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 final TelephonyManager tele = TelephonyManager.from(context);
7008 final SubscriptionManager sub = SubscriptionManager.from(context);
7009
7010 // Figure out what subscribers are currently active
7011 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012
Jordan Liub49b04b2019-05-06 14:45:15 -07007013 // Only consider subs which match the current subId
7014 // This logic can be simplified. See b/131189269 for progress.
7015 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007016 activeSubscriberIds.add(tele.getSubscriberId(subId));
7017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018
7019 // First pass, find a number override for an active subscriber
7020 String mergeNumber = null;
7021 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7022 for (String key : prefs.keySet()) {
7023 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7024 final String subscriberId = (String) prefs.get(key);
7025 if (activeSubscriberIds.contains(subscriberId)) {
7026 final String iccId = key.substring(
7027 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7028 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7029 mergeNumber = (String) prefs.get(numberKey);
7030 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007031 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007032 + " for active subscriber " + subscriberId);
7033 }
7034 if (!TextUtils.isEmpty(mergeNumber)) {
7035 break;
7036 }
7037 }
7038 }
7039 }
7040
7041 // Shortcut when no active merged subscribers
7042 if (TextUtils.isEmpty(mergeNumber)) {
7043 return null;
7044 }
7045
7046 // Second pass, find all subscribers under that line override
7047 final ArraySet<String> result = new ArraySet<>();
7048 for (String key : prefs.keySet()) {
7049 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7050 final String number = (String) prefs.get(key);
7051 if (mergeNumber.equals(number)) {
7052 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7053 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7054 final String subscriberId = (String) prefs.get(subscriberKey);
7055 if (!TextUtils.isEmpty(subscriberId)) {
7056 result.add(subscriberId);
7057 }
7058 }
7059 }
7060 }
7061
7062 final String[] resultArray = result.toArray(new String[result.size()]);
7063 Arrays.sort(resultArray);
7064 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007065 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007066 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7067 }
7068 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007069 } finally {
7070 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007071 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007072 }
7073
7074 @Override
zoey chen38003472019-12-13 17:16:31 +08007075 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7076 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007077
7078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 final TelephonyManager telephonyManager = mApp.getSystemService(
7081 TelephonyManager.class);
7082 String subscriberId = telephonyManager.getSubscriberId(subId);
7083 if (subscriberId == null) {
7084 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007085 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007086 + subId);
7087 }
7088 return null;
7089 }
7090
7091 final SubscriptionInfo info = SubscriptionController.getInstance()
7092 .getSubscriptionInfo(subId);
7093 final ParcelUuid groupUuid = info.getGroupUuid();
7094 // If it doesn't belong to any group, return just subscriberId of itself.
7095 if (groupUuid == null) {
7096 return new String[]{subscriberId};
7097 }
7098
7099 // Get all subscriberIds from the group.
7100 final List<String> mergedSubscriberIds = new ArrayList<>();
7101 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007102 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007103 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007104 for (SubscriptionInfo subInfo : groupInfos) {
7105 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7106 if (subscriberId != null) {
7107 mergedSubscriberIds.add(subscriberId);
7108 }
7109 }
7110
7111 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
7114
7115 }
7116 }
7117
7118 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007119 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007120 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007121 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122
7123 final long identity = Binder.clearCallingIdentity();
7124 try {
7125 final Phone phone = getPhone(subId);
7126 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7127 } finally {
7128 Binder.restoreCallingIdentity(identity);
7129 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007130 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007131
7132 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007133 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007134 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7135 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007136 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7137 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 final Phone phone = getPhone(subId);
7142 if (phone == null) {
7143 return false;
7144 }
7145 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7146 cdmaNonRoamingList);
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007149 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007150 }
7151
7152 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007153 @Deprecated
7154 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7155 enforceModifyPermission();
7156
7157 int returnValue = 0;
7158 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007159 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007160 if(result.exception == null) {
7161 if (result.result != null) {
7162 byte[] responseData = (byte[])(result.result);
7163 if(responseData.length > oemResp.length) {
7164 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7165 responseData.length + "bytes. Buffer Size is " +
7166 oemResp.length + "bytes.");
7167 }
7168 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7169 returnValue = responseData.length;
7170 }
7171 } else {
7172 CommandException ex = (CommandException) result.exception;
7173 returnValue = ex.getCommandError().ordinal();
7174 if(returnValue > 0) returnValue *= -1;
7175 }
7176 } catch (RuntimeException e) {
7177 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7178 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7179 if(returnValue > 0) returnValue *= -1;
7180 }
7181
7182 return returnValue;
7183 }
7184
7185 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007186 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007187 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007188 try {
7189 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007190 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007191 mApp, phone.getSubId(), "getRadioAccessFamily");
7192 } catch (SecurityException e) {
7193 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7194 throw e;
7195 }
chen xub97461a2018-10-26 14:17:57 -07007196 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007197 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007198 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007199 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 final long identity = Binder.clearCallingIdentity();
7201 try {
chen xub97461a2018-10-26 14:17:57 -07007202 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007203 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007204 mApp, phone.getSubId(), "getRadioAccessFamily");
7205 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
chen xub97461a2018-10-26 14:17:57 -07007209 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007210 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007211
7212 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007213 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007214 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007215 try {
7216 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7217 Binder.getCallingUid())) {
7218 throw new SecurityException("Package uid and package name do not match: "
7219 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7220 }
7221 } catch (PackageManager.NameNotFoundException e) {
7222 throw new SecurityException("Package name invalid:" + callingPackage);
7223 }
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);
7605 if (phone != null) {
7606 SubscriptionManager.setSubscriptionProperty(subId,
7607 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7608 "user=" + RadioAccessFamily.getRafFromNetworkType(
7609 RILConstants.PREFERRED_NETWORK_MODE));
7610 phone.loadAllowedNetworksFromSubscriptionDatabase();
7611 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007612 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007613 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007614 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007615 // There has been issues when Sms raw table somehow stores orphan
7616 // fragments. They lead to garbled message when new fragments come
7617 // in and combined with those stale ones. In case this happens again,
7618 // user can reset all network settings which will clean up this table.
7619 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007620 // Clean up IMS settings as well here.
7621 int slotId = getSlotIndex(subId);
7622 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7623 ImsManager.getInstance(mApp, slotId).factoryReset();
7624 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007625
Kai Shif70f46f2021-03-03 13:59:46 -08007626 if (defaultPhone == null) {
7627 return;
7628 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007629 // Erase modem config if erase modem on network setting is enabled.
7630 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7631 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7632 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007633 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007634 }
Kai Shif70f46f2021-03-03 13:59:46 -08007635
7636 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007637 } finally {
7638 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007639 }
7640 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007641
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007642 private void cleanUpSmsRawTable(Context context) {
7643 ContentResolver resolver = context.getContentResolver();
7644 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7645 resolver.delete(uri, null, null);
7646 }
7647
Narayan Kamath1c496c22015-04-16 14:40:19 +01007648 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007649 public String getSimLocaleForSubscriber(int subId) {
7650 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7651 final Phone phone = getPhone(subId);
7652 if (phone == null) {
7653 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007654 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 final long identity = Binder.clearCallingIdentity();
7657 try {
chen xu5d3637b2019-01-21 23:31:38 -08007658 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007659 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007660 if (info == null) {
7661 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7662 return null;
7663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664 // Try and fetch the locale from the carrier properties or from the SIM language
7665 // preferences (EF-PL and EF-LI)...
7666 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007668 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7669 if (localeFromDefaultSim != null) {
7670 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7671 if (DBG) log("Using locale from subId: " + subId + " locale: "
7672 + localeFromDefaultSim);
7673 return localeFromDefaultSim.toLanguageTag();
7674 } else {
7675 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 }
7677 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 // The SIM language preferences only store a language (e.g. fr = French), not an
7680 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7681 // the SIM and carrier preferences does not include a country we add the country
7682 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007683 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007684 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007685 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 return mccLocale.toLanguageTag();
7687 }
7688
7689 if (DBG) log("No locale found - returning null");
7690 return null;
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007694 }
7695
7696 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007697 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007698 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007699 }
7700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 /**
7702 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7703 */
7704 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007705 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007706 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007707 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007708
Chenjie Yu1ba97252018-01-11 18:16:20 -08007709 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007710 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007711
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007712 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007713 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7714 * representing the state of the modem.
7715 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007716 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7717 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007718 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007719 */
7720 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007721 public void requestModemActivityInfo(ResultReceiver result) {
7722 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007723 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724
7725 final long identity = Binder.clearCallingIdentity();
7726 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007727 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 } finally {
7729 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007730 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007731 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007732
Siddharth Rayb8114062018-06-17 15:02:38 -07007733 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7734 // less than total activity duration.
7735 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7736 if (info == null) {
7737 return false;
7738 }
7739 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007740 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7741 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7742
Siddharth Rayb8114062018-06-17 15:02:38 -07007743 return (info.isValid()
7744 && (info.getSleepTimeMillis() <= activityDurationMs)
7745 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007746 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007747 && (totalTxTimeMs <= activityDurationMs));
7748 }
7749
Jack Yu85bd38a2015-11-09 11:34:32 -08007750 /**
7751 * {@hide}
7752 * Returns the service state information on specified subscription.
7753 */
7754 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007755 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7756 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007758 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007759 return null;
7760 }
7761
Hall Liuf19c44f2018-11-27 14:38:17 -08007762 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7763 LocationAccessPolicy.checkLocationPermission(mApp,
7764 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7765 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007766 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007767 .setCallingPid(Binder.getCallingPid())
7768 .setCallingUid(Binder.getCallingUid())
7769 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007770 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007771 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007772 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7773 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007774 .build());
7775
7776 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7777 LocationAccessPolicy.checkLocationPermission(mApp,
7778 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7779 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007780 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007781 .setCallingPid(Binder.getCallingPid())
7782 .setCallingUid(Binder.getCallingUid())
7783 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007784 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007785 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007786 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7787 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007788 .build());
7789 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7790 boolean hasFinePermission =
7791 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7792 boolean hasCoarsePermission =
7793 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7794
Jack Yu479f40e2020-10-27 21:29:25 -07007795 final Phone phone = getPhone(subId);
7796 if (phone == null) {
7797 return null;
7798 }
7799
Jordan Liu0f2bc442020-11-18 16:47:37 -08007800 final long identity = Binder.clearCallingIdentity();
7801
Jack Yu479f40e2020-10-27 21:29:25 -07007802 boolean isCallingPackageDataService = phone.getDataServicePackages()
7803 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007805 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7806 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7807 Rlog.d(LOG_TAG,
7808 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7809 return null;
7810 }
7811
Hall Liuf19c44f2018-11-27 14:38:17 -08007812 ServiceState ss = phone.getServiceState();
7813
7814 // Scrub out the location info in ServiceState depending on what level of access
7815 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007816 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007817 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7818 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 } finally {
7820 Binder.restoreCallingIdentity(identity);
7821 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007822 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007823
7824 /**
7825 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7826 *
7827 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7828 * voicemail ringtone.
7829 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7830 * PhoneAccount.
7831 */
7832 @Override
7833 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 final long identity = Binder.clearCallingIdentity();
7835 try {
7836 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7837 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007838 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007839 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7842 } finally {
7843 Binder.restoreCallingIdentity(identity);
7844 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007845 }
7846
7847 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007848 * Sets the per-account voicemail ringtone.
7849 *
7850 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7851 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7852 *
7853 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7854 * voicemail ringtone.
7855 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7856 * PhoneAccount.
7857 */
7858 @Override
7859 public void setVoicemailRingtoneUri(String callingPackage,
7860 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007861 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007862 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007863 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7864 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7866 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7867 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007868 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869
7870 final long identity = Binder.clearCallingIdentity();
7871 try {
7872 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7873 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007874 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 }
7876 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7877 } finally {
7878 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007879 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007880 }
7881
7882 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007883 * Returns whether vibration is set for voicemail notification in Phone settings.
7884 *
7885 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7886 * voicemail vibration setting.
7887 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7888 */
7889 @Override
7890 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7894 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007895 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7899 } finally {
7900 Binder.restoreCallingIdentity(identity);
7901 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007902 }
7903
Youhan Wange64578a2016-05-02 15:32:42 -07007904 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007905 * Sets the per-account voicemail vibration.
7906 *
7907 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7908 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7909 *
7910 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7911 * voicemail vibration setting.
7912 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7913 * specific PhoneAccount.
7914 */
7915 @Override
7916 public void setVoicemailVibrationEnabled(String callingPackage,
7917 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007918 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007919 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007920 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7921 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007922 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7923 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7924 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007925 }
7926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007927 final long identity = Binder.clearCallingIdentity();
7928 try {
7929 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7930 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007931 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 }
7933 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007936 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007937 }
7938
7939 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007940 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7941 *
7942 * @throws SecurityException if the caller does not have the required permission
7943 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007944 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007945 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007946 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007947 }
7948
7949 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007950 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7951 * permission.
7952 *
7953 * @throws SecurityException if the caller does not have the required permission
7954 */
7955 private void enforceSendSmsPermission() {
7956 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7957 }
7958
7959 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007960 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007961 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007962 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007963 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007964 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 final long identity = Binder.clearCallingIdentity();
7966 try {
7967 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007968 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 if (componentName == null) {
7970 throw new SecurityException(
7971 "Caller not current active visual voicemail package[null]");
7972 }
7973 String vvmPackage = componentName.getPackageName();
7974 if (!callingPackage.equals(vvmPackage)) {
7975 throw new SecurityException("Caller not current active visual voicemail package["
7976 + vvmPackage + "]");
7977 }
7978 } finally {
7979 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007980 }
7981 }
7982
7983 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007984 * Return the application ID for the app type.
7985 *
7986 * @param subId the subscription ID that this request applies to.
7987 * @param appType the uicc app type.
7988 * @return Application ID for specificied app type, or null if no uicc.
7989 */
7990 @Override
7991 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007992 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007993 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007994
7995 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007996 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 if (phone == null) {
7998 return null;
7999 }
8000 String aid = null;
8001 try {
8002 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8003 .getApplicationByType(appType).getAid();
8004 } catch (Exception e) {
8005 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8006 }
8007 return aid;
8008 } finally {
8009 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008010 }
Youhan Wange64578a2016-05-02 15:32:42 -07008011 }
8012
Youhan Wang4001d252016-05-11 10:29:41 -07008013 /**
8014 * Return the Electronic Serial Number.
8015 *
8016 * @param subId the subscription ID that this request applies to.
8017 * @return ESN or null if error.
8018 */
8019 @Override
8020 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008021 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008022 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023
8024 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008025 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 if (phone == null) {
8027 return null;
8028 }
8029 String esn = null;
8030 try {
8031 esn = phone.getEsn();
8032 } catch (Exception e) {
8033 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8034 }
8035 return esn;
8036 } finally {
8037 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008038 }
Youhan Wang4001d252016-05-11 10:29:41 -07008039 }
8040
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008041 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008042 * Return the Preferred Roaming List Version.
8043 *
8044 * @param subId the subscription ID that this request applies to.
8045 * @return PRLVersion or null if error.
8046 */
8047 @Override
8048 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008049 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008050 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051
8052 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008053 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 if (phone == null) {
8055 return null;
8056 }
8057 String cdmaPrlVersion = null;
8058 try {
8059 cdmaPrlVersion = phone.getCdmaPrlVersion();
8060 } catch (Exception e) {
8061 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8062 }
8063 return cdmaPrlVersion;
8064 } finally {
8065 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008066 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008067 }
8068
8069 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008070 * Get snapshot of Telephony histograms
8071 * @return List of Telephony histograms
8072 * @hide
8073 */
8074 @Override
8075 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8077 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008078
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 return RIL.getTelephonyRILTimingHistograms();
8082 } finally {
8083 Binder.restoreCallingIdentity(identity);
8084 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008085 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008086
8087 /**
8088 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008089 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8090 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008091 * Require system privileges. In the future we may add this to carrier APIs.
8092 *
Michele Berionne482f8202018-11-27 18:57:59 -08008093 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008094 */
8095 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008096 @TelephonyManager.SetCarrierRestrictionResult
8097 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008098 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008099 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008100
Michele Berionne482f8202018-11-27 18:57:59 -08008101 if (carrierRestrictionRules == null) {
8102 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008103 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008105 final long identity = Binder.clearCallingIdentity();
8106 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008107 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008108 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008109 } finally {
8110 Binder.restoreCallingIdentity(identity);
8111 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008112 }
8113
8114 /**
8115 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008116 * Get the allowed carrier list and the excluded carrier list, including the priority between
8117 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008118 * Require system privileges. In the future we may add this to carrier APIs.
8119 *
Michele Berionne482f8202018-11-27 18:57:59 -08008120 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008121 */
8122 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008123 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008124 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008125 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008126
8127 final long identity = Binder.clearCallingIdentity();
8128 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008129 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8130 if (response instanceof CarrierRestrictionRules) {
8131 return (CarrierRestrictionRules) response;
8132 }
8133 // Response is an Exception of some kind,
8134 // which is signalled to the user as a NULL retval
8135 return null;
8136 } catch (Exception e) {
8137 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8138 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 } finally {
8140 Binder.restoreCallingIdentity(identity);
8141 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008142 }
8143
fionaxu59545b42016-05-25 15:53:37 -07008144 /**
fionaxu59545b42016-05-25 15:53:37 -07008145 * Action set from carrier signalling broadcast receivers to enable/disable radio
8146 * @param subId the subscription ID that this action applies to.
8147 * @param enabled control enable or disable radio.
8148 * {@hide}
8149 */
8150 @Override
8151 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8152 enforceModifyPermission();
8153 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008154
8155 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008156 if (phone == null) {
8157 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8158 return;
8159 }
8160 try {
8161 phone.carrierActionSetRadioEnabled(enabled);
8162 } catch (Exception e) {
8163 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008164 } finally {
8165 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008166 }
8167 }
8168
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008169 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008170 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8171 * network status based on which carrier apps could apply actions accordingly,
8172 * enable/disable default url handler for example.
8173 *
8174 * @param subId the subscription ID that this action applies to.
8175 * @param report control start/stop reporting the default network status.
8176 * {@hide}
8177 */
8178 @Override
8179 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8180 enforceModifyPermission();
8181 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182
8183 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008184 if (phone == null) {
8185 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8186 return;
8187 }
8188 try {
8189 phone.carrierActionReportDefaultNetworkStatus(report);
8190 } catch (Exception e) {
8191 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192 } finally {
8193 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008194 }
8195 }
8196
8197 /**
fionaxud9622282017-07-17 17:51:30 -07008198 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8199 * @param subId the subscription ID that this action applies to.
8200 * {@hide}
8201 */
8202 @Override
8203 public void carrierActionResetAll(int subId) {
8204 enforceModifyPermission();
8205 final Phone phone = getPhone(subId);
8206 if (phone == null) {
8207 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8208 return;
8209 }
8210 try {
8211 phone.carrierActionResetAll();
8212 } catch (Exception e) {
8213 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8214 }
8215 }
8216
8217 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008218 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8219 * bug report is being generated.
8220 */
8221 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008222 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008223 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8224 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008225 writer.println("Permission Denial: can't dump Phone from pid="
8226 + Binder.getCallingPid()
8227 + ", uid=" + Binder.getCallingUid()
8228 + "without permission "
8229 + android.Manifest.permission.DUMP);
8230 return;
8231 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008232 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008233 }
Jack Yueb89b242016-06-22 13:27:47 -07008234
Brad Ebingerdac2f002018-04-03 15:17:52 -07008235 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008236 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8237 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8238 @NonNull String[] args) {
8239 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8240 this, in.getFileDescriptor(), out.getFileDescriptor(),
8241 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008242 }
8243
Jack Yueb89b242016-06-22 13:27:47 -07008244 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008245 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008246 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008247 * @param reason the reason the data enable change is taking place
8248 * @param enabled True if enabling the data, otherwise disabling.
8249 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008250 */
8251 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008252 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008253 boolean enabled) {
8254 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8255 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8256 try {
8257 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008258 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008259 } catch (SecurityException se) {
8260 enforceModifyPermission();
8261 }
8262 } else {
8263 enforceModifyPermission();
8264 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265
8266 final long identity = Binder.clearCallingIdentity();
8267 try {
8268 Phone phone = getPhone(subId);
8269 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008270 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8271 phone.carrierActionSetMeteredApnsEnabled(enabled);
8272 } else {
8273 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008275 }
8276 } finally {
8277 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008278 }
8279 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008280
8281 /**
8282 * Get Client request stats
8283 * @return List of Client Request Stats
8284 * @hide
8285 */
8286 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008287 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8288 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008290 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008291 return null;
8292 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008293 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 final long identity = Binder.clearCallingIdentity();
8296 try {
8297 if (phone != null) {
8298 return phone.getClientRequestStats();
8299 }
8300
8301 return null;
8302 } finally {
8303 Binder.restoreCallingIdentity(identity);
8304 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008305 }
8306
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008307 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008308 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008309 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008310 }
Jack Yueb4124c2017-02-16 15:32:43 -08008311
8312 /**
Grace Chen70990072017-03-24 17:21:30 -07008313 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008314 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008315 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008316 * @param state State of SIM (power down, power up, pass through)
8317 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8318 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8319 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008320 *
8321 **/
8322 @Override
Grace Chen70990072017-03-24 17:21:30 -07008323 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008324 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008325 Phone phone = PhoneFactory.getPhone(slotIndex);
8326
vagdeviaf9a5b92018-08-15 16:01:53 -07008327 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008329 final long identity = Binder.clearCallingIdentity();
8330 try {
8331 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008332 phone.setSimPowerState(state, null, workSource);
8333 }
8334 } finally {
8335 Binder.restoreCallingIdentity(identity);
8336 }
8337 }
8338
8339 /**
8340 * Set SIM card power state.
8341 *
8342 * @param slotIndex SIM slot id.
8343 * @param state State of SIM (power down, power up, pass through)
8344 * @param callback callback to trigger after success or failure
8345 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8346 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8347 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8348 *
8349 **/
8350 @Override
8351 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8352 IIntegerConsumer callback) {
8353 enforceModifyPermission();
8354 Phone phone = PhoneFactory.getPhone(slotIndex);
8355
8356 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8357
8358 final long identity = Binder.clearCallingIdentity();
8359 try {
8360 if (phone != null) {
8361 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8362 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363 }
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008366 }
8367 }
Shuo Qiandd210312017-04-12 22:11:33 +00008368
Tyler Gunn65d45c22017-06-05 11:22:26 -07008369 private boolean isUssdApiAllowed(int subId) {
8370 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008371 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008372 if (configManager == null) {
8373 return false;
8374 }
8375 PersistableBundle pb = configManager.getConfigForSubId(subId);
8376 if (pb == null) {
8377 return false;
8378 }
8379 return pb.getBoolean(
8380 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8381 }
8382
Shuo Qiandd210312017-04-12 22:11:33 +00008383 /**
8384 * Check if phone is in emergency callback mode
8385 * @return true if phone is in emergency callback mode
8386 * @param subId sub id
8387 */
goneil9c5f4872017-12-05 14:07:56 -08008388 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008389 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008390 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008391 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392
8393 final long identity = Binder.clearCallingIdentity();
8394 try {
8395 if (phone != null) {
8396 return phone.isInEcm();
8397 } else {
8398 return false;
8399 }
8400 } finally {
8401 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008402 }
8403 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008404
8405 /**
8406 * Get the current signal strength information for the given subscription.
8407 * Because this information is not updated when the device is in a low power state
8408 * it should not be relied-upon to be current.
8409 * @param subId Subscription index
8410 * @return the most recent cached signal strength info from the modem
8411 */
8412 @Override
8413 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414 final long identity = Binder.clearCallingIdentity();
8415 try {
8416 Phone p = getPhone(subId);
8417 if (p == null) {
8418 return null;
8419 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421 return p.getSignalStrength();
8422 } finally {
8423 Binder.restoreCallingIdentity(identity);
8424 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008425 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008426
Pengquan Meng77b7f132018-08-22 14:49:57 -07008427 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008428 * Get the current modem radio state for the given slot.
8429 * @param slotIndex slot index.
8430 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008431 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008432 * @return the current radio power state from the modem
8433 */
8434 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008435 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008436 Phone phone = PhoneFactory.getPhone(slotIndex);
8437 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8439 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008440 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8441 }
8442
8443 final long identity = Binder.clearCallingIdentity();
8444 try {
8445 return phone.getRadioPowerState();
8446 } finally {
8447 Binder.restoreCallingIdentity(identity);
8448 }
8449 }
8450 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8451 }
8452
8453 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008454 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8455 *
8456 * <p>Requires one of the following permissions:
8457 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8458 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8459 * privileges.
8460 *
8461 * @param subId subscription id
8462 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8463 * {@code false}.
8464 */
8465 @Override
8466 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008467 try {
8468 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8469 null);
8470 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008471 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008472 mApp, subId, "isDataRoamingEnabled");
8473 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008474
Pengquan Menga1bb6272018-09-06 09:59:22 -07008475 boolean isEnabled = false;
8476 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008477 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008478 Phone phone = getPhone(subId);
8479 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008480 } finally {
8481 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008482 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008483 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008484 }
8485
8486
8487 /**
8488 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8489 *
8490 * <p> Requires permission:
8491 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8492 * privileges.
8493 *
8494 * @param subId subscription id
8495 * @param isEnabled {@code true} means enable, {@code false} means disable.
8496 */
8497 @Override
8498 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8500 mApp, subId, "setDataRoamingEnabled");
8501
Pengquan Menga1bb6272018-09-06 09:59:22 -07008502 final long identity = Binder.clearCallingIdentity();
8503 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008504 Phone phone = getPhone(subId);
8505 if (phone != null) {
8506 phone.setDataRoamingEnabled(isEnabled);
8507 }
8508 } finally {
8509 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008510 }
8511 }
8512
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008513 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008514 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008515 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008516 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008517 mApp, subId, "isManualNetworkSelectionAllowed");
8518
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008519 boolean isAllowed = true;
8520 final long identity = Binder.clearCallingIdentity();
8521 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008522 Phone phone = getPhone(subId);
8523 if (phone != null) {
8524 isAllowed = phone.isCspPlmnEnabled();
8525 }
8526 } finally {
8527 Binder.restoreCallingIdentity(identity);
8528 }
8529 return isAllowed;
8530 }
8531
8532 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008533 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008534 // Verify that tha callingPackage belongs to the calling UID
8535 mApp.getSystemService(AppOpsManager.class)
8536 .checkPackage(Binder.getCallingUid(), callingPackage);
8537
Jordan Liu1e142fc2019-04-22 15:10:43 -07008538 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008539 try {
8540 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008541 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008542 } catch (SecurityException e) {
8543 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8544 // has carrier privileges on an active UICC
8545 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8546 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008547 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008548 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008549 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008550
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008553 UiccController uiccController = UiccController.getInstance();
8554 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008555 if (hasReadPermission) {
8556 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008557 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008558
8559 // Remove private info if the caller doesn't have access
8560 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8561 for (UiccCardInfo cardInfo : cardInfos) {
8562 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8563 // is available
8564 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8565 if (card == null || card.getUiccProfile() == null) {
8566 // assume no access if the card or profile is unavailable
8567 filteredInfos.add(cardInfo.getUnprivileged());
8568 continue;
8569 }
8570 UiccProfile profile = card.getUiccProfile();
8571 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8572 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8573 filteredInfos.add(cardInfo);
8574 } else {
8575 filteredInfos.add(cardInfo.getUnprivileged());
8576 }
8577 }
8578 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
8582 }
8583
8584 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008585 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008586 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008588 final long identity = Binder.clearCallingIdentity();
8589 try {
8590 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8591 if (slots == null) {
8592 Rlog.i(LOG_TAG, "slots is null.");
8593 return null;
8594 }
8595
8596 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8597 for (int i = 0; i < slots.length; i++) {
8598 UiccSlot slot = slots[i];
8599 if (slot == null) {
8600 continue;
8601 }
8602
Jordan Liu7be7e652019-05-06 18:55:02 +00008603 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008604 UiccCard card = slot.getUiccCard();
8605 if (card != null) {
8606 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008607 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008608 cardId = slot.getEid();
8609 if (TextUtils.isEmpty(cardId)) {
8610 cardId = slot.getIccId();
8611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008612 }
8613
Jordan Liu857451f2019-05-09 16:35:35 -07008614 if (cardId != null) {
8615 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8616 // if cardId is an EID, it's all digits so this is fine
8617 cardId = IccUtils.stripTrailingFs(cardId);
8618 }
8619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008620 int cardState = 0;
8621 switch (slot.getCardState()) {
8622 case CARDSTATE_ABSENT:
8623 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8624 break;
8625 case CARDSTATE_PRESENT:
8626 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8627 break;
8628 case CARDSTATE_ERROR:
8629 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8630 break;
8631 case CARDSTATE_RESTRICTED:
8632 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8633 break;
8634 default:
8635 break;
8636
8637 }
8638
8639 infos[i] = new UiccSlotInfo(
8640 slot.isActive(),
8641 slot.isEuicc(),
8642 cardId,
8643 cardState,
8644 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008645 slot.isExtendedApduSupported(),
8646 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008647 }
8648 return infos;
8649 } finally {
8650 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008651 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008652 }
8653
8654 @Override
8655 public boolean switchSlots(int[] physicalSlots) {
8656 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008657
8658 final long identity = Binder.clearCallingIdentity();
8659 try {
8660 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8661 } finally {
8662 Binder.restoreCallingIdentity(identity);
8663 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008664 }
Jack Yu4c988042018-02-27 15:30:01 -08008665
8666 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008667 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008668 final long identity = Binder.clearCallingIdentity();
8669 try {
8670 return UiccController.getInstance().getCardIdForDefaultEuicc();
8671 } finally {
8672 Binder.restoreCallingIdentity(identity);
8673 }
8674 }
8675
Pengquan Meng85728fb2018-03-12 16:31:21 -07008676 /**
goneil47ffb6e2018-04-06 15:40:58 -07008677 * A test API to reload the UICC profile.
8678 *
8679 * <p>Requires that the calling app has permission
8680 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8681 * @hide
8682 */
8683 @Override
8684 public void refreshUiccProfile(int subId) {
8685 enforceModifyPermission();
8686
8687 final long identity = Binder.clearCallingIdentity();
8688 try {
8689 Phone phone = getPhone(subId);
8690 if (phone == null) {
8691 return;
8692 }
8693 UiccCard uiccCard = phone.getUiccCard();
8694 if (uiccCard == null) {
8695 return;
8696 }
8697 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8698 if (uiccProfile == null) {
8699 return;
8700 }
8701 uiccProfile.refresh();
8702 } finally {
8703 Binder.restoreCallingIdentity(identity);
8704 }
8705 }
8706
8707 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008708 * Returns false if the mobile data is disabled by default, otherwise return true.
8709 */
8710 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008711 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008712 }
8713
8714 /**
8715 * Returns true if the data roaming is enabled by default, i.e the system property
8716 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8717 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8718 */
8719 private boolean getDefaultDataRoamingEnabled(int subId) {
8720 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008721 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008722 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008723 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8724 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8725 return isDataRoamingEnabled;
8726 }
8727
8728 /**
8729 * Returns the default network type for the given {@code subId}, if the default network type is
8730 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8731 */
8732 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008733 List<Integer> list = TelephonyProperties.default_network();
8734 int phoneId = mSubscriptionController.getPhoneId(subId);
8735 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8736 return list.get(phoneId);
8737 }
8738 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008739 }
fionaxua13278b2018-03-21 00:08:13 -07008740
8741 @Override
8742 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008743 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008745
8746 final long identity = Binder.clearCallingIdentity();
8747 try {
8748 final Phone phone = getPhone(subId);
8749 if (phone == null) {
8750 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8751 return;
8752 }
chen xueaba88a2019-03-15 13:15:10 -07008753 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8754 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008755 if (carrierPrivilegeRules == null) {
8756 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8757 } else {
8758 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008760 } finally {
8761 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008762 }
fionaxua13278b2018-03-21 00:08:13 -07008763 }
8764
8765 @Override
8766 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008767 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008768
8769 final long identity = Binder.clearCallingIdentity();
8770 try {
8771 final Phone phone = getPhone(subId);
8772 if (phone == null) {
8773 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8774 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8775 }
8776 return phone.getCarrierIdListVersion();
8777 } finally {
8778 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008779 }
fionaxua13278b2018-03-21 00:08:13 -07008780 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008781
8782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008783 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8784 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008786 mApp, subId, callingPackage, callingFeatureId,
8787 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008788 return -1;
8789 }
8790
8791 final long identity = Binder.clearCallingIdentity();
8792 try {
8793 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8794 } finally {
8795 Binder.restoreCallingIdentity(identity);
8796 }
8797 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008798
8799 @Override
8800 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008801 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008802 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008803 mApp, subId, "getCdmaRoamingMode");
8804
8805 final long identity = Binder.clearCallingIdentity();
8806 try {
8807 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8808 } finally {
8809 Binder.restoreCallingIdentity(identity);
8810 }
8811 }
8812
8813 @Override
8814 public boolean setCdmaRoamingMode(int subId, int mode) {
8815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8816 mApp, subId, "setCdmaRoamingMode");
8817
8818 final long identity = Binder.clearCallingIdentity();
8819 try {
8820 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8821 } finally {
8822 Binder.restoreCallingIdentity(identity);
8823 }
8824 }
8825
8826 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008827 public int getCdmaSubscriptionMode(int subId) {
8828 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008829 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008830 mApp, subId, "getCdmaSubscriptionMode");
8831
8832 final long identity = Binder.clearCallingIdentity();
8833 try {
8834 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8835 } finally {
8836 Binder.restoreCallingIdentity(identity);
8837 }
8838 }
8839
8840 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008841 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8843 mApp, subId, "setCdmaSubscriptionMode");
8844
8845 final long identity = Binder.clearCallingIdentity();
8846 try {
8847 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8848 } finally {
8849 Binder.restoreCallingIdentity(identity);
8850 }
8851 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008852
sqianc5eccab2018-10-19 18:46:41 -07008853 @Override
sqian8c685422019-02-22 15:55:18 -08008854 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008855 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008857 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8858 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008859 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8860 }
8861 final long identity = Binder.clearCallingIdentity();
8862 try {
sqian854d44b2018-12-12 16:48:18 -08008863 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8864 for (Phone phone: PhoneFactory.getPhones()) {
8865 if (phone.getEmergencyNumberTracker() != null
8866 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8867 emergencyNumberListInternal.put(
8868 phone.getSubId(),
8869 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8870 }
sqian11b7a0e2018-12-05 18:48:28 -08008871 }
sqian854d44b2018-12-12 16:48:18 -08008872 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008873 } finally {
8874 Binder.restoreCallingIdentity(identity);
8875 }
sqianc5eccab2018-10-19 18:46:41 -07008876 }
8877
8878 @Override
sqian8c685422019-02-22 15:55:18 -08008879 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008880 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008881 if (!exactMatch) {
8882 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008883 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008884 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008885 }
8886 final long identity = Binder.clearCallingIdentity();
8887 try {
sqian854d44b2018-12-12 16:48:18 -08008888 for (Phone phone: PhoneFactory.getPhones()) {
8889 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008890 && phone.getEmergencyNumberTracker()
8891 .isEmergencyNumber(number, exactMatch)) {
8892 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008893 }
sqian11b7a0e2018-12-05 18:48:28 -08008894 }
8895 return false;
8896 } finally {
8897 Binder.restoreCallingIdentity(identity);
8898 }
8899 }
8900
sqianf4ca7ed2019-01-15 18:32:07 -08008901 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008902 * Start emergency callback mode for GsmCdmaPhone for testing.
8903 */
8904 @Override
8905 public void startEmergencyCallbackMode() {
8906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8907 "startEmergencyCallbackMode");
8908 enforceModifyPermission();
8909 final long identity = Binder.clearCallingIdentity();
8910 try {
8911 for (Phone phone : PhoneFactory.getPhones()) {
8912 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8913 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8914 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8915 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8916 gsmCdmaPhone.obtainMessage(
8917 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8918 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8919 }
8920 }
8921 } finally {
8922 Binder.restoreCallingIdentity(identity);
8923 }
8924 }
8925
8926 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008927 * Update emergency number list for test mode.
8928 */
8929 @Override
8930 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8931 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8932 "updateEmergencyNumberListTestMode");
8933
8934 final long identity = Binder.clearCallingIdentity();
8935 try {
8936 for (Phone phone: PhoneFactory.getPhones()) {
8937 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8938 if (tracker != null) {
8939 tracker.executeEmergencyNumberTestModeCommand(action, num);
8940 }
8941 }
8942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
8945 }
8946
8947 /**
8948 * Get the full emergency number list for test mode.
8949 */
8950 @Override
8951 public List<String> getEmergencyNumberListTestMode() {
8952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8953 "getEmergencyNumberListTestMode");
8954
8955 final long identity = Binder.clearCallingIdentity();
8956 try {
8957 Set<String> emergencyNumbers = new HashSet<>();
8958 for (Phone phone: PhoneFactory.getPhones()) {
8959 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8960 if (tracker != null) {
8961 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8962 emergencyNumbers.add(num.getNumber());
8963 }
8964 }
8965 }
8966 return new ArrayList<>(emergencyNumbers);
8967 } finally {
8968 Binder.restoreCallingIdentity(identity);
8969 }
8970 }
8971
chen xud6b45bd2018-10-30 22:27:10 -07008972 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008973 public int getEmergencyNumberDbVersion(int subId) {
8974 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8975
8976 final long identity = Binder.clearCallingIdentity();
8977 try {
8978 final Phone phone = getPhone(subId);
8979 if (phone == null) {
8980 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8981 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8982 }
8983 return phone.getEmergencyNumberDbVersion();
8984 } finally {
8985 Binder.restoreCallingIdentity(identity);
8986 }
8987 }
8988
8989 @Override
8990 public void notifyOtaEmergencyNumberDbInstalled() {
8991 enforceModifyPermission();
8992
8993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 for (Phone phone: PhoneFactory.getPhones()) {
8996 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8997 if (tracker != null) {
8998 tracker.updateOtaEmergencyNumberDatabase();
8999 }
9000 }
9001 } finally {
9002 Binder.restoreCallingIdentity(identity);
9003 }
9004 }
9005
9006 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009007 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009008 enforceActiveEmergencySessionPermission();
9009
9010 final long identity = Binder.clearCallingIdentity();
9011 try {
9012 for (Phone phone: PhoneFactory.getPhones()) {
9013 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9014 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009015 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9016 }
9017 }
9018 } finally {
9019 Binder.restoreCallingIdentity(identity);
9020 }
9021 }
9022
9023 @Override
9024 public void resetOtaEmergencyNumberDbFilePath() {
9025 enforceActiveEmergencySessionPermission();
9026
9027 final long identity = Binder.clearCallingIdentity();
9028 try {
9029 for (Phone phone: PhoneFactory.getPhones()) {
9030 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9031 if (tracker != null) {
9032 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009033 }
9034 }
9035 } finally {
9036 Binder.restoreCallingIdentity(identity);
9037 }
9038 }
9039
9040 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009041 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9042 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9043 Phone phone = getPhone(subId);
9044 if (phone == null) {
9045 return null;
9046 }
9047 final long identity = Binder.clearCallingIdentity();
9048 try {
9049 UiccProfile profile = UiccController.getInstance()
9050 .getUiccProfileForPhone(phone.getPhoneId());
9051 if (profile != null) {
9052 return profile.getCertsFromCarrierPrivilegeAccessRules();
9053 }
9054 } finally {
9055 Binder.restoreCallingIdentity(identity);
9056 }
9057 return null;
9058 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009059
9060 /**
9061 * Enable or disable a modem stack.
9062 */
9063 @Override
9064 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9065 enforceModifyPermission();
9066
9067 final long identity = Binder.clearCallingIdentity();
9068 try {
9069 Phone phone = PhoneFactory.getPhone(slotIndex);
9070 if (phone == null) {
9071 return false;
9072 } else {
9073 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9074 }
9075 } finally {
9076 Binder.restoreCallingIdentity(identity);
9077 }
9078 }
Michelecea4cf22018-12-21 15:00:11 -08009079
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009080 /**
9081 * Whether a modem stack is enabled or not.
9082 */
9083 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009084 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9085 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009086 Phone phone = PhoneFactory.getPhone(slotIndex);
9087 if (phone == null) return false;
9088
9089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009090 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9091 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009092 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9093 }
9094
9095 final long identity = Binder.clearCallingIdentity();
9096 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009097 try {
9098 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9099 } catch (NoSuchElementException ex) {
9100 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9101 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009102 } finally {
9103 Binder.restoreCallingIdentity(identity);
9104 }
9105 }
9106
Michelecea4cf22018-12-21 15:00:11 -08009107 @Override
Michele0ea7d782019-03-19 14:58:42 -07009108 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009109 enforceModifyPermission();
9110
9111 final long identity = Binder.clearCallingIdentity();
9112 try {
9113 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009114 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009115 .commit();
9116 } finally {
9117 Binder.restoreCallingIdentity(identity);
9118 }
9119 }
9120
9121 @Override
Michele0ea7d782019-03-19 14:58:42 -07009122 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009123 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009125 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9126 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009127 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009128 }
Michelecea4cf22018-12-21 15:00:11 -08009129
9130 final long identity = Binder.clearCallingIdentity();
9131 try {
Michele0ea7d782019-03-19 14:58:42 -07009132 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009133 } finally {
9134 Binder.restoreCallingIdentity(identity);
9135 }
9136 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009137
Michele0ea7d782019-03-19 14:58:42 -07009138 @TelephonyManager.IsMultiSimSupportedResult
9139 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009140 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9141 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9142 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009143 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9144 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009145 }
9146 // Check if the hardware supports multisim functionality. If usage of multisim is not
9147 // supported by the modem, indicate that it is restricted.
9148 PhoneCapability staticCapability =
9149 mPhoneConfigurationManager.getStaticPhoneCapability();
9150 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009151 loge("isMultiSimSupportedInternal: no static configuration available");
9152 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009153 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009154 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009155 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9156 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009157 }
9158 // Check if support of multiple SIMs is restricted by carrier
9159 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009160 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009161 }
9162
Michele0ea7d782019-03-19 14:58:42 -07009163 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009164 }
9165
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009166 /**
9167 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009168 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9169 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9170 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009171 * @param numOfSims number of active sims we want to switch to
9172 */
9173 @Override
9174 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009175 if (numOfSims == 1) {
9176 enforceModifyPermission();
9177 } else {
9178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9179 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9180 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009181 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009182
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009183 try {
Michele30b57b22019-03-01 12:01:14 -08009184 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009185 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009186 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9187 return;
9188 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009189 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9190 } finally {
9191 Binder.restoreCallingIdentity(identity);
9192 }
9193 }
9194
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009195 @Override
9196 public boolean isApplicationOnUicc(int subId, int appType) {
9197 enforceReadPrivilegedPermission("isApplicationOnUicc");
9198 Phone phone = getPhone(subId);
9199 if (phone == null) {
9200 return false;
9201 }
9202 final long identity = Binder.clearCallingIdentity();
9203 try {
9204 UiccCard uiccCard = phone.getUiccCard();
9205 if (uiccCard == null) {
9206 return false;
9207 }
9208 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9209 if (uiccProfile == null) {
9210 return false;
9211 }
9212 if (TelephonyManager.APPTYPE_SIM <= appType
9213 && appType <= TelephonyManager.APPTYPE_ISIM) {
9214 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9215 }
9216 return false;
9217 } finally {
9218 Binder.restoreCallingIdentity(identity);
9219 }
9220 }
9221
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009222 /**
chen xub4baa772019-04-03 10:23:41 -07009223 * Get whether making changes to modem configurations will trigger reboot.
9224 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009225 */
9226 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009227 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9228 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009230 mApp, subId, callingPackage, callingFeatureId,
9231 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009232 return false;
9233 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009234 final long identity = Binder.clearCallingIdentity();
9235 try {
9236 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9237 } finally {
9238 Binder.restoreCallingIdentity(identity);
9239 }
9240 }
9241
Nathan Harold29f5f052019-02-15 13:41:57 -08009242 private void updateModemStateMetrics() {
9243 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9244 // TODO: check the state for each modem if the api is ready.
9245 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9246 }
9247
Pengquan Meng3889a572019-01-23 11:16:29 -08009248 @Override
9249 public int[] getSlotsMapping() {
9250 enforceReadPrivilegedPermission("getSlotsMapping");
9251
9252 final long identity = Binder.clearCallingIdentity();
9253 try {
9254 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9255 // All logical slots should have a mapping to a physical slot.
9256 int[] logicalSlotsMapping = new int[phoneCount];
9257 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9258 for (int i = 0; i < slotInfos.length; i++) {
9259 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9260 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9261 }
9262 }
9263 return logicalSlotsMapping;
9264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
9267 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009268
9269 /**
9270 * Get the IRadio HAL Version
9271 */
9272 @Override
9273 public int getRadioHalVersion() {
9274 Phone phone = getDefaultPhone();
9275 if (phone == null) return -1;
9276 HalVersion hv = phone.getHalVersion();
9277 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9278 return hv.major * 100 + hv.minor;
9279 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009280
9281 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009282 * Get the current calling package name.
9283 * @return the current calling package name
9284 */
9285 @Override
9286 public String getCurrentPackageName() {
9287 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9288 }
9289
9290 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009291 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9292 * corresponding network requests on a subId.
9293 *
9294 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009295 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009296 * 2) APN is un-metered for this subscription, or
9297 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009298 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009299 *
9300 * @return whether data is allowed for a apn type.
9301 *
9302 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009303 */
9304 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009305 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009306 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9307 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009308
9309 // Now that all security checks passes, perform the operation as ourselves.
9310 final long identity = Binder.clearCallingIdentity();
9311 try {
9312 Phone phone = getPhone(subId);
9313 if (phone == null) return false;
9314
Jack Yu41407ee2019-05-13 16:54:09 -07009315 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009316 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9317 } finally {
9318 Binder.restoreCallingIdentity(identity);
9319 }
9320 }
9321
9322 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009323 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009324 enforceReadPrivilegedPermission("isApnMetered");
9325
9326 // Now that all security checks passes, perform the operation as ourselves.
9327 final long identity = Binder.clearCallingIdentity();
9328 try {
9329 Phone phone = getPhone(subId);
9330 if (phone == null) return true; // By default return true.
9331
Jack Yu41407ee2019-05-13 16:54:09 -07009332 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009333 } finally {
9334 Binder.restoreCallingIdentity(identity);
9335 }
9336 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009337
9338 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009339 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9340 int subscriptionId, IBooleanConsumer resultCallback) {
9341 enforceModifyPermission();
9342 long token = Binder.clearCallingIdentity();
9343 try {
9344 Phone phone = getPhone(subscriptionId);
9345 if (phone == null) {
9346 try {
9347 if (resultCallback != null) {
9348 resultCallback.accept(false);
9349 }
9350 } catch (RemoteException e) {
9351 // ignore
9352 }
9353 return;
9354 }
9355 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9356 Pair.create(specifiers, (x) -> {
9357 try {
9358 if (resultCallback != null) {
9359 resultCallback.accept(x);
9360 }
9361 } catch (RemoteException e) {
9362 // ignore
9363 }
9364 });
9365 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9366 } finally {
9367 Binder.restoreCallingIdentity(token);
9368 }
9369 }
9370
9371 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009372 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9373 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009374 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009375 mApp, subId, "getSystemSelectionChannels");
9376 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009379 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9380 if (result instanceof IllegalStateException) {
9381 throw (IllegalStateException) result;
9382 }
9383 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009384 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9385 return specifiers;
9386 } finally {
9387 Binder.restoreCallingIdentity(identity);
9388 }
9389 }
9390
9391 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009392 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009393 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009394 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9395 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9396 if (iccRecords == null) {
9397 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9398 return false;
9399 }
9400 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9401 }
9402
9403 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009404 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9405 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009406 if (callingPackage == null) {
9407 callingPackage = getCurrentPackageName();
9408 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009409 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9410 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009411 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9412 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009413 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9414 }
9415 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9416 Intent intent = new Intent();
9417 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9418 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9419 // Bring up choose default SMS subscription dialog right now
9420 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9421 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9422 mApp.startActivity(intent);
9423 }
chen xud5ca2d52019-05-28 15:20:57 -07009424
9425 @Override
9426 public String getMmsUAProfUrl(int subId) {
9427 //TODO investigate if this API should require proper permission check in R b/133791609
9428 final long identity = Binder.clearCallingIdentity();
9429 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009430 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9431 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9432 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9433 return carrierUAProfUrl;
9434 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009435 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9436 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
9441
9442 @Override
9443 public String getMmsUserAgent(int subId) {
9444 //TODO investigate if this API should require proper permission check in R b/133791609
9445 final long identity = Binder.clearCallingIdentity();
9446 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009447 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9448 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9449 if (!TextUtils.isEmpty(carrierUserAgent)) {
9450 return carrierUserAgent;
9451 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009452 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9453 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009454 } finally {
9455 Binder.restoreCallingIdentity(identity);
9456 }
9457 }
Jack Yub07d4972019-05-28 16:12:25 -07009458
9459 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009460 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9461 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009462
Jack Yub07d4972019-05-28 16:12:25 -07009463 final long identity = Binder.clearCallingIdentity();
9464 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009465 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009466 if (phone == null) return false;
9467
Hall Liua62f5da2020-09-25 10:42:19 -07009468 switch (policy) {
9469 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9470 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9471 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9472 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9473 default:
9474 throw new IllegalArgumentException(policy + " is not a valid policy");
9475 }
Jack Yub07d4972019-05-28 16:12:25 -07009476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
9479 }
9480
9481 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009482 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009483 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009484 enforceModifyPermission();
9485
changbettyd5c246e2019-12-24 15:40:37 +08009486 final long identity = Binder.clearCallingIdentity();
9487 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009488 Phone phone = getPhone(subscriptionId);
9489 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009490
Hall Liua62f5da2020-09-25 10:42:19 -07009491 switch (policy) {
9492 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9493 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9494 break;
9495 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9496 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9497 break;
9498 default:
9499 throw new IllegalArgumentException(policy + " is not a valid policy");
9500 }
changbettyd5c246e2019-12-24 15:40:37 +08009501 } finally {
9502 Binder.restoreCallingIdentity(identity);
9503 }
9504 }
9505
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009506 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009507 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009508 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9509 * otherwise.
9510 */
9511 @Override
9512 public void setCepEnabled(boolean isCepEnabled) {
9513 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9514
9515 final long identity = Binder.clearCallingIdentity();
9516 try {
9517 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9518 for (Phone phone : PhoneFactory.getPhones()) {
9519 Phone defaultPhone = phone.getImsPhone();
9520 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9521 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9522 ImsPhoneCallTracker imsPhoneCallTracker =
9523 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9524 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9525 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9526 + imsPhone.getMsisdn());
9527 }
9528 }
9529 } finally {
9530 Binder.restoreCallingIdentity(identity);
9531 }
9532 }
allenwtsu46dcc572020-01-08 18:24:03 +08009533
9534 /**
9535 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9536 *
9537 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9538 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9539 * before being read.
9540 */
9541 @Override
9542 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9543 isCompressed) {
9544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9545 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009546 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9547 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9548 }
9549 if (!isImsAvailableOnDevice()) {
9550 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9551 "IMS not available on device.");
9552 }
9553
9554 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009555 try {
Hui Wang761a6682020-10-31 05:12:53 +00009556 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9557 } finally {
9558 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009559 }
9560 }
zoey chene02881a2019-12-30 16:11:23 +08009561
9562 @Override
9563 public boolean isIccLockEnabled(int subId) {
9564 enforceReadPrivilegedPermission("isIccLockEnabled");
9565
9566 // Now that all security checks passes, perform the operation as ourselves.
9567 final long identity = Binder.clearCallingIdentity();
9568 try {
9569 Phone phone = getPhone(subId);
9570 if (phone != null && phone.getIccCard() != null) {
9571 return phone.getIccCard().getIccLockEnabled();
9572 } else {
9573 return false;
9574 }
9575 } finally {
9576 Binder.restoreCallingIdentity(identity);
9577 }
9578 }
9579
9580 /**
9581 * Set the ICC pin lock enabled or disabled.
9582 *
9583 * @return an integer representing the status of IccLock enabled or disabled in the following
9584 * three cases:
9585 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9586 * successfully.
9587 * - Positive number and zero for remaining password attempts.
9588 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9589 *
9590 */
9591 @Override
9592 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9593 enforceModifyPermission();
9594
9595 Phone phone = getPhone(subId);
9596 if (phone == null) {
9597 return 0;
9598 }
9599 // Now that all security checks passes, perform the operation as ourselves.
9600 final long identity = Binder.clearCallingIdentity();
9601 try {
9602 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9603 new Pair<Boolean, String>(enabled, password), phone, null);
9604 return attemptsRemaining;
9605
9606 } catch (Exception e) {
9607 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9608 } finally {
9609 Binder.restoreCallingIdentity(identity);
9610 }
9611 return 0;
9612 }
9613
9614 /**
9615 * Change the ICC password used in ICC pin lock.
9616 *
9617 * @return an integer representing the status of IccLock changed in the following three cases:
9618 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9619 * - Positive number and zero for remaining password attempts.
9620 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9621 *
9622 */
9623 @Override
9624 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9625 enforceModifyPermission();
9626
9627 Phone phone = getPhone(subId);
9628 if (phone == null) {
9629 return 0;
9630 }
9631 // Now that all security checks passes, perform the operation as ourselves.
9632 final long identity = Binder.clearCallingIdentity();
9633 try {
9634 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9635 new Pair<String, String>(oldPassword, newPassword), phone, null);
9636 return attemptsRemaining;
9637
9638 } catch (Exception e) {
9639 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 return 0;
9644 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009645
9646 /**
9647 * Request for receiving user activity notification
9648 */
9649 @Override
9650 public void requestUserActivityNotification() {
9651 if (!mNotifyUserActivity.get()
9652 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9653 mNotifyUserActivity.set(true);
9654 }
9655 }
9656
9657 /**
9658 * Called when userActivity is signalled in the power manager.
9659 * This is safe to call from any thread, with any window manager locks held or not.
9660 */
9661 @Override
9662 public void userActivity() {
9663 // ***************************************
9664 // * Inherited from PhoneWindowManager *
9665 // ***************************************
9666 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9667 // WITH ITS LOCKS HELD.
9668 //
9669 // This code must be VERY careful about the locks
9670 // it acquires.
9671 // In fact, the current code acquires way too many,
9672 // and probably has lurking deadlocks.
9673
9674 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9675 throw new SecurityException("Only the OS may call notifyUserActivity()");
9676 }
9677
9678 if (mNotifyUserActivity.getAndSet(false)) {
9679 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9680 USER_ACTIVITY_NOTIFICATION_DELAY);
9681 }
9682 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009683
9684 @Override
9685 public boolean canConnectTo5GInDsdsMode() {
9686 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9687 }
Jack Yud10cdd42020-09-28 20:28:01 -07009688
9689 @Override
9690 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9691 String callingFeatureId) {
9692 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9693 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9694 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9695 }
9696
9697 Phone phone = getPhone(subId);
9698 if (phone == null) {
9699 throw new RuntimeException("phone is not available");
9700 }
9701 // Now that all security checks passes, perform the operation as ourselves.
9702 final long identity = Binder.clearCallingIdentity();
9703 try {
9704 return phone.getEquivalentHomePlmns();
9705 } finally {
9706 Binder.restoreCallingIdentity(identity);
9707 }
9708 }
Daniel Bright59e67312020-11-13 11:49:37 -08009709
9710 @Override
9711 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009712 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9713 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009714 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009715 if (radioInterfaceCapabilities == null) {
9716 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009717 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009718 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009719 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009720
Hui Wang641e81c2020-10-12 12:14:23 -07009721 @Override
9722 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9723 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009724 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9725 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9726 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9727 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9728 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009729 if (DBG) {
9730 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9731 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9732 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9733 }
9734
9735 if (!SubscriptionManager.isValidSubscriptionId(subId)
9736 || appType < TelephonyManager.APPTYPE_UNKNOWN
9737 || appType > TelephonyManager.APPTYPE_ISIM
9738 || nafUrl == null || securityProtocol == null || callback == null) {
9739 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9740 if (callback != null) {
9741 try {
9742 callback.onAuthenticationFailure(
9743 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9744 } catch (RemoteException exception) {
9745 log("Fail to notify onAuthenticationFailure due to " + exception);
9746 }
9747 return;
9748 }
9749 }
9750
9751 final long token = Binder.clearCallingIdentity();
9752 try {
9753 getGbaManager(subId).bootstrapAuthenticationRequest(
9754 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9755 forceBootStrapping, callback));
9756 } finally {
9757 Binder.restoreCallingIdentity(token);
9758 }
9759 }
9760
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009761 /**
9762 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9763 * requested radio power state will actually be set. See {@link
9764 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9765 *
9766 * @param subId the subscription ID of the phone requesting to set the radio power state.
9767 * @param enable {@code true} if trying to turn radio on.
9768 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9769 * false}.
9770 */
9771 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9772 Phone phone = getPhone(subId);
9773 if (phone != null) {
9774 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9775 return true;
9776 }
9777 return false;
9778 }
9779
9780 private int handleDataThrottlingRequest(int subId,
9781 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009782 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9783 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9784 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9785 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9786 throw new IllegalArgumentException("modem does not support data throttling");
9787 }
9788
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009789 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9790 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9791 if (!setRadioPowerForThermal(subId, true)) {
9792 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9793 }
9794
9795 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9796
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009797 if (isDataThrottlingSupported) {
9798 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009799 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009800 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9801 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9802 } else if (thermalMitigationResult
9803 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009804 log("Modem likely does not support data throttling on secondary carrier. Data " +
9805 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9806 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009807 }
9808 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009809 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009810
9811 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009812 }
9813
Jack Nudelman644b91a2021-03-12 14:09:48 -08009814 private static List<String> getThermalMitigationAllowlist(Context context) {
9815 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9816 for (String pckg : context.getResources()
9817 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9818 sThermalMitigationAllowlistedPackages.add(pckg);
9819 }
9820 }
9821
9822 return sThermalMitigationAllowlistedPackages;
9823 }
9824
9825 /**
9826 * Used by shell commands to add an authorized package name for thermal mitigation.
9827 * @param packageName name of package to be allowlisted
9828 * @param context
9829 */
9830 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9831 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9832 sThermalMitigationAllowlistedPackages.add(packageName);
9833 }
9834
9835 /**
9836 * Used by shell commands to remove an authorized package name for thermal mitigation.
9837 * @param packageName name of package to remove from allowlist
9838 * @param context
9839 */
9840 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9841 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9842 sThermalMitigationAllowlistedPackages.remove(packageName);
9843 }
9844
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009845 /**
9846 * Thermal mitigation request to control functionalities at modem.
9847 *
9848 * @param subId the id of the subscription.
9849 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009850 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009851 *
9852 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9853 */
9854 @Override
9855 @ThermalMitigationResult
9856 public int sendThermalMitigationRequest(
9857 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009858 ThermalMitigationRequest thermalMitigationRequest,
9859 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009860 enforceModifyPermission();
9861
Jack Nudelman644b91a2021-03-12 14:09:48 -08009862 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9863 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9864 .contains(callingPackage)) {
9865 throw new SecurityException("Calling package must be configured in the device config. "
9866 + "calling package: " + callingPackage);
9867 }
9868
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009869 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9870 final long identity = Binder.clearCallingIdentity();
9871
9872 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9873 try {
9874 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9875 switch (thermalMitigationAction) {
9876 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9877 thermalMitigationResult =
9878 handleDataThrottlingRequest(subId,
9879 thermalMitigationRequest.getDataThrottlingRequest());
9880 break;
9881 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9882 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9883 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9884 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9885 }
9886
9887 // Ensure that radio is on. If not able to power on due to phone being
9888 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9889 if (!setRadioPowerForThermal(subId, true)) {
9890 thermalMitigationResult =
9891 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9892 break;
9893 }
9894
9895 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9896 false);
9897 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9898 break;
9899 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9900 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9901 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9902 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9903 }
9904
9905 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9906 if (registry != null) {
9907 TelephonyConnectionService service =
9908 registry.getTelephonyConnectionService();
9909 Phone phone = getPhone(subId);
9910 if (phone == null) {
9911 thermalMitigationResult =
9912 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9913 break;
9914 }
9915
9916 if (PhoneConstantConversions.convertCallState(phone.getState())
9917 != TelephonyManager.CALL_STATE_IDLE
9918 || phone.isInEmergencySmsMode() || phone.isInEcm()
9919 || (service != null && service.isEmergencyCallPending())) {
9920 String errorMessage = "Phone state is not valid. call state = "
9921 + PhoneConstantConversions.convertCallState(phone.getState())
9922 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9923 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9924 errorMessage += service == null
9925 ? " TelephonyConnectionService is null"
9926 : " isEmergencyCallPending = "
9927 + service.isEmergencyCallPending();
9928 Log.e(LOG_TAG, errorMessage);
9929 thermalMitigationResult =
9930 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9931 break;
9932 }
9933 } else {
9934 thermalMitigationResult =
9935 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9936 break;
9937 }
9938
9939 // Turn radio off. If not able to power off due to phone being unavailable,
9940 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9941 if (!setRadioPowerForThermal(subId, false)) {
9942 thermalMitigationResult =
9943 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9944 break;
9945 }
9946 thermalMitigationResult =
9947 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9948 break;
9949 default:
9950 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9951 + "not exist. Requested action: " + thermalMitigationAction);
9952 }
9953 } catch (IllegalArgumentException e) {
9954 throw e;
9955 } catch (Exception e) {
9956 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9957 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9958 } finally {
9959 Binder.restoreCallingIdentity(identity);
9960 }
9961
9962 if (DBG) {
9963 log("thermalMitigationRequest returning with thermalMitigationResult: "
9964 + thermalMitigationResult);
9965 }
9966
9967 return thermalMitigationResult;
9968 }
Hui Wang641e81c2020-10-12 12:14:23 -07009969
9970 /**
9971 * Set the GbaService Package Name that Telephony will bind to.
9972 *
9973 * @param subId The sim that the GbaService is associated with.
9974 * @param packageName The name of the package to be replaced with.
9975 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9976 */
9977 @Override
9978 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9979 enforceModifyPermission();
9980
9981 final long identity = Binder.clearCallingIdentity();
9982 try {
9983 return getGbaManager(subId).overrideServicePackage(packageName);
9984 } finally {
9985 Binder.restoreCallingIdentity(identity);
9986 }
9987 }
9988
9989 /**
9990 * Return the package name of the currently bound GbaService.
9991 *
9992 * @param subId The sim that the GbaService is associated with.
9993 * @return the package name of the GbaService configuration, null if GBA is not supported.
9994 */
9995 @Override
9996 public String getBoundGbaService(int subId) {
9997 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9998
9999 final long identity = Binder.clearCallingIdentity();
10000 try {
10001 return getGbaManager(subId).getServicePackage();
10002 } finally {
10003 Binder.restoreCallingIdentity(identity);
10004 }
10005 }
10006
10007 /**
10008 * Set the release time for telephony to unbind GbaService.
10009 *
10010 * @param subId The sim that the GbaService is associated with.
10011 * @param interval The release time to unbind GbaService by millisecond.
10012 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10013 */
10014 @Override
10015 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10016 enforceModifyPermission();
10017
10018 final long identity = Binder.clearCallingIdentity();
10019 try {
10020 return getGbaManager(subId).overrideReleaseTime(interval);
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024 }
10025
10026 /**
10027 * Return the release time for telephony to unbind GbaService.
10028 *
10029 * @param subId The sim that the GbaService is associated with.
10030 * @return The release time to unbind GbaService by millisecond.
10031 */
10032 @Override
10033 public int getGbaReleaseTime(int subId) {
10034 enforceReadPrivilegedPermission("getGbaReleaseTime");
10035
10036 final long identity = Binder.clearCallingIdentity();
10037 try {
10038 return getGbaManager(subId).getReleaseTime();
10039 } finally {
10040 Binder.restoreCallingIdentity(identity);
10041 }
10042 }
10043
10044 private GbaManager getGbaManager(int subId) {
10045 GbaManager instance = GbaManager.getInstance(subId);
10046 if (instance == null) {
10047 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10048 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10049 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10050 }
10051 return instance;
10052 }
Hui Wang761a6682020-10-31 05:12:53 +000010053
10054 /**
10055 * indicate whether the device and the carrier can support
10056 * RCS VoLTE single registration.
10057 */
10058 @Override
10059 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010060 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10061 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10062 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10063 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010064
10065 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10066 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10067 }
10068
10069 final long identity = Binder.clearCallingIdentity();
10070 try {
10071 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10072 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010073 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10074 if (isCapable != null) {
10075 return isCapable;
10076 }
Hui Wang761a6682020-10-31 05:12:53 +000010077 }
Hui Wang67af90e2021-06-04 16:57:15 -070010078 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10079 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010080 } finally {
10081 Binder.restoreCallingIdentity(identity);
10082 }
10083 }
10084
10085 /**
10086 * Register RCS provisioning callback.
10087 */
10088 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010089 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010090 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010091 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010092 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010093 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10094 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010095
10096 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10097 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10098 }
10099 if (!isImsAvailableOnDevice()) {
10100 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10101 "IMS not available on device.");
10102 }
10103
10104 final long identity = Binder.clearCallingIdentity();
10105 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010106 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010107 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010108 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10109 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010110 }
Hui Wang761a6682020-10-31 05:12:53 +000010111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
10115
10116 /**
10117 * Unregister RCS provisioning callback.
10118 */
10119 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010120 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010121 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010122 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010123 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010124 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10125 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010126
10127 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10128 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10129 }
10130 if (!isImsAvailableOnDevice()) {
10131 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10132 "IMS not available on device.");
10133 }
10134
10135 final long identity = Binder.clearCallingIdentity();
10136 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010137 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010138 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010139 } finally {
10140 Binder.restoreCallingIdentity(identity);
10141 }
10142 }
10143
10144 /**
10145 * trigger RCS reconfiguration.
10146 */
10147 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010148 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10149 "triggerRcsReconfiguration",
10150 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010151
10152 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10153 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10154 }
10155 if (!isImsAvailableOnDevice()) {
10156 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10157 "IMS not available on device.");
10158 }
10159
10160 final long identity = Binder.clearCallingIdentity();
10161 try {
10162 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10163 } finally {
10164 Binder.restoreCallingIdentity(identity);
10165 }
10166 }
10167
10168 /**
10169 * Provide the client configuration parameters of the RCS application.
10170 */
10171 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010172 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10173 "setRcsClientConfiguration",
10174 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010175
10176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10177 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10178 }
10179 if (!isImsAvailableOnDevice()) {
10180 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10181 "IMS not available on device.");
10182 }
10183
10184 final long identity = Binder.clearCallingIdentity();
10185
10186 try {
10187 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10188 if (configBinder == null) {
10189 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010190 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10191 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010192 } else {
10193 configBinder.setRcsClientConfiguration(rcc);
10194 }
10195 } catch (RemoteException e) {
10196 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010197 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10198 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010199 } finally {
10200 Binder.restoreCallingIdentity(identity);
10201 }
10202 }
10203
10204 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010205 * Enables or disables the test mode for RCS VoLTE single registration.
10206 */
10207 @Override
10208 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10209 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10210 "setRcsSingleRegistrationTestModeEnabled");
10211
10212 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10213 }
10214
10215 /**
10216 * Gets the test mode for RCS VoLTE single registration.
10217 */
10218 @Override
10219 public boolean getRcsSingleRegistrationTestModeEnabled() {
10220 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10221 "getRcsSingleRegistrationTestModeEnabled");
10222
10223 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10224 }
10225
10226 /**
Hui Wang761a6682020-10-31 05:12:53 +000010227 * Overrides the config of RCS VoLTE single registration enabled for the device.
10228 */
10229 @Override
10230 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10232 "setDeviceSingleRegistrationEnabledOverride");
10233 enforceModifyPermission();
10234
10235 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10236 : Boolean.parseBoolean(enabledStr);
10237 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010238 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010239 }
10240
10241 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010242 * Sends a device to device communication message. Only usable via shell.
10243 * @param message message to send.
10244 * @param value message value.
10245 */
10246 @Override
10247 public void sendDeviceToDeviceMessage(int message, int value) {
10248 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010249 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010250 enforceModifyPermission();
10251
10252 final long identity = Binder.clearCallingIdentity();
10253 try {
10254 TelephonyConnectionService service =
10255 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10256 if (service == null) {
10257 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10258 return;
10259 }
10260 service.sendTestDeviceToDeviceMessage(message, value);
10261 } finally {
10262 Binder.restoreCallingIdentity(identity);
10263 }
10264 }
10265
Tyler Gunnbabbda02021-02-10 11:05:02 -080010266 /**
10267 * Sets the specified device to device transport active.
10268 * @param transport The transport to set active.
10269 */
10270 @Override
10271 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10273 "setActiveDeviceToDeviceTransport");
10274 enforceModifyPermission();
10275
10276 final long identity = Binder.clearCallingIdentity();
10277 try {
10278 TelephonyConnectionService service =
10279 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10280 if (service == null) {
10281 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10282 return;
10283 }
10284 service.setActiveDeviceToDeviceTransport(transport);
10285 } finally {
10286 Binder.restoreCallingIdentity(identity);
10287 }
10288 }
Tyler Gunn92479152021-01-20 16:30:10 -080010289
Tyler Gunnd4575212021-05-03 14:46:49 -070010290 @Override
10291 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10292 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10293 "setDeviceToDeviceForceEnabled");
10294
10295 final long identity = Binder.clearCallingIdentity();
10296 try {
10297 Arrays.stream(PhoneFactory.getPhones()).forEach(
10298 p -> {
10299 Phone thePhone = p.getImsPhone();
10300 if (thePhone != null && thePhone instanceof ImsPhone) {
10301 ImsPhone imsPhone = (ImsPhone) thePhone;
10302 CallTracker tracker = imsPhone.getCallTracker();
10303 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10304 ImsPhoneCallTracker imsPhoneCallTracker =
10305 (ImsPhoneCallTracker) tracker;
10306 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10307 }
10308 }
10309 }
10310 );
10311 } finally {
10312 Binder.restoreCallingIdentity(identity);
10313 }
10314 }
10315
Tyler Gunn92479152021-01-20 16:30:10 -080010316 /**
Hui Wang761a6682020-10-31 05:12:53 +000010317 * Gets the config of RCS VoLTE single registration enabled for the device.
10318 */
10319 @Override
10320 public boolean getDeviceSingleRegistrationEnabled() {
10321 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10322 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10323 }
10324
10325 /**
10326 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10327 */
10328 @Override
10329 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10330 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10331 "setCarrierSingleRegistrationEnabledOverride");
10332 enforceModifyPermission();
10333
10334 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10335 : Boolean.parseBoolean(enabledStr);
10336 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10337 subId, enabled);
10338 }
10339
10340 /**
10341 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10342 */
10343 @Override
10344 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10345 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10346 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10347 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010348
10349 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010350 * Overrides the ims feature validation result
10351 */
10352 @Override
10353 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10354 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10355 "setImsFeatureValidationOverride");
10356
10357 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10358 : Boolean.parseBoolean(enabledStr);
10359 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10360 subId, enabled);
10361 }
10362
10363 /**
10364 * Gets the ims feature validation override value
10365 */
10366 @Override
10367 public boolean getImsFeatureValidationOverride(int subId) {
10368 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10369 "getImsFeatureValidationOverride");
10370 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10371 }
10372
10373 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010374 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10375 * their mobile plan.
10376 */
10377 @Override
10378 public String getMobileProvisioningUrl() {
10379 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10380 final long identity = Binder.clearCallingIdentity();
10381 try {
10382 return getDefaultPhone().getMobileProvisioningUrl();
10383 } finally {
10384 Binder.restoreCallingIdentity(identity);
10385 }
10386 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010387
James.cf Linbcdf8b32021-01-14 16:44:13 +080010388 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010389 * Get the EAB contact from the EAB database.
10390 */
10391 @Override
10392 public String getContactFromEab(String contact) {
10393 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10394 enforceModifyPermission();
10395 final long identity = Binder.clearCallingIdentity();
10396 try {
10397 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10398 } finally {
10399 Binder.restoreCallingIdentity(identity);
10400 }
10401 }
10402
10403 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010404 * Remove the EAB contacts from the EAB database.
10405 */
10406 @Override
10407 public int removeContactFromEab(int subId, String contacts) {
10408 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10409 enforceModifyPermission();
10410 final long identity = Binder.clearCallingIdentity();
10411 try {
10412 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416 }
10417
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010418 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010419 public boolean getDeviceUceEnabled() {
10420 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10421 final long identity = Binder.clearCallingIdentity();
10422 try {
10423 return mApp.getDeviceUceEnabled();
10424 } finally {
10425 Binder.restoreCallingIdentity(identity);
10426 }
10427 }
10428
10429 @Override
10430 public void setDeviceUceEnabled(boolean isEnabled) {
10431 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10432 final long identity = Binder.clearCallingIdentity();
10433 try {
10434 mApp.setDeviceUceEnabled(isEnabled);
10435 } finally {
10436 Binder.restoreCallingIdentity(identity);
10437 }
10438 }
10439
Brad Ebinger14d467f2021-02-12 06:18:28 +000010440 /**
10441 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10442 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10443 */
10444 // Used for SHELL command only right now.
10445 @Override
10446 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10447 List<String> featureTags) {
10448 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10449 "addUceRegistrationOverrideShell");
10450 final long identity = Binder.clearCallingIdentity();
10451 try {
10452 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10453 new ArraySet<>(featureTags));
10454 } catch (ImsException e) {
10455 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10456 } finally {
10457 Binder.restoreCallingIdentity(identity);
10458 }
10459 }
10460
10461 /**
10462 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10463 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10464 */
10465 // Used for SHELL command only right now.
10466 @Override
10467 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10468 List<String> featureTags) {
10469 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10470 "removeUceRegistrationOverrideShell");
10471 final long identity = Binder.clearCallingIdentity();
10472 try {
10473 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10474 new ArraySet<>(featureTags));
10475 } catch (ImsException e) {
10476 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10477 } finally {
10478 Binder.restoreCallingIdentity(identity);
10479 }
10480 }
10481
10482 /**
10483 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10484 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10485 */
10486 // Used for SHELL command only right now.
10487 @Override
10488 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10489 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10490 "clearUceRegistrationOverrideShell");
10491 final long identity = Binder.clearCallingIdentity();
10492 try {
10493 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10494 } catch (ImsException e) {
10495 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10496 } finally {
10497 Binder.restoreCallingIdentity(identity);
10498 }
10499 }
10500
10501 /**
10502 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10503 */
10504 // Used for SHELL command only right now.
10505 @Override
10506 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10507 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10508 "getLatestRcsContactUceCapabilityShell");
10509 final long identity = Binder.clearCallingIdentity();
10510 try {
10511 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10512 } catch (ImsException e) {
10513 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10514 } finally {
10515 Binder.restoreCallingIdentity(identity);
10516 }
10517 }
10518
10519 /**
10520 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10521 * device does not have an active PUBLISH.
10522 */
10523 // Used for SHELL command only right now.
10524 @Override
10525 public String getLastUcePidfXmlShell(int subId) {
10526 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10527 final long identity = Binder.clearCallingIdentity();
10528 try {
10529 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10530 } catch (ImsException e) {
10531 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10532 } finally {
10533 Binder.restoreCallingIdentity(identity);
10534 }
10535 }
10536
James.cf Line8713a42021-04-29 16:04:26 +080010537 /**
10538 * Remove UCE requests cannot be sent to the network status.
10539 */
10540 // Used for SHELL command only right now.
10541 @Override
10542 public boolean removeUceRequestDisallowedStatus(int subId) {
10543 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10544 final long identity = Binder.clearCallingIdentity();
10545 try {
10546 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10547 } catch (ImsException e) {
10548 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10549 } finally {
10550 Binder.restoreCallingIdentity(identity);
10551 }
10552 }
10553
James.cf Lin0fc71b02021-05-25 01:37:38 +080010554 /**
10555 * Remove UCE requests cannot be sent to the network status.
10556 */
10557 // Used for SHELL command only.
10558 @Override
10559 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10560 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10561 final long identity = Binder.clearCallingIdentity();
10562 try {
10563 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10564 } catch (ImsException e) {
10565 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10566 } finally {
10567 Binder.restoreCallingIdentity(identity);
10568 }
10569 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010570
James.cf Lin4b784aa2021-01-31 03:25:15 +080010571 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010572 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10573 String callingPackage) {
10574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10575 mApp, subId, "setSignalStrengthUpdateRequest");
10576
10577 final int callingUid = Binder.getCallingUid();
10578 // Verify that tha callingPackage belongs to the calling UID
10579 mApp.getSystemService(AppOpsManager.class)
10580 .checkPackage(callingUid, callingPackage);
10581
10582 validateSignalStrengthUpdateRequest(request, callingUid);
10583
10584 final long identity = Binder.clearCallingIdentity();
10585 try {
10586 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10587 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10588
10589 if (result instanceof IllegalStateException) {
10590 throw (IllegalStateException) result;
10591 }
10592 } finally {
10593 Binder.restoreCallingIdentity(identity);
10594 }
10595 }
10596
10597 @Override
10598 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10599 String callingPackage) {
10600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10601 mApp, subId, "clearSignalStrengthUpdateRequest");
10602
10603 final int callingUid = Binder.getCallingUid();
10604 // Verify that tha callingPackage belongs to the calling UID
10605 mApp.getSystemService(AppOpsManager.class)
10606 .checkPackage(callingUid, callingPackage);
10607
10608 final long identity = Binder.clearCallingIdentity();
10609 try {
10610 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10611 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10612
10613 if (result instanceof IllegalStateException) {
10614 throw (IllegalStateException) result;
10615 }
10616 } finally {
10617 Binder.restoreCallingIdentity(identity);
10618 }
10619 }
10620
10621 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10622 int callingUid) {
10623 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10624 // phone/system process do not have further restriction on request
10625 return;
10626 }
10627
10628 // Applications has restrictions on how to use the request:
10629 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10630 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10631 // This is not system caller which has been checked above
10632 throw new IllegalArgumentException(
10633 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10634 }
10635
10636 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10637 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10638 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10639 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10640 || info.isEnabled()) {
10641 throw new IllegalArgumentException(
10642 "Only system can set hide fields in SignalThresholdInfo");
10643 }
10644
10645 // Thresholds length for each RAN need in range. This has been validated in
10646 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10647 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10648 final int[] thresholds = info.getThresholds();
10649 Objects.requireNonNull(thresholds);
10650 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10651 || thresholds.length
10652 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10653 throw new IllegalArgumentException(
10654 "thresholds length is out of range: " + thresholds.length);
10655 }
10656 }
10657 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010658
10659 /**
10660 * Gets the current phone capability.
10661 *
10662 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10663 * @return the PhoneCapability which describes the data connection capability of modem.
10664 * It's used to evaluate possible phone config change, for example from single
10665 * SIM device to multi-SIM device.
10666 */
10667 @Override
10668 public PhoneCapability getPhoneCapability() {
10669 enforceReadPrivilegedPermission("getPhoneCapability");
10670 final long identity = Binder.clearCallingIdentity();
10671 try {
10672 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10673 } finally {
10674 Binder.restoreCallingIdentity(identity);
10675 }
10676 }
Michele Berionne5e411512020-11-13 02:36:59 +000010677
10678 /**
10679 * Prepare TelephonyManager for an unattended reboot. The reboot is
10680 * required to be done shortly after the API is invoked.
10681 */
10682 @Override
10683 @TelephonyManager.PrepareUnattendedRebootResult
10684 public int prepareForUnattendedReboot() {
10685 enforceRebootPermission();
10686
10687 final long identity = Binder.clearCallingIdentity();
10688 try {
10689 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10690 } finally {
10691 Binder.restoreCallingIdentity(identity);
10692 }
10693 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010694
10695 /**
10696 * Request to get the current slicing configuration including URSP rules and
10697 * NSSAIs (configured, allowed and rejected).
10698 *
10699 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10700 */
10701 @Override
10702 public void getSlicingConfig(ResultReceiver callback) {
10703 enforceReadPrivilegedPermission("getSlicingConfig");
10704
10705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 Phone phone = getDefaultPhone();
10708 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10709 } finally {
10710 Binder.restoreCallingIdentity(identity);
10711 }
10712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010713}