blob: f3a0a268f70bdec1ed7633acefae5767b0de800a [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;
2092 while (request == null && now < deadline) {
2093 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 Ebinger4ae57f92019-01-09 16:51:30 -08003848 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003849 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 .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 Wang8ea57e32020-06-25 11:03:56 -07003872 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003873 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3874 .removeRegistrationCallbackForSubscription(c, subId);
3875 } catch (ImsException e) {
3876 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3877 + "is inactive, ignoring unregister.");
3878 // If the subscription is no longer active, just return, since the callback
3879 // will already have been removed internally.
3880 } finally {
3881 Binder.restoreCallingIdentity(token);
3882 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003883 }
3884
Brad Ebingera34a6c22019-10-22 17:36:18 -07003885 /**
3886 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3887 */
3888 @Override
3889 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3890 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3891 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3892 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3893 "IMS not available on device.");
3894 }
3895 final long token = Binder.clearCallingIdentity();
3896 try {
3897 Phone phone = getPhone(subId);
3898 if (phone == null) {
3899 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3900 + subId + "'");
3901 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3902 }
3903 phone.getImsRegistrationState(regState -> {
3904 try {
3905 consumer.accept((regState == null)
3906 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3907 } catch (RemoteException e) {
3908 // Ignore if the remote process is no longer available to call back.
3909 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3910 }
3911 });
3912 } finally {
3913 Binder.restoreCallingIdentity(token);
3914 }
3915 }
3916
3917 /**
3918 * Get the transport type for the IMS service registration state.
3919 */
3920 @Override
3921 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003922 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003923 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003924 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3925 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3926 "IMS not available on device.");
3927 }
3928 final long token = Binder.clearCallingIdentity();
3929 try {
3930 Phone phone = getPhone(subId);
3931 if (phone == null) {
3932 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3933 + subId + "'");
3934 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3935 }
3936 phone.getImsRegistrationTech(regTech -> {
3937 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3938 int regTechConverted = (regTech == null)
3939 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3940 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3941 regTechConverted);
3942 try {
3943 consumer.accept(regTechConverted);
3944 } catch (RemoteException e) {
3945 // Ignore if the remote process is no longer available to call back.
3946 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3947 }
3948 });
3949 } finally {
3950 Binder.restoreCallingIdentity(token);
3951 }
3952 }
3953
shilu366312e2019-12-17 09:28:10 -08003954 /**
3955 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3956 * @param subId The subscription to use to check the configuration.
3957 * @param c The callback that will be used to send the result.
3958 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003960 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3961 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003962 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003963 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003964 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3965 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3966 "IMS not available on device.");
3967 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3969 final long token = Binder.clearCallingIdentity();
3970 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003971 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003973 } catch (ImsException e) {
3974 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 } finally {
3976 Binder.restoreCallingIdentity(token);
3977 }
3978 }
3979
shilu366312e2019-12-17 09:28:10 -08003980 /**
3981 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3982 * @param subId The subscription to use to check the configuration.
3983 * @param c The callback that will be used to send the result.
3984 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003986 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003987 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003988 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003989 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3990 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3991 }
Meng Wangafbc5852019-09-19 17:37:13 -07003992
3993 final long token = Binder.clearCallingIdentity();
3994 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003995 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003996 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003997 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003998 } catch (ImsException e) {
3999 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4000 + "is inactive, ignoring unregister.");
4001 // If the subscription is no longer active, just return, since the callback
4002 // will already have been removed internally.
4003 } finally {
4004 Binder.restoreCallingIdentity(token);
4005 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 }
4007
4008 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004009 public boolean isCapable(int subId, int capability, int regTech) {
4010 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4012 final long token = Binder.clearCallingIdentity();
4013 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004014 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004016 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004017 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4018 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004019 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004020 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4021 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004022 } finally {
4023 Binder.restoreCallingIdentity(token);
4024 }
4025 }
4026
4027 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004028 public boolean isAvailable(int subId, int capability, int regTech) {
4029 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 final long token = Binder.clearCallingIdentity();
4031 try {
4032 Phone phone = getPhone(subId);
4033 if (phone == null) return false;
4034 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004035 } catch (com.android.ims.ImsException e) {
4036 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4037 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 } finally {
4039 Binder.restoreCallingIdentity(token);
4040 }
4041 }
4042
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004043 /**
4044 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4045 * subscription.
4046 * @param subId The subscription to use to check the configuration.
4047 * @param callback The callback that will be used to send the result.
4048 * @param capability The MmTelFeature capability that will be used to send the result.
4049 * @param transportType The transport type of the MmTelFeature capability.
4050 */
4051 @Override
4052 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4053 int transportType) {
4054 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4055 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4056 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4057 "IMS not available on device.");
4058 }
4059 final long token = Binder.clearCallingIdentity();
4060 try {
4061 int slotId = getSlotIndex(subId);
4062 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4063 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4064 + subId + "'");
4065 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4066 }
4067 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4068 transportType, aBoolean -> {
4069 try {
4070 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4071 } catch (RemoteException e) {
4072 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4073 + "running. Ignore");
4074 }
4075 });
4076 } finally {
4077 Binder.restoreCallingIdentity(token);
4078 }
4079 }
4080
shilu366312e2019-12-17 09:28:10 -08004081 /**
4082 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4083 * @param subId The subscription to use to check the configuration.
4084 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 @Override
4086 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004087 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004088 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004089
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4091 final long token = Binder.clearCallingIdentity();
4092 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004093 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004095 } catch (ImsException e) {
4096 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 } finally {
4098 Binder.restoreCallingIdentity(token);
4099 }
4100 }
4101
4102 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004103 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004105 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004109 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004111 } catch (ImsException e) {
4112 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 } finally {
4114 Binder.restoreCallingIdentity(identity);
4115 }
4116 }
4117
shilu366312e2019-12-17 09:28:10 -08004118 /**
4119 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4120 * @param subId The subscription to use to check the configuration.
4121 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004123 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004124 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004125 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004129 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4130 } catch (ImsException e) {
4131 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
4135 }
4136
4137 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004138 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004140 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 final long identity = Binder.clearCallingIdentity();
4142 try {
4143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004144 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004145 } catch (ImsException e) {
4146 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
4150 }
4151
shilu366312e2019-12-17 09:28:10 -08004152 /**
4153 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4154 * @param subId The subscription to use to check the configuration.
4155 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 @Override
4157 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004158 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004159 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004163 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004165 } catch (ImsException e) {
4166 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 } finally {
4168 Binder.restoreCallingIdentity(identity);
4169 }
4170 }
4171
4172 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004173 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004174 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004175 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004179 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004180 } catch (ImsException e) {
4181 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004182 } finally {
4183 Binder.restoreCallingIdentity(identity);
4184 }
4185 }
4186
shilu366312e2019-12-17 09:28:10 -08004187 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004188 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4189 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4190 * @param subId The subscription to use to check the configuration.
4191 */
4192 @Override
4193 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004194 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004195 mApp, subId, "isCrossSimCallingEnabledByUser");
4196 final long identity = Binder.clearCallingIdentity();
4197 try {
4198 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4199 return ImsManager.getInstance(mApp,
4200 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4201 } catch (ImsException e) {
4202 throw new ServiceSpecificException(e.getCode());
4203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
4206 }
4207
4208 /**
4209 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4210 * Requires MODIFY_PHONE_STATE permission.
4211 * @param subId The subscription to use to check the configuration.
4212 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4213 * false otherwise
4214 */
4215 @Override
4216 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4218 "setCrossSimCallingEnabled");
4219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4222 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4223 .setCrossSimCallingEnabled(isEnabled);
4224 } catch (ImsException e) {
4225 throw new ServiceSpecificException(e.getCode());
4226 } finally {
4227 Binder.restoreCallingIdentity(identity);
4228 }
4229 }
4230
4231 /**
shilu366312e2019-12-17 09:28:10 -08004232 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4233 * @param subId The subscription to use to check the configuration.
4234 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004236
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004238 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004239 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004243 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004245 } catch (ImsException e) {
4246 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004247 } finally {
4248 Binder.restoreCallingIdentity(identity);
4249 }
4250 }
4251
4252 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004253 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004255 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004256 final long identity = Binder.clearCallingIdentity();
4257 try {
4258 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004259 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004261 } catch (ImsException e) {
4262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004263 } finally {
4264 Binder.restoreCallingIdentity(identity);
4265 }
4266 }
4267
4268 @Override
4269 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4271 "setVoWiFiNonPersistent");
4272 final long identity = Binder.clearCallingIdentity();
4273 try {
4274 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004275 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004276 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004277 } catch (ImsException e) {
4278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
4282 }
4283
shilu366312e2019-12-17 09:28:10 -08004284 /**
4285 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4286 * @param subId The subscription to use to check the configuration.
4287 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004288 @Override
4289 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004290 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004291 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 final long identity = Binder.clearCallingIdentity();
4293 try {
4294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004295 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004297 } catch (ImsException e) {
4298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
4302 }
4303
4304 @Override
4305 public void setVoWiFiModeSetting(int subId, int mode) {
4306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4307 "setVoWiFiModeSetting");
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004311 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004313 } catch (ImsException e) {
4314 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
4318 }
4319
4320 @Override
4321 public int getVoWiFiRoamingModeSetting(int subId) {
4322 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4323 final long identity = Binder.clearCallingIdentity();
4324 try {
4325 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004326 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004327 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004328 } catch (ImsException e) {
4329 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004330 } finally {
4331 Binder.restoreCallingIdentity(identity);
4332 }
4333 }
4334
4335 @Override
4336 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4338 "setVoWiFiRoamingModeSetting");
4339 final long identity = Binder.clearCallingIdentity();
4340 try {
4341 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004342 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004343 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004344 } catch (ImsException e) {
4345 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
4349 }
4350
4351 @Override
4352 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4354 "setRttCapabilityEnabled");
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004358 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4359 } catch (ImsException e) {
4360 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
4364 }
4365
shilu366312e2019-12-17 09:28:10 -08004366 /**
4367 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4368 * @param subId The subscription to use to check the configuration.
4369 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 @Override
4371 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004372 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004373 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004377 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004379 } catch (ImsException e) {
4380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 } finally {
4382 Binder.restoreCallingIdentity(identity);
4383 }
4384 }
4385
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004386 @Override
4387 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4388 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4389 final long identity = Binder.clearCallingIdentity();
4390 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004391 if (!isImsAvailableOnDevice()) {
4392 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4393 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004394 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004395 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004396 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004397 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004398 } catch (ImsException e) {
4399 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004400 } finally {
4401 Binder.restoreCallingIdentity(identity);
4402 }
4403 }
4404
4405 @Override
4406 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4407 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4408 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004409 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4410 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4411 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004412 try {
4413 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004414 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004415 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004416 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004417 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4418 + "is inactive, ignoring unregister.");
4419 // If the subscription is no longer active, just return, since the callback will already
4420 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004421 } finally {
4422 Binder.restoreCallingIdentity(identity);
4423 }
4424 }
4425
allenwtsu99c623b2020-01-03 18:24:23 +08004426
4427 private void checkModifyPhoneStatePermission(int subId, String message) {
4428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4429 message);
4430 }
4431
4432 private boolean isImsProvisioningRequired(int subId, int capability,
4433 boolean isMmtelCapability) {
4434 Phone phone = getPhone(subId);
4435 if (phone == null) {
4436 loge("phone instance null for subid " + subId);
4437 return false;
4438 }
4439 if (isMmtelCapability) {
4440 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4441 return false;
4442 }
4443 } else {
4444 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4445 return false;
4446 }
4447 }
4448 return true;
4449 }
4450
4451 @Override
4452 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4453 boolean isProvisioned) {
4454 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4455
4456 final long identity = Binder.clearCallingIdentity();
4457 try {
4458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4459 if (!isImsProvisioningRequired(subId, capability, false)) {
4460 return;
4461 }
4462
4463 // this capability requires provisioning, route to the correct API.
4464 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4465 switch (capability) {
4466 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4467 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4468 ims.setEabProvisioned(isProvisioned);
4469 break;
4470 default: {
4471 throw new IllegalArgumentException("Tried to set provisioning for "
4472 + "rcs capability '" + capability + "', which does not require "
4473 + "provisioning.");
4474 }
4475 }
4476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
4479
4480 }
4481
4482
4483 @Override
4484 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4485 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4486 final long identity = Binder.clearCallingIdentity();
4487 try {
4488 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4489 if (!isImsProvisioningRequired(subId, capability, false)) {
4490 return true;
4491 }
4492
4493 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4494 switch (capability) {
4495 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4496 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4497 return ims.isEabProvisionedOnDevice();
4498
4499 default: {
4500 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4501 + "capability '" + capability + "', which does not require "
4502 + "provisioning.");
4503 }
4504 }
4505
4506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
4509 }
4510
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004511 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004512 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4513 boolean isProvisioned) {
4514 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004515 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4516 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4517 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004518 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4519 }
allenwtsu99c623b2020-01-03 18:24:23 +08004520 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004521 final long identity = Binder.clearCallingIdentity();
4522 try {
4523 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004524 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004525 return;
4526 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004527 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4528 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4529 loge("setImsProvisioningStatusForCapability: called for technology that does "
4530 + "not support provisioning - " + tech);
4531 return;
4532 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004533
4534 // this capability requires provisioning, route to the correct API.
4535 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4536 switch (capability) {
4537 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4538 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4539 ims.setVolteProvisioned(isProvisioned);
4540 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4541 ims.setWfcProvisioned(isProvisioned);
4542 }
4543 break;
4544 }
4545 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4546 // There is currently no difference in VT provisioning type.
4547 ims.setVtProvisioned(isProvisioned);
4548 break;
4549 }
4550 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4551 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4552 // change the capability of the feature instead if needed.
4553 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4554 == isProvisioned) {
4555 // No change in provisioning.
4556 return;
4557 }
4558 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4559 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004560 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004561 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004562 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4563 + ", Exception" + e.getMessage());
4564 }
4565 break;
4566 }
4567 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004568 throw new IllegalArgumentException("Tried to set provisioning for "
4569 + "MmTel capability '" + capability + "', which does not require "
4570 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004571 }
4572 }
4573
4574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
4577 }
4578
4579 @Override
4580 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4581 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004582 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4583 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4584 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004585 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4586 }
4587 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4588 final long identity = Binder.clearCallingIdentity();
4589 try {
4590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004591 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004592 return true;
4593 }
4594
Brad Ebinger0d79c572021-04-17 15:20:49 -07004595 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4596 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4597 loge("getImsProvisioningStatusForCapability: called for technology that does "
4598 + "not support provisioning - " + tech);
4599 return true;
4600 }
4601
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004602 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4603 switch (capability) {
4604 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4605 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4606 return ims.isVolteProvisionedOnDevice();
4607 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4608 return ims.isWfcProvisionedOnDevice();
4609 }
4610 // This should never happen, since we are checking tech above to make sure it
4611 // is either LTE or IWLAN.
4612 throw new IllegalArgumentException("Invalid radio technology for voice "
4613 + "capability.");
4614 }
4615 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4616 // There is currently no difference in VT provisioning type.
4617 return ims.isVtProvisionedOnDevice();
4618 }
4619 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4620 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4621 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4622 }
4623 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004624 throw new IllegalArgumentException(
4625 "Tried to get provisioning for MmTel capability '" + capability
4626 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004627 }
4628 }
4629
4630 } finally {
4631 Binder.restoreCallingIdentity(identity);
4632 }
4633 }
4634
4635 @Override
4636 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4637 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4638 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4639 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4640 }
4641 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4642 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4643 return (provisionedBits & capability) > 0;
4644 }
4645
4646 @Override
4647 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4648 boolean isProvisioned) {
4649 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4650 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4651 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4652 }
4653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4654 "setProvisioningStatusForCapability");
4655 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4656 // If the current provisioning status for capability already matches isProvisioned,
4657 // do nothing.
4658 if (((provisionedBits & capability) > 0) == isProvisioned) {
4659 return;
4660 }
4661 if (isProvisioned) {
4662 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4663 } else {
4664 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4665 }
4666 }
4667
4668 /**
4669 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4670 * technology. The bitfield should mirror the bitfield defined by
4671 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4672 */
4673 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4674 String key = getMmTelProvisioningKey(subId, tech);
4675 // Default is no capabilities are provisioned.
4676 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4677 }
4678
4679 /**
4680 * Sets the MmTel capability provisioning bitfield (defined by
4681 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4682 * technology specified.
4683 *
4684 * Note: This is a synchronous command and should not be called on UI thread.
4685 */
4686 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4687 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4688 String key = getMmTelProvisioningKey(subId, tech);
4689 editor.putInt(key, newField);
4690 editor.commit();
4691 }
4692
4693 private static String getMmTelProvisioningKey(int subId, int tech) {
4694 // resulting key is provision_ims_mmtel_{subId}_{tech}
4695 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4696 }
4697
4698 /**
4699 * Query CarrierConfig to see if the specified capability requires provisioning for the
4700 * carrier associated with the subscription id.
4701 */
4702 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4703 int capability) {
4704 CarrierConfigManager configManager = new CarrierConfigManager(context);
4705 PersistableBundle c = configManager.getConfigForSubId(subId);
4706 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004707 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4709 false);
4710 boolean requireVoiceVtProvisioning = c.getBoolean(
4711 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4712
4713 // First check to make sure that the capability requires provisioning.
4714 switch (capability) {
4715 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4716 // intentional fallthrough
4717 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4718 if (requireVoiceVtProvisioning) {
4719 // Voice and Video requires provisioning
4720 return true;
4721 }
4722 break;
4723 }
4724 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4725 if (requireUtProvisioning) {
4726 // UT requires provisioning
4727 return true;
4728 }
4729 break;
4730 }
4731 }
4732 return false;
4733 }
4734
allenwtsu99c623b2020-01-03 18:24:23 +08004735 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4736 int capability) {
4737 CarrierConfigManager configManager = new CarrierConfigManager(context);
4738 PersistableBundle c = configManager.getConfigForSubId(subId);
4739
4740 boolean requireRcsProvisioning = c.getBoolean(
4741 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4742
4743 // First check to make sure that the capability requires provisioning.
4744 switch (capability) {
4745 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4746 // intentional fallthrough
4747 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4748 if (requireRcsProvisioning) {
4749 // OPTION or PRESENCE requires provisioning
4750 return true;
4751 }
4752 break;
4753 }
4754 }
4755 return false;
4756 }
4757
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004758 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004759 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4761 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4762 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004763 enforceReadPrivilegedPermission("getImsProvisioningInt");
4764 final long identity = Binder.clearCallingIdentity();
4765 try {
4766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004767 int slotId = getSlotIndex(subId);
4768 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4769 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4770 + subId + "' for key:" + key);
4771 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4772 }
calvinpanb5a34062021-02-08 19:59:36 +08004773 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004774 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004775 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4776 + subId + "' for key:" + key);
4777 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004778 } finally {
4779 Binder.restoreCallingIdentity(identity);
4780 }
4781 }
4782
4783 @Override
4784 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004785 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4786 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4787 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004788 enforceReadPrivilegedPermission("getImsProvisioningString");
4789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004792 int slotId = getSlotIndex(subId);
4793 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4794 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4795 + subId + "' for key:" + key);
4796 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4797 }
calvinpanb5a34062021-02-08 19:59:36 +08004798 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004799 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004800 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4801 + subId + "' for key:" + key);
4802 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
4806 }
4807
4808 @Override
4809 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004810 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4811 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4812 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004813 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4814 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004815 final long identity = Binder.clearCallingIdentity();
4816 try {
4817 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004818 int slotId = getSlotIndex(subId);
4819 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4820 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4821 + subId + "' for key:" + key);
4822 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4823 }
calvinpanb5a34062021-02-08 19:59:36 +08004824 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4825 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004826 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004827 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004828 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004829 } finally {
4830 Binder.restoreCallingIdentity(identity);
4831 }
4832 }
4833
4834 @Override
4835 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4837 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4838 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4840 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004841 final long identity = Binder.clearCallingIdentity();
4842 try {
4843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004844 int slotId = getSlotIndex(subId);
4845 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4846 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4847 + subId + "' for key:" + key);
4848 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4849 }
calvinpanb5a34062021-02-08 19:59:36 +08004850 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4851 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004852 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004853 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004854 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004855 } finally {
4856 Binder.restoreCallingIdentity(identity);
4857 }
4858 }
4859
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004860 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004861 int slotId = SubscriptionManager.getSlotIndex(subId);
4862 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004863 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4864 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004865 }
4866 return slotId;
4867 }
4868
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004869 private int getSlotIndex(int subId) {
4870 int slotId = SubscriptionManager.getSlotIndex(subId);
4871 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4872 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4873 }
4874 return slotId;
4875 }
4876
Wink Saville36469e72014-06-11 15:17:00 -07004877 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004878 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004879 */
4880 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004881 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4882 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004883 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004884 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004885 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004886 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004887 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004888 mApp, subId, callingPackage, callingFeatureId,
4889 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004890 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4891 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893 final long identity = Binder.clearCallingIdentity();
4894 try {
4895 final Phone phone = getPhone(subId);
4896 if (phone != null) {
4897 return phone.getServiceState().getDataNetworkType();
4898 } else {
4899 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4900 }
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004904 }
4905
4906 /**
4907 * Returns the data network type
4908 */
4909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004910 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004911 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4912 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004913 }
4914
4915 /**
4916 * Returns the data network type for a subId
4917 */
4918 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004919 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4920 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004922 mApp, subId, callingPackage, callingFeatureId,
4923 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004924 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4925 }
4926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 final long identity = Binder.clearCallingIdentity();
4928 try {
4929 final Phone phone = getPhone(subId);
4930 if (phone != null) {
4931 return phone.getServiceState().getDataNetworkType();
4932 } else {
4933 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4934 }
4935 } finally {
4936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004938 }
4939
4940 /**
Wink Saville36469e72014-06-11 15:17:00 -07004941 * Returns the Voice network type for a subId
4942 */
4943 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004944 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4945 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004946 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004947 mApp, subId, callingPackage, callingFeatureId,
4948 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004949 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4950 }
4951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 final long identity = Binder.clearCallingIdentity();
4953 try {
4954 final Phone phone = getPhone(subId);
4955 if (phone != null) {
4956 return phone.getServiceState().getVoiceNetworkType();
4957 } else {
4958 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4959 }
4960 } finally {
4961 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004963 }
4964
4965 /**
4966 * @return true if a ICC card is present
4967 */
4968 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004969 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004970 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4971 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004972 }
4973
4974 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004975 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004976 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004977 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004978 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004979 final long identity = Binder.clearCallingIdentity();
4980 try {
4981 final Phone phone = PhoneFactory.getPhone(slotIndex);
4982 if (phone != null) {
4983 return phone.getIccCard().hasIccCard();
4984 } else {
4985 return false;
4986 }
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004990 }
4991
4992 /**
4993 * Return if the current radio is LTE on CDMA. This
4994 * is a tri-state return value as for a period of time
4995 * the mode may be unknown.
4996 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004997 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004998 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004999 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005000 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005001 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005002 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5003 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5004 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005005 }
5006
Sanket Padawe356d7632015-06-22 14:03:32 -07005007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005008 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5009 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005010 try {
5011 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5012 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005013 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5014 }
5015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 final long identity = Binder.clearCallingIdentity();
5017 try {
5018 final Phone phone = getPhone(subId);
5019 if (phone == null) {
5020 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5021 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005022 return TelephonyProperties.lte_on_cdma_device()
5023 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 }
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005027 }
Wink Saville36469e72014-06-11 15:17:00 -07005028 }
5029
Wink Saville36469e72014-06-11 15:17:00 -07005030 /**
5031 * {@hide}
5032 * Returns Default subId, 0 in the case of single standby.
5033 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005034 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005035 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005036 }
5037
Shishir Agrawala9f32182016-04-12 12:00:16 -07005038 private int getSlotForDefaultSubscription() {
5039 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5040 }
5041
Wink Savilleb564aae2014-10-23 10:18:09 -07005042 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005043 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005044 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005045
Pengquan Menge92a50d2018-09-21 15:54:48 -07005046 private boolean isActiveSubscription(int subId) {
5047 return mSubscriptionController.isActiveSubId(subId);
5048 }
5049
Ihab Awadf2177b72013-11-25 13:33:23 -08005050 /**
5051 * @see android.telephony.TelephonyManager.WifiCallingChoices
5052 */
5053 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005056 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5058 getWhenToMakeWifiCallsDefaultPreference());
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
5061 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005062 }
5063
5064 /**
5065 * @see android.telephony.TelephonyManager.WifiCallingChoices
5066 */
5067 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005071 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
5075 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005076 }
5077
Sailesh Nepald1e68152013-12-12 19:08:02 -08005078 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005079 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005080 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005081 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005082
Jordan Liu4c733742019-02-28 12:03:40 -08005083 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5084 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5085 if (phoneId == -1) {
5086 throw new IllegalArgumentException("Given slot index: " + slotIndex
5087 + " does not correspond to an active phone");
5088 }
5089 return PhoneFactory.getPhone(phoneId);
5090 }
5091
Shishir Agrawal566b7612013-10-28 14:41:00 -07005092 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005093 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5094 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005095 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5096 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005098 if (DBG) {
5099 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5100 }
5101 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5102 p2);
5103 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005104
Jordan Liu4c733742019-02-28 12:03:40 -08005105
5106 @Override
5107 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5108 int slotIndex, String callingPackage, String aid, int p2) {
5109 enforceModifyPermission();
5110 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5111 if (DBG) {
5112 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5113 }
5114 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5115 callingPackage, aid, p2);
5116 }
5117
5118 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5119 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 final long identity = Binder.clearCallingIdentity();
5121 try {
5122 if (TextUtils.equals(ISDR_AID, aid)) {
5123 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005124 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5125 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005126 if (bestComponent == null
5127 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5128 loge("The calling package is not allowed to access ISD-R.");
5129 throw new SecurityException(
5130 "The calling package is not allowed to access ISD-R.");
5131 }
Derek Tan740e1672017-06-27 14:56:27 -07005132 }
Derek Tan740e1672017-06-27 14:56:27 -07005133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005135 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5136 null /* workSource */);
5137 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 return response;
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
5141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005142 }
5143
5144 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005145 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5147 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005148 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5149 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5150 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005151
Jordan Liu4c733742019-02-28 12:03:40 -08005152 @Override
5153 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5154 enforceModifyPermission();
5155 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5156 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5157 channel);
5158 }
5159
5160 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161 final long identity = Binder.clearCallingIdentity();
5162 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 if (channel < 0) {
5164 return false;
5165 }
Jordan Liu4c733742019-02-28 12:03:40 -08005166 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5167 null /* workSource */);
5168 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 return success;
5170 } finally {
5171 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005172 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005173 }
5174
5175 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005176 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005177 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5179 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005180 if (DBG) {
5181 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5182 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5183 + p3 + " data=" + data);
5184 }
5185 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5186 command, p1, p2, p3, data);
5187 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005188
Jordan Liu4c733742019-02-28 12:03:40 -08005189 @Override
5190 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5191 int command, int p1, int p2, int p3, String data) {
5192 enforceModifyPermission();
5193 if (DBG) {
5194 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5195 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5196 + p3 + " data=" + data);
5197 }
5198 return iccTransmitApduLogicalChannelWithPermission(
5199 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5200 data);
5201 }
5202
5203 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5204 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 final long identity = Binder.clearCallingIdentity();
5206 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005207 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 return "";
5209 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005212 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5213 null /* workSource */);
5214 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 // Append the returned status code to the end of the response payload.
5217 String s = Integer.toHexString(
5218 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5219 if (response.payload != null) {
5220 s = IccUtils.bytesToHexString(response.payload) + s;
5221 }
5222 return s;
5223 } finally {
5224 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005225 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005226 }
Jake Hambye994d462014-02-03 13:10:13 -08005227
Evan Charltonc66da362014-05-16 14:06:40 -07005228 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005229 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5230 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5232 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005234 if (DBG) {
5235 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5236 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5237 }
5238 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5239 cla, command, p1, p2, p3, data);
5240 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005241
Jordan Liu4c733742019-02-28 12:03:40 -08005242 @Override
5243 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5244 int command, int p1, int p2, int p3, String data) {
5245 enforceModifyPermission();
5246 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5247 if (DBG) {
5248 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5249 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5250 + " data=" + data);
5251 }
5252
5253 return iccTransmitApduBasicChannelWithPermission(
5254 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5255 p2, p3, data);
5256 }
5257
5258 // open APDU basic channel assuming the caller has sufficient permissions
5259 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5260 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005261 final long identity = Binder.clearCallingIdentity();
5262 try {
5263 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5264 && TextUtils.equals(ISDR_AID, data)) {
5265 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005266 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5267 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 if (bestComponent == null
5269 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5270 loge("The calling package is not allowed to select ISD-R.");
5271 throw new SecurityException(
5272 "The calling package is not allowed to select ISD-R.");
5273 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005274 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005277 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5278 null /* workSource */);
5279 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 // Append the returned status code to the end of the response payload.
5282 String s = Integer.toHexString(
5283 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5284 if (response.payload != null) {
5285 s = IccUtils.bytesToHexString(response.payload) + s;
5286 }
5287 return s;
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005290 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005291 }
5292
5293 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005294 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005295 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5297 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 final long identity = Binder.clearCallingIdentity();
5300 try {
5301 if (DBG) {
5302 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5303 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5304 }
5305
5306 IccIoResult response =
5307 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5308 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5309 subId);
5310
5311 if (DBG) {
5312 log("Exchange SIM_IO [R]" + response);
5313 }
5314
5315 byte[] result = null;
5316 int length = 2;
5317 if (response.payload != null) {
5318 length = 2 + response.payload.length;
5319 result = new byte[length];
5320 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5321 } else {
5322 result = new byte[length];
5323 }
5324
5325 result[length - 1] = (byte) response.sw2;
5326 result[length - 2] = (byte) response.sw1;
5327 return result;
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005330 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005331 }
5332
Nathan Haroldb3014052017-01-25 15:57:32 -08005333 /**
5334 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5335 * on a particular subscription
5336 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005337 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5338 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005340 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005341 return null;
5342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343
5344 final long identity = Binder.clearCallingIdentity();
5345 try {
5346 if (appType != TelephonyManager.APPTYPE_USIM
5347 && appType != TelephonyManager.APPTYPE_SIM) {
5348 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5349 return null;
5350 }
5351 Object response = sendRequest(
5352 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5353 if (response instanceof String[]) {
5354 return (String[]) response;
5355 }
yincheng zhao2737e882019-09-06 17:06:54 -07005356 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005358 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 } finally {
5360 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005361 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005362 }
5363
yincheng zhao2737e882019-09-06 17:06:54 -07005364 /**
5365 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5366 * subscription.
5367 *
5368 * @param subId the id of the subscription.
5369 * @param appType the uicc app type, must be USIM or SIM.
5370 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5371 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005372 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005373 * @return number of fplmns that is successfully written to the SIM.
5374 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005375 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5376 String callingFeatureId) {
5377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5378 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005379 if (DBG) logv("no permissions for setForbiddenplmns");
5380 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5381 }
5382 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5383 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5384 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5385 }
5386 if (fplmns == null) {
5387 throw new IllegalArgumentException("Fplmn List provided is null");
5388 }
5389 for (String fplmn : fplmns) {
5390 if (!CellIdentity.isValidPlmn(fplmn)) {
5391 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5392 }
5393 }
5394 final long identity = Binder.clearCallingIdentity();
5395 try {
5396 Object response = sendRequest(
5397 CMD_SET_FORBIDDEN_PLMNS,
5398 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5399 subId);
5400 return (int) response;
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
5404 }
5405
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005406 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005407 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5409 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005410
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5414 if (response.payload == null) {
5415 return "";
5416 }
Evan Charltonc66da362014-05-16 14:06:40 -07005417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 // Append the returned status code to the end of the response payload.
5419 String s = Integer.toHexString(
5420 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5421 s = IccUtils.bytesToHexString(response.payload) + s;
5422 return s;
5423 } finally {
5424 Binder.restoreCallingIdentity(identity);
5425 }
Evan Charltonc66da362014-05-16 14:06:40 -07005426 }
5427
Jake Hambye994d462014-02-03 13:10:13 -08005428 /**
5429 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5430 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5431 *
5432 * @param itemID the ID of the item to read
5433 * @return the NV item as a String, or null on error.
5434 */
5435 @Override
5436 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005437 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5439 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005440
5441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005444 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5446 return value;
5447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
Jake Hambye994d462014-02-03 13:10:13 -08005450 }
5451
5452 /**
5453 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5454 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5455 *
5456 * @param itemID the ID of the item to read
5457 * @param itemValue the value to write, as a String
5458 * @return true on success; false on any failure
5459 */
5460 @Override
5461 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005462 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5464 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005465
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5469 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005470 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5472 return success;
5473 } finally {
5474 Binder.restoreCallingIdentity(identity);
5475 }
Jake Hambye994d462014-02-03 13:10:13 -08005476 }
5477
5478 /**
5479 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5480 * Used for device configuration by some CDMA operators.
5481 *
5482 * @param preferredRoamingList byte array containing the new PRL
5483 * @return true on success; false on any failure
5484 */
5485 @Override
5486 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5488 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489
5490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5493 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5494 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5495 return success;
5496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
Jake Hambye994d462014-02-03 13:10:13 -08005499 }
5500
5501 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005502 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005503 * Used for device configuration by some CDMA operators.
5504 *
chen xu6dac5ab2018-10-26 17:39:23 -07005505 * @param slotIndex - device slot.
5506 *
Jake Hambye994d462014-02-03 13:10:13 -08005507 * @return true on success; false on any failure
5508 */
5509 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005510 public boolean resetModemConfig(int slotIndex) {
5511 Phone phone = PhoneFactory.getPhone(slotIndex);
5512 if (phone != null) {
5513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5514 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515
chen xu6dac5ab2018-10-26 17:39:23 -07005516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5519 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5520 return success;
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 }
chen xu6dac5ab2018-10-26 17:39:23 -07005525 return false;
5526 }
5527
5528 /**
5529 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5530 *
5531 * @param slotIndex - device slot.
5532 *
5533 * @return true on success; false on any failure
5534 */
5535 @Override
5536 public boolean rebootModem(int slotIndex) {
5537 Phone phone = PhoneFactory.getPhone(slotIndex);
5538 if (phone != null) {
5539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5540 mApp, phone.getSubId(), "rebootModem");
5541
5542 final long identity = Binder.clearCallingIdentity();
5543 try {
5544 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5545 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5546 return success;
5547 } finally {
5548 Binder.restoreCallingIdentity(identity);
5549 }
5550 }
5551 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005552 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005553
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005554 public String[] getPcscfAddress(String apnType, String callingPackage,
5555 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005556 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5558 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005559 return new String[0];
5560 }
5561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 final long identity = Binder.clearCallingIdentity();
5563 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005564 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
Wink Saville36469e72014-06-11 15:17:00 -07005568 }
5569
Brad Ebinger51f743a2017-01-23 13:50:20 -08005570 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005571 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5572 * {@link #disableIms(int)}.
5573 * @param slotIndex device slot.
5574 */
5575 public void resetIms(int slotIndex) {
5576 enforceModifyPermission();
5577
5578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 if (mImsResolver == null) {
5581 // may happen if the does not support IMS.
5582 return;
5583 }
5584 mImsResolver.disableIms(slotIndex);
5585 mImsResolver.enableIms(slotIndex);
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
5589 }
5590
5591 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005592 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5593 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005594 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005595 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005596 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597
5598 final long identity = Binder.clearCallingIdentity();
5599 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005600 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005601 // may happen if the device does not support IMS.
5602 return;
5603 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005604 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005608 }
5609
5610 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005611 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5612 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005613 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005614 public void disableIms(int slotId) {
5615 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.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 } finally {
5625 Binder.restoreCallingIdentity(identity);
5626 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005627 }
5628
5629 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005630 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5631 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005632 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005633 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005634 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636
5637 final long identity = Binder.clearCallingIdentity();
5638 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005639 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005640 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5641 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005642 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005643 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005647 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005648 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005649 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5650 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005651 @Override
5652 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005653 enforceModifyPermission();
5654
5655 final long identity = Binder.clearCallingIdentity();
5656 try {
5657 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005658 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
5662 }
5663
5664 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005665 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005666 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005667 */
5668 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5669 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005673 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005674 // may happen if the device does not support IMS.
5675 return null;
5676 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005677 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 } finally {
5679 Binder.restoreCallingIdentity(identity);
5680 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005681 }
5682
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005683 /**
5684 * Returns the {@link IImsConfig} 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 Ebinger22bc3e42018-01-16 09:39:35 -08005686 */
5687 public IImsConfig getImsConfig(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.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005700 }
5701
Brad Ebinger884c07b2018-02-15 16:17:40 -08005702 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005703 * Sets the ImsService Package Name that Telephony will bind to.
5704 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005705 * @param slotIndex the slot ID that the ImsService should bind for.
5706 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005707 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005708 * @param featureTypes An integer array of feature types associated with a packageName.
5709 * @param packageName The name of the package that the current configuration will be replaced
5710 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005711 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005712 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005713 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5714 int[] featureTypes, String packageName) {
5715 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5716 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5718 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005719 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005720
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 final long identity = Binder.clearCallingIdentity();
5722 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005723 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005724 // may happen if the device does not support IMS.
5725 return false;
5726 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005727 Map<Integer, String> featureConfig = new HashMap<>();
5728 for (int featureType : featureTypes) {
5729 featureConfig.put(featureType, packageName);
5730 }
5731 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5732 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005736 }
5737
5738 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005739 * Clears any carrier ImsService overrides for the slot index specified that were previously
5740 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5741 *
5742 * This should only be used for testing.
5743 *
5744 * @param slotIndex the slot ID that the ImsService should bind for.
5745 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5746 */
5747 @Override
5748 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5749 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5751 "clearCarrierImsServiceOverride");
5752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5753 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5754 "clearCarrierImsServiceOverride");
5755
5756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 if (mImsResolver == null) {
5759 // may happen if the device does not support IMS.
5760 return false;
5761 }
5762 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
5766 }
5767
5768 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005769 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005770 *
5771 * @param slotId The slot that the ImsService is associated with.
5772 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5773 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005774 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005775 * @return the package name of the ImsService configuration.
5776 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005777 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5778 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005779 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005780 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005781 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005782 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5783 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 final long identity = Binder.clearCallingIdentity();
5786 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005787 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005788 // may happen if the device does not support IMS.
5789 return "";
5790 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005791 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005792 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5793 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005797 }
5798
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005799 /**
5800 * Get the MmTelFeature state associated with the requested subscription id.
5801 * @param subId The subscription that the MmTelFeature is associated with.
5802 * @param callback A callback with an integer containing the
5803 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5804 */
5805 @Override
5806 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5807 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5808 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5809 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5810 "IMS not available on device.");
5811 }
5812 final long token = Binder.clearCallingIdentity();
5813 try {
5814 int slotId = getSlotIndex(subId);
5815 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5816 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5817 + subId + "'");
5818 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5819 }
5820 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5821 try {
5822 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5823 } catch (RemoteException e) {
5824 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5825 + "Ignore");
5826 }
5827 });
5828 } finally {
5829 Binder.restoreCallingIdentity(token);
5830 }
5831 }
5832
Daniel Brightbb5840b2021-01-12 15:48:18 -08005833 /**
5834 * Sets the ims registration state on all valid {@link Phone}s.
5835 */
5836 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005837 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838
5839 final long identity = Binder.clearCallingIdentity();
5840 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005841 // NOTE: Before S, this method only set the default phone.
5842 for (final Phone phone : PhoneFactory.getPhones()) {
5843 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5844 phone.setImsRegistrationState(registered);
5845 }
5846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 } finally {
5848 Binder.restoreCallingIdentity(identity);
5849 }
Wink Saville36469e72014-06-11 15:17:00 -07005850 }
5851
5852 /**
Stuart Scott54788802015-03-30 13:18:01 -07005853 * Set the network selection mode to automatic.
5854 *
5855 */
5856 @Override
5857 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5859 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
shilufc958392020-01-20 11:36:01 -08005863 if (!isActiveSubscription(subId)) {
5864 return;
5865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005867 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5868 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
Stuart Scott54788802015-03-30 13:18:01 -07005872 }
5873
Jack Yud10cdd42020-09-28 20:28:01 -07005874 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005875 * Ask the radio to connect to the input network and change selection mode to manual.
5876 *
5877 * @param subId the id of the subscription.
5878 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5879 * the operator to attach to.
5880 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5881 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5882 * normal network selection next time.
5883 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005884 */
5885 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005886 public boolean setNetworkSelectionModeManual(
5887 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5889 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005890
5891 if (!isActiveSubscription(subId)) {
5892 return false;
5893 }
5894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 final long identity = Binder.clearCallingIdentity();
5896 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005897 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005899 if (DBG) {
5900 log("setNetworkSelectionModeManual: subId: " + subId
5901 + " operator: " + operatorInfo);
5902 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5904 } finally {
5905 Binder.restoreCallingIdentity(identity);
5906 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005907 }
shilu84f6e8b2019-12-19 13:58:01 -08005908 /**
5909 * Get the manual network selection
5910 *
5911 * @param subId the id of the subscription.
5912 *
5913 * @return the previously saved user selected PLMN
5914 */
5915 @Override
5916 public String getManualNetworkSelectionPlmn(int subId) {
5917 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005918 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005919 mApp, subId, "getManualNetworkSelectionPlmn");
5920
5921 final long identity = Binder.clearCallingIdentity();
5922 try {
5923 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005924 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005925 }
5926
5927 final Phone phone = getPhone(subId);
5928 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005929 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005930 }
5931 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5932 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5933 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5934 } finally {
5935 Binder.restoreCallingIdentity(identity);
5936 }
5937 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005938
5939 /**
5940 * Scans for available networks.
5941 */
5942 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005943 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5944 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5946 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005947 LocationAccessPolicy.LocationPermissionResult locationResult =
5948 LocationAccessPolicy.checkLocationPermission(mApp,
5949 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5950 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005951 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005952 .setCallingPid(Binder.getCallingPid())
5953 .setCallingUid(Binder.getCallingUid())
5954 .setMethod("getCellNetworkScanResults")
5955 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005956 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5957 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005958 .build());
5959 switch (locationResult) {
5960 case DENIED_HARD:
5961 throw new SecurityException("Not allowed to access scan results -- location");
5962 case DENIED_SOFT:
5963 return null;
5964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965
Pengquan Menga1bb6272018-09-06 09:59:22 -07005966 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 try {
5968 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005969 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005974 }
5975
5976 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005977 * Get the call forwarding info, given the call forwarding reason.
5978 */
5979 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005980 public void getCallForwarding(int subId, int callForwardingReason,
5981 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005982 enforceReadPrivilegedPermission("getCallForwarding");
5983 long identity = Binder.clearCallingIdentity();
5984 try {
5985 if (DBG) {
5986 log("getCallForwarding: subId " + subId
5987 + " callForwardingReason" + callForwardingReason);
5988 }
Hall Liu27d24262020-09-18 19:04:59 -07005989
5990 Phone phone = getPhone(subId);
5991 if (phone == null) {
5992 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005993 callback.onError(
5994 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005995 } catch (RemoteException e) {
5996 // ignore
5997 }
5998 return;
5999 }
6000
6001 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6002 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6003 @Override
6004 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6005 try {
6006 callback.onCallForwardingInfoAvailable(info);
6007 } catch (RemoteException e) {
6008 // ignore
6009 }
6010 }
6011
6012 @Override
6013 public void onError(int error) {
6014 try {
6015 callback.onError(error);
6016 } catch (RemoteException e) {
6017 // ignore
6018 }
6019 }
6020 });
6021 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006022 } finally {
6023 Binder.restoreCallingIdentity(identity);
6024 }
6025 }
6026
6027 /**
6028 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6029 * reason, the number to forward, and the timeout before the forwarding is attempted.
6030 */
6031 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006032 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6033 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006034 enforceModifyPermission();
6035 long identity = Binder.clearCallingIdentity();
6036 try {
6037 if (DBG) {
6038 log("setCallForwarding: subId " + subId
6039 + " callForwardingInfo" + callForwardingInfo);
6040 }
Hall Liu27d24262020-09-18 19:04:59 -07006041
6042 Phone phone = getPhone(subId);
6043 if (phone == null) {
6044 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006045 callback.accept(
6046 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006047 } catch (RemoteException e) {
6048 // ignore
6049 }
6050 return;
6051 }
6052
6053 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6054 FunctionalUtils.ignoreRemoteException(callback::accept));
6055
6056 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006057 } finally {
6058 Binder.restoreCallingIdentity(identity);
6059 }
6060 }
6061
6062 /**
Hall Liu27d24262020-09-18 19:04:59 -07006063 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006064 */
6065 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006066 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006067 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006068 long identity = Binder.clearCallingIdentity();
6069 try {
Hall Liu27d24262020-09-18 19:04:59 -07006070 Phone phone = getPhone(subId);
6071 if (phone == null) {
6072 try {
6073 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6074 } catch (RemoteException e) {
6075 // ignore
6076 }
6077 return;
6078 }
SongFerngWang0e767992021-03-31 22:08:45 +08006079 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6080 PersistableBundle c = configManager.getConfigForSubId(subId);
6081 boolean requireUssd = c.getBoolean(
6082 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006083
Shuo Qian4a594052020-01-23 11:59:30 -08006084 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006085 if (requireUssd) {
6086 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6087 getSubscriptionCarrierId(subId));
6088 String newUssdCommand = "";
6089 try {
6090 newUssdCommand = carrierXmlParser.getFeature(
6091 CarrierXmlParser.FEATURE_CALL_WAITING)
6092 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6093 } catch (NullPointerException e) {
6094 loge("Failed to generate USSD number" + e);
6095 }
6096 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6097 mMainThreadHandler, callback, carrierXmlParser,
6098 CarrierXmlParser.SsEntry.SSAction.QUERY);
6099 final String ussdCommand = newUssdCommand;
6100 Executors.newSingleThreadExecutor().execute(() -> {
6101 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6102 });
6103 } else {
6104 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6105 callback::accept);
6106 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6107 }
Shuo Qian4a594052020-01-23 11:59:30 -08006108 } finally {
6109 Binder.restoreCallingIdentity(identity);
6110 }
6111 }
6112
6113 /**
Hall Liu27d24262020-09-18 19:04:59 -07006114 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006115 */
6116 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006117 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006118 enforceModifyPermission();
6119 long identity = Binder.clearCallingIdentity();
6120 try {
Hall Liu27d24262020-09-18 19:04:59 -07006121 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6122
6123 Phone phone = getPhone(subId);
6124 if (phone == null) {
6125 try {
6126 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6127 } catch (RemoteException e) {
6128 // ignore
6129 }
6130 return;
6131 }
6132
SongFerngWang0e767992021-03-31 22:08:45 +08006133 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6134 PersistableBundle c = configManager.getConfigForSubId(subId);
6135 boolean requireUssd = c.getBoolean(
6136 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006137
SongFerngWang0e767992021-03-31 22:08:45 +08006138 if (DBG) log("getCallWaitingStatus: subId " + subId);
6139 if (requireUssd) {
6140 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6141 getSubscriptionCarrierId(subId));
6142 CarrierXmlParser.SsEntry.SSAction ssAction =
6143 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6144 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6145 String newUssdCommand = "";
6146 try {
6147 newUssdCommand = carrierXmlParser.getFeature(
6148 CarrierXmlParser.FEATURE_CALL_WAITING)
6149 .makeCommand(ssAction, null);
6150 } catch (NullPointerException e) {
6151 loge("Failed to generate USSD number" + e);
6152 }
6153 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6154 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6155 final String ussdCommand = newUssdCommand;
6156 Executors.newSingleThreadExecutor().execute(() -> {
6157 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6158 });
6159 } else {
6160 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6161 FunctionalUtils.ignoreRemoteException(callback::accept));
6162
6163 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6164 }
Shuo Qian4a594052020-01-23 11:59:30 -08006165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
6168 }
6169
6170 /**
yinxub1bed742017-04-17 11:45:04 -07006171 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006172 *
yinxub1bed742017-04-17 11:45:04 -07006173 * @param subId id of the subscription
6174 * @param request contains the radio access networks with bands/channels to scan
6175 * @param messenger callback messenger for scan results or errors
6176 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006177 * @return the id of the requested scan which can be used to stop the scan.
6178 */
6179 @Override
6180 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006181 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6183 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006184 LocationAccessPolicy.LocationPermissionResult locationResult =
6185 LocationAccessPolicy.checkLocationPermission(mApp,
6186 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6187 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006188 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006189 .setCallingPid(Binder.getCallingPid())
6190 .setCallingUid(Binder.getCallingUid())
6191 .setMethod("requestNetworkScan")
6192 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006193 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6194 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006195 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006196 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006197 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6198 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006199 if (e != null) {
6200 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6201 throw e;
6202 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006203 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006204 return TelephonyScanManager.INVALID_SCAN_ID;
6205 }
6206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207 }
Hall Liu912dfd32019-04-25 14:02:26 -07006208 int callingUid = Binder.getCallingUid();
6209 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006210 final long identity = Binder.clearCallingIdentity();
6211 try {
6212 return mNetworkScanRequestTracker.startNetworkScan(
6213 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006214 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006215 } finally {
6216 Binder.restoreCallingIdentity(identity);
6217 }
yinxu504e1392017-04-12 16:03:22 -07006218 }
6219
Hall Liub2ac8ef2019-02-28 15:56:23 -08006220 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006221 NetworkScanRequest request, int subId, String callingPackage) {
6222 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006223 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6224 boolean hasNetworkScanPermission =
6225 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6226 == PERMISSION_GRANTED;
6227
6228 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6229 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6230 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006231 }
6232
6233 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6234 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006235 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6236 return new SecurityException("Specific channels must not be"
6237 + " scanned without location access.");
6238 }
6239 }
6240 }
6241
Hall Liub2ac8ef2019-02-28 15:56:23 -08006242 return null;
6243 }
6244
yinxu504e1392017-04-12 16:03:22 -07006245 /**
6246 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006247 *
6248 * @param subId id of the subscription
6249 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006250 */
6251 @Override
6252 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6254 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255
Hall Liu912dfd32019-04-25 14:02:26 -07006256 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 final long identity = Binder.clearCallingIdentity();
6258 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006259 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 } finally {
6261 Binder.restoreCallingIdentity(identity);
6262 }
yinxu504e1392017-04-12 16:03:22 -07006263 }
6264
6265 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006266 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006267 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006268 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006269 */
6270 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006271 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006272 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006273 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006274 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275
6276 final long identity = Binder.clearCallingIdentity();
6277 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006278 if (DBG) log("getAllowedNetworkTypesBitmask");
6279 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6280 int networkTypesBitmask = (result != null ? result[0] : -1);
6281 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6282 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 } finally {
6284 Binder.restoreCallingIdentity(identity);
6285 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006286 }
6287
6288 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006289 * Get the allowed network types for certain reason.
6290 *
6291 * @param subId the id of the subscription.
6292 * @param reason the reason the allowed network type change is taking place
6293 * @return the allowed network types.
6294 */
6295 @Override
6296 public long getAllowedNetworkTypesForReason(int subId,
6297 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006298 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006299 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006300 final long identity = Binder.clearCallingIdentity();
6301 try {
6302 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6303 } finally {
6304 Binder.restoreCallingIdentity(identity);
6305 }
6306 }
6307
6308 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006309 * Enable/Disable E-UTRA-NR Dual Connectivity
6310 * @param subId subscription id of the sim card
6311 * @param nrDualConnectivityState expected NR dual connectivity state
6312 * This can be passed following states
6313 * <ol>
6314 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6315 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6316 * <li>Disable NR dual connectivity and force secondary cell to be released
6317 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6318 * </ol>
6319 * @return operation result.
6320 */
6321 @Override
6322 public int setNrDualConnectivityState(int subId,
6323 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6325 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006326 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006327 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6328 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6329 }
6330
Sooraj Sasindran37444802020-08-11 10:40:43 -07006331 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6335 nrDualConnectivityState, subId,
6336 workSource);
6337 if (DBG) log("enableNRDualConnectivity result: " + result);
6338 return result;
6339 } finally {
6340 Binder.restoreCallingIdentity(identity);
6341 }
6342 }
6343
6344 /**
6345 * Is E-UTRA-NR Dual Connectivity enabled
6346 * @return true if dual connectivity is enabled else false
6347 */
6348 @Override
6349 public boolean isNrDualConnectivityEnabled(int subId) {
6350 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006351 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006352 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006353 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006354 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6355 return false;
6356 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
6360 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6361 null, subId, workSource);
6362 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6363 return isEnabled;
6364 } finally {
6365 Binder.restoreCallingIdentity(identity);
6366 }
6367 }
6368
6369 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006370 * Set the allowed network types of the device and
6371 * provide the reason triggering the allowed network change.
6372 *
6373 * @param subId the id of the subscription.
6374 * @param reason the reason the allowed network type change is taking place
6375 * @param allowedNetworkTypes the allowed network types.
6376 * @return true on success; false on any failure.
6377 */
6378 @Override
6379 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006380 @TelephonyManager.AllowedNetworkTypesReason int reason,
6381 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6383 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006384 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006385 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6386 return false;
6387 }
6388 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6389 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006390 return false;
6391 }
6392
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006393 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6394 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6395
6396
6397 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6398 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6399 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006400 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006401
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006402 final long identity = Binder.clearCallingIdentity();
6403 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006404 Boolean success = (Boolean) sendRequest(
6405 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6406 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6407
6408 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6409 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006410 } finally {
6411 Binder.restoreCallingIdentity(identity);
6412 }
6413 }
6414
6415 /**
Miaoa84611c2019-03-15 09:21:10 +08006416 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006417 *
Miaoa84611c2019-03-15 09:21:10 +08006418 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006419 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006420 * @hide
6421 */
6422 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006423 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006424 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006425 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006426 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 try {
Miaoa84611c2019-03-15 09:21:10 +08006428 if (phone != null) {
6429 return phone.hasMatchedTetherApnSetting();
6430 } else {
6431 return false;
6432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 } finally {
6434 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006435 }
Junda Liu475951f2014-11-07 16:45:03 -08006436 }
6437
6438 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006439 * Enable or disable always reporting signal strength changes from radio.
6440 *
6441 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6442 */
6443 @Override
6444 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6445 enforceModifyPermission();
6446 enforceSystemCaller();
6447
6448 final long identity = Binder.clearCallingIdentity();
6449 final Phone phone = getPhone(subId);
6450 try {
6451 if (phone != null) {
6452 if (DBG) {
6453 log("setAlwaysReportSignalStrength: subId=" + subId
6454 + " isEnable=" + isEnable);
6455 }
6456 phone.setAlwaysReportSignalStrength(isEnable);
6457 } else {
6458 loge("setAlwaysReportSignalStrength: no phone found for subId="
6459 + subId);
6460 }
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
6464 }
6465
6466 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006467 * Get the user enabled state of Mobile Data.
6468 *
6469 * TODO: remove and use isUserDataEnabled.
6470 * This can't be removed now because some vendor codes
6471 * calls through ITelephony directly while they should
6472 * use TelephonyManager.
6473 *
6474 * @return true on enabled
6475 */
6476 @Override
6477 public boolean getDataEnabled(int subId) {
6478 return isUserDataEnabled(subId);
6479 }
6480
6481 /**
6482 * Get whether mobile data is enabled per user setting.
6483 *
6484 * There are other factors deciding whether mobile data is actually enabled, but they are
6485 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006486 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006487 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006488 *
6489 * @return {@code true} if data is enabled else {@code false}
6490 */
6491 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006492 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006493 try {
6494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6495 null);
6496 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6498 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500
6501 final long identity = Binder.clearCallingIdentity();
6502 try {
6503 int phoneId = mSubscriptionController.getPhoneId(subId);
6504 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6505 Phone phone = PhoneFactory.getPhone(phoneId);
6506 if (phone != null) {
6507 boolean retVal = phone.isUserDataEnabled();
6508 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6509 return retVal;
6510 } else {
6511 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6512 return false;
6513 }
6514 } finally {
6515 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006516 }
6517 }
6518
6519 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006520 * Checks if the device is capable of mobile data by considering whether whether the
6521 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6522 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006523 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006524 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006525 */
6526 @Override
6527 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006528 try {
6529 try {
6530 mApp.enforceCallingOrSelfPermission(
6531 android.Manifest.permission.ACCESS_NETWORK_STATE,
6532 null);
6533 } catch (Exception e) {
6534 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6535 "isDataEnabled");
6536 }
6537 } catch (Exception e) {
6538 enforceReadPrivilegedPermission("isDataEnabled");
6539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540
6541 final long identity = Binder.clearCallingIdentity();
6542 try {
6543 int phoneId = mSubscriptionController.getPhoneId(subId);
6544 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6545 Phone phone = PhoneFactory.getPhone(phoneId);
6546 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006547 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6549 return retVal;
6550 } else {
6551 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6552 return false;
6553 }
6554 } finally {
6555 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006556 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006557 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006558
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006559 /**
6560 * Check if data is enabled for a specific reason
6561 * @param subId Subscription index
6562 * @param reason the reason the data enable change is taking place
6563 * @return {@code true} if the overall data is enabled; {@code false} if not.
6564 */
6565 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006566 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006567 @TelephonyManager.DataEnabledReason int reason) {
6568 try {
6569 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6570 null);
6571 } catch (Exception e) {
6572 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006573 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006574 }
6575
6576
6577 final long identity = Binder.clearCallingIdentity();
6578 try {
6579 int phoneId = mSubscriptionController.getPhoneId(subId);
6580 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006581 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006582 + " reason=" + reason);
6583 }
6584 Phone phone = PhoneFactory.getPhone(phoneId);
6585 if (phone != null) {
6586 boolean retVal;
6587 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6588 retVal = phone.isUserDataEnabled();
6589 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006590 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006591 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006592 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006593 return retVal;
6594 } else {
6595 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006596 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006597 + subId + " retVal=false");
6598 }
6599 return false;
6600 }
6601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
6604 }
6605
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006606 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006607 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006608 if (uid == Process.PHONE_UID) {
6609 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6610 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006611 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6612 }
6613
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006614 //load access rules from carrier configs, and check those as well: b/139133814
6615 SubscriptionController subController = SubscriptionController.getInstance();
6616 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6617 || subController == null) return privilegeFromSim;
6618
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006619 PackageManager pkgMgr = phone.getContext().getPackageManager();
6620 String[] packages = pkgMgr.getPackagesForUid(uid);
6621
6622 final long identity = Binder.clearCallingIdentity();
6623 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006624 int subId = phone.getSubId();
6625 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6626 // A test override is in place for the privileges for this subId, so don't try to
6627 // read the subscription privileges.
6628 return privilegeFromSim;
6629 }
6630 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006631 SubscriptionManager subManager = (SubscriptionManager)
6632 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6633 for (String pkg : packages) {
6634 if (subManager.canManageSubscription(subInfo, pkg)) {
6635 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6636 }
6637 }
6638 return privilegeFromSim;
6639 } finally {
6640 Binder.restoreCallingIdentity(identity);
6641 }
6642 }
6643
6644 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6645 String pkgName) {
6646 //load access rules from carrier configs, and check those as well: b/139133814
6647 SubscriptionController subController = SubscriptionController.getInstance();
6648 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6649 || subController == null) return privilegeFromSim;
6650
6651 final long identity = Binder.clearCallingIdentity();
6652 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006653 int subId = phone.getSubId();
6654 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6655 // A test override is in place for the privileges for this subId, so don't try to
6656 // read the subscription privileges.
6657 return privilegeFromSim;
6658 }
6659 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006660 SubscriptionManager subManager = (SubscriptionManager)
6661 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6662 return subManager.canManageSubscription(subInfo, pkgName)
6663 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6664 } finally {
6665 Binder.restoreCallingIdentity(identity);
6666 }
6667 }
6668
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006669 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006670 public int getCarrierPrivilegeStatus(int subId) {
6671 final Phone phone = getPhone(subId);
6672 if (phone == null) {
6673 loge("getCarrierPrivilegeStatus: Invalid subId");
6674 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6675 }
6676 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006677 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006678 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006679 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6680 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006681
6682 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6683 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006684 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006685 }
Junda Liu29340342014-07-10 15:23:27 -07006686
6687 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006688 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006689 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006690 final Phone phone = getPhone(subId);
6691 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006692 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006693 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6694 }
6695 UiccProfile profile =
6696 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6697 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006698 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006699 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6700 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006701 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006702 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006703 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006704 }
6705
6706 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006707 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006708 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006709 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006710 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006711 }
6712
6713 int phoneId = SubscriptionManager.getPhoneId(subId);
6714 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006715 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006716 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006717 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6718 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006719 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6720 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6721 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006722 }
6723
6724 @Override
6725 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006726 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006727 if (TextUtils.isEmpty(pkgName))
6728 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006729 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6730 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6731 UiccCard card = UiccController.getInstance().getUiccCard(i);
6732 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006733 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006734 continue;
6735 }
6736
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006737 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6738 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6739 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006740 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6741 break;
6742 }
6743 }
6744
6745 return result;
Junda Liu29340342014-07-10 15:23:27 -07006746 }
Derek Tan89e89d42014-07-08 17:00:10 -07006747
6748 @Override
Junda Liue64de782015-04-16 17:19:16 -07006749 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006750 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006751 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6752 loge("phoneId " + phoneId + " is not valid.");
6753 return null;
6754 }
6755 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006756 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006757 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006758 return null ;
6759 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006760 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006761 }
6762
Amith Yamasani6e118872016-02-19 12:53:51 -08006763 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006764 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006765 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006766 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006767 List<String> privilegedPackages = new ArrayList<>();
6768 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006769 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6770 // has UICC in that slot.
6771 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006772 if (card.hasCarrierPrivilegeRules()) {
6773 if (packages == null) {
6774 // Only check packages in user 0 for now
6775 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006776 PackageManager.MATCH_DISABLED_COMPONENTS
6777 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006778 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006779 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006780 }
6781 for (int p = packages.size() - 1; p >= 0; p--) {
6782 PackageInfo pkgInfo = packages.get(p);
6783 if (pkgInfo != null && pkgInfo.packageName != null
6784 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006785 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006786 privilegedPackages.add(pkgInfo.packageName);
6787 }
6788 }
6789 }
6790 }
6791 return privilegedPackages;
6792 }
6793
chen xuf7e9fe82019-05-09 19:31:02 -07006794 @Override
6795 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006796 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6797
6798 final long identity = Binder.clearCallingIdentity();
6799
chen xuf7e9fe82019-05-09 19:31:02 -07006800 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006801 try {
6802 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6803 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6804 }
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006807 }
6808 return privilegedPackages;
6809 }
6810
Wink Savilleb564aae2014-10-23 10:18:09 -07006811 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006812 final Phone phone = getPhone(subId);
6813 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006814 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006815 return null;
6816 }
6817 String iccId = card.getIccId();
6818 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006819 return null;
6820 }
6821 return iccId;
6822 }
6823
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006824 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006825 public void setCallComposerStatus(int subId, int status) {
6826 enforceModifyPermission();
6827
6828 final long identity = Binder.clearCallingIdentity();
6829 try {
6830 Phone phone = getPhone(subId);
6831 if (phone != null) {
6832 Phone defaultPhone = phone.getImsPhone();
6833 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6834 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6835 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006836 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6837 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006838 }
6839 }
Shuo Qian284ae752020-12-22 19:10:14 -08006840 } catch (ImsException e) {
6841 throw new ServiceSpecificException(e.getCode());
6842 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006843 Binder.restoreCallingIdentity(identity);
6844 }
6845 }
6846
6847 @Override
6848 public int getCallComposerStatus(int subId) {
6849 enforceReadPrivilegedPermission("getCallComposerStatus");
6850
6851 final long identity = Binder.clearCallingIdentity();
6852 try {
6853 Phone phone = getPhone(subId);
6854 if (phone != null) {
6855 Phone defaultPhone = phone.getImsPhone();
6856 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6857 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6858 return imsPhone.getCallComposerStatus();
6859 }
6860 }
6861 } finally {
6862 Binder.restoreCallingIdentity(identity);
6863 }
6864 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6865 }
6866
6867 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006868 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6869 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006870 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006871 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 final long identity = Binder.clearCallingIdentity();
6874 try {
6875 final String iccId = getIccId(subId);
6876 final Phone phone = getPhone(subId);
6877 if (phone == null) {
6878 return false;
6879 }
6880 final String subscriberId = phone.getSubscriberId();
6881
6882 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006883 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006884 + subscriberId + " to " + number);
6885 }
6886
6887 if (TextUtils.isEmpty(iccId)) {
6888 return false;
6889 }
6890
6891 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6892
6893 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6894 if (alphaTag == null) {
6895 editor.remove(alphaTagPrefKey);
6896 } else {
6897 editor.putString(alphaTagPrefKey, alphaTag);
6898 }
6899
6900 // Record both the line number and IMSI for this ICCID, since we need to
6901 // track all merged IMSIs based on line number
6902 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6903 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6904 if (number == null) {
6905 editor.remove(numberPrefKey);
6906 editor.remove(subscriberPrefKey);
6907 } else {
6908 editor.putString(numberPrefKey, number);
6909 editor.putString(subscriberPrefKey, subscriberId);
6910 }
6911
6912 editor.commit();
6913 return true;
6914 } finally {
6915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006916 }
Derek Tan7226c842014-07-02 17:42:23 -07006917 }
6918
6919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006920 public String getLine1NumberForDisplay(int subId, String callingPackage,
6921 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006922 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006924 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006925 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006926 return null;
6927 }
Derek Tan97ebb422014-09-05 16:55:38 -07006928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 final long identity = Binder.clearCallingIdentity();
6930 try {
6931 String iccId = getIccId(subId);
6932 if (iccId != null) {
6933 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6934 if (DBG_MERGE) {
6935 log("getLine1NumberForDisplay returning "
6936 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6937 }
6938 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006939 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6941 return null;
6942 } finally {
6943 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006944 }
Derek Tan7226c842014-07-02 17:42:23 -07006945 }
6946
6947 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006948 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6949 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006950 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006951 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006952 return null;
6953 }
Derek Tan97ebb422014-09-05 16:55:38 -07006954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 final long identity = Binder.clearCallingIdentity();
6956 try {
6957 String iccId = getIccId(subId);
6958 if (iccId != null) {
6959 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6960 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6961 }
6962 return null;
6963 } finally {
6964 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006965 }
Derek Tan7226c842014-07-02 17:42:23 -07006966 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006967
6968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006969 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6970 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006971 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6972 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006973 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006974 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006975 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006976 return null;
6977 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006978
Jordan Liub49b04b2019-05-06 14:45:15 -07006979 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6980 // the process, where TelephonyManager was instantiated.
6981 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006982 final long identity = Binder.clearCallingIdentity();
6983 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006984 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985 final TelephonyManager tele = TelephonyManager.from(context);
6986 final SubscriptionManager sub = SubscriptionManager.from(context);
6987
6988 // Figure out what subscribers are currently active
6989 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990
Jordan Liub49b04b2019-05-06 14:45:15 -07006991 // Only consider subs which match the current subId
6992 // This logic can be simplified. See b/131189269 for progress.
6993 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006994 activeSubscriberIds.add(tele.getSubscriberId(subId));
6995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996
6997 // First pass, find a number override for an active subscriber
6998 String mergeNumber = null;
6999 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7000 for (String key : prefs.keySet()) {
7001 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7002 final String subscriberId = (String) prefs.get(key);
7003 if (activeSubscriberIds.contains(subscriberId)) {
7004 final String iccId = key.substring(
7005 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7006 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7007 mergeNumber = (String) prefs.get(numberKey);
7008 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007009 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 + " for active subscriber " + subscriberId);
7011 }
7012 if (!TextUtils.isEmpty(mergeNumber)) {
7013 break;
7014 }
7015 }
7016 }
7017 }
7018
7019 // Shortcut when no active merged subscribers
7020 if (TextUtils.isEmpty(mergeNumber)) {
7021 return null;
7022 }
7023
7024 // Second pass, find all subscribers under that line override
7025 final ArraySet<String> result = new ArraySet<>();
7026 for (String key : prefs.keySet()) {
7027 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7028 final String number = (String) prefs.get(key);
7029 if (mergeNumber.equals(number)) {
7030 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7031 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7032 final String subscriberId = (String) prefs.get(subscriberKey);
7033 if (!TextUtils.isEmpty(subscriberId)) {
7034 result.add(subscriberId);
7035 }
7036 }
7037 }
7038 }
7039
7040 final String[] resultArray = result.toArray(new String[result.size()]);
7041 Arrays.sort(resultArray);
7042 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007043 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7045 }
7046 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007047 } finally {
7048 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007049 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007050 }
7051
7052 @Override
zoey chen38003472019-12-13 17:16:31 +08007053 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7054 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007055
7056 final long identity = Binder.clearCallingIdentity();
7057 try {
7058 final TelephonyManager telephonyManager = mApp.getSystemService(
7059 TelephonyManager.class);
7060 String subscriberId = telephonyManager.getSubscriberId(subId);
7061 if (subscriberId == null) {
7062 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007063 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007064 + subId);
7065 }
7066 return null;
7067 }
7068
7069 final SubscriptionInfo info = SubscriptionController.getInstance()
7070 .getSubscriptionInfo(subId);
7071 final ParcelUuid groupUuid = info.getGroupUuid();
7072 // If it doesn't belong to any group, return just subscriberId of itself.
7073 if (groupUuid == null) {
7074 return new String[]{subscriberId};
7075 }
7076
7077 // Get all subscriberIds from the group.
7078 final List<String> mergedSubscriberIds = new ArrayList<>();
7079 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007080 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007081 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007082 for (SubscriptionInfo subInfo : groupInfos) {
7083 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7084 if (subscriberId != null) {
7085 mergedSubscriberIds.add(subscriberId);
7086 }
7087 }
7088
7089 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7090 } finally {
7091 Binder.restoreCallingIdentity(identity);
7092
7093 }
7094 }
7095
7096 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007097 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007098 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007099 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100
7101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 final Phone phone = getPhone(subId);
7104 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7105 } finally {
7106 Binder.restoreCallingIdentity(identity);
7107 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007108 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007109
7110 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007111 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007112 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7113 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007114 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7115 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116
7117 final long identity = Binder.clearCallingIdentity();
7118 try {
7119 final Phone phone = getPhone(subId);
7120 if (phone == null) {
7121 return false;
7122 }
7123 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7124 cdmaNonRoamingList);
7125 } finally {
7126 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007127 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007128 }
7129
7130 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007131 @Deprecated
7132 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7133 enforceModifyPermission();
7134
7135 int returnValue = 0;
7136 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007137 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007138 if(result.exception == null) {
7139 if (result.result != null) {
7140 byte[] responseData = (byte[])(result.result);
7141 if(responseData.length > oemResp.length) {
7142 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7143 responseData.length + "bytes. Buffer Size is " +
7144 oemResp.length + "bytes.");
7145 }
7146 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7147 returnValue = responseData.length;
7148 }
7149 } else {
7150 CommandException ex = (CommandException) result.exception;
7151 returnValue = ex.getCommandError().ordinal();
7152 if(returnValue > 0) returnValue *= -1;
7153 }
7154 } catch (RuntimeException e) {
7155 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7156 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7157 if(returnValue > 0) returnValue *= -1;
7158 }
7159
7160 return returnValue;
7161 }
7162
7163 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007164 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007165 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007166 try {
7167 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007168 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007169 mApp, phone.getSubId(), "getRadioAccessFamily");
7170 } catch (SecurityException e) {
7171 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7172 throw e;
7173 }
chen xub97461a2018-10-26 14:17:57 -07007174 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007175 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007176 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007177 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178 final long identity = Binder.clearCallingIdentity();
7179 try {
chen xub97461a2018-10-26 14:17:57 -07007180 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007181 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007182 mApp, phone.getSubId(), "getRadioAccessFamily");
7183 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
chen xub97461a2018-10-26 14:17:57 -07007187 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007188 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007189
7190 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007191 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007192 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007193 try {
7194 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7195 Binder.getCallingUid())) {
7196 throw new SecurityException("Package uid and package name do not match: "
7197 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7198 }
7199 } catch (PackageManager.NameNotFoundException e) {
7200 throw new SecurityException("Package name invalid:" + callingPackage);
7201 }
7202 RoleManager rm = mApp.getSystemService(RoleManager.class);
7203 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7204 if (!dialerRoleHolders.contains(callingPackage)) {
7205 throw new SecurityException("App must be the dialer role holder to"
7206 + " upload a call composer pic");
7207 }
7208
7209 Executors.newSingleThreadExecutor().execute(() -> {
7210 ByteArrayOutputStream output = new ByteArrayOutputStream(
7211 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7212 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7213 boolean readUntilEnd = false;
7214 int totalBytesRead = 0;
7215 byte[] buffer = new byte[16 * 1024];
7216 while (true) {
7217 int numRead;
7218 try {
7219 numRead = input.read(buffer);
7220 } catch (IOException e) {
7221 try {
7222 fd.checkError();
7223 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7224 null);
7225 } catch (IOException e1) {
7226 // This means that the other side closed explicitly with an error. If this
7227 // happens, log and ignore.
7228 loge("Remote end of call composer picture pipe closed: " + e1);
7229 }
7230 break;
7231 }
7232 if (numRead == -1) {
7233 readUntilEnd = true;
7234 break;
7235 }
7236 totalBytesRead += numRead;
7237 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7238 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7239 try {
7240 input.close();
7241 } catch (IOException e) {
7242 // ignore
7243 }
7244 break;
7245 }
7246 output.write(buffer, 0, numRead);
7247 }
7248 // Generally, the remote end will close the file descriptors. The only case where we
7249 // close is above, where the picture size is too big.
7250
7251 try {
7252 fd.checkError();
7253 } catch (IOException e) {
7254 loge("Remote end for call composer closed with an error: " + e);
7255 return;
7256 }
7257
Hall Liuaa4211e2021-01-20 15:43:39 -08007258 if (!readUntilEnd) {
7259 loge("Did not finish reading entire image; aborting");
7260 return;
7261 }
Hall Liu82694d52020-12-11 18:22:04 -08007262
Hall Liuaa4211e2021-01-20 15:43:39 -08007263 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7264 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7265 new CallComposerPictureTransfer.Factory() {},
7266 imageData,
7267 (result) -> {
7268 if (result.first != null) {
7269 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7270 Bundle outputResult = new Bundle();
7271 outputResult.putParcelable(
7272 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7273 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7274 outputResult);
7275 } else {
7276 callback.send(result.second, null);
7277 }
7278 }
7279 );
Hall Liu82694d52020-12-11 18:22:04 -08007280 });
7281 }
7282
7283 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007284 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007285 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007287
7288 final long identity = Binder.clearCallingIdentity();
7289 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007290 ImsManager.getInstance(defaultPhone.getContext(),
7291 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007292 } finally {
7293 Binder.restoreCallingIdentity(identity);
7294 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007295 }
7296
7297 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007298 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007299 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7301 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007302 return false;
7303 }
Svet Ganovb320e182015-04-16 12:30:10 -07007304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 // Check the user preference and the system-level IMS setting. Even if the user has
7308 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7309 // In the long run, we may instead need to check if there exists a connection service
7310 // which can support video calling.
7311 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007312 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 return imsManager.isVtEnabledByPlatform()
7314 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7315 && imsManager.isVtEnabledByUser();
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007319 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007320
Andrew Leea1239f22015-03-02 17:44:07 -08007321 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007322 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7323 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007325 mApp, subId, callingPackage, callingFeatureId,
7326 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 return false;
7328 }
7329
7330 final long identity = Binder.clearCallingIdentity();
7331 try {
7332 CarrierConfigManager configManager =
7333 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007334 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
Andrew Leea1239f22015-03-02 17:44:07 -08007339 }
7340
7341 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007342 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007344 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 return false;
7346 }
7347
7348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 CarrierConfigManager configManager =
7351 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007352 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007353 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7354 } finally {
7355 Binder.restoreCallingIdentity(identity);
7356 }
Andrew Leea1239f22015-03-02 17:44:07 -08007357 }
7358
Andrew Lee9431b832015-03-09 18:46:45 -07007359 @Override
7360 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007361 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007362 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007363 }
7364
7365 @Override
7366 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 final long identity = Binder.clearCallingIdentity();
7368 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007369 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 } finally {
7371 Binder.restoreCallingIdentity(identity);
7372 }
Andrew Lee9431b832015-03-09 18:46:45 -07007373 }
7374
Hall Liuf6668912018-10-31 17:05:23 -07007375 /**
7376 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7377 * support for the feature and device firmware support.
7378 *
7379 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7380 */
7381 @Override
7382 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007384 final Phone phone = getPhone(subscriptionId);
7385 if (phone == null) {
7386 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7387 return false;
7388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007390 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7392 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007393 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394 return isCarrierSupported && isDeviceSupported;
7395 } finally {
7396 Binder.restoreCallingIdentity(identity);
7397 }
Hall Liu98187582018-01-22 19:15:32 -08007398 }
7399
Hall Liuf6668912018-10-31 17:05:23 -07007400 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007401 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7402 * RTT setting, will return true if the device and carrier both support RTT.
7403 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007404 */
7405 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 final long identity = Binder.clearCallingIdentity();
7407 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007408 boolean isRttSupported = isRttSupported(subscriptionId);
7409 boolean isUserRttSettingOn = Settings.Secure.getInt(
7410 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7411 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7412 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7413 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 } finally {
7415 Binder.restoreCallingIdentity(identity);
7416 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007417 }
7418
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007419 @Deprecated
7420 @Override
7421 public String getDeviceId(String callingPackage) {
7422 return getDeviceIdWithFeature(callingPackage, null);
7423 }
7424
Sanket Padawe7310cc72015-01-14 09:53:20 -08007425 /**
7426 * Returns the unique device ID of phone, for example, the IMEI for
7427 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7428 *
7429 * <p>Requires Permission:
7430 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7431 */
7432 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007433 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007434 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007435 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007436 return null;
7437 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007438 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007439 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007440 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007441 return null;
7442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443
7444 final long identity = Binder.clearCallingIdentity();
7445 try {
7446 return phone.getDeviceId();
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007450 }
7451
Ping Sunc67b7c22016-03-02 19:16:45 +08007452 /**
7453 * {@hide}
7454 * Returns the IMS Registration Status on a particular subid
7455 *
7456 * @param subId
7457 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007458 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007459 Phone phone = getPhone(subId);
7460 if (phone != null) {
7461 return phone.isImsRegistered();
7462 } else {
7463 return false;
7464 }
7465 }
7466
Santos Cordon7a1885b2015-02-03 11:15:19 -08007467 @Override
7468 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 final long identity = Binder.clearCallingIdentity();
7470 try {
7471 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7472 } finally {
7473 Binder.restoreCallingIdentity(identity);
7474 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007475 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007476
Tyler Gunnf70ed162019-04-03 15:28:53 -07007477 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007478 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007479 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007481 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007482 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7483 }
7484 final long identity = Binder.clearCallingIdentity();
7485 try {
7486 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
7490 }
7491
7492 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007493 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007494 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007495 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007496 mApp,
7497 subscriptionId,
7498 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007499 final long identity = Binder.clearCallingIdentity();
7500 try {
7501 Phone phone = getPhone(subscriptionId);
7502 if (phone == null) {
7503 return null;
7504 }
7505 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7506 } finally {
7507 Binder.restoreCallingIdentity(identity);
7508 }
7509 }
7510
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007511 /**
7512 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007513 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007514 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 final long identity = Binder.clearCallingIdentity();
7516 try {
7517 Phone phone = getPhone(subId);
7518 if (phone != null) {
7519 return phone.isWifiCallingEnabled();
7520 } else {
7521 return false;
7522 }
7523 } finally {
7524 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007525 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007526 }
7527
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007528 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007529 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007530 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007531 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007532 final long identity = Binder.clearCallingIdentity();
7533 try {
7534 Phone phone = getPhone(subId);
7535 if (phone != null) {
7536 return phone.isVideoEnabled();
7537 } else {
7538 return false;
7539 }
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007542 }
7543 }
7544
7545 /**
7546 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7547 * defined in {@link ImsRegistrationImplBase}.
7548 */
7549 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 Phone phone = getPhone(subId);
7553 if (phone != null) {
7554 return phone.getImsRegistrationTech();
7555 } else {
7556 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7557 }
7558 } finally {
7559 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007560 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007561 }
7562
Stuart Scott8eef64f2015-04-08 15:13:54 -07007563 @Override
7564 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007565 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007566 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7567 return;
7568 }
Kai Shif70f46f2021-03-03 13:59:46 -08007569 Phone defaultPhone = getDefaultPhone();
7570 if (defaultPhone != null) {
7571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7572 mApp, getDefaultPhone().getSubId(), "factoryReset");
7573 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007574 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007575
Svet Ganovcc087f82015-05-12 20:35:54 -07007576 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007577 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7578 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007579 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007580 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007581 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007582 Phone phone = getPhone(subId);
7583 if (phone != null) {
7584 SubscriptionManager.setSubscriptionProperty(subId,
7585 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7586 "user=" + RadioAccessFamily.getRafFromNetworkType(
7587 RILConstants.PREFERRED_NETWORK_MODE));
7588 phone.loadAllowedNetworksFromSubscriptionDatabase();
7589 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007590 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007591 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007592 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007593 // There has been issues when Sms raw table somehow stores orphan
7594 // fragments. They lead to garbled message when new fragments come
7595 // in and combined with those stale ones. In case this happens again,
7596 // user can reset all network settings which will clean up this table.
7597 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007598 // Clean up IMS settings as well here.
7599 int slotId = getSlotIndex(subId);
7600 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7601 ImsManager.getInstance(mApp, slotId).factoryReset();
7602 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007603
Kai Shif70f46f2021-03-03 13:59:46 -08007604 if (defaultPhone == null) {
7605 return;
7606 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007607 // Erase modem config if erase modem on network setting is enabled.
7608 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7609 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7610 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007611 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007612 }
Kai Shif70f46f2021-03-03 13:59:46 -08007613
7614 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007615 } finally {
7616 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007617 }
7618 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007619
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007620 private void cleanUpSmsRawTable(Context context) {
7621 ContentResolver resolver = context.getContentResolver();
7622 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7623 resolver.delete(uri, null, null);
7624 }
7625
Narayan Kamath1c496c22015-04-16 14:40:19 +01007626 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007627 public String getSimLocaleForSubscriber(int subId) {
7628 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7629 final Phone phone = getPhone(subId);
7630 if (phone == null) {
7631 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007632 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 final long identity = Binder.clearCallingIdentity();
7635 try {
chen xu5d3637b2019-01-21 23:31:38 -08007636 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007637 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007638 if (info == null) {
7639 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7640 return null;
7641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 // Try and fetch the locale from the carrier properties or from the SIM language
7643 // preferences (EF-PL and EF-LI)...
7644 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007646 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7647 if (localeFromDefaultSim != null) {
7648 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7649 if (DBG) log("Using locale from subId: " + subId + " locale: "
7650 + localeFromDefaultSim);
7651 return localeFromDefaultSim.toLanguageTag();
7652 } else {
7653 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 }
7655 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 // The SIM language preferences only store a language (e.g. fr = French), not an
7658 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7659 // the SIM and carrier preferences does not include a country we add the country
7660 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007661 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007663 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007664 return mccLocale.toLanguageTag();
7665 }
7666
7667 if (DBG) log("No locale found - returning null");
7668 return null;
7669 } finally {
7670 Binder.restoreCallingIdentity(identity);
7671 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007672 }
7673
7674 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007675 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007676 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007677 }
7678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007679 /**
7680 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7681 */
7682 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007683 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007684 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007685 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007686
Chenjie Yu1ba97252018-01-11 18:16:20 -08007687 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007688 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007689
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007690 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007691 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7692 * representing the state of the modem.
7693 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007694 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7695 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007696 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007697 */
7698 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007699 public void requestModemActivityInfo(ResultReceiver result) {
7700 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007701 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702
7703 final long identity = Binder.clearCallingIdentity();
7704 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007705 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706 } finally {
7707 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007708 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007709 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007710
Siddharth Rayb8114062018-06-17 15:02:38 -07007711 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7712 // less than total activity duration.
7713 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7714 if (info == null) {
7715 return false;
7716 }
7717 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007718 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7719 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7720
Siddharth Rayb8114062018-06-17 15:02:38 -07007721 return (info.isValid()
7722 && (info.getSleepTimeMillis() <= activityDurationMs)
7723 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007724 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007725 && (totalTxTimeMs <= activityDurationMs));
7726 }
7727
Jack Yu85bd38a2015-11-09 11:34:32 -08007728 /**
7729 * {@hide}
7730 * Returns the service state information on specified subscription.
7731 */
7732 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007733 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7734 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007736 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007737 return null;
7738 }
7739
Hall Liuf19c44f2018-11-27 14:38:17 -08007740 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7741 LocationAccessPolicy.checkLocationPermission(mApp,
7742 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7743 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007744 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007745 .setCallingPid(Binder.getCallingPid())
7746 .setCallingUid(Binder.getCallingUid())
7747 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007748 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007749 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007750 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7751 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007752 .build());
7753
7754 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7755 LocationAccessPolicy.checkLocationPermission(mApp,
7756 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7757 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007758 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007759 .setCallingPid(Binder.getCallingPid())
7760 .setCallingUid(Binder.getCallingUid())
7761 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007762 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007763 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007764 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7765 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007766 .build());
7767 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7768 boolean hasFinePermission =
7769 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7770 boolean hasCoarsePermission =
7771 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7772
Jack Yu479f40e2020-10-27 21:29:25 -07007773 final Phone phone = getPhone(subId);
7774 if (phone == null) {
7775 return null;
7776 }
7777
Jordan Liu0f2bc442020-11-18 16:47:37 -08007778 final long identity = Binder.clearCallingIdentity();
7779
Jack Yu479f40e2020-10-27 21:29:25 -07007780 boolean isCallingPackageDataService = phone.getDataServicePackages()
7781 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007782 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007783 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7784 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7785 Rlog.d(LOG_TAG,
7786 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7787 return null;
7788 }
7789
Hall Liuf19c44f2018-11-27 14:38:17 -08007790 ServiceState ss = phone.getServiceState();
7791
7792 // Scrub out the location info in ServiceState depending on what level of access
7793 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007794 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007795 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7796 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 } finally {
7798 Binder.restoreCallingIdentity(identity);
7799 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007800 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007801
7802 /**
7803 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7804 *
7805 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7806 * voicemail ringtone.
7807 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7808 * PhoneAccount.
7809 */
7810 @Override
7811 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 final long identity = Binder.clearCallingIdentity();
7813 try {
7814 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7815 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007816 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007817 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7820 } finally {
7821 Binder.restoreCallingIdentity(identity);
7822 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007823 }
7824
7825 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007826 * Sets the per-account voicemail ringtone.
7827 *
7828 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7829 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7830 *
7831 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7832 * voicemail ringtone.
7833 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7834 * PhoneAccount.
7835 */
7836 @Override
7837 public void setVoicemailRingtoneUri(String callingPackage,
7838 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007839 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007840 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007841 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7842 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7844 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7845 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847
7848 final long identity = Binder.clearCallingIdentity();
7849 try {
7850 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7851 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007852 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007853 }
7854 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7855 } finally {
7856 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007857 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007858 }
7859
7860 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007861 * Returns whether vibration is set for voicemail notification in Phone settings.
7862 *
7863 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7864 * voicemail vibration setting.
7865 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7866 */
7867 @Override
7868 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869 final long identity = Binder.clearCallingIdentity();
7870 try {
7871 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7872 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007873 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007874 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007875
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007876 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7877 } finally {
7878 Binder.restoreCallingIdentity(identity);
7879 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007880 }
7881
Youhan Wange64578a2016-05-02 15:32:42 -07007882 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007883 * Sets the per-account voicemail vibration.
7884 *
7885 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7886 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7887 *
7888 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7889 * voicemail vibration setting.
7890 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7891 * specific PhoneAccount.
7892 */
7893 @Override
7894 public void setVoicemailVibrationEnabled(String callingPackage,
7895 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007896 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007897 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007898 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7899 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7901 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7902 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007903 }
7904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 final long identity = Binder.clearCallingIdentity();
7906 try {
7907 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7908 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007909 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910 }
7911 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007914 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007915 }
7916
7917 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007918 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7919 *
7920 * @throws SecurityException if the caller does not have the required permission
7921 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007922 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007923 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007924 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007925 }
7926
7927 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007928 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7929 * permission.
7930 *
7931 * @throws SecurityException if the caller does not have the required permission
7932 */
7933 private void enforceSendSmsPermission() {
7934 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7935 }
7936
7937 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007938 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007939 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007940 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007941 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007942 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943 final long identity = Binder.clearCallingIdentity();
7944 try {
7945 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007946 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007947 if (componentName == null) {
7948 throw new SecurityException(
7949 "Caller not current active visual voicemail package[null]");
7950 }
7951 String vvmPackage = componentName.getPackageName();
7952 if (!callingPackage.equals(vvmPackage)) {
7953 throw new SecurityException("Caller not current active visual voicemail package["
7954 + vvmPackage + "]");
7955 }
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007958 }
7959 }
7960
7961 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007962 * Return the application ID for the app type.
7963 *
7964 * @param subId the subscription ID that this request applies to.
7965 * @param appType the uicc app type.
7966 * @return Application ID for specificied app type, or null if no uicc.
7967 */
7968 @Override
7969 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007970 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007971 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007972
7973 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007974 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007975 if (phone == null) {
7976 return null;
7977 }
7978 String aid = null;
7979 try {
7980 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7981 .getApplicationByType(appType).getAid();
7982 } catch (Exception e) {
7983 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7984 }
7985 return aid;
7986 } finally {
7987 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007988 }
Youhan Wange64578a2016-05-02 15:32:42 -07007989 }
7990
Youhan Wang4001d252016-05-11 10:29:41 -07007991 /**
7992 * Return the Electronic Serial Number.
7993 *
7994 * @param subId the subscription ID that this request applies to.
7995 * @return ESN or null if error.
7996 */
7997 @Override
7998 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007999 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008000 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001
8002 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008003 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004 if (phone == null) {
8005 return null;
8006 }
8007 String esn = null;
8008 try {
8009 esn = phone.getEsn();
8010 } catch (Exception e) {
8011 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8012 }
8013 return esn;
8014 } finally {
8015 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008016 }
Youhan Wang4001d252016-05-11 10:29:41 -07008017 }
8018
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008019 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008020 * Return the Preferred Roaming List Version.
8021 *
8022 * @param subId the subscription ID that this request applies to.
8023 * @return PRLVersion or null if error.
8024 */
8025 @Override
8026 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008027 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008028 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029
8030 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008031 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032 if (phone == null) {
8033 return null;
8034 }
8035 String cdmaPrlVersion = null;
8036 try {
8037 cdmaPrlVersion = phone.getCdmaPrlVersion();
8038 } catch (Exception e) {
8039 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8040 }
8041 return cdmaPrlVersion;
8042 } finally {
8043 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008044 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008045 }
8046
8047 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008048 * Get snapshot of Telephony histograms
8049 * @return List of Telephony histograms
8050 * @hide
8051 */
8052 @Override
8053 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8055 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056
8057 final long identity = Binder.clearCallingIdentity();
8058 try {
8059 return RIL.getTelephonyRILTimingHistograms();
8060 } finally {
8061 Binder.restoreCallingIdentity(identity);
8062 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008063 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008064
8065 /**
8066 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008067 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8068 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008069 * Require system privileges. In the future we may add this to carrier APIs.
8070 *
Michele Berionne482f8202018-11-27 18:57:59 -08008071 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008072 */
8073 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008074 @TelephonyManager.SetCarrierRestrictionResult
8075 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008076 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008077 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008078
Michele Berionne482f8202018-11-27 18:57:59 -08008079 if (carrierRestrictionRules == null) {
8080 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008081 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008083 final long identity = Binder.clearCallingIdentity();
8084 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008085 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008086 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008087 } finally {
8088 Binder.restoreCallingIdentity(identity);
8089 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008090 }
8091
8092 /**
8093 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008094 * Get the allowed carrier list and the excluded carrier list, including the priority between
8095 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008096 * Require system privileges. In the future we may add this to carrier APIs.
8097 *
Michele Berionne482f8202018-11-27 18:57:59 -08008098 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008099 */
8100 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008101 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008102 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008103 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104
8105 final long identity = Binder.clearCallingIdentity();
8106 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008107 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8108 if (response instanceof CarrierRestrictionRules) {
8109 return (CarrierRestrictionRules) response;
8110 }
8111 // Response is an Exception of some kind,
8112 // which is signalled to the user as a NULL retval
8113 return null;
8114 } catch (Exception e) {
8115 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8116 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008117 } finally {
8118 Binder.restoreCallingIdentity(identity);
8119 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008120 }
8121
fionaxu59545b42016-05-25 15:53:37 -07008122 /**
fionaxu59545b42016-05-25 15:53:37 -07008123 * Action set from carrier signalling broadcast receivers to enable/disable radio
8124 * @param subId the subscription ID that this action applies to.
8125 * @param enabled control enable or disable radio.
8126 * {@hide}
8127 */
8128 @Override
8129 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8130 enforceModifyPermission();
8131 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132
8133 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008134 if (phone == null) {
8135 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8136 return;
8137 }
8138 try {
8139 phone.carrierActionSetRadioEnabled(enabled);
8140 } catch (Exception e) {
8141 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008142 } finally {
8143 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008144 }
8145 }
8146
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008147 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008148 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8149 * network status based on which carrier apps could apply actions accordingly,
8150 * enable/disable default url handler for example.
8151 *
8152 * @param subId the subscription ID that this action applies to.
8153 * @param report control start/stop reporting the default network status.
8154 * {@hide}
8155 */
8156 @Override
8157 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8158 enforceModifyPermission();
8159 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008160
8161 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008162 if (phone == null) {
8163 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8164 return;
8165 }
8166 try {
8167 phone.carrierActionReportDefaultNetworkStatus(report);
8168 } catch (Exception e) {
8169 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 } finally {
8171 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008172 }
8173 }
8174
8175 /**
fionaxud9622282017-07-17 17:51:30 -07008176 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8177 * @param subId the subscription ID that this action applies to.
8178 * {@hide}
8179 */
8180 @Override
8181 public void carrierActionResetAll(int subId) {
8182 enforceModifyPermission();
8183 final Phone phone = getPhone(subId);
8184 if (phone == null) {
8185 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8186 return;
8187 }
8188 try {
8189 phone.carrierActionResetAll();
8190 } catch (Exception e) {
8191 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8192 }
8193 }
8194
8195 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008196 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8197 * bug report is being generated.
8198 */
8199 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008200 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008201 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8202 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008203 writer.println("Permission Denial: can't dump Phone from pid="
8204 + Binder.getCallingPid()
8205 + ", uid=" + Binder.getCallingUid()
8206 + "without permission "
8207 + android.Manifest.permission.DUMP);
8208 return;
8209 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008210 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008211 }
Jack Yueb89b242016-06-22 13:27:47 -07008212
Brad Ebingerdac2f002018-04-03 15:17:52 -07008213 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008214 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8215 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8216 @NonNull String[] args) {
8217 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8218 this, in.getFileDescriptor(), out.getFileDescriptor(),
8219 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008220 }
8221
Jack Yueb89b242016-06-22 13:27:47 -07008222 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008223 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008224 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008225 * @param reason the reason the data enable change is taking place
8226 * @param enabled True if enabling the data, otherwise disabling.
8227 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008228 */
8229 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008230 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008231 boolean enabled) {
8232 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8233 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8234 try {
8235 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008236 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008237 } catch (SecurityException se) {
8238 enforceModifyPermission();
8239 }
8240 } else {
8241 enforceModifyPermission();
8242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243
8244 final long identity = Binder.clearCallingIdentity();
8245 try {
8246 Phone phone = getPhone(subId);
8247 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008248 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8249 phone.carrierActionSetMeteredApnsEnabled(enabled);
8250 } else {
8251 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253 }
8254 } finally {
8255 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008256 }
8257 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008258
8259 /**
8260 * Get Client request stats
8261 * @return List of Client Request Stats
8262 * @hide
8263 */
8264 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008265 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8266 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008268 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008269 return null;
8270 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008271 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 final long identity = Binder.clearCallingIdentity();
8274 try {
8275 if (phone != null) {
8276 return phone.getClientRequestStats();
8277 }
8278
8279 return null;
8280 } finally {
8281 Binder.restoreCallingIdentity(identity);
8282 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008283 }
8284
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008285 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008286 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008287 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008288 }
Jack Yueb4124c2017-02-16 15:32:43 -08008289
8290 /**
Grace Chen70990072017-03-24 17:21:30 -07008291 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008292 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008293 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008294 * @param state State of SIM (power down, power up, pass through)
8295 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8296 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8297 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008298 *
8299 **/
8300 @Override
Grace Chen70990072017-03-24 17:21:30 -07008301 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008302 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008303 Phone phone = PhoneFactory.getPhone(slotIndex);
8304
vagdeviaf9a5b92018-08-15 16:01:53 -07008305 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008307 final long identity = Binder.clearCallingIdentity();
8308 try {
8309 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008310 phone.setSimPowerState(state, null, workSource);
8311 }
8312 } finally {
8313 Binder.restoreCallingIdentity(identity);
8314 }
8315 }
8316
8317 /**
8318 * Set SIM card power state.
8319 *
8320 * @param slotIndex SIM slot id.
8321 * @param state State of SIM (power down, power up, pass through)
8322 * @param callback callback to trigger after success or failure
8323 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8324 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8325 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8326 *
8327 **/
8328 @Override
8329 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8330 IIntegerConsumer callback) {
8331 enforceModifyPermission();
8332 Phone phone = PhoneFactory.getPhone(slotIndex);
8333
8334 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8335
8336 final long identity = Binder.clearCallingIdentity();
8337 try {
8338 if (phone != null) {
8339 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8340 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008341 }
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008344 }
8345 }
Shuo Qiandd210312017-04-12 22:11:33 +00008346
Tyler Gunn65d45c22017-06-05 11:22:26 -07008347 private boolean isUssdApiAllowed(int subId) {
8348 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008349 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008350 if (configManager == null) {
8351 return false;
8352 }
8353 PersistableBundle pb = configManager.getConfigForSubId(subId);
8354 if (pb == null) {
8355 return false;
8356 }
8357 return pb.getBoolean(
8358 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8359 }
8360
Shuo Qiandd210312017-04-12 22:11:33 +00008361 /**
8362 * Check if phone is in emergency callback mode
8363 * @return true if phone is in emergency callback mode
8364 * @param subId sub id
8365 */
goneil9c5f4872017-12-05 14:07:56 -08008366 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008367 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008368 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008369 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008370
8371 final long identity = Binder.clearCallingIdentity();
8372 try {
8373 if (phone != null) {
8374 return phone.isInEcm();
8375 } else {
8376 return false;
8377 }
8378 } finally {
8379 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008380 }
8381 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008382
8383 /**
8384 * Get the current signal strength information for the given subscription.
8385 * Because this information is not updated when the device is in a low power state
8386 * it should not be relied-upon to be current.
8387 * @param subId Subscription index
8388 * @return the most recent cached signal strength info from the modem
8389 */
8390 @Override
8391 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008392 final long identity = Binder.clearCallingIdentity();
8393 try {
8394 Phone p = getPhone(subId);
8395 if (p == null) {
8396 return null;
8397 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008398
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008399 return p.getSignalStrength();
8400 } finally {
8401 Binder.restoreCallingIdentity(identity);
8402 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008403 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008404
Pengquan Meng77b7f132018-08-22 14:49:57 -07008405 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008406 * Get the current modem radio state for the given slot.
8407 * @param slotIndex slot index.
8408 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008409 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008410 * @return the current radio power state from the modem
8411 */
8412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008413 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008414 Phone phone = PhoneFactory.getPhone(slotIndex);
8415 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8417 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008418 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8419 }
8420
8421 final long identity = Binder.clearCallingIdentity();
8422 try {
8423 return phone.getRadioPowerState();
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
8427 }
8428 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8429 }
8430
8431 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008432 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8433 *
8434 * <p>Requires one of the following permissions:
8435 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8436 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8437 * privileges.
8438 *
8439 * @param subId subscription id
8440 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8441 * {@code false}.
8442 */
8443 @Override
8444 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008445 try {
8446 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8447 null);
8448 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008449 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008450 mApp, subId, "isDataRoamingEnabled");
8451 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008452
Pengquan Menga1bb6272018-09-06 09:59:22 -07008453 boolean isEnabled = false;
8454 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008455 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008456 Phone phone = getPhone(subId);
8457 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008458 } finally {
8459 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008460 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008461 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008462 }
8463
8464
8465 /**
8466 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8467 *
8468 * <p> Requires permission:
8469 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8470 * privileges.
8471 *
8472 * @param subId subscription id
8473 * @param isEnabled {@code true} means enable, {@code false} means disable.
8474 */
8475 @Override
8476 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8478 mApp, subId, "setDataRoamingEnabled");
8479
Pengquan Menga1bb6272018-09-06 09:59:22 -07008480 final long identity = Binder.clearCallingIdentity();
8481 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008482 Phone phone = getPhone(subId);
8483 if (phone != null) {
8484 phone.setDataRoamingEnabled(isEnabled);
8485 }
8486 } finally {
8487 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008488 }
8489 }
8490
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008491 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008492 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008493 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008494 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008495 mApp, subId, "isManualNetworkSelectionAllowed");
8496
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008497 boolean isAllowed = true;
8498 final long identity = Binder.clearCallingIdentity();
8499 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008500 Phone phone = getPhone(subId);
8501 if (phone != null) {
8502 isAllowed = phone.isCspPlmnEnabled();
8503 }
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
8506 }
8507 return isAllowed;
8508 }
8509
8510 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008511 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008512 // Verify that tha callingPackage belongs to the calling UID
8513 mApp.getSystemService(AppOpsManager.class)
8514 .checkPackage(Binder.getCallingUid(), callingPackage);
8515
Jordan Liu1e142fc2019-04-22 15:10:43 -07008516 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008517 try {
8518 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008519 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008520 } catch (SecurityException e) {
8521 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8522 // has carrier privileges on an active UICC
8523 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8524 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008525 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008526 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008527 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008528
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008531 UiccController uiccController = UiccController.getInstance();
8532 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008533 if (hasReadPermission) {
8534 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008535 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008536
8537 // Remove private info if the caller doesn't have access
8538 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8539 for (UiccCardInfo cardInfo : cardInfos) {
8540 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8541 // is available
8542 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8543 if (card == null || card.getUiccProfile() == null) {
8544 // assume no access if the card or profile is unavailable
8545 filteredInfos.add(cardInfo.getUnprivileged());
8546 continue;
8547 }
8548 UiccProfile profile = card.getUiccProfile();
8549 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8550 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8551 filteredInfos.add(cardInfo);
8552 } else {
8553 filteredInfos.add(cardInfo.getUnprivileged());
8554 }
8555 }
8556 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008557 } finally {
8558 Binder.restoreCallingIdentity(identity);
8559 }
8560 }
8561
8562 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008563 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008564 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008566 final long identity = Binder.clearCallingIdentity();
8567 try {
8568 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8569 if (slots == null) {
8570 Rlog.i(LOG_TAG, "slots is null.");
8571 return null;
8572 }
8573
8574 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8575 for (int i = 0; i < slots.length; i++) {
8576 UiccSlot slot = slots[i];
8577 if (slot == null) {
8578 continue;
8579 }
8580
Jordan Liu7be7e652019-05-06 18:55:02 +00008581 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008582 UiccCard card = slot.getUiccCard();
8583 if (card != null) {
8584 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008585 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008586 cardId = slot.getEid();
8587 if (TextUtils.isEmpty(cardId)) {
8588 cardId = slot.getIccId();
8589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008590 }
8591
Jordan Liu857451f2019-05-09 16:35:35 -07008592 if (cardId != null) {
8593 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8594 // if cardId is an EID, it's all digits so this is fine
8595 cardId = IccUtils.stripTrailingFs(cardId);
8596 }
8597
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008598 int cardState = 0;
8599 switch (slot.getCardState()) {
8600 case CARDSTATE_ABSENT:
8601 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8602 break;
8603 case CARDSTATE_PRESENT:
8604 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8605 break;
8606 case CARDSTATE_ERROR:
8607 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8608 break;
8609 case CARDSTATE_RESTRICTED:
8610 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8611 break;
8612 default:
8613 break;
8614
8615 }
8616
8617 infos[i] = new UiccSlotInfo(
8618 slot.isActive(),
8619 slot.isEuicc(),
8620 cardId,
8621 cardState,
8622 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008623 slot.isExtendedApduSupported(),
8624 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008625 }
8626 return infos;
8627 } finally {
8628 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008629 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008630 }
8631
8632 @Override
8633 public boolean switchSlots(int[] physicalSlots) {
8634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008635
8636 final long identity = Binder.clearCallingIdentity();
8637 try {
8638 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8639 } finally {
8640 Binder.restoreCallingIdentity(identity);
8641 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008642 }
Jack Yu4c988042018-02-27 15:30:01 -08008643
8644 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008645 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008646 final long identity = Binder.clearCallingIdentity();
8647 try {
8648 return UiccController.getInstance().getCardIdForDefaultEuicc();
8649 } finally {
8650 Binder.restoreCallingIdentity(identity);
8651 }
8652 }
8653
Pengquan Meng85728fb2018-03-12 16:31:21 -07008654 /**
goneil47ffb6e2018-04-06 15:40:58 -07008655 * A test API to reload the UICC profile.
8656 *
8657 * <p>Requires that the calling app has permission
8658 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8659 * @hide
8660 */
8661 @Override
8662 public void refreshUiccProfile(int subId) {
8663 enforceModifyPermission();
8664
8665 final long identity = Binder.clearCallingIdentity();
8666 try {
8667 Phone phone = getPhone(subId);
8668 if (phone == null) {
8669 return;
8670 }
8671 UiccCard uiccCard = phone.getUiccCard();
8672 if (uiccCard == null) {
8673 return;
8674 }
8675 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8676 if (uiccProfile == null) {
8677 return;
8678 }
8679 uiccProfile.refresh();
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
8684
8685 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008686 * Returns false if the mobile data is disabled by default, otherwise return true.
8687 */
8688 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008689 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008690 }
8691
8692 /**
8693 * Returns true if the data roaming is enabled by default, i.e the system property
8694 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8695 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8696 */
8697 private boolean getDefaultDataRoamingEnabled(int subId) {
8698 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008699 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008700 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008701 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8702 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8703 return isDataRoamingEnabled;
8704 }
8705
8706 /**
8707 * Returns the default network type for the given {@code subId}, if the default network type is
8708 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8709 */
8710 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008711 List<Integer> list = TelephonyProperties.default_network();
8712 int phoneId = mSubscriptionController.getPhoneId(subId);
8713 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8714 return list.get(phoneId);
8715 }
8716 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008717 }
fionaxua13278b2018-03-21 00:08:13 -07008718
8719 @Override
8720 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008721 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008723
8724 final long identity = Binder.clearCallingIdentity();
8725 try {
8726 final Phone phone = getPhone(subId);
8727 if (phone == null) {
8728 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8729 return;
8730 }
chen xueaba88a2019-03-15 13:15:10 -07008731 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8732 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008733 if (carrierPrivilegeRules == null) {
8734 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8735 } else {
8736 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008738 } finally {
8739 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008740 }
fionaxua13278b2018-03-21 00:08:13 -07008741 }
8742
8743 @Override
8744 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008745 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008746
8747 final long identity = Binder.clearCallingIdentity();
8748 try {
8749 final Phone phone = getPhone(subId);
8750 if (phone == null) {
8751 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8752 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8753 }
8754 return phone.getCarrierIdListVersion();
8755 } finally {
8756 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008757 }
fionaxua13278b2018-03-21 00:08:13 -07008758 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008759
8760 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008761 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8762 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008764 mApp, subId, callingPackage, callingFeatureId,
8765 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008766 return -1;
8767 }
8768
8769 final long identity = Binder.clearCallingIdentity();
8770 try {
8771 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8772 } finally {
8773 Binder.restoreCallingIdentity(identity);
8774 }
8775 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008776
8777 @Override
8778 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008779 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008780 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008781 mApp, subId, "getCdmaRoamingMode");
8782
8783 final long identity = Binder.clearCallingIdentity();
8784 try {
8785 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8786 } finally {
8787 Binder.restoreCallingIdentity(identity);
8788 }
8789 }
8790
8791 @Override
8792 public boolean setCdmaRoamingMode(int subId, int mode) {
8793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8794 mApp, subId, "setCdmaRoamingMode");
8795
8796 final long identity = Binder.clearCallingIdentity();
8797 try {
8798 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
8802 }
8803
8804 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008805 public int getCdmaSubscriptionMode(int subId) {
8806 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008807 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008808 mApp, subId, "getCdmaSubscriptionMode");
8809
8810 final long identity = Binder.clearCallingIdentity();
8811 try {
8812 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8813 } finally {
8814 Binder.restoreCallingIdentity(identity);
8815 }
8816 }
8817
8818 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008819 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8821 mApp, subId, "setCdmaSubscriptionMode");
8822
8823 final long identity = Binder.clearCallingIdentity();
8824 try {
8825 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8826 } finally {
8827 Binder.restoreCallingIdentity(identity);
8828 }
8829 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008830
sqianc5eccab2018-10-19 18:46:41 -07008831 @Override
sqian8c685422019-02-22 15:55:18 -08008832 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008833 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008835 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8836 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008837 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8838 }
8839 final long identity = Binder.clearCallingIdentity();
8840 try {
sqian854d44b2018-12-12 16:48:18 -08008841 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8842 for (Phone phone: PhoneFactory.getPhones()) {
8843 if (phone.getEmergencyNumberTracker() != null
8844 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8845 emergencyNumberListInternal.put(
8846 phone.getSubId(),
8847 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8848 }
sqian11b7a0e2018-12-05 18:48:28 -08008849 }
sqian854d44b2018-12-12 16:48:18 -08008850 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008851 } finally {
8852 Binder.restoreCallingIdentity(identity);
8853 }
sqianc5eccab2018-10-19 18:46:41 -07008854 }
8855
8856 @Override
sqian8c685422019-02-22 15:55:18 -08008857 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008858 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008859 if (!exactMatch) {
8860 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008861 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008862 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008863 }
8864 final long identity = Binder.clearCallingIdentity();
8865 try {
sqian854d44b2018-12-12 16:48:18 -08008866 for (Phone phone: PhoneFactory.getPhones()) {
8867 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008868 && phone.getEmergencyNumberTracker()
8869 .isEmergencyNumber(number, exactMatch)) {
8870 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008871 }
sqian11b7a0e2018-12-05 18:48:28 -08008872 }
8873 return false;
8874 } finally {
8875 Binder.restoreCallingIdentity(identity);
8876 }
8877 }
8878
sqianf4ca7ed2019-01-15 18:32:07 -08008879 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008880 * Start emergency callback mode for GsmCdmaPhone for testing.
8881 */
8882 @Override
8883 public void startEmergencyCallbackMode() {
8884 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8885 "startEmergencyCallbackMode");
8886 enforceModifyPermission();
8887 final long identity = Binder.clearCallingIdentity();
8888 try {
8889 for (Phone phone : PhoneFactory.getPhones()) {
8890 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8891 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8892 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8893 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8894 gsmCdmaPhone.obtainMessage(
8895 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8896 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8897 }
8898 }
8899 } finally {
8900 Binder.restoreCallingIdentity(identity);
8901 }
8902 }
8903
8904 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008905 * Update emergency number list for test mode.
8906 */
8907 @Override
8908 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8909 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8910 "updateEmergencyNumberListTestMode");
8911
8912 final long identity = Binder.clearCallingIdentity();
8913 try {
8914 for (Phone phone: PhoneFactory.getPhones()) {
8915 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8916 if (tracker != null) {
8917 tracker.executeEmergencyNumberTestModeCommand(action, num);
8918 }
8919 }
8920 } finally {
8921 Binder.restoreCallingIdentity(identity);
8922 }
8923 }
8924
8925 /**
8926 * Get the full emergency number list for test mode.
8927 */
8928 @Override
8929 public List<String> getEmergencyNumberListTestMode() {
8930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8931 "getEmergencyNumberListTestMode");
8932
8933 final long identity = Binder.clearCallingIdentity();
8934 try {
8935 Set<String> emergencyNumbers = new HashSet<>();
8936 for (Phone phone: PhoneFactory.getPhones()) {
8937 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8938 if (tracker != null) {
8939 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8940 emergencyNumbers.add(num.getNumber());
8941 }
8942 }
8943 }
8944 return new ArrayList<>(emergencyNumbers);
8945 } finally {
8946 Binder.restoreCallingIdentity(identity);
8947 }
8948 }
8949
chen xud6b45bd2018-10-30 22:27:10 -07008950 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008951 public int getEmergencyNumberDbVersion(int subId) {
8952 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8953
8954 final long identity = Binder.clearCallingIdentity();
8955 try {
8956 final Phone phone = getPhone(subId);
8957 if (phone == null) {
8958 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8959 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8960 }
8961 return phone.getEmergencyNumberDbVersion();
8962 } finally {
8963 Binder.restoreCallingIdentity(identity);
8964 }
8965 }
8966
8967 @Override
8968 public void notifyOtaEmergencyNumberDbInstalled() {
8969 enforceModifyPermission();
8970
8971 final long identity = Binder.clearCallingIdentity();
8972 try {
8973 for (Phone phone: PhoneFactory.getPhones()) {
8974 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8975 if (tracker != null) {
8976 tracker.updateOtaEmergencyNumberDatabase();
8977 }
8978 }
8979 } finally {
8980 Binder.restoreCallingIdentity(identity);
8981 }
8982 }
8983
8984 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008985 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008986 enforceActiveEmergencySessionPermission();
8987
8988 final long identity = Binder.clearCallingIdentity();
8989 try {
8990 for (Phone phone: PhoneFactory.getPhones()) {
8991 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8992 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008993 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8994 }
8995 }
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
9000
9001 @Override
9002 public void resetOtaEmergencyNumberDbFilePath() {
9003 enforceActiveEmergencySessionPermission();
9004
9005 final long identity = Binder.clearCallingIdentity();
9006 try {
9007 for (Phone phone: PhoneFactory.getPhones()) {
9008 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9009 if (tracker != null) {
9010 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009011 }
9012 }
9013 } finally {
9014 Binder.restoreCallingIdentity(identity);
9015 }
9016 }
9017
9018 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009019 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9020 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9021 Phone phone = getPhone(subId);
9022 if (phone == null) {
9023 return null;
9024 }
9025 final long identity = Binder.clearCallingIdentity();
9026 try {
9027 UiccProfile profile = UiccController.getInstance()
9028 .getUiccProfileForPhone(phone.getPhoneId());
9029 if (profile != null) {
9030 return profile.getCertsFromCarrierPrivilegeAccessRules();
9031 }
9032 } finally {
9033 Binder.restoreCallingIdentity(identity);
9034 }
9035 return null;
9036 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009037
9038 /**
9039 * Enable or disable a modem stack.
9040 */
9041 @Override
9042 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9043 enforceModifyPermission();
9044
9045 final long identity = Binder.clearCallingIdentity();
9046 try {
9047 Phone phone = PhoneFactory.getPhone(slotIndex);
9048 if (phone == null) {
9049 return false;
9050 } else {
9051 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9052 }
9053 } finally {
9054 Binder.restoreCallingIdentity(identity);
9055 }
9056 }
Michelecea4cf22018-12-21 15:00:11 -08009057
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009058 /**
9059 * Whether a modem stack is enabled or not.
9060 */
9061 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009062 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9063 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009064 Phone phone = PhoneFactory.getPhone(slotIndex);
9065 if (phone == null) return false;
9066
9067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009068 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9069 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009070 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9071 }
9072
9073 final long identity = Binder.clearCallingIdentity();
9074 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009075 try {
9076 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9077 } catch (NoSuchElementException ex) {
9078 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9079 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009080 } finally {
9081 Binder.restoreCallingIdentity(identity);
9082 }
9083 }
9084
Michelecea4cf22018-12-21 15:00:11 -08009085 @Override
Michele0ea7d782019-03-19 14:58:42 -07009086 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009087 enforceModifyPermission();
9088
9089 final long identity = Binder.clearCallingIdentity();
9090 try {
9091 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009092 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009093 .commit();
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
9096 }
9097 }
9098
9099 @Override
Michele0ea7d782019-03-19 14:58:42 -07009100 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009101 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009103 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9104 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009105 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009106 }
Michelecea4cf22018-12-21 15:00:11 -08009107
9108 final long identity = Binder.clearCallingIdentity();
9109 try {
Michele0ea7d782019-03-19 14:58:42 -07009110 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009111 } finally {
9112 Binder.restoreCallingIdentity(identity);
9113 }
9114 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009115
Michele0ea7d782019-03-19 14:58:42 -07009116 @TelephonyManager.IsMultiSimSupportedResult
9117 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009118 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9119 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9120 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009121 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9122 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009123 }
9124 // Check if the hardware supports multisim functionality. If usage of multisim is not
9125 // supported by the modem, indicate that it is restricted.
9126 PhoneCapability staticCapability =
9127 mPhoneConfigurationManager.getStaticPhoneCapability();
9128 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009129 loge("isMultiSimSupportedInternal: no static configuration available");
9130 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009131 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009132 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009133 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9134 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009135 }
9136 // Check if support of multiple SIMs is restricted by carrier
9137 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009138 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009139 }
9140
Michele0ea7d782019-03-19 14:58:42 -07009141 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009142 }
9143
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009144 /**
9145 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009146 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9147 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9148 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009149 * @param numOfSims number of active sims we want to switch to
9150 */
9151 @Override
9152 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009153 if (numOfSims == 1) {
9154 enforceModifyPermission();
9155 } else {
9156 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9157 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9158 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009159 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009160
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009161 try {
Michele30b57b22019-03-01 12:01:14 -08009162 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009163 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009164 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9165 return;
9166 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009167 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9168 } finally {
9169 Binder.restoreCallingIdentity(identity);
9170 }
9171 }
9172
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009173 @Override
9174 public boolean isApplicationOnUicc(int subId, int appType) {
9175 enforceReadPrivilegedPermission("isApplicationOnUicc");
9176 Phone phone = getPhone(subId);
9177 if (phone == null) {
9178 return false;
9179 }
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 UiccCard uiccCard = phone.getUiccCard();
9183 if (uiccCard == null) {
9184 return false;
9185 }
9186 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9187 if (uiccProfile == null) {
9188 return false;
9189 }
9190 if (TelephonyManager.APPTYPE_SIM <= appType
9191 && appType <= TelephonyManager.APPTYPE_ISIM) {
9192 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9193 }
9194 return false;
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009200 /**
chen xub4baa772019-04-03 10:23:41 -07009201 * Get whether making changes to modem configurations will trigger reboot.
9202 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009203 */
9204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009205 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9206 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009208 mApp, subId, callingPackage, callingFeatureId,
9209 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009210 return false;
9211 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009212 final long identity = Binder.clearCallingIdentity();
9213 try {
9214 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9215 } finally {
9216 Binder.restoreCallingIdentity(identity);
9217 }
9218 }
9219
Nathan Harold29f5f052019-02-15 13:41:57 -08009220 private void updateModemStateMetrics() {
9221 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9222 // TODO: check the state for each modem if the api is ready.
9223 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9224 }
9225
Pengquan Meng3889a572019-01-23 11:16:29 -08009226 @Override
9227 public int[] getSlotsMapping() {
9228 enforceReadPrivilegedPermission("getSlotsMapping");
9229
9230 final long identity = Binder.clearCallingIdentity();
9231 try {
9232 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9233 // All logical slots should have a mapping to a physical slot.
9234 int[] logicalSlotsMapping = new int[phoneCount];
9235 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9236 for (int i = 0; i < slotInfos.length; i++) {
9237 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9238 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9239 }
9240 }
9241 return logicalSlotsMapping;
9242 } finally {
9243 Binder.restoreCallingIdentity(identity);
9244 }
9245 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009246
9247 /**
9248 * Get the IRadio HAL Version
9249 */
9250 @Override
9251 public int getRadioHalVersion() {
9252 Phone phone = getDefaultPhone();
9253 if (phone == null) return -1;
9254 HalVersion hv = phone.getHalVersion();
9255 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9256 return hv.major * 100 + hv.minor;
9257 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009258
9259 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009260 * Get the current calling package name.
9261 * @return the current calling package name
9262 */
9263 @Override
9264 public String getCurrentPackageName() {
9265 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9266 }
9267
9268 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009269 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9270 * corresponding network requests on a subId.
9271 *
9272 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009273 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009274 * 2) APN is un-metered for this subscription, or
9275 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009276 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009277 *
9278 * @return whether data is allowed for a apn type.
9279 *
9280 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009281 */
9282 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009283 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009284 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9285 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009286
9287 // Now that all security checks passes, perform the operation as ourselves.
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
9290 Phone phone = getPhone(subId);
9291 if (phone == null) return false;
9292
Jack Yu41407ee2019-05-13 16:54:09 -07009293 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009294 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9295 } finally {
9296 Binder.restoreCallingIdentity(identity);
9297 }
9298 }
9299
9300 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009301 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009302 enforceReadPrivilegedPermission("isApnMetered");
9303
9304 // Now that all security checks passes, perform the operation as ourselves.
9305 final long identity = Binder.clearCallingIdentity();
9306 try {
9307 Phone phone = getPhone(subId);
9308 if (phone == null) return true; // By default return true.
9309
Jack Yu41407ee2019-05-13 16:54:09 -07009310 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009311 } finally {
9312 Binder.restoreCallingIdentity(identity);
9313 }
9314 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009315
9316 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009317 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9318 int subscriptionId, IBooleanConsumer resultCallback) {
9319 enforceModifyPermission();
9320 long token = Binder.clearCallingIdentity();
9321 try {
9322 Phone phone = getPhone(subscriptionId);
9323 if (phone == null) {
9324 try {
9325 if (resultCallback != null) {
9326 resultCallback.accept(false);
9327 }
9328 } catch (RemoteException e) {
9329 // ignore
9330 }
9331 return;
9332 }
9333 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9334 Pair.create(specifiers, (x) -> {
9335 try {
9336 if (resultCallback != null) {
9337 resultCallback.accept(x);
9338 }
9339 } catch (RemoteException e) {
9340 // ignore
9341 }
9342 });
9343 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9344 } finally {
9345 Binder.restoreCallingIdentity(token);
9346 }
9347 }
9348
9349 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009350 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9351 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009352 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009353 mApp, subId, "getSystemSelectionChannels");
9354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9355 final long identity = Binder.clearCallingIdentity();
9356 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009357 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9358 if (result instanceof IllegalStateException) {
9359 throw (IllegalStateException) result;
9360 }
9361 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009362 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9363 return specifiers;
9364 } finally {
9365 Binder.restoreCallingIdentity(identity);
9366 }
9367 }
9368
9369 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009370 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009371 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009372 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9373 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9374 if (iccRecords == null) {
9375 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9376 return false;
9377 }
9378 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9379 }
9380
9381 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009382 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9383 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009384 if (callingPackage == null) {
9385 callingPackage = getCurrentPackageName();
9386 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009387 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9388 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009389 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9390 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009391 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9392 }
9393 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9394 Intent intent = new Intent();
9395 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9396 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9397 // Bring up choose default SMS subscription dialog right now
9398 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9399 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9400 mApp.startActivity(intent);
9401 }
chen xud5ca2d52019-05-28 15:20:57 -07009402
9403 @Override
9404 public String getMmsUAProfUrl(int subId) {
9405 //TODO investigate if this API should require proper permission check in R b/133791609
9406 final long identity = Binder.clearCallingIdentity();
9407 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009408 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9409 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9410 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9411 return carrierUAProfUrl;
9412 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009413 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9414 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009415 } finally {
9416 Binder.restoreCallingIdentity(identity);
9417 }
9418 }
9419
9420 @Override
9421 public String getMmsUserAgent(int subId) {
9422 //TODO investigate if this API should require proper permission check in R b/133791609
9423 final long identity = Binder.clearCallingIdentity();
9424 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009425 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9426 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9427 if (!TextUtils.isEmpty(carrierUserAgent)) {
9428 return carrierUserAgent;
9429 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009430 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9431 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 }
Jack Yub07d4972019-05-28 16:12:25 -07009436
9437 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009438 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9439 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009440
Jack Yub07d4972019-05-28 16:12:25 -07009441 final long identity = Binder.clearCallingIdentity();
9442 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009443 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009444 if (phone == null) return false;
9445
Hall Liua62f5da2020-09-25 10:42:19 -07009446 switch (policy) {
9447 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9448 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9449 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9450 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9451 default:
9452 throw new IllegalArgumentException(policy + " is not a valid policy");
9453 }
Jack Yub07d4972019-05-28 16:12:25 -07009454 } finally {
9455 Binder.restoreCallingIdentity(identity);
9456 }
9457 }
9458
9459 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009460 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009461 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009462 enforceModifyPermission();
9463
changbettyd5c246e2019-12-24 15:40:37 +08009464 final long identity = Binder.clearCallingIdentity();
9465 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009466 Phone phone = getPhone(subscriptionId);
9467 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009468
Hall Liua62f5da2020-09-25 10:42:19 -07009469 switch (policy) {
9470 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9471 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9472 break;
9473 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9474 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9475 break;
9476 default:
9477 throw new IllegalArgumentException(policy + " is not a valid policy");
9478 }
changbettyd5c246e2019-12-24 15:40:37 +08009479 } finally {
9480 Binder.restoreCallingIdentity(identity);
9481 }
9482 }
9483
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009484 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009485 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009486 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9487 * otherwise.
9488 */
9489 @Override
9490 public void setCepEnabled(boolean isCepEnabled) {
9491 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9492
9493 final long identity = Binder.clearCallingIdentity();
9494 try {
9495 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9496 for (Phone phone : PhoneFactory.getPhones()) {
9497 Phone defaultPhone = phone.getImsPhone();
9498 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9499 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9500 ImsPhoneCallTracker imsPhoneCallTracker =
9501 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9502 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9503 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9504 + imsPhone.getMsisdn());
9505 }
9506 }
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510 }
allenwtsu46dcc572020-01-08 18:24:03 +08009511
9512 /**
9513 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9514 *
9515 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9516 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9517 * before being read.
9518 */
9519 @Override
9520 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9521 isCompressed) {
9522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9523 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009524 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9525 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9526 }
9527 if (!isImsAvailableOnDevice()) {
9528 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9529 "IMS not available on device.");
9530 }
9531
9532 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009533 try {
Hui Wang761a6682020-10-31 05:12:53 +00009534 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9535 } finally {
9536 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009537 }
9538 }
zoey chene02881a2019-12-30 16:11:23 +08009539
9540 @Override
9541 public boolean isIccLockEnabled(int subId) {
9542 enforceReadPrivilegedPermission("isIccLockEnabled");
9543
9544 // Now that all security checks passes, perform the operation as ourselves.
9545 final long identity = Binder.clearCallingIdentity();
9546 try {
9547 Phone phone = getPhone(subId);
9548 if (phone != null && phone.getIccCard() != null) {
9549 return phone.getIccCard().getIccLockEnabled();
9550 } else {
9551 return false;
9552 }
9553 } finally {
9554 Binder.restoreCallingIdentity(identity);
9555 }
9556 }
9557
9558 /**
9559 * Set the ICC pin lock enabled or disabled.
9560 *
9561 * @return an integer representing the status of IccLock enabled or disabled in the following
9562 * three cases:
9563 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9564 * successfully.
9565 * - Positive number and zero for remaining password attempts.
9566 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9567 *
9568 */
9569 @Override
9570 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9571 enforceModifyPermission();
9572
9573 Phone phone = getPhone(subId);
9574 if (phone == null) {
9575 return 0;
9576 }
9577 // Now that all security checks passes, perform the operation as ourselves.
9578 final long identity = Binder.clearCallingIdentity();
9579 try {
9580 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9581 new Pair<Boolean, String>(enabled, password), phone, null);
9582 return attemptsRemaining;
9583
9584 } catch (Exception e) {
9585 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9586 } finally {
9587 Binder.restoreCallingIdentity(identity);
9588 }
9589 return 0;
9590 }
9591
9592 /**
9593 * Change the ICC password used in ICC pin lock.
9594 *
9595 * @return an integer representing the status of IccLock changed in the following three cases:
9596 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9597 * - Positive number and zero for remaining password attempts.
9598 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9599 *
9600 */
9601 @Override
9602 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9603 enforceModifyPermission();
9604
9605 Phone phone = getPhone(subId);
9606 if (phone == null) {
9607 return 0;
9608 }
9609 // Now that all security checks passes, perform the operation as ourselves.
9610 final long identity = Binder.clearCallingIdentity();
9611 try {
9612 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9613 new Pair<String, String>(oldPassword, newPassword), phone, null);
9614 return attemptsRemaining;
9615
9616 } catch (Exception e) {
9617 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9618 } finally {
9619 Binder.restoreCallingIdentity(identity);
9620 }
9621 return 0;
9622 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009623
9624 /**
9625 * Request for receiving user activity notification
9626 */
9627 @Override
9628 public void requestUserActivityNotification() {
9629 if (!mNotifyUserActivity.get()
9630 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9631 mNotifyUserActivity.set(true);
9632 }
9633 }
9634
9635 /**
9636 * Called when userActivity is signalled in the power manager.
9637 * This is safe to call from any thread, with any window manager locks held or not.
9638 */
9639 @Override
9640 public void userActivity() {
9641 // ***************************************
9642 // * Inherited from PhoneWindowManager *
9643 // ***************************************
9644 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9645 // WITH ITS LOCKS HELD.
9646 //
9647 // This code must be VERY careful about the locks
9648 // it acquires.
9649 // In fact, the current code acquires way too many,
9650 // and probably has lurking deadlocks.
9651
9652 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9653 throw new SecurityException("Only the OS may call notifyUserActivity()");
9654 }
9655
9656 if (mNotifyUserActivity.getAndSet(false)) {
9657 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9658 USER_ACTIVITY_NOTIFICATION_DELAY);
9659 }
9660 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009661
9662 @Override
9663 public boolean canConnectTo5GInDsdsMode() {
9664 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9665 }
Jack Yud10cdd42020-09-28 20:28:01 -07009666
9667 @Override
9668 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9669 String callingFeatureId) {
9670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9671 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9672 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9673 }
9674
9675 Phone phone = getPhone(subId);
9676 if (phone == null) {
9677 throw new RuntimeException("phone is not available");
9678 }
9679 // Now that all security checks passes, perform the operation as ourselves.
9680 final long identity = Binder.clearCallingIdentity();
9681 try {
9682 return phone.getEquivalentHomePlmns();
9683 } finally {
9684 Binder.restoreCallingIdentity(identity);
9685 }
9686 }
Daniel Bright59e67312020-11-13 11:49:37 -08009687
9688 @Override
9689 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009690 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9691 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009692 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009693 if (radioInterfaceCapabilities == null) {
9694 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009695 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009696 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009697 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009698
Hui Wang641e81c2020-10-12 12:14:23 -07009699 @Override
9700 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9701 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009702 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9703 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9704 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9705 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9706 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009707 if (DBG) {
9708 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9709 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9710 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9711 }
9712
9713 if (!SubscriptionManager.isValidSubscriptionId(subId)
9714 || appType < TelephonyManager.APPTYPE_UNKNOWN
9715 || appType > TelephonyManager.APPTYPE_ISIM
9716 || nafUrl == null || securityProtocol == null || callback == null) {
9717 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9718 if (callback != null) {
9719 try {
9720 callback.onAuthenticationFailure(
9721 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9722 } catch (RemoteException exception) {
9723 log("Fail to notify onAuthenticationFailure due to " + exception);
9724 }
9725 return;
9726 }
9727 }
9728
9729 final long token = Binder.clearCallingIdentity();
9730 try {
9731 getGbaManager(subId).bootstrapAuthenticationRequest(
9732 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9733 forceBootStrapping, callback));
9734 } finally {
9735 Binder.restoreCallingIdentity(token);
9736 }
9737 }
9738
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009739 /**
9740 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9741 * requested radio power state will actually be set. See {@link
9742 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9743 *
9744 * @param subId the subscription ID of the phone requesting to set the radio power state.
9745 * @param enable {@code true} if trying to turn radio on.
9746 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9747 * false}.
9748 */
9749 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9750 Phone phone = getPhone(subId);
9751 if (phone != null) {
9752 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9753 return true;
9754 }
9755 return false;
9756 }
9757
9758 private int handleDataThrottlingRequest(int subId,
9759 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009760 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9761 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9762 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9763 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9764 throw new IllegalArgumentException("modem does not support data throttling");
9765 }
9766
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009767 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9768 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9769 if (!setRadioPowerForThermal(subId, true)) {
9770 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9771 }
9772
9773 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9774
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009775 if (isDataThrottlingSupported) {
9776 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009777 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009778 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9779 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9780 } else if (thermalMitigationResult
9781 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9782 throw new IllegalArgumentException("modem does not support data throttling");
9783 }
9784 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009785 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009786
9787 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009788 }
9789
Jack Nudelman644b91a2021-03-12 14:09:48 -08009790 private static List<String> getThermalMitigationAllowlist(Context context) {
9791 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9792 for (String pckg : context.getResources()
9793 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9794 sThermalMitigationAllowlistedPackages.add(pckg);
9795 }
9796 }
9797
9798 return sThermalMitigationAllowlistedPackages;
9799 }
9800
9801 /**
9802 * Used by shell commands to add an authorized package name for thermal mitigation.
9803 * @param packageName name of package to be allowlisted
9804 * @param context
9805 */
9806 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9807 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9808 sThermalMitigationAllowlistedPackages.add(packageName);
9809 }
9810
9811 /**
9812 * Used by shell commands to remove an authorized package name for thermal mitigation.
9813 * @param packageName name of package to remove from allowlist
9814 * @param context
9815 */
9816 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9817 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9818 sThermalMitigationAllowlistedPackages.remove(packageName);
9819 }
9820
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009821 /**
9822 * Thermal mitigation request to control functionalities at modem.
9823 *
9824 * @param subId the id of the subscription.
9825 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009826 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009827 *
9828 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9829 */
9830 @Override
9831 @ThermalMitigationResult
9832 public int sendThermalMitigationRequest(
9833 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009834 ThermalMitigationRequest thermalMitigationRequest,
9835 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009836 enforceModifyPermission();
9837
Jack Nudelman644b91a2021-03-12 14:09:48 -08009838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9839 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9840 .contains(callingPackage)) {
9841 throw new SecurityException("Calling package must be configured in the device config. "
9842 + "calling package: " + callingPackage);
9843 }
9844
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009845 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9846 final long identity = Binder.clearCallingIdentity();
9847
9848 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9849 try {
9850 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9851 switch (thermalMitigationAction) {
9852 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9853 thermalMitigationResult =
9854 handleDataThrottlingRequest(subId,
9855 thermalMitigationRequest.getDataThrottlingRequest());
9856 break;
9857 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9858 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9859 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9860 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9861 }
9862
9863 // Ensure that radio is on. If not able to power on due to phone being
9864 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9865 if (!setRadioPowerForThermal(subId, true)) {
9866 thermalMitigationResult =
9867 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9868 break;
9869 }
9870
9871 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9872 false);
9873 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9874 break;
9875 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9876 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9877 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9878 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9879 }
9880
9881 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9882 if (registry != null) {
9883 TelephonyConnectionService service =
9884 registry.getTelephonyConnectionService();
9885 Phone phone = getPhone(subId);
9886 if (phone == null) {
9887 thermalMitigationResult =
9888 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9889 break;
9890 }
9891
9892 if (PhoneConstantConversions.convertCallState(phone.getState())
9893 != TelephonyManager.CALL_STATE_IDLE
9894 || phone.isInEmergencySmsMode() || phone.isInEcm()
9895 || (service != null && service.isEmergencyCallPending())) {
9896 String errorMessage = "Phone state is not valid. call state = "
9897 + PhoneConstantConversions.convertCallState(phone.getState())
9898 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9899 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9900 errorMessage += service == null
9901 ? " TelephonyConnectionService is null"
9902 : " isEmergencyCallPending = "
9903 + service.isEmergencyCallPending();
9904 Log.e(LOG_TAG, errorMessage);
9905 thermalMitigationResult =
9906 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9907 break;
9908 }
9909 } else {
9910 thermalMitigationResult =
9911 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9912 break;
9913 }
9914
9915 // Turn radio off. If not able to power off due to phone being unavailable,
9916 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9917 if (!setRadioPowerForThermal(subId, false)) {
9918 thermalMitigationResult =
9919 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9920 break;
9921 }
9922 thermalMitigationResult =
9923 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9924 break;
9925 default:
9926 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9927 + "not exist. Requested action: " + thermalMitigationAction);
9928 }
9929 } catch (IllegalArgumentException e) {
9930 throw e;
9931 } catch (Exception e) {
9932 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9933 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9934 } finally {
9935 Binder.restoreCallingIdentity(identity);
9936 }
9937
9938 if (DBG) {
9939 log("thermalMitigationRequest returning with thermalMitigationResult: "
9940 + thermalMitigationResult);
9941 }
9942
9943 return thermalMitigationResult;
9944 }
Hui Wang641e81c2020-10-12 12:14:23 -07009945
9946 /**
9947 * Set the GbaService Package Name that Telephony will bind to.
9948 *
9949 * @param subId The sim that the GbaService is associated with.
9950 * @param packageName The name of the package to be replaced with.
9951 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9952 */
9953 @Override
9954 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9955 enforceModifyPermission();
9956
9957 final long identity = Binder.clearCallingIdentity();
9958 try {
9959 return getGbaManager(subId).overrideServicePackage(packageName);
9960 } finally {
9961 Binder.restoreCallingIdentity(identity);
9962 }
9963 }
9964
9965 /**
9966 * Return the package name of the currently bound GbaService.
9967 *
9968 * @param subId The sim that the GbaService is associated with.
9969 * @return the package name of the GbaService configuration, null if GBA is not supported.
9970 */
9971 @Override
9972 public String getBoundGbaService(int subId) {
9973 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9974
9975 final long identity = Binder.clearCallingIdentity();
9976 try {
9977 return getGbaManager(subId).getServicePackage();
9978 } finally {
9979 Binder.restoreCallingIdentity(identity);
9980 }
9981 }
9982
9983 /**
9984 * Set the release time for telephony to unbind GbaService.
9985 *
9986 * @param subId The sim that the GbaService is associated with.
9987 * @param interval The release time to unbind GbaService by millisecond.
9988 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9989 */
9990 @Override
9991 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9992 enforceModifyPermission();
9993
9994 final long identity = Binder.clearCallingIdentity();
9995 try {
9996 return getGbaManager(subId).overrideReleaseTime(interval);
9997 } finally {
9998 Binder.restoreCallingIdentity(identity);
9999 }
10000 }
10001
10002 /**
10003 * Return the release time for telephony to unbind GbaService.
10004 *
10005 * @param subId The sim that the GbaService is associated with.
10006 * @return The release time to unbind GbaService by millisecond.
10007 */
10008 @Override
10009 public int getGbaReleaseTime(int subId) {
10010 enforceReadPrivilegedPermission("getGbaReleaseTime");
10011
10012 final long identity = Binder.clearCallingIdentity();
10013 try {
10014 return getGbaManager(subId).getReleaseTime();
10015 } finally {
10016 Binder.restoreCallingIdentity(identity);
10017 }
10018 }
10019
10020 private GbaManager getGbaManager(int subId) {
10021 GbaManager instance = GbaManager.getInstance(subId);
10022 if (instance == null) {
10023 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10024 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10025 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10026 }
10027 return instance;
10028 }
Hui Wang761a6682020-10-31 05:12:53 +000010029
10030 /**
10031 * indicate whether the device and the carrier can support
10032 * RCS VoLTE single registration.
10033 */
10034 @Override
10035 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010036 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10037 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10038 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10039 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010040
10041 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10042 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10043 }
10044
10045 final long identity = Binder.clearCallingIdentity();
10046 try {
10047 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10048 if (rpm != null) {
10049 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
10050 }
10051 return false;
10052 } finally {
10053 Binder.restoreCallingIdentity(identity);
10054 }
10055 }
10056
10057 /**
10058 * Register RCS provisioning callback.
10059 */
10060 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010061 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010062 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010063 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010064 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010065 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10066 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010067
10068 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10069 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10070 }
10071 if (!isImsAvailableOnDevice()) {
10072 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10073 "IMS not available on device.");
10074 }
10075
10076 final long identity = Binder.clearCallingIdentity();
10077 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010078 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010079 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -080010080 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10081 "Service not available for the subscription.");
10082 }
Hui Wang761a6682020-10-31 05:12:53 +000010083 } finally {
10084 Binder.restoreCallingIdentity(identity);
10085 }
10086 }
10087
10088 /**
10089 * Unregister RCS provisioning callback.
10090 */
10091 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010092 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010093 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010094 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010095 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010096 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10097 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010098
10099 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10100 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10101 }
10102 if (!isImsAvailableOnDevice()) {
10103 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10104 "IMS not available on device.");
10105 }
10106
10107 final long identity = Binder.clearCallingIdentity();
10108 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010109 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010110 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010111 } finally {
10112 Binder.restoreCallingIdentity(identity);
10113 }
10114 }
10115
10116 /**
10117 * trigger RCS reconfiguration.
10118 */
10119 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010120 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10121 "triggerRcsReconfiguration",
10122 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010123
10124 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10125 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10126 }
10127 if (!isImsAvailableOnDevice()) {
10128 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10129 "IMS not available on device.");
10130 }
10131
10132 final long identity = Binder.clearCallingIdentity();
10133 try {
10134 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10135 } finally {
10136 Binder.restoreCallingIdentity(identity);
10137 }
10138 }
10139
10140 /**
10141 * Provide the client configuration parameters of the RCS application.
10142 */
10143 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010144 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10145 "setRcsClientConfiguration",
10146 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010147
10148 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10149 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10150 }
10151 if (!isImsAvailableOnDevice()) {
10152 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10153 "IMS not available on device.");
10154 }
10155
10156 final long identity = Binder.clearCallingIdentity();
10157
10158 try {
10159 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10160 if (configBinder == null) {
10161 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
10162 } else {
10163 configBinder.setRcsClientConfiguration(rcc);
10164 }
10165 } catch (RemoteException e) {
10166 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
10167 } finally {
10168 Binder.restoreCallingIdentity(identity);
10169 }
10170 }
10171
10172 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010173 * Enables or disables the test mode for RCS VoLTE single registration.
10174 */
10175 @Override
10176 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10177 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10178 "setRcsSingleRegistrationTestModeEnabled");
10179
10180 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10181 }
10182
10183 /**
10184 * Gets the test mode for RCS VoLTE single registration.
10185 */
10186 @Override
10187 public boolean getRcsSingleRegistrationTestModeEnabled() {
10188 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10189 "getRcsSingleRegistrationTestModeEnabled");
10190
10191 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10192 }
10193
10194 /**
Hui Wang761a6682020-10-31 05:12:53 +000010195 * Overrides the config of RCS VoLTE single registration enabled for the device.
10196 */
10197 @Override
10198 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10200 "setDeviceSingleRegistrationEnabledOverride");
10201 enforceModifyPermission();
10202
10203 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10204 : Boolean.parseBoolean(enabledStr);
10205 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010206 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010207 }
10208
10209 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010210 * Sends a device to device communication message. Only usable via shell.
10211 * @param message message to send.
10212 * @param value message value.
10213 */
10214 @Override
10215 public void sendDeviceToDeviceMessage(int message, int value) {
10216 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010217 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010218 enforceModifyPermission();
10219
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 TelephonyConnectionService service =
10223 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10224 if (service == null) {
10225 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10226 return;
10227 }
10228 service.sendTestDeviceToDeviceMessage(message, value);
10229 } finally {
10230 Binder.restoreCallingIdentity(identity);
10231 }
10232 }
10233
Tyler Gunnbabbda02021-02-10 11:05:02 -080010234 /**
10235 * Sets the specified device to device transport active.
10236 * @param transport The transport to set active.
10237 */
10238 @Override
10239 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10240 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10241 "setActiveDeviceToDeviceTransport");
10242 enforceModifyPermission();
10243
10244 final long identity = Binder.clearCallingIdentity();
10245 try {
10246 TelephonyConnectionService service =
10247 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10248 if (service == null) {
10249 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10250 return;
10251 }
10252 service.setActiveDeviceToDeviceTransport(transport);
10253 } finally {
10254 Binder.restoreCallingIdentity(identity);
10255 }
10256 }
Tyler Gunn92479152021-01-20 16:30:10 -080010257
Tyler Gunnd4575212021-05-03 14:46:49 -070010258 @Override
10259 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10260 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10261 "setDeviceToDeviceForceEnabled");
10262
10263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 Arrays.stream(PhoneFactory.getPhones()).forEach(
10266 p -> {
10267 Phone thePhone = p.getImsPhone();
10268 if (thePhone != null && thePhone instanceof ImsPhone) {
10269 ImsPhone imsPhone = (ImsPhone) thePhone;
10270 CallTracker tracker = imsPhone.getCallTracker();
10271 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10272 ImsPhoneCallTracker imsPhoneCallTracker =
10273 (ImsPhoneCallTracker) tracker;
10274 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10275 }
10276 }
10277 }
10278 );
10279 } finally {
10280 Binder.restoreCallingIdentity(identity);
10281 }
10282 }
10283
Tyler Gunn92479152021-01-20 16:30:10 -080010284 /**
Hui Wang761a6682020-10-31 05:12:53 +000010285 * Gets the config of RCS VoLTE single registration enabled for the device.
10286 */
10287 @Override
10288 public boolean getDeviceSingleRegistrationEnabled() {
10289 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10290 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10291 }
10292
10293 /**
10294 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10295 */
10296 @Override
10297 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10298 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10299 "setCarrierSingleRegistrationEnabledOverride");
10300 enforceModifyPermission();
10301
10302 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10303 : Boolean.parseBoolean(enabledStr);
10304 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10305 subId, enabled);
10306 }
10307
10308 /**
10309 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10310 */
10311 @Override
10312 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10313 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10314 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10315 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010316
10317 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010318 * Overrides the ims feature validation result
10319 */
10320 @Override
10321 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10322 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10323 "setImsFeatureValidationOverride");
10324
10325 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10326 : Boolean.parseBoolean(enabledStr);
10327 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10328 subId, enabled);
10329 }
10330
10331 /**
10332 * Gets the ims feature validation override value
10333 */
10334 @Override
10335 public boolean getImsFeatureValidationOverride(int subId) {
10336 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10337 "getImsFeatureValidationOverride");
10338 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10339 }
10340
10341 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010342 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10343 * their mobile plan.
10344 */
10345 @Override
10346 public String getMobileProvisioningUrl() {
10347 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
10350 return getDefaultPhone().getMobileProvisioningUrl();
10351 } finally {
10352 Binder.restoreCallingIdentity(identity);
10353 }
10354 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010355
James.cf Linbcdf8b32021-01-14 16:44:13 +080010356 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010357 * Get the EAB contact from the EAB database.
10358 */
10359 @Override
10360 public String getContactFromEab(String contact) {
10361 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10362 enforceModifyPermission();
10363 final long identity = Binder.clearCallingIdentity();
10364 try {
10365 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
10370
10371 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010372 * Remove the EAB contacts from the EAB database.
10373 */
10374 @Override
10375 public int removeContactFromEab(int subId, String contacts) {
10376 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10377 enforceModifyPermission();
10378 final long identity = Binder.clearCallingIdentity();
10379 try {
10380 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10381 } finally {
10382 Binder.restoreCallingIdentity(identity);
10383 }
10384 }
10385
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010386 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010387 public boolean getDeviceUceEnabled() {
10388 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10389 final long identity = Binder.clearCallingIdentity();
10390 try {
10391 return mApp.getDeviceUceEnabled();
10392 } finally {
10393 Binder.restoreCallingIdentity(identity);
10394 }
10395 }
10396
10397 @Override
10398 public void setDeviceUceEnabled(boolean isEnabled) {
10399 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10400 final long identity = Binder.clearCallingIdentity();
10401 try {
10402 mApp.setDeviceUceEnabled(isEnabled);
10403 } finally {
10404 Binder.restoreCallingIdentity(identity);
10405 }
10406 }
10407
Brad Ebinger14d467f2021-02-12 06:18:28 +000010408 /**
10409 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10410 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10411 */
10412 // Used for SHELL command only right now.
10413 @Override
10414 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10415 List<String> featureTags) {
10416 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10417 "addUceRegistrationOverrideShell");
10418 final long identity = Binder.clearCallingIdentity();
10419 try {
10420 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10421 new ArraySet<>(featureTags));
10422 } catch (ImsException e) {
10423 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10424 } finally {
10425 Binder.restoreCallingIdentity(identity);
10426 }
10427 }
10428
10429 /**
10430 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10431 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10432 */
10433 // Used for SHELL command only right now.
10434 @Override
10435 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10436 List<String> featureTags) {
10437 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10438 "removeUceRegistrationOverrideShell");
10439 final long identity = Binder.clearCallingIdentity();
10440 try {
10441 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10442 new ArraySet<>(featureTags));
10443 } catch (ImsException e) {
10444 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10445 } finally {
10446 Binder.restoreCallingIdentity(identity);
10447 }
10448 }
10449
10450 /**
10451 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10452 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10453 */
10454 // Used for SHELL command only right now.
10455 @Override
10456 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10457 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10458 "clearUceRegistrationOverrideShell");
10459 final long identity = Binder.clearCallingIdentity();
10460 try {
10461 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10462 } catch (ImsException e) {
10463 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467 }
10468
10469 /**
10470 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10471 */
10472 // Used for SHELL command only right now.
10473 @Override
10474 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10475 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10476 "getLatestRcsContactUceCapabilityShell");
10477 final long identity = Binder.clearCallingIdentity();
10478 try {
10479 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10480 } catch (ImsException e) {
10481 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10482 } finally {
10483 Binder.restoreCallingIdentity(identity);
10484 }
10485 }
10486
10487 /**
10488 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10489 * device does not have an active PUBLISH.
10490 */
10491 // Used for SHELL command only right now.
10492 @Override
10493 public String getLastUcePidfXmlShell(int subId) {
10494 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10495 final long identity = Binder.clearCallingIdentity();
10496 try {
10497 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10498 } catch (ImsException e) {
10499 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10500 } finally {
10501 Binder.restoreCallingIdentity(identity);
10502 }
10503 }
10504
James.cf Line8713a42021-04-29 16:04:26 +080010505 /**
10506 * Remove UCE requests cannot be sent to the network status.
10507 */
10508 // Used for SHELL command only right now.
10509 @Override
10510 public boolean removeUceRequestDisallowedStatus(int subId) {
10511 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10512 final long identity = Binder.clearCallingIdentity();
10513 try {
10514 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10515 } catch (ImsException e) {
10516 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10517 } finally {
10518 Binder.restoreCallingIdentity(identity);
10519 }
10520 }
10521
Brad Ebinger14d467f2021-02-12 06:18:28 +000010522
James.cf Lin4b784aa2021-01-31 03:25:15 +080010523 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010524 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10525 String callingPackage) {
10526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10527 mApp, subId, "setSignalStrengthUpdateRequest");
10528
10529 final int callingUid = Binder.getCallingUid();
10530 // Verify that tha callingPackage belongs to the calling UID
10531 mApp.getSystemService(AppOpsManager.class)
10532 .checkPackage(callingUid, callingPackage);
10533
10534 validateSignalStrengthUpdateRequest(request, callingUid);
10535
10536 final long identity = Binder.clearCallingIdentity();
10537 try {
10538 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10539 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10540
10541 if (result instanceof IllegalStateException) {
10542 throw (IllegalStateException) result;
10543 }
10544 } finally {
10545 Binder.restoreCallingIdentity(identity);
10546 }
10547 }
10548
10549 @Override
10550 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10551 String callingPackage) {
10552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10553 mApp, subId, "clearSignalStrengthUpdateRequest");
10554
10555 final int callingUid = Binder.getCallingUid();
10556 // Verify that tha callingPackage belongs to the calling UID
10557 mApp.getSystemService(AppOpsManager.class)
10558 .checkPackage(callingUid, callingPackage);
10559
10560 final long identity = Binder.clearCallingIdentity();
10561 try {
10562 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10563 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10564
10565 if (result instanceof IllegalStateException) {
10566 throw (IllegalStateException) result;
10567 }
10568 } finally {
10569 Binder.restoreCallingIdentity(identity);
10570 }
10571 }
10572
10573 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10574 int callingUid) {
10575 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10576 // phone/system process do not have further restriction on request
10577 return;
10578 }
10579
10580 // Applications has restrictions on how to use the request:
10581 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10582 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10583 // This is not system caller which has been checked above
10584 throw new IllegalArgumentException(
10585 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10586 }
10587
10588 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10589 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10590 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10591 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10592 || info.isEnabled()) {
10593 throw new IllegalArgumentException(
10594 "Only system can set hide fields in SignalThresholdInfo");
10595 }
10596
10597 // Thresholds length for each RAN need in range. This has been validated in
10598 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10599 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10600 final int[] thresholds = info.getThresholds();
10601 Objects.requireNonNull(thresholds);
10602 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10603 || thresholds.length
10604 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10605 throw new IllegalArgumentException(
10606 "thresholds length is out of range: " + thresholds.length);
10607 }
10608 }
10609 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010610
10611 /**
10612 * Gets the current phone capability.
10613 *
10614 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10615 * @return the PhoneCapability which describes the data connection capability of modem.
10616 * It's used to evaluate possible phone config change, for example from single
10617 * SIM device to multi-SIM device.
10618 */
10619 @Override
10620 public PhoneCapability getPhoneCapability() {
10621 enforceReadPrivilegedPermission("getPhoneCapability");
10622 final long identity = Binder.clearCallingIdentity();
10623 try {
10624 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10625 } finally {
10626 Binder.restoreCallingIdentity(identity);
10627 }
10628 }
Michele Berionne5e411512020-11-13 02:36:59 +000010629
10630 /**
10631 * Prepare TelephonyManager for an unattended reboot. The reboot is
10632 * required to be done shortly after the API is invoked.
10633 */
10634 @Override
10635 @TelephonyManager.PrepareUnattendedRebootResult
10636 public int prepareForUnattendedReboot() {
10637 enforceRebootPermission();
10638
10639 final long identity = Binder.clearCallingIdentity();
10640 try {
10641 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10642 } finally {
10643 Binder.restoreCallingIdentity(identity);
10644 }
10645 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010646
10647 /**
10648 * Request to get the current slicing configuration including URSP rules and
10649 * NSSAIs (configured, allowed and rejected).
10650 *
10651 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10652 */
10653 @Override
10654 public void getSlicingConfig(ResultReceiver callback) {
10655 enforceReadPrivilegedPermission("getSlicingConfig");
10656
10657 final long identity = Binder.clearCallingIdentity();
10658 try {
10659 Phone phone = getDefaultPhone();
10660 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10661 } finally {
10662 Binder.restoreCallingIdentity(identity);
10663 }
10664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010665}