blob: db14924f1d7558ce42aeb4578f8f540cbab3ae37 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700189import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800192import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000193import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800194import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700195import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800197import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800198import com.android.phone.callcomposer.CallComposerPictureManager;
199import com.android.phone.callcomposer.CallComposerPictureTransfer;
200import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700201import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800203import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700205import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800206import com.android.services.telephony.TelecomAccountRegistry;
207import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800208import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800209
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700211import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.IOException;
213import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700214import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800217import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800218import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800219import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100220import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700222import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800226import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800227import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229/**
230 * Implementation of the ITelephony interface.
231 */
Santos Cordon117fee72014-05-16 17:56:12 -0700232public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 private static final String LOG_TAG = "PhoneInterfaceManager";
234 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
235 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238 // Message codes used with mMainThreadHandler
239 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700240 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
241 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242 private static final int CMD_OPEN_CHANNEL = 9;
243 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
244 private static final int CMD_CLOSE_CHANNEL = 11;
245 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800246 private static final int CMD_NV_READ_ITEM = 13;
247 private static final int EVENT_NV_READ_ITEM_DONE = 14;
248 private static final int CMD_NV_WRITE_ITEM = 15;
249 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
250 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
251 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700252 private static final int CMD_RESET_MODEM_CONFIG = 19;
253 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800254 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
255 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800256 private static final int CMD_SEND_ENVELOPE = 25;
257 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000258 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
259 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700260 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
261 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
262 private static final int CMD_EXCHANGE_SIM_IO = 31;
263 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
265 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700266 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
267 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700268 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
269 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700270 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
271 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
272 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
273 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700274 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
275 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
276 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
277 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700278 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800279 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
280 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000281 private static final int CMD_SWITCH_SLOTS = 50;
282 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700283 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
284 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
285 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
286 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
287 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
288 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
289 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
290 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700291 private static final int CMD_GET_ALL_CELL_INFO = 60;
292 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
293 private static final int CMD_GET_CELL_LOCATION = 62;
294 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700295 private static final int CMD_MODEM_REBOOT = 64;
296 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700297 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
298 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800299 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
300 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700301 private static final int CMD_GET_MODEM_STATUS = 70;
302 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700303 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
304 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700305 private static final int CMD_ERASE_MODEM_CONFIG = 74;
306 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800307 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
308 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
309 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
310 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800311 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
312 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800314 private static final int CMD_GET_CALL_FORWARDING = 83;
315 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
316 private static final int CMD_SET_CALL_FORWARDING = 85;
317 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
318 private static final int CMD_GET_CALL_WAITING = 87;
319 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
320 private static final int CMD_SET_CALL_WAITING = 89;
321 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700322 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
323 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
324 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
325 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700326 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
327 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800328 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
329 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800330 private static final int CMD_SET_DATA_THROTTLING = 99;
331 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800332 private static final int CMD_SET_SIM_POWER = 101;
333 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800334 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
335 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
336 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
337 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800338 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
339 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000340 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800341 private static final int CMD_GET_SLICING_CONFIG = 110;
342 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800343 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800345 // Parameters of select command.
346 private static final int SELECT_COMMAND = 0xA4;
347 private static final int SELECT_P1 = 0x04;
348 private static final int SELECT_P2 = 0;
349 private static final int SELECT_P3 = 0x10;
350
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 /** The singleton instance. */
352 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800353 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
Wink Saville3ab207e2014-11-20 13:07:20 -0800355 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800356 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800357 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700358 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700360 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800362 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700364 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800365 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366
Peter Wangdafb9ac2020-01-15 14:13:38 -0800367 /** User Activity */
368 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800369 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
370
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700371 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
372
Derek Tan97ebb422014-09-05 16:55:38 -0700373 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
374 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800375 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800376 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700377
Michelecea4cf22018-12-21 15:00:11 -0800378 // String to store multi SIM allowed
379 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
380
Derek Tan740e1672017-06-27 14:56:27 -0700381 // The AID of ISD-R.
382 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
383
yinxub1bed742017-04-17 11:45:04 -0700384 private NetworkScanRequestTracker mNetworkScanRequestTracker;
385
David Kelly5e06a7f2018-03-12 14:10:59 +0000386 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
387 private static final int MANUFACTURER_CODE_LENGTH = 8;
388
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800389 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800390 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800391
Derek Tan89e89d42014-07-08 17:00:10 -0700392 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700393 * Experiment flag to enable erase modem config on reset network, default value is false
394 */
395 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
396 "reset_network_erase_modem_config_enabled";
397
Rambo Wang0f050d82021-02-12 11:43:36 -0800398 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
399
Naina Nallurid63128d2019-09-17 14:10:30 -0700400 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700401 * A request object to use for transmitting data to an ICC.
402 */
403 private static final class IccAPDUArgument {
404 public int channel, cla, command, p1, p2, p3;
405 public String data;
406
407 public IccAPDUArgument(int channel, int cla, int command,
408 int p1, int p2, int p3, String data) {
409 this.channel = channel;
410 this.cla = cla;
411 this.command = command;
412 this.p1 = p1;
413 this.p2 = p2;
414 this.p3 = p3;
415 this.data = data;
416 }
417 }
418
419 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700420 * A request object to use for transmitting data to an ICC.
421 */
422 private static final class ManualNetworkSelectionArgument {
423 public OperatorInfo operatorInfo;
424 public boolean persistSelection;
425
426 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
427 this.operatorInfo = operatorInfo;
428 this.persistSelection = persistSelection;
429 }
430 }
431
432 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
434 * request after sending. The main thread will notify the request when it is complete.
435 */
436 private static final class MainThreadRequest {
437 /** The argument to use for the request */
438 public Object argument;
439 /** The result of the request that is run on the main thread */
440 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800441 // The subscriber id that this request applies to. Defaults to
442 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
443 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444
Nathan Harold92bed182018-10-12 18:16:49 -0700445 // In cases where subId is unavailable, the caller needs to specify the phone.
446 public Phone phone;
447
vagdeviaf9a5b92018-08-15 16:01:53 -0700448 public WorkSource workSource;
449
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 public MainThreadRequest(Object argument) {
451 this.argument = argument;
452 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800453
Nathan Harold92bed182018-10-12 18:16:49 -0700454 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
455 this.argument = argument;
456 if (phone != null) {
457 this.phone = phone;
458 }
459 this.workSource = workSource;
460 }
461
vagdeviaf9a5b92018-08-15 16:01:53 -0700462 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800463 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800464 if (subId != null) {
465 this.subId = subId;
466 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700467 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800468 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700469 }
470
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800471 private static final class IncomingThirdPartyCallArgs {
472 public final ComponentName component;
473 public final String callId;
474 public final String callerDisplayName;
475
476 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
477 String callerDisplayName) {
478 this.component = component;
479 this.callId = callId;
480 this.callerDisplayName = callerDisplayName;
481 }
482 }
483
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 /**
485 * A handler that processes messages on the main thread in the phone process. Since many
486 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
487 * inbound binder threads to the main thread in the phone process. The Binder thread
488 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
489 * on, which will be notified when the operation completes and will contain the result of the
490 * request.
491 *
492 * <p>If a MainThreadRequest object is provided in the msg.obj field,
493 * note that request.result must be set to something non-null for the calling thread to
494 * unblock.
495 */
496 private final class MainThreadHandler extends Handler {
497 @Override
498 public void handleMessage(Message msg) {
499 MainThreadRequest request;
500 Message onCompleted;
501 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800502 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800504 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505
506 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700507 case CMD_HANDLE_USSD_REQUEST: {
508 request = (MainThreadRequest) msg.obj;
509 final Phone phone = getPhoneFromRequest(request);
510 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
511 String ussdRequest = ussdObject.first;
512 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700513
Pengquan Menga1bb6272018-09-06 09:59:22 -0700514 if (!isUssdApiAllowed(request.subId)) {
515 // Carrier does not support use of this API, return failure.
516 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
517 UssdResponse response = new UssdResponse(ussdRequest, null);
518 Bundle returnData = new Bundle();
519 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
520 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700521
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 request.result = true;
523 notifyRequester(request);
524 return;
525 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700526
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 try {
528 request.result = phone != null
529 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
530 } catch (CallStateException cse) {
531 request.result = false;
532 }
533 // Wake up the requesting thread
534 notifyRequester(request);
535 break;
pkanwar32d516d2016-10-14 19:37:38 -0700536 }
537
Yorke Lee716f67e2015-06-17 15:39:16 -0700538 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700540 final Phone phone = getPhoneFromRequest(request);
541 request.result = phone != null ?
542 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
543 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("iccTransmitApduLogicalChannel: No UICC");
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
559 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 iccArgument.channel, iccArgument.cla, iccArgument.command,
562 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 break;
566
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
572 } else {
573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
574 if (ar.result == null) {
575 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800576 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800578 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 } else {
580 loge("iccTransmitApduLogicalChannel: Unknown exception");
581 }
582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 break;
585
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
587 request = (MainThreadRequest) msg.obj;
588 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800589 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 if (uiccCard == null) {
591 loge("iccTransmitApduBasicChannel: No UICC");
592 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700593 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 } else {
595 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
596 request);
597 uiccCard.iccTransmitApduBasicChannel(
598 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
599 iccArgument.p3, iccArgument.data, onCompleted);
600 }
601 break;
602
603 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
608 } else {
609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("iccTransmitApduBasicChannel: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("iccTransmitApduBasicChannel: CommandException: " +
614 ar.exception);
615 } else {
616 loge("iccTransmitApduBasicChannel: Unknown exception");
617 }
618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 break;
621
622 case CMD_EXCHANGE_SIM_IO:
623 request = (MainThreadRequest) msg.obj;
624 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 if (uiccCard == null) {
627 loge("iccExchangeSimIO: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
632 request);
633 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
634 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
635 iccArgument.data, onCompleted);
636 }
637 break;
638
639 case EVENT_EXCHANGE_SIM_IO_DONE:
640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result;
644 } else {
645 request.result = new IccIoResult(0x6f, 0, (byte[])null);
646 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700648 break;
649
Derek Tan4d5e5c12014-02-04 11:54:58 -0800650 case CMD_SEND_ENVELOPE:
651 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800652 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 if (uiccCard == null) {
654 loge("sendEnvelopeWithStatus: No UICC");
655 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
659 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
660 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800661 break;
662
663 case EVENT_SEND_ENVELOPE_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800668 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700669 request.result = new IccIoResult(0x6F, 0, (byte[])null);
670 if (ar.result == null) {
671 loge("sendEnvelopeWithStatus: Empty response");
672 } else if (ar.exception instanceof CommandException) {
673 loge("sendEnvelopeWithStatus: CommandException: " +
674 ar.exception);
675 } else {
676 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
677 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800680 break;
681
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 case CMD_OPEN_CHANNEL:
683 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800684 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800685 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 if (uiccCard == null) {
687 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800688 request.result = new IccOpenLogicalChannelResponse(-1,
689 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700690 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 } else {
692 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800693 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
694 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
698 case EVENT_OPEN_CHANNEL_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700703 int[] result = (int[]) ar.result;
704 int channelId = result[0];
705 byte[] selectResponse = null;
706 if (result.length > 1) {
707 selectResponse = new byte[result.length - 1];
708 for (int i = 1; i < result.length; ++i) {
709 selectResponse[i - 1] = (byte) result[i];
710 }
711 }
712 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700713 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 if (ar.result == null) {
716 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700718 if (ar.exception != null) {
719 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
720 }
721
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700722 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700723 if (ar.exception instanceof CommandException) {
724 CommandException.Error error =
725 ((CommandException) (ar.exception)).getCommandError();
726 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700728 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700729 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700730 }
731 }
732 openChannelResp = new IccOpenLogicalChannelResponse(
733 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700735 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700737 break;
738
739 case CMD_CLOSE_CHANNEL:
740 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800741 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 if (uiccCard == null) {
743 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900744 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 } else {
747 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
748 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
749 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700750 break;
751
752 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800753 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
754 break;
755
756 case CMD_NV_READ_ITEM:
757 request = (MainThreadRequest) msg.obj;
758 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800759 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
760 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800761 break;
762
763 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 ar = (AsyncResult) msg.obj;
765 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800766 if (ar.exception == null && ar.result != null) {
767 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800769 request.result = "";
770 if (ar.result == null) {
771 loge("nvReadItem: Empty response");
772 } else if (ar.exception instanceof CommandException) {
773 loge("nvReadItem: CommandException: " +
774 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800776 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700777 }
778 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700779 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 break;
781
Jake Hambye994d462014-02-03 13:10:13 -0800782 case CMD_NV_WRITE_ITEM:
783 request = (MainThreadRequest) msg.obj;
784 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
785 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800786 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700787 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
790 case EVENT_NV_WRITE_ITEM_DONE:
791 handleNullReturnEvent(msg, "nvWriteItem");
792 break;
793
794 case CMD_NV_WRITE_CDMA_PRL:
795 request = (MainThreadRequest) msg.obj;
796 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800797 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800798 break;
799
800 case EVENT_NV_WRITE_CDMA_PRL_DONE:
801 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
802 break;
803
chen xu6dac5ab2018-10-26 17:39:23 -0700804 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800805 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700806 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800807 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800808 break;
809
chen xu6dac5ab2018-10-26 17:39:23 -0700810 case EVENT_RESET_MODEM_CONFIG_DONE:
811 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
Sooraj Sasindran37444802020-08-11 10:40:43 -0700814 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
817 request);
818 Phone phone = getPhoneFromRequest(request);
819 if (phone != null) {
820 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
821 } else {
822 loge("isNRDualConnectivityEnabled: No phone object");
823 request.result = false;
824 notifyRequester(request);
825 }
826 break;
827 }
828
829 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null && ar.result != null) {
833 request.result = ar.result;
834 } else {
835 // request.result must be set to something non-null
836 // for the calling thread to unblock
837 if (request.result != null) {
838 request.result = ar.result;
839 } else {
840 request.result = false;
841 }
842 if (ar.result == null) {
843 loge("isNRDualConnectivityEnabled: Empty response");
844 } else if (ar.exception instanceof CommandException) {
845 loge("isNRDualConnectivityEnabled: CommandException: "
846 + ar.exception);
847 } else {
848 loge("isNRDualConnectivityEnabled: Unknown exception");
849 }
850 }
851 notifyRequester(request);
852 break;
853
854 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
855 request = (MainThreadRequest) msg.obj;
856 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
857 Phone phone = getPhoneFromRequest(request);
858 if (phone != null) {
859 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
860 request.workSource);
861 } else {
862 loge("enableNrDualConnectivity: No phone object");
863 request.result =
864 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
865 notifyRequester(request);
866 }
867 break;
868 }
869
870 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null) {
874 request.result =
875 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
876 } else {
877 request.result =
878 TelephonyManager
879 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
880 if (ar.exception instanceof CommandException) {
881 CommandException.Error error =
882 ((CommandException) (ar.exception)).getCommandError();
883 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
884 request.result =
885 TelephonyManager
886 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000887 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
888 request.result =
889 TelephonyManager
890 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700891 }
892 loge("enableNrDualConnectivity" + ": CommandException: "
893 + ar.exception);
894 } else {
895 loge("enableNrDualConnectivity" + ": Unknown exception");
896 }
897 }
898 notifyRequester(request);
899 break;
900 }
901
SongFerngWang3ef3e072020-12-21 16:41:52 +0800902 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800904 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
905 request);
906 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 break;
908
SongFerngWang3ef3e072020-12-21 16:41:52 +0800909 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result; // Integer
914 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530915 // request.result must be set to something non-null
916 // for the calling thread to unblock
917 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800919 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800921 loge("getAllowedNetworkTypesBitmask: CommandException: "
922 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800924 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800925 }
926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700927 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800928 break;
929
SongFerngWang3ef3e072020-12-21 16:41:52 +0800930 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800931 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800932 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
933 request);
934 Pair<Integer, Long> reasonWithNetworkTypes =
935 (Pair<Integer, Long>) request.argument;
936 getPhoneFromRequest(request).setAllowedNetworkTypes(
937 reasonWithNetworkTypes.first,
938 reasonWithNetworkTypes.second,
939 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800940 break;
941
SongFerngWang3ef3e072020-12-21 16:41:52 +0800942 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
943 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800944 break;
945
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000946 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
947 request = (MainThreadRequest)msg.obj;
948 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800949 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000950 break;
951
952 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
953 ar = (AsyncResult)msg.obj;
954 request = (MainThreadRequest)ar.userObj;
955 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000957 break;
958
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800959 case CMD_SET_VOICEMAIL_NUMBER:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
962 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800963 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
964 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800965 break;
966
967 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
968 handleNullReturnEvent(msg, "setVoicemailNumber");
969 break;
970
Stuart Scott54788802015-03-30 13:18:01 -0700971 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
974 request);
975 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
976 break;
977
978 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
979 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
980 break;
981
Shishir Agrawal302c8692015-06-19 13:49:39 -0700982 case CMD_PERFORM_NETWORK_SCAN:
983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
985 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
986 break;
987
Hall Liu27d24262020-09-18 19:04:59 -0700988 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700991 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
992 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
993 request.argument;
994 int callForwardingReason = args.first;
995 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800996 break;
Hall Liu27d24262020-09-18 19:04:59 -0700997 }
998 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001001 TelephonyManager.CallForwardingInfoCallback callback =
1002 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1003 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001004 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001005 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001006 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1007 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1008 // Service Class is a bit mask per 3gpp 27.007. Search for
1009 // any service for voice call.
1010 if ((callForwardInfo.serviceClass
1011 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001012 callForwardingInfo = new CallForwardingInfo(true,
1013 callForwardInfo.reason,
1014 callForwardInfo.number,
1015 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001016 break;
1017 }
1018 }
1019 // Didn't find a call forward info for voice call.
1020 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001021 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1022 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001023 }
Hall Liu27d24262020-09-18 19:04:59 -07001024 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001025 } else {
1026 if (ar.result == null) {
1027 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1028 }
1029 if (ar.exception != null) {
1030 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1031 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001032 int errorCode = TelephonyManager
1033 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001034 if (ar.exception instanceof CommandException) {
1035 CommandException.Error error =
1036 ((CommandException) (ar.exception)).getCommandError();
1037 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001038 errorCode = TelephonyManager
1039 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001040 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001041 errorCode = TelephonyManager
1042 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001043 }
1044 }
Hall Liu27d24262020-09-18 19:04:59 -07001045 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001046 }
Shuo Qian4a594052020-01-23 11:59:30 -08001047 break;
Hall Liu27d24262020-09-18 19:04:59 -07001048 }
Shuo Qian4a594052020-01-23 11:59:30 -08001049
Hall Liu27d24262020-09-18 19:04:59 -07001050 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001053 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001054 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001055 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1056 request.argument).first;
1057 request.phone.setCallForwardingOption(
1058 callForwardingInfoToSet.isEnabled()
1059 ? CommandsInterface.CF_ACTION_ENABLE
1060 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001061 callForwardingInfoToSet.getReason(),
1062 callForwardingInfoToSet.getNumber(),
1063 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1064 break;
Hall Liu27d24262020-09-18 19:04:59 -07001065 }
Shuo Qian4a594052020-01-23 11:59:30 -08001066
Hall Liu27d24262020-09-18 19:04:59 -07001067 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001070 Consumer<Integer> callback =
1071 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1072 request.argument).second;
1073 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001074 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001075 int errorCode = TelephonyManager.CallForwardingInfoCallback
1076 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001077 if (ar.exception instanceof CommandException) {
1078 CommandException.Error error =
1079 ((CommandException) (ar.exception)).getCommandError();
1080 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001081 errorCode = TelephonyManager.CallForwardingInfoCallback
1082 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001083 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001084 errorCode = TelephonyManager.CallForwardingInfoCallback
1085 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001086 }
1087 }
1088 callback.accept(errorCode);
1089 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001090 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001091 }
Shuo Qian4a594052020-01-23 11:59:30 -08001092 break;
Hall Liu27d24262020-09-18 19:04:59 -07001093 }
Shuo Qian4a594052020-01-23 11:59:30 -08001094
Hall Liu27d24262020-09-18 19:04:59 -07001095 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1098 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1099 break;
Hall Liu27d24262020-09-18 19:04:59 -07001100 }
Shuo Qian4a594052020-01-23 11:59:30 -08001101
Hall Liu27d24262020-09-18 19:04:59 -07001102 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001103 ar = (AsyncResult) msg.obj;
1104 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001105 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001106 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1107 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001108 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001109 // Service Class is a bit mask per 3gpp 27.007.
1110 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001111 if (callForwardResults.length > 1
1112 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001113 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001114 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001115 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1116 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001117 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001118 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001119 }
1120 } else {
1121 if (ar.result == null) {
1122 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1123 }
1124 if (ar.exception != null) {
1125 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1126 }
1127 if (ar.exception instanceof CommandException) {
1128 CommandException.Error error =
1129 ((CommandException) (ar.exception)).getCommandError();
1130 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1131 callForwardingStatus =
1132 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1133 }
1134 }
1135 }
Hall Liu27d24262020-09-18 19:04:59 -07001136 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001137 break;
Hall Liu27d24262020-09-18 19:04:59 -07001138 }
Shuo Qian4a594052020-01-23 11:59:30 -08001139
Hall Liu27d24262020-09-18 19:04:59 -07001140 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001141 request = (MainThreadRequest) msg.obj;
1142 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001143 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1144 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001145 break;
Hall Liu27d24262020-09-18 19:04:59 -07001146 }
Shuo Qian4a594052020-01-23 11:59:30 -08001147
Hall Liu27d24262020-09-18 19:04:59 -07001148 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001151 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1152 Consumer<Integer> callback =
1153 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1154 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001156 if (ar.exception instanceof CommandException) {
1157 CommandException.Error error =
1158 ((CommandException) (ar.exception)).getCommandError();
1159 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1160 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1161 } else {
1162 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1163 }
1164 } else {
1165 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1166 }
1167 } else {
1168 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1169 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001170 }
Shuo Qian4a594052020-01-23 11:59:30 -08001171 break;
Hall Liu27d24262020-09-18 19:04:59 -07001172 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001173 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1174 ar = (AsyncResult) msg.obj;
1175 request = (MainThreadRequest) ar.userObj;
1176 CellNetworkScanResult cellScanResult;
1177 if (ar.exception == null && ar.result != null) {
1178 cellScanResult = new CellNetworkScanResult(
1179 CellNetworkScanResult.STATUS_SUCCESS,
1180 (List<OperatorInfo>) ar.result);
1181 } else {
1182 if (ar.result == null) {
1183 loge("getCellNetworkScanResults: Empty response");
1184 }
1185 if (ar.exception != null) {
1186 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1187 }
1188 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1189 if (ar.exception instanceof CommandException) {
1190 CommandException.Error error =
1191 ((CommandException) (ar.exception)).getCommandError();
1192 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1193 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1194 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1195 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1196 }
1197 }
1198 cellScanResult = new CellNetworkScanResult(errorCode, null);
1199 }
1200 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001201 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001202 break;
1203
1204 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1205 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001206 ManualNetworkSelectionArgument selArg =
1207 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001208 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1209 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001210 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1211 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001212 break;
1213
1214 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001215 ar = (AsyncResult) msg.obj;
1216 request = (MainThreadRequest) ar.userObj;
1217 if (ar.exception == null) {
1218 request.result = true;
1219 } else {
1220 request.result = false;
1221 loge("setNetworkSelectionModeManual " + ar.exception);
1222 }
1223 notifyRequester(request);
1224 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001225 break;
1226
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001227 case CMD_GET_MODEM_ACTIVITY_INFO:
1228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001230 if (defaultPhone != null) {
1231 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001232 } else {
1233 ResultReceiver result = (ResultReceiver) request.argument;
1234 Bundle bundle = new Bundle();
1235 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001236 new ModemActivityInfo(0, 0, 0,
1237 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001238 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001239 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 break;
1241
Hall Liud0f208c2020-10-14 16:54:44 -07001242 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001243 ar = (AsyncResult) msg.obj;
1244 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001245 ResultReceiver result = (ResultReceiver) request.argument;
1246
Hall Liud0f208c2020-10-14 16:54:44 -07001247 ModemActivityInfo ret = null;
1248 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001249 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001250 // Update the last modem activity info and the result of the request.
1251 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1252 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001253 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001254 int[] txTimeMs = info.getTransmitTimeMillis();
1255 int[] lastModemTxTimeMs = mLastModemActivityInfo
1256 .getTransmitTimeMillis();
1257 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1258 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1259 }
Hall Liu49656c02020-10-09 19:00:11 -07001260 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001261 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1262 + mLastModemActivityInfo.getSleepTimeMillis());
1263 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1264 + mLastModemActivityInfo.getIdleTimeMillis());
1265 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1266 mLastModemActivityInfo.setReceiveTimeMillis(
1267 info.getReceiveTimeMillis()
1268 + mLastModemActivityInfo.getReceiveTimeMillis());
1269 }
Hall Liu49656c02020-10-09 19:00:11 -07001270 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001271 mLastModemActivityInfo.getSleepTimeMillis(),
1272 mLastModemActivityInfo.getIdleTimeMillis(),
1273 mLastModemActivityInfo.getTransmitTimeMillis(),
1274 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001275 } else {
1276 if (ar.result == null) {
1277 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001278 error = TelephonyManager.ModemActivityInfoException
1279 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001280 } else if (ar.exception instanceof CommandException) {
1281 loge("queryModemActivityInfo: CommandException: " +
1282 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001283 error = TelephonyManager.ModemActivityInfoException
1284 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001285 } else {
1286 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001287 error = TelephonyManager.ModemActivityInfoException
1288 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001289 }
1290 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001291 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001292 if (ret != null) {
1293 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1294 } else {
1295 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1296 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001297 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001298 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001299 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001300 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001301
Meng Wang1a7c35a2016-05-05 20:56:15 -07001302 case CMD_SET_ALLOWED_CARRIERS:
1303 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001304 CarrierRestrictionRules argument =
1305 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001307 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001308 break;
1309
1310 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1311 ar = (AsyncResult) msg.obj;
1312 request = (MainThreadRequest) ar.userObj;
1313 if (ar.exception == null && ar.result != null) {
1314 request.result = ar.result;
1315 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001316 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1317 if (ar.exception instanceof CommandException) {
1318 loge("setAllowedCarriers: CommandException: " + ar.exception);
1319 CommandException.Error error =
1320 ((CommandException) (ar.exception)).getCommandError();
1321 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1322 request.result =
1323 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1324 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001325 } else {
1326 loge("setAllowedCarriers: Unknown exception");
1327 }
1328 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001329 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001330 break;
1331
1332 case CMD_GET_ALLOWED_CARRIERS:
1333 request = (MainThreadRequest) msg.obj;
1334 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001335 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001336 break;
1337
1338 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1339 ar = (AsyncResult) msg.obj;
1340 request = (MainThreadRequest) ar.userObj;
1341 if (ar.exception == null && ar.result != null) {
1342 request.result = ar.result;
1343 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001344 request.result = new IllegalStateException(
1345 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001346 if (ar.result == null) {
1347 loge("getAllowedCarriers: Empty response");
1348 } else if (ar.exception instanceof CommandException) {
1349 loge("getAllowedCarriers: CommandException: " +
1350 ar.exception);
1351 } else {
1352 loge("getAllowedCarriers: Unknown exception");
1353 }
1354 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001355 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001356 break;
1357
Nathan Haroldb3014052017-01-25 15:57:32 -08001358 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1359 ar = (AsyncResult) msg.obj;
1360 request = (MainThreadRequest) ar.userObj;
1361 if (ar.exception == null && ar.result != null) {
1362 request.result = ar.result;
1363 } else {
1364 request.result = new IllegalArgumentException(
1365 "Failed to retrieve Forbidden Plmns");
1366 if (ar.result == null) {
1367 loge("getForbiddenPlmns: Empty response");
1368 } else {
1369 loge("getForbiddenPlmns: Unknown exception");
1370 }
1371 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001372 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001373 break;
1374
1375 case CMD_GET_FORBIDDEN_PLMNS:
1376 request = (MainThreadRequest) msg.obj;
1377 uiccCard = getUiccCardFromRequest(request);
1378 if (uiccCard == null) {
1379 loge("getForbiddenPlmns() UiccCard is null");
1380 request.result = new IllegalArgumentException(
1381 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001382 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001383 break;
1384 }
1385 Integer appType = (Integer) request.argument;
1386 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1387 if (uiccApp == null) {
1388 loge("getForbiddenPlmns() no app with specified type -- "
1389 + appType);
1390 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001391 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001392 break;
1393 } else {
1394 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1395 + " specified type -- " + appType);
1396 }
1397 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1398 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1399 onCompleted);
1400 break;
1401
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001402 case CMD_SWITCH_SLOTS:
1403 request = (MainThreadRequest) msg.obj;
1404 int[] physicalSlots = (int[]) request.argument;
1405 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1406 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1407 break;
1408
1409 case EVENT_SWITCH_SLOTS_DONE:
1410 ar = (AsyncResult) msg.obj;
1411 request = (MainThreadRequest) ar.userObj;
1412 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001413 notifyRequester(request);
1414 break;
1415 case CMD_GET_NETWORK_SELECTION_MODE:
1416 request = (MainThreadRequest) msg.obj;
1417 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1418 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1419 break;
1420
1421 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1422 ar = (AsyncResult) msg.obj;
1423 request = (MainThreadRequest) ar.userObj;
1424 if (ar.exception != null) {
1425 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1426 } else {
1427 int mode = ((int[]) ar.result)[0];
1428 if (mode == 0) {
1429 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1430 } else {
1431 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1432 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001433 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001434 notifyRequester(request);
1435 break;
1436 case CMD_GET_CDMA_ROAMING_MODE:
1437 request = (MainThreadRequest) msg.obj;
1438 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1439 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1440 break;
1441 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1442 ar = (AsyncResult) msg.obj;
1443 request = (MainThreadRequest) ar.userObj;
1444 if (ar.exception != null) {
1445 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1446 } else {
1447 request.result = ((int[]) ar.result)[0];
1448 }
1449 notifyRequester(request);
1450 break;
1451 case CMD_SET_CDMA_ROAMING_MODE:
1452 request = (MainThreadRequest) msg.obj;
1453 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1454 int mode = (int) request.argument;
1455 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1456 break;
1457 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1458 ar = (AsyncResult) msg.obj;
1459 request = (MainThreadRequest) ar.userObj;
1460 request.result = ar.exception == null;
1461 notifyRequester(request);
1462 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001463 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1464 request = (MainThreadRequest) msg.obj;
1465 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1466 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1467 break;
1468 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
1471 if (ar.exception != null) {
1472 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1473 } else {
1474 request.result = ((int[]) ar.result)[0];
1475 }
1476 notifyRequester(request);
1477 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001478 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1479 request = (MainThreadRequest) msg.obj;
1480 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1481 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001482 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1483 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001484 break;
1485 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1486 ar = (AsyncResult) msg.obj;
1487 request = (MainThreadRequest) ar.userObj;
1488 request.result = ar.exception == null;
1489 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001490 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 case CMD_GET_ALL_CELL_INFO:
1492 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001494 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001496 case EVENT_GET_ALL_CELL_INFO_DONE:
1497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001499 // If a timeout occurs, the response will be null
1500 request.result = (ar.exception == null && ar.result != null)
1501 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 synchronized (request) {
1503 request.notifyAll();
1504 }
1505 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001506 case CMD_REQUEST_CELL_INFO_UPDATE:
1507 request = (MainThreadRequest) msg.obj;
1508 request.phone.requestCellInfoUpdate(request.workSource,
1509 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1510 break;
1511 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1512 ar = (AsyncResult) msg.obj;
1513 request = (MainThreadRequest) ar.userObj;
1514 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1515 try {
1516 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001517 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001518 cb.onError(
1519 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1520 ar.exception.getClass().getName(),
1521 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001522 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001523 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001524 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001525 } else {
1526 // use the result as returned
1527 cb.onCellInfo((List<CellInfo>) ar.result);
1528 }
1529 } catch (RemoteException re) {
1530 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1531 }
1532 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001533 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001534 request = (MainThreadRequest) msg.obj;
1535 WorkSource ws = (WorkSource) request.argument;
1536 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001537 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001538 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001539 }
1540 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001541 ar = (AsyncResult) msg.obj;
1542 request = (MainThreadRequest) ar.userObj;
1543 if (ar.exception == null) {
1544 request.result = ar.result;
1545 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001546 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001547 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001548 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001549 }
1550
1551 synchronized (request) {
1552 request.notifyAll();
1553 }
1554 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001555 }
chen xu6dac5ab2018-10-26 17:39:23 -07001556 case CMD_MODEM_REBOOT:
1557 request = (MainThreadRequest) msg.obj;
1558 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001559 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001560 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001561 case EVENT_CMD_MODEM_REBOOT_DONE:
1562 handleNullReturnEvent(msg, "rebootModem");
1563 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001564 case CMD_REQUEST_ENABLE_MODEM:
1565 request = (MainThreadRequest) msg.obj;
1566 boolean enable = (boolean) request.argument;
1567 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001568 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001569 PhoneConfigurationManager.getInstance()
1570 .enablePhone(request.phone, enable, onCompleted);
1571 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001572 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001576 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001577 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001578 if ((boolean) request.result) {
1579 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1580 updateModemStateMetrics();
1581 } else {
1582 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1583 + ar.exception);
1584 }
1585 notifyRequester(request);
1586 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001587 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001588 case CMD_GET_MODEM_STATUS:
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1591 PhoneConfigurationManager.getInstance()
1592 .getPhoneStatusFromModem(request.phone, onCompleted);
1593 break;
1594 case EVENT_GET_MODEM_STATUS_DONE:
1595 ar = (AsyncResult) msg.obj;
1596 request = (MainThreadRequest) ar.userObj;
1597 int id = request.phone.getPhoneId();
1598 if (ar.exception == null && ar.result != null) {
1599 request.result = ar.result;
1600 //update the cache as modem status has changed
1601 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1602 (boolean) request.result);
1603 } else {
1604 // Return true if modem status cannot be retrieved. For most cases,
1605 // modem status is on. And for older version modems, GET_MODEM_STATUS
1606 // and disable modem are not supported. Modem is always on.
1607 // TODO: this should be fixed in R to support a third
1608 // status UNKNOWN b/131631629
1609 request.result = true;
1610 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1611 + ar.exception);
1612 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001613 notifyRequester(request);
1614 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001615 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1616 request = (MainThreadRequest) msg.obj;
1617 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1618 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1619 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1620 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1621 break;
1622 }
1623 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1624 ar = (AsyncResult) msg.obj;
1625 request = (MainThreadRequest) ar.userObj;
1626 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1627 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1628 args.second.accept(ar.exception == null);
1629 notifyRequester(request);
1630 break;
1631 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001632 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1633 request = (MainThreadRequest) msg.obj;
1634 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1635 Phone phone = getPhoneFromRequest(request);
1636 if (phone != null) {
1637 phone.getSystemSelectionChannels(onCompleted);
1638 } else {
1639 loge("getSystemSelectionChannels: No phone object");
1640 request.result = new ArrayList<RadioAccessSpecifier>();
1641 notifyRequester(request);
1642 }
1643 break;
1644 }
1645 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1646 ar = (AsyncResult) msg.obj;
1647 request = (MainThreadRequest) ar.userObj;
1648 if (ar.exception == null && ar.result != null) {
1649 request.result = ar.result;
1650 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001651 request.result = new IllegalStateException(
1652 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001653 if (ar.result == null) {
1654 loge("getSystemSelectionChannels: Empty response");
1655 } else {
1656 loge("getSystemSelectionChannels: Unknown exception");
1657 }
1658 }
1659 notifyRequester(request);
1660 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001661 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1662 ar = (AsyncResult) msg.obj;
1663 request = (MainThreadRequest) ar.userObj;
1664 if (ar.exception == null && ar.result != null) {
1665 request.result = ar.result;
1666 } else {
1667 request.result = -1;
1668 loge("Failed to set Forbidden Plmns");
1669 if (ar.result == null) {
1670 loge("setForbidenPlmns: Empty response");
1671 } else if (ar.exception != null) {
1672 loge("setForbiddenPlmns: Exception: " + ar.exception);
1673 request.result = -1;
1674 } else {
1675 loge("setForbiddenPlmns: Unknown exception");
1676 }
1677 }
1678 notifyRequester(request);
1679 break;
1680 case CMD_SET_FORBIDDEN_PLMNS:
1681 request = (MainThreadRequest) msg.obj;
1682 uiccCard = getUiccCardFromRequest(request);
1683 if (uiccCard == null) {
1684 loge("setForbiddenPlmns: UiccCard is null");
1685 request.result = -1;
1686 notifyRequester(request);
1687 break;
1688 }
1689 Pair<Integer, List<String>> setFplmnsArgs =
1690 (Pair<Integer, List<String>>) request.argument;
1691 appType = setFplmnsArgs.first;
1692 List<String> fplmns = setFplmnsArgs.second;
1693 uiccApp = uiccCard.getApplicationByType(appType);
1694 if (uiccApp == null) {
1695 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1696 request.result = -1;
1697 loge("Failed to get UICC App");
1698 notifyRequester(request);
1699 } else {
1700 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1701 ((SIMRecords) uiccApp.getIccRecords())
1702 .setForbiddenPlmns(onCompleted, fplmns);
1703 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001704 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001705 case CMD_ERASE_MODEM_CONFIG:
1706 request = (MainThreadRequest) msg.obj;
1707 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1708 defaultPhone.eraseModemConfig(onCompleted);
1709 break;
1710 case EVENT_ERASE_MODEM_CONFIG_DONE:
1711 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001712 break;
zoey chene02881a2019-12-30 16:11:23 +08001713
Kai Shif70f46f2021-03-03 13:59:46 -08001714 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1715 request = (MainThreadRequest) msg.obj;
1716 request.result = defaultPhone.eraseDataInSharedPreferences();
1717 notifyRequester(request);
1718 break;
1719
zoey chene02881a2019-12-30 16:11:23 +08001720 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1723 Pair<String, String> changed = (Pair<String, String>) request.argument;
1724 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1725 changed.first, changed.second, onCompleted);
1726 break;
1727 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1728 ar = (AsyncResult) msg.obj;
1729 request = (MainThreadRequest) ar.userObj;
1730 if (ar.exception == null) {
1731 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001732 // If the operation is successful, update the PIN storage
1733 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1734 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001735 UiccController.getInstance().getPinStorage()
1736 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001737 } else {
1738 request.result = msg.arg1;
1739 }
1740 notifyRequester(request);
1741 break;
1742
Michele Berionne5e411512020-11-13 02:36:59 +00001743 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001744 request = (MainThreadRequest) msg.obj;
1745 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1746 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1747 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1748 enabled.first, enabled.second, onCompleted);
1749 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001750 }
zoey chene02881a2019-12-30 16:11:23 +08001751 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1752 ar = (AsyncResult) msg.obj;
1753 request = (MainThreadRequest) ar.userObj;
1754 if (ar.exception == null) {
1755 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001756 // If the operation is successful, update the PIN storage
1757 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1758 int phoneId = getPhoneFromRequest(request).getPhoneId();
1759 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001760 UiccController.getInstance().getPinStorage()
1761 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001762 } else {
1763 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1764 }
zoey chene02881a2019-12-30 16:11:23 +08001765 } else {
1766 request.result = msg.arg1;
1767 }
Michele Berionne5e411512020-11-13 02:36:59 +00001768
1769
zoey chene02881a2019-12-30 16:11:23 +08001770 notifyRequester(request);
1771 break;
1772
Peter Wangdafb9ac2020-01-15 14:13:38 -08001773 case MSG_NOTIFY_USER_ACTIVITY:
1774 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001775 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001776 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1777 getDefaultPhone().getContext().sendBroadcastAsUser(
1778 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1779 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001780
1781 case CMD_SET_DATA_THROTTLING: {
1782 request = (MainThreadRequest) msg.obj;
1783 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1784 DataThrottlingRequest dataThrottlingRequest =
1785 (DataThrottlingRequest) request.argument;
1786 Phone phone = getPhoneFromRequest(request);
1787 if (phone != null) {
1788 phone.setDataThrottling(onCompleted,
1789 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1790 dataThrottlingRequest.getCompletionDurationMillis());
1791 } else {
1792 loge("setDataThrottling: No phone object");
1793 request.result =
1794 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1795 notifyRequester(request);
1796 }
1797
1798 break;
1799 }
1800 case EVENT_SET_DATA_THROTTLING_DONE:
1801 ar = (AsyncResult) msg.obj;
1802 request = (MainThreadRequest) ar.userObj;
1803
1804 if (ar.exception == null) {
1805 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1806 } else if (ar.exception instanceof CommandException) {
1807 loge("setDataThrottling: CommandException: " + ar.exception);
1808 CommandException.Error error =
1809 ((CommandException) (ar.exception)).getCommandError();
1810
1811 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1812 request.result = TelephonyManager
1813 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1814 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1815 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001816 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1817 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001818 } else {
1819 request.result =
1820 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1821 }
1822 } else {
1823 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1824 }
1825 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1826 notifyRequester(request);
1827 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001828
1829 case CMD_SET_SIM_POWER: {
1830 request = (MainThreadRequest) msg.obj;
1831 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1832 request = (MainThreadRequest) msg.obj;
1833 int stateToSet =
1834 ((Pair<Integer, IIntegerConsumer>)
1835 request.argument).first;
1836 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1837 break;
1838 }
1839 case EVENT_SET_SIM_POWER_DONE: {
1840 ar = (AsyncResult) msg.obj;
1841 request = (MainThreadRequest) ar.userObj;
1842 IIntegerConsumer callback =
1843 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1844 if (ar.exception != null) {
1845 loge("setSimPower exception: " + ar.exception);
1846 int errorCode = TelephonyManager.CallForwardingInfoCallback
1847 .RESULT_ERROR_UNKNOWN;
1848 if (ar.exception instanceof CommandException) {
1849 CommandException.Error error =
1850 ((CommandException) (ar.exception)).getCommandError();
1851 if (error == CommandException.Error.SIM_ERR) {
1852 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1853 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1854 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1855 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1856 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1857 } else {
1858 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1859 }
1860 }
1861 try {
1862 callback.accept(errorCode);
1863 } catch (RemoteException e) {
1864 // Ignore if the remote process is no longer available to call back.
1865 Log.w(LOG_TAG, "setSimPower: callback not available.");
1866 }
1867 } else {
1868 try {
1869 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1870 } catch (RemoteException e) {
1871 // Ignore if the remote process is no longer available to call back.
1872 Log.w(LOG_TAG, "setSimPower: callback not available.");
1873 }
1874 }
1875 break;
1876 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001877 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1878 request = (MainThreadRequest) msg.obj;
1879
1880 final Phone phone = getPhoneFromRequest(request);
1881 if (phone == null || phone.getServiceStateTracker() == null) {
1882 request.result = new IllegalStateException("Phone or SST is null");
1883 notifyRequester(request);
1884 break;
1885 }
1886
1887 Pair<Integer, SignalStrengthUpdateRequest> pair =
1888 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1889 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1890 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001891 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001892 request.subId, pair.first /*callingUid*/,
1893 pair.second /*request*/, onCompleted);
1894 break;
1895 }
1896 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1897 ar = (AsyncResult) msg.obj;
1898 request = (MainThreadRequest) ar.userObj;
1899 // request.result will be the exception of ar if present, true otherwise.
1900 // Be cautious not to leave result null which will wait() forever
1901 request.result = ar.exception != null ? ar.exception : true;
1902 notifyRequester(request);
1903 break;
1904 }
1905 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1906 request = (MainThreadRequest) msg.obj;
1907
1908 Phone phone = getPhoneFromRequest(request);
1909 if (phone == null || phone.getServiceStateTracker() == null) {
1910 request.result = new IllegalStateException("Phone or SST is null");
1911 notifyRequester(request);
1912 break;
1913 }
1914
1915 Pair<Integer, SignalStrengthUpdateRequest> pair =
1916 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1917 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1918 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001919 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001920 request.subId, pair.first /*callingUid*/,
1921 pair.second /*request*/, onCompleted);
1922 break;
1923 }
1924 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1925 ar = (AsyncResult) msg.obj;
1926 request = (MainThreadRequest) ar.userObj;
1927 request.result = ar.exception != null ? ar.exception : true;
1928 notifyRequester(request);
1929 break;
1930 }
Jordan Liu109698e2020-11-24 14:50:34 -08001931
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001932 case CMD_GET_SLICING_CONFIG: {
1933 request = (MainThreadRequest) msg.obj;
1934 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1935 request.phone.getSlicingConfig(onCompleted);
1936 break;
1937 }
1938 case EVENT_GET_SLICING_CONFIG_DONE: {
1939 ar = (AsyncResult) msg.obj;
1940 request = (MainThreadRequest) ar.userObj;
1941 ResultReceiver result = (ResultReceiver) request.argument;
1942
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001943 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001944 Bundle bundle = new Bundle();
1945 int resultCode = 0;
1946 if (ar.exception != null) {
1947 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1948 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001949 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001950 } else if (ar.result == null) {
1951 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001952 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001953 } else {
1954 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001955 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1956 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001957 }
1958
1959 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001960 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001961 }
1962 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1963 result.send(resultCode, bundle);
1964 notifyRequester(request);
1965 break;
1966 }
1967
Michele Berionne5e411512020-11-13 02:36:59 +00001968 case CMD_PREPARE_UNATTENDED_REBOOT:
1969 request = (MainThreadRequest) msg.obj;
1970 request.result =
1971 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1972 notifyRequester(request);
1973 break;
1974
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 default:
1976 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1977 break;
1978 }
1979 }
Jake Hambye994d462014-02-03 13:10:13 -08001980
Pengquan Menga1bb6272018-09-06 09:59:22 -07001981 private void notifyRequester(MainThreadRequest request) {
1982 synchronized (request) {
1983 request.notifyAll();
1984 }
1985 }
1986
Jake Hambye994d462014-02-03 13:10:13 -08001987 private void handleNullReturnEvent(Message msg, String command) {
1988 AsyncResult ar = (AsyncResult) msg.obj;
1989 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1990 if (ar.exception == null) {
1991 request.result = true;
1992 } else {
1993 request.result = false;
1994 if (ar.exception instanceof CommandException) {
1995 loge(command + ": CommandException: " + ar.exception);
1996 } else {
1997 loge(command + ": Unknown exception");
1998 }
1999 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002000 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 }
2003
2004 /**
2005 * Posts the specified command to be executed on the main thread,
2006 * waits for the request to complete, and returns the result.
2007 * @see #sendRequestAsync
2008 */
2009 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002010 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2011 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002012 }
2013
2014 /**
2015 * Posts the specified command to be executed on the main thread,
2016 * waits for the request to complete, and returns the result.
2017 * @see #sendRequestAsync
2018 */
2019 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2020 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002021 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002022 }
2023
2024 /**
2025 * Posts the specified command to be executed on the main thread,
2026 * waits for the request to complete, and returns the result.
2027 * @see #sendRequestAsync
2028 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002029 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002030 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2031 }
2032
2033 /**
2034 * Posts the specified command to be executed on the main thread,
2035 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2036 * if not timeout or null otherwise.
2037 * @see #sendRequestAsync
2038 */
2039 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2040 long timeoutInMs) {
2041 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002042 }
2043
2044 /**
2045 * Posts the specified command to be executed on the main thread,
2046 * waits for the request to complete, and returns the result.
2047 * @see #sendRequestAsync
2048 */
Nathan Harold92bed182018-10-12 18:16:49 -07002049 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002050 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002051 }
2052
2053 /**
2054 * Posts the specified command to be executed on the main thread,
2055 * waits for the request to complete, and returns the result.
2056 * @see #sendRequestAsync
2057 */
2058 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002059 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2060 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002061 }
2062
2063 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002064 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2065 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2066 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002067 * @see #sendRequestAsync
2068 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002069 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2070 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2072 throw new RuntimeException("This method will deadlock if called from the main thread.");
2073 }
2074
Nathan Harold92bed182018-10-12 18:16:49 -07002075 MainThreadRequest request = null;
2076 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2077 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2078 } else if (phone != null) {
2079 request = new MainThreadRequest(argument, phone, workSource);
2080 } else {
2081 request = new MainThreadRequest(argument, subId, workSource);
2082 }
2083
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084 Message msg = mMainThreadHandler.obtainMessage(command, request);
2085 msg.sendToTarget();
2086
Rambo Wang0f050d82021-02-12 11:43:36 -08002087
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002089 if (timeoutInMs >= 0) {
2090 // Wait for at least timeoutInMs before returning null request result
2091 long now = SystemClock.elapsedRealtime();
2092 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002093 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002094 try {
2095 request.wait(deadline - now);
2096 } catch (InterruptedException e) {
2097 // Do nothing, go back and check if request is completed or timeout
2098 } finally {
2099 now = SystemClock.elapsedRealtime();
2100 }
2101 }
2102 } else {
2103 // Wait for the request to complete
2104 while (request.result == null) {
2105 try {
2106 request.wait();
2107 } catch (InterruptedException e) {
2108 // Do nothing, go back and wait until the request is complete
2109 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111 }
2112 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002113 if (request.result == null) {
2114 Log.wtf(LOG_TAG,
2115 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117 return request.result;
2118 }
2119
2120 /**
2121 * Asynchronous ("fire and forget") version of sendRequest():
2122 * Posts the specified command to be executed on the main thread, and
2123 * returns immediately.
2124 * @see #sendRequest
2125 */
2126 private void sendRequestAsync(int command) {
2127 mMainThreadHandler.sendEmptyMessage(command);
2128 }
2129
2130 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002131 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002132 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002133 */
2134 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002135 sendRequestAsync(command, argument, null, null);
2136 }
2137
2138 /**
2139 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2140 * @see {@link #sendRequest(int,Object)}
2141 */
2142 private void sendRequestAsync(
2143 int command, Object argument, Phone phone, WorkSource workSource) {
2144 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002145 Message msg = mMainThreadHandler.obtainMessage(command, request);
2146 msg.sendToTarget();
2147 }
2148
2149 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 * Initialize the singleton PhoneInterfaceManager instance.
2151 * This is only done once, at startup, from PhoneApp.onCreate().
2152 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002153 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 synchronized (PhoneInterfaceManager.class) {
2155 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002156 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 } else {
2158 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2159 }
2160 return sInstance;
2161 }
2162 }
2163
2164 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002165 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002168 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002169 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002171 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002173 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002174 mTelephonySharedPreferences =
2175 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002176 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002177 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002178 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002179 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002180
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 publish();
2182 }
2183
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002184 private Phone getDefaultPhone() {
2185 Phone thePhone = getPhone(getDefaultSubscription());
2186 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2187 }
2188
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 private void publish() {
2190 if (DBG) log("publish: " + this);
2191
Peter Wangc035ce42020-01-08 21:00:22 -08002192 TelephonyFrameworkInitializer
2193 .getTelephonyServiceManager()
2194 .getTelephonyServiceRegisterer()
2195 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
Stuart Scott584921c2015-01-15 17:10:34 -08002198 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002199 if (request.phone != null) {
2200 return request.phone;
2201 } else {
2202 return getPhoneFromSubId(request.subId);
2203 }
2204 }
2205
2206 private Phone getPhoneFromSubId(int subId) {
2207 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2208 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002209 }
2210
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002211 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2212 Phone phone = getPhoneFromRequest(request);
2213 return phone == null ? null :
2214 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2215 }
2216
Wink Saville36469e72014-06-11 15:17:00 -07002217 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002218 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002219 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221
Kai Shif70f46f2021-03-03 13:59:46 -08002222 private void sendEraseModemConfig(@NonNull Phone phone) {
2223 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2224 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2225 }
2226
2227 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2228 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2229 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002230 }
2231
Peter Wang44b186e2020-01-13 23:33:09 -08002232 private boolean isImsAvailableOnDevice() {
2233 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2234 if (pm == null) {
2235 // For some reason package manger is not available.. This will fail internally anyway,
2236 // so do not throw error and allow.
2237 return true;
2238 }
2239 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2240 }
2241
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002243 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002244 }
2245
Wink Savilleb564aae2014-10-23 10:18:09 -07002246 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 if (DBG) log("dial: " + number);
2248 // No permission check needed here: This is just a wrapper around the
2249 // ACTION_DIAL intent, which is available to any app since it puts up
2250 // the UI before it does anything.
2251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252 final long identity = Binder.clearCallingIdentity();
2253 try {
2254 String url = createTelUrl(number);
2255 if (url == null) {
2256 return;
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002259 // PENDING: should we just silently fail if phone is offhook or ringing?
2260 PhoneConstants.State state = mCM.getState(subId);
2261 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2262 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2263 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2264 mApp.startActivity(intent);
2265 }
2266 } finally {
2267 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269 }
2270
2271 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002272 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002273 }
2274
Wink Savilleb564aae2014-10-23 10:18:09 -07002275 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 if (DBG) log("call: " + number);
2277
2278 // This is just a wrapper around the ACTION_CALL intent, but we still
2279 // need to do a permission check since we're calling startActivity()
2280 // from the context of the phone app.
2281 enforceCallPermission();
2282
Jordan Liu1617b712019-07-10 15:06:26 -07002283 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 != AppOpsManager.MODE_ALLOWED) {
2285 return;
2286 }
2287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 String url = createTelUrl(number);
2291 if (url == null) {
2292 return;
2293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 boolean isValid = false;
2296 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2297 if (slist != null) {
2298 for (SubscriptionInfo subInfoRecord : slist) {
2299 if (subInfoRecord.getSubscriptionId() == subId) {
2300 isValid = true;
2301 break;
2302 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002303 }
Wink Saville08874612014-08-31 19:19:58 -07002304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 if (!isValid) {
2306 return;
2307 }
Wink Saville08874612014-08-31 19:19:58 -07002308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002309 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2310 intent.putExtra(SUBSCRIPTION_KEY, subId);
2311 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2312 mApp.startActivity(intent);
2313 } finally {
2314 Binder.restoreCallingIdentity(identity);
2315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 }
2317
Wink Savilleb564aae2014-10-23 10:18:09 -07002318 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002319 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002320 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2321 }
2322
Wink Savilleb564aae2014-10-23 10:18:09 -07002323 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002324 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002325 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2326 }
2327
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002333 Phone phone = getPhone(subId);
2334 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002335 checkSimPin.start();
2336 return checkSimPin.unlockSim(null, pin);
2337 } finally {
2338 Binder.restoreCallingIdentity(identity);
2339 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
2341
Wink Savilleb564aae2014-10-23 10:18:09 -07002342 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002347 Phone phone = getPhone(subId);
2348 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002349 checkSimPuk.start();
2350 return checkSimPuk.unlockSim(puk, pin);
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
2353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 }
2355
2356 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002357 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 * a synchronous one.
2359 */
2360 private static class UnlockSim extends Thread {
2361
2362 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002363 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364
2365 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002366 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2367 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368
2369 // For replies from SimCard interface
2370 private Handler mHandler;
2371
2372 // For async handler to identify request type
2373 private static final int SUPPLY_PIN_COMPLETE = 100;
2374
Michele Berionne5e411512020-11-13 02:36:59 +00002375 UnlockSim(int phoneId, IccCard simCard) {
2376 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 mSimCard = simCard;
2378 }
2379
2380 @Override
2381 public void run() {
2382 Looper.prepare();
2383 synchronized (UnlockSim.this) {
2384 mHandler = new Handler() {
2385 @Override
2386 public void handleMessage(Message msg) {
2387 AsyncResult ar = (AsyncResult) msg.obj;
2388 switch (msg.what) {
2389 case SUPPLY_PIN_COMPLETE:
2390 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2391 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002392 mRetryCount = msg.arg1;
2393 if (ar.exception != null) {
2394 if (ar.exception instanceof CommandException &&
2395 ((CommandException)(ar.exception)).getCommandError()
2396 == CommandException.Error.PASSWORD_INCORRECT) {
2397 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002398 } //When UiccCardApp dispose,handle message and return exception
2399 else if (ar.exception instanceof CommandException &&
2400 ((CommandException) (ar.exception)).getCommandError()
2401 == CommandException.Error.ABORTED) {
2402 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002403 } else {
2404 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2405 }
2406 } else {
2407 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002409 mDone = true;
2410 UnlockSim.this.notifyAll();
2411 }
2412 break;
2413 }
2414 }
2415 };
2416 UnlockSim.this.notifyAll();
2417 }
2418 Looper.loop();
2419 }
2420
2421 /*
2422 * Use PIN or PUK to unlock SIM card
2423 *
2424 * If PUK is null, unlock SIM card with PIN
2425 *
2426 * If PUK is not null, unlock SIM card with PUK and set PIN code
2427 */
Wink Saville9de0f752013-10-22 19:04:03 -07002428 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429
2430 while (mHandler == null) {
2431 try {
2432 wait();
2433 } catch (InterruptedException e) {
2434 Thread.currentThread().interrupt();
2435 }
2436 }
2437 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2438
2439 if (puk == null) {
2440 mSimCard.supplyPin(pin, callback);
2441 } else {
2442 mSimCard.supplyPuk(puk, pin, callback);
2443 }
2444
2445 while (!mDone) {
2446 try {
2447 Log.d(LOG_TAG, "wait for done");
2448 wait();
2449 } catch (InterruptedException e) {
2450 // Restore the interrupted status
2451 Thread.currentThread().interrupt();
2452 }
2453 }
2454 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002455 int[] resultArray = new int[2];
2456 resultArray[0] = mResult;
2457 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002458
2459 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002460 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002461 }
2462
Wink Saville9de0f752013-10-22 19:04:03 -07002463 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465 }
2466
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002467 /**
2468 * This method has been removed due to privacy and stability concerns.
2469 */
2470 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002472 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2473 return;
Wink Saville36469e72014-06-11 15:17:00 -07002474 }
2475
Nathan Harold1f889d82020-06-04 17:05:26 -07002476 @Override
2477 public void updateServiceLocationWithPackageName(String callingPackage) {
2478 mApp.getSystemService(AppOpsManager.class)
2479 .checkPackage(Binder.getCallingUid(), callingPackage);
2480
Nathan Haroldf096d982020-11-18 17:18:06 -08002481 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002482 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2483 // Callers targeting S have no business invoking this method.
2484 return;
2485 }
2486
2487 LocationAccessPolicy.LocationPermissionResult locationResult =
2488 LocationAccessPolicy.checkLocationPermission(mApp,
2489 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2490 .setCallingPackage(callingPackage)
2491 .setCallingFeatureId(null)
2492 .setCallingPid(Binder.getCallingPid())
2493 .setCallingUid(Binder.getCallingUid())
2494 .setMethod("updateServiceLocation")
2495 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2496 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2497 .build());
2498 // Apps that lack location permission have no business calling this method;
2499 // however, because no permission was declared in the public API, denials must
2500 // all be "soft".
2501 switch (locationResult) {
2502 case DENIED_HARD: /* fall through */
2503 case DENIED_SOFT:
2504 return;
2505 }
2506
2507 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 final long identity = Binder.clearCallingIdentity();
2509 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002510 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002512 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002519 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002520 @Override
2521 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002522 return isRadioOnWithFeature(callingPackage, null);
2523 }
2524
2525
2526 @Override
2527 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2528 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2529 callingFeatureId);
2530 }
2531
2532 @Deprecated
2533 @Override
2534 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2535 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002536 }
2537
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002538 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002539 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2540 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002541 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002542 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002543 return false;
2544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
2548 return isRadioOnForSubscriber(subId);
2549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002552 }
2553
2554 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 final Phone phone = getPhone(subId);
2558 if (phone != null) {
2559 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2560 } else {
2561 return false;
2562 }
2563 } finally {
2564 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
2567
2568 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002569 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 }
Wink Saville36469e72014-06-11 15:17:00 -07002571
Wink Savilleb564aae2014-10-23 10:18:09 -07002572 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null) {
2579 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2580 }
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002583 }
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
2586 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002587 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
Wink Savilleb564aae2014-10-23 10:18:09 -07002590 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 final Phone phone = getPhone(subId);
2596 if (phone == null) {
2597 return false;
2598 }
2599 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2600 toggleRadioOnOffForSubscriber(subId);
2601 }
2602 return true;
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002606 }
Wink Saville36469e72014-06-11 15:17:00 -07002607
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002608 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002609 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002610 /*
2611 * If any of the Radios are available, it will need to be
2612 * shutdown. So return true if any Radio is available.
2613 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2617 Phone phone = PhoneFactory.getPhone(i);
2618 if (phone != null && phone.isRadioAvailable()) return true;
2619 }
2620 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2621 return false;
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002624 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002625 }
2626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002628 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002629 enforceModifyPermission();
2630
2631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2634 logv("Shutting down Phone " + i);
2635 shutdownRadioUsingPhoneId(i);
2636 }
2637 } finally {
2638 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002639 }
2640 }
2641
2642 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002643 Phone phone = PhoneFactory.getPhone(phoneId);
2644 if (phone != null && phone.isRadioAvailable()) {
2645 phone.shutdownRadio();
2646 }
2647 }
2648
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002649 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002650 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651
2652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2655 if (defaultPhone != null) {
2656 defaultPhone.setRadioPower(turnOn);
2657 return true;
2658 } else {
2659 loge("There's no default phone.");
2660 return false;
2661 }
2662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002664 }
Wink Saville36469e72014-06-11 15:17:00 -07002665 }
2666
Wink Savilleb564aae2014-10-23 10:18:09 -07002667 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669
2670 final long identity = Binder.clearCallingIdentity();
2671 try {
2672 final Phone phone = getPhone(subId);
2673 if (phone != null) {
2674 phone.setRadioPower(turnOn);
2675 return true;
2676 } else {
2677 return false;
2678 }
2679 } finally {
2680 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002681 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
2683
Wink Saville36469e72014-06-11 15:17:00 -07002684 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002685 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002686 public boolean enableDataConnectivity() {
2687 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 int subId = mSubscriptionController.getDefaultDataSubId();
2692 final Phone phone = getPhone(subId);
2693 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002694 phone.getDataEnabledSettings().setDataEnabled(
2695 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 return true;
2697 } else {
2698 return false;
2699 }
2700 } finally {
2701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 }
2704
Wink Saville36469e72014-06-11 15:17:00 -07002705 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002706 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 public boolean disableDataConnectivity() {
2708 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
2710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 int subId = mSubscriptionController.getDefaultDataSubId();
2713 final Phone phone = getPhone(subId);
2714 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002715 phone.getDataEnabledSettings().setDataEnabled(
2716 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 return true;
2718 } else {
2719 return false;
2720 }
2721 } finally {
2722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
2725
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002727 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002728 final long identity = Binder.clearCallingIdentity();
2729 try {
2730 final Phone phone = getPhone(subId);
2731 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002732 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733 } else {
2734 return false;
2735 }
2736 } finally {
2737 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 }
2740
2741 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002742 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002743 }
2744
pkanwarae03a6b2016-11-06 20:37:09 -08002745 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 enforceCallPermission();
2747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
2750 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2751 return;
2752 }
2753 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2754 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
2757 }
pkanwar32d516d2016-10-14 19:37:38 -07002758 };
2759
Wink Savilleb564aae2014-10-23 10:18:09 -07002760 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
2765 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2766 return false;
2767 }
2768 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2769 } finally {
2770 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002771 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 }
2773
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002774 /**
2775 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2776 * tag on getCallState Binder call.
2777 */
2778 @Deprecated
2779 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002781 if (CompatChanges.isChangeEnabled(
2782 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2783 Binder.getCallingUid())) {
2784 // Do not allow this API to be called on API version 31+, it should only be
2785 // called on old apps using this Binder call directly.
2786 throw new SecurityException("This method can only be used for applications "
2787 + "targeting API version 30 or less.");
2788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002791 Phone phone = getPhone(getDefaultSubscription());
2792 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2793 PhoneConstantConversions.convertCallState(phone.getState());
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
2796 }
2797 }
2798
2799 @Override
2800 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2801 if (CompatChanges.isChangeEnabled(
2802 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2803 Binder.getCallingUid())) {
2804 // Check READ_PHONE_STATE for API version 31+
2805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2806 featureId, "getCallStateForSubscription")) {
2807 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2808 + "targeting API level 31+.");
2809 }
2810 }
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
2813 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2815 PhoneConstantConversions.convertCallState(phone.getState());
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
2818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002822 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002823 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2824 }
2825
2826 @Override
2827 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 final long identity = Binder.clearCallingIdentity();
2829 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002830 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002831 if (phone != null) {
2832 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2833 } else {
2834 return PhoneConstantConversions.convertDataState(
2835 PhoneConstants.DataState.DISCONNECTED);
2836 }
2837 } finally {
2838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002840 }
2841
Sanket Padawe356d7632015-06-22 14:03:32 -07002842 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002843 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002844 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2845 }
2846
2847 @Override
2848 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849 final long identity = Binder.clearCallingIdentity();
2850 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002851 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 if (phone != null) {
2853 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2854 } else {
2855 return TelephonyManager.DATA_ACTIVITY_NONE;
2856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
2862 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002863 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002865 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002866
2867 LocationAccessPolicy.LocationPermissionResult locationResult =
2868 LocationAccessPolicy.checkLocationPermission(mApp,
2869 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2870 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002871 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002872 .setCallingPid(Binder.getCallingPid())
2873 .setCallingUid(Binder.getCallingUid())
2874 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002875 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002876 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2877 .build());
2878 switch (locationResult) {
2879 case DENIED_HARD:
2880 throw new SecurityException("Not allowed to access cell location");
2881 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002882 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2883 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884 }
2885
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887 final long identity = Binder.clearCallingIdentity();
2888 try {
2889 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002890 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002891 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 } finally {
2893 Binder.restoreCallingIdentity(identity);
2894 }
Svetoslav64fad262015-04-14 14:35:21 -07002895 }
2896
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002897 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002898 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002899 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2900 // registered cell info, so return a NULL country instead.
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002903 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2904 // Get default phone in this case.
2905 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2906 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002907 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002909 if (phone == null) return "";
2910 ServiceStateTracker sst = phone.getServiceStateTracker();
2911 if (sst == null) return "";
2912 LocaleTracker lt = sst.getLocaleTracker();
2913 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002914 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002915 } finally {
2916 Binder.restoreCallingIdentity(identity);
2917 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002918 }
2919
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002920 /**
2921 * This method was removed due to potential issues caused by performing partial
2922 * updates of service state, and lack of a credible use case.
2923 *
2924 * This has the ability to break the telephony implementation by disabling notification of
2925 * changes in device connectivity. DO NOT USE THIS!
2926 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002927 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 public void enableLocationUpdates() {
2929 mApp.enforceCallingOrSelfPermission(
2930 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
2932
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002933 /**
2934 * This method was removed due to potential issues caused by performing partial
2935 * updates of service state, and lack of a credible use case.
2936 *
2937 * This has the ability to break the telephony implementation by disabling notification of
2938 * changes in device connectivity. DO NOT USE THIS!
2939 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002940 @Override
2941 public void disableLocationUpdates() {
2942 mApp.enforceCallingOrSelfPermission(
2943 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002944 }
2945
2946 @Override
2947 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002948 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2949 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002950 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002951 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2952 throw new SecurityException(
2953 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2954 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002955
Jordan Liu1617b712019-07-10 15:06:26 -07002956 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2958 return null;
2959 }
Svetoslav64fad262015-04-14 14:35:21 -07002960
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002961 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002962
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002963 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002964 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965
Nathan Haroldf180aac2018-06-01 18:43:55 -07002966 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2967 for (CellInfo ci : info) {
2968 if (ci instanceof CellInfoGsm) {
2969 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2970 } else if (ci instanceof CellInfoWcdma) {
2971 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2972 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002974 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002975 }
2976
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002977 private List<CellInfo> getCachedCellInfo() {
2978 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2979 for (Phone phone : PhoneFactory.getPhones()) {
2980 List<CellInfo> info = phone.getAllCellInfo();
2981 if (info != null) cellInfos.addAll(info);
2982 }
2983 return cellInfos;
2984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002985
2986 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002987 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002988 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002989 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002990
2991 LocationAccessPolicy.LocationPermissionResult locationResult =
2992 LocationAccessPolicy.checkLocationPermission(mApp,
2993 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2994 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002995 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002996 .setCallingPid(Binder.getCallingPid())
2997 .setCallingUid(Binder.getCallingUid())
2998 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002999 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003000 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3001 .build());
3002 switch (locationResult) {
3003 case DENIED_HARD:
3004 throw new SecurityException("Not allowed to access cell info");
3005 case DENIED_SOFT:
3006 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003007 }
3008
Nathan Haroldf096d982020-11-18 17:18:06 -08003009 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003010 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3011 return getCachedCellInfo();
3012 }
3013
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003014 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003015 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 final long identity = Binder.clearCallingIdentity();
3017 try {
3018 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3019 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003020 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003021 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003022 if (info != null) cellInfos.addAll(info);
3023 }
3024 return cellInfos;
3025 } finally {
3026 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003027 }
3028 }
3029
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003030 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003031 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3032 String callingFeatureId) {
3033 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3034 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003035 }
3036
3037 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003038 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3039 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003040 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003041 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003042 }
3043
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003044 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3045 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003046 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003047 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003048
3049 LocationAccessPolicy.LocationPermissionResult locationResult =
3050 LocationAccessPolicy.checkLocationPermission(mApp,
3051 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3052 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003053 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003054 .setCallingPid(Binder.getCallingPid())
3055 .setCallingUid(Binder.getCallingUid())
3056 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003057 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3058 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003059 .build());
3060 switch (locationResult) {
3061 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003062 if (TelephonyPermissions
3063 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003064 // Safetynet logging for b/154934934
3065 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3066 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003067 throw new SecurityException("Not allowed to access cell info");
3068 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003069 if (TelephonyPermissions
3070 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003071 // Safetynet logging for b/154934934
3072 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3073 }
Nathan Harold5320c422019-05-09 10:26:08 -07003074 try {
3075 cb.onCellInfo(new ArrayList<CellInfo>());
3076 } catch (RemoteException re) {
3077 // Drop without consequences
3078 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003079 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003080 }
3081
Nathan Harolda939a962019-05-09 10:13:47 -07003082
3083 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003084 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3085
3086 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3087 }
3088
3089 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003090 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003091 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003092 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003096 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097 } finally {
3098 Binder.restoreCallingIdentity(identity);
3099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003100 }
3101
Shishir Agrawala9f32182016-04-12 12:00:16 -07003102 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003103 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003104 Phone phone = PhoneFactory.getPhone(slotIndex);
3105 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003106 return null;
3107 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003108 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003109 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003110 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003111 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003112 return null;
3113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003114
3115 final long identity = Binder.clearCallingIdentity();
3116 try {
3117 return phone.getImei();
3118 } finally {
3119 Binder.restoreCallingIdentity(identity);
3120 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003121 }
3122
3123 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003124 public String getTypeAllocationCodeForSlot(int slotIndex) {
3125 Phone phone = PhoneFactory.getPhone(slotIndex);
3126 String tac = null;
3127 if (phone != null) {
3128 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003129 try {
3130 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3131 } catch (IndexOutOfBoundsException e) {
3132 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3133 return null;
3134 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003135 }
3136 return tac;
3137 }
3138
3139 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003140 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003141 Phone phone = PhoneFactory.getPhone(slotIndex);
3142 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003143 return null;
3144 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003145
Jeff Davidson913390f2018-02-23 17:11:49 -08003146 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003147 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003148 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003149 return null;
3150 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151
3152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 return phone.getMeid();
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
3157 }
Jack Yu2af8d712017-03-15 17:14:14 -07003158 }
3159
3160 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003161 public String getManufacturerCodeForSlot(int slotIndex) {
3162 Phone phone = PhoneFactory.getPhone(slotIndex);
3163 String manufacturerCode = null;
3164 if (phone != null) {
3165 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003166 try {
3167 manufacturerCode =
3168 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3169 } catch (IndexOutOfBoundsException e) {
3170 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3171 return null;
3172 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003173 }
3174 return manufacturerCode;
3175 }
3176
3177 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003178 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3179 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003180 Phone phone = PhoneFactory.getPhone(slotIndex);
3181 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003182 return null;
3183 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003184 int subId = phone.getSubId();
3185 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003186 mApp, subId, callingPackage, callingFeatureId,
3187 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003188 return null;
3189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003190
3191 final long identity = Binder.clearCallingIdentity();
3192 try {
3193 return phone.getDeviceSvn();
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003197 }
3198
fionaxu43304da2017-11-27 22:51:16 -08003199 @Override
3200 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003201 final long identity = Binder.clearCallingIdentity();
3202 try {
3203 final Phone phone = getPhone(subId);
3204 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
fionaxu43304da2017-11-27 22:51:16 -08003208 }
3209
3210 @Override
3211 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212 final long identity = Binder.clearCallingIdentity();
3213 try {
3214 final Phone phone = getPhone(subId);
3215 return phone == null ? null : phone.getCarrierName();
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
fionaxu43304da2017-11-27 22:51:16 -08003219 }
3220
calvinpanffe225e2018-11-01 19:43:06 +08003221 @Override
chen xu0026ca62019-03-06 15:28:50 -08003222 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003223 final long identity = Binder.clearCallingIdentity();
3224 try {
3225 final Phone phone = getPhone(subId);
3226 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003227 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
3231 }
3232
3233 @Override
chen xu0026ca62019-03-06 15:28:50 -08003234 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003235 final long identity = Binder.clearCallingIdentity();
3236 try {
3237 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003238 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003239 } finally {
3240 Binder.restoreCallingIdentity(identity);
3241 }
3242 }
3243
chen xu651eec72018-11-11 19:03:44 -08003244 @Override
chen xu864e11c2018-12-06 22:10:03 -08003245 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3246 if (!isSubscriptionMccMnc) {
3247 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3248 }
chen xu651eec72018-11-11 19:03:44 -08003249 final Phone phone = PhoneFactory.getPhone(slotIndex);
3250 if (phone == null) {
3251 return TelephonyManager.UNKNOWN_CARRIER_ID;
3252 }
3253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
3259 }
3260
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003261 //
3262 // Internal helper methods.
3263 //
3264
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003265 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003266 * Make sure the caller is the calling package itself
3267 *
3268 * @throws SecurityException if the caller is not the calling package
3269 */
3270 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3271 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003272 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3273 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003274 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003275 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003276 } catch (PackageManager.NameNotFoundException e) {
3277 // packageUid is -1
3278 }
3279 if (packageUid != callingUid) {
3280 throw new SecurityException(message + ": Package " + callingPackage
3281 + " does not belong to " + callingUid);
3282 }
3283 }
3284
3285 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3287 *
3288 * @throws SecurityException if the caller does not have the required permission
3289 */
3290 private void enforceModifyPermission() {
3291 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3292 }
3293
Shuo Qiancd19c462020-01-16 20:51:11 -08003294 /**
3295 * Make sure the caller is system.
3296 *
3297 * @throws SecurityException if the caller is not system.
3298 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003299 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003300 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3301 throw new SecurityException("Caller must be system");
3302 }
3303 }
3304
Shuo Qian3b6ee772019-11-13 17:43:31 -08003305 private void enforceActiveEmergencySessionPermission() {
3306 mApp.enforceCallingOrSelfPermission(
3307 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3308 }
3309
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003310 /**
3311 * Make sure the caller has the CALL_PHONE permission.
3312 *
3313 * @throws SecurityException if the caller does not have the required permission
3314 */
3315 private void enforceCallPermission() {
3316 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3317 }
3318
paulhu5a773602019-08-23 19:17:33 +08003319 private void enforceSettingsPermission() {
3320 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003321 }
3322
Michele Berionne5e411512020-11-13 02:36:59 +00003323 private void enforceRebootPermission() {
3324 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3325 }
3326
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003327 private String createTelUrl(String number) {
3328 if (TextUtils.isEmpty(number)) {
3329 return null;
3330 }
3331
Jake Hambye994d462014-02-03 13:10:13 -08003332 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003333 }
3334
Ihab Awadf9e92732013-12-05 18:02:52 -08003335 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003336 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3337 }
3338
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003339 private static void logv(String msg) {
3340 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3341 }
3342
Ihab Awadf9e92732013-12-05 18:02:52 -08003343 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003344 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3345 }
3346
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003347 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003348 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003349 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003350 }
3351
Sanket Padawe356d7632015-06-22 14:03:32 -07003352 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003353 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 final Phone phone = PhoneFactory.getPhone(slotIndex);
3357 if (phone == null) {
3358 return PhoneConstants.PHONE_TYPE_NONE;
3359 } else {
3360 return phone.getPhoneType();
3361 }
3362 } finally {
3363 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003365 }
3366
3367 /**
3368 * Returns the CDMA ERI icon index to display
3369 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003370 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003371 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3372 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3373 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003374 }
3375
Sanket Padawe356d7632015-06-22 14:03:32 -07003376 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003377 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3378 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003379 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003380 mApp, subId, callingPackage, callingFeatureId,
3381 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003382 return -1;
3383 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003384
3385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 final Phone phone = getPhone(subId);
3388 if (phone != null) {
3389 return phone.getCdmaEriIconIndex();
3390 } else {
3391 return -1;
3392 }
3393 } finally {
3394 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003396 }
3397
3398 /**
3399 * Returns the CDMA ERI icon mode,
3400 * 0 - ON
3401 * 1 - FLASHING
3402 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003403 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003404 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3405 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3406 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003407 }
3408
Sanket Padawe356d7632015-06-22 14:03:32 -07003409 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003410 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3411 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003412 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003413 mApp, subId, callingPackage, callingFeatureId,
3414 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003415 return -1;
3416 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417
3418 final long identity = Binder.clearCallingIdentity();
3419 try {
3420 final Phone phone = getPhone(subId);
3421 if (phone != null) {
3422 return phone.getCdmaEriIconMode();
3423 } else {
3424 return -1;
3425 }
3426 } finally {
3427 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003429 }
3430
3431 /**
3432 * Returns the CDMA ERI text,
3433 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003434 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003435 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3436 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3437 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003438 }
3439
Sanket Padawe356d7632015-06-22 14:03:32 -07003440 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003441 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3442 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003444 mApp, subId, callingPackage, callingFeatureId,
3445 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003446 return null;
3447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448
3449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 final Phone phone = getPhone(subId);
3452 if (phone != null) {
3453 return phone.getCdmaEriText();
3454 } else {
3455 return null;
3456 }
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003460 }
3461
3462 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003463 * Returns the CDMA MDN.
3464 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003465 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003466 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3468 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003469
3470 final long identity = Binder.clearCallingIdentity();
3471 try {
3472 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003473 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474 return phone.getLine1Number();
3475 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003476 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477 return null;
3478 }
3479 } finally {
3480 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003481 }
3482 }
3483
3484 /**
3485 * Returns the CDMA MIN.
3486 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003487 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003488 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3490 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 final Phone phone = getPhone(subId);
3495 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3496 return phone.getCdmaMin();
3497 } else {
3498 return null;
3499 }
3500 } finally {
3501 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003502 }
3503 }
3504
Hall Liud892bec2018-11-30 14:51:45 -08003505 @Override
3506 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3507 INumberVerificationCallback callback, String callingPackage) {
3508 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3509 != PERMISSION_GRANTED) {
3510 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3511 }
3512 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3513
3514 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3515 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003516 throw new SecurityException("Calling package must be configured in the device config: "
3517 + "calling package: " + callingPackage
3518 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003519 }
3520
3521 if (range == null) {
3522 throw new NullPointerException("Range must be non-null");
3523 }
3524
3525 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003526 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003527
3528 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3529 }
3530
Junda Liuca05d5d2014-08-14 22:36:34 -07003531 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 * Returns true if CDMA provisioning needs to run.
3533 */
3534 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 final long identity = Binder.clearCallingIdentity();
3536 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003537 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003541 }
3542
3543 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003544 * Sets the voice mail number of a given subId.
3545 */
3546 @Override
3547 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003548 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3549 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550
3551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3554 new Pair<String, String>(alphaTag, number), new Integer(subId));
3555 return success;
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
3558 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003559 }
3560
Ta-wei Yen87c49842016-05-13 21:19:52 -07003561 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003562 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3563 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003564 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3565 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003566 if (!TextUtils.equals(callingPackage, systemDialer)) {
3567 throw new SecurityException("caller must be system dialer");
3568 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3573 if (phoneAccountHandle == null) {
3574 return null;
3575 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003576 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577 } finally {
3578 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003579 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003580 }
3581
3582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003583 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3584 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003587 mApp, subId, callingPackage, callingFeatureId,
3588 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003589 return null;
3590 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003592 final long identity = Binder.clearCallingIdentity();
3593 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003594 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003598 }
3599
3600 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003601 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3602 VisualVoicemailSmsFilterSettings settings) {
3603 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604
3605 final long identity = Binder.clearCallingIdentity();
3606 try {
3607 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003608 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609 } finally {
3610 Binder.restoreCallingIdentity(identity);
3611 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003612 }
3613
3614 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003615 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003617
3618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003621 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003622 } finally {
3623 Binder.restoreCallingIdentity(identity);
3624 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003625 }
3626
3627 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003628 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3629 String callingPackage, int subId) {
3630 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631
3632 final long identity = Binder.clearCallingIdentity();
3633 try {
3634 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003635 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003639 }
3640
3641 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003642 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644
3645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003648 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003652 }
3653
3654 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003655 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3656 String callingAttributionTag, int subId, String number, int port, String text,
3657 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003658 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003659 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003660 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003661 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003662 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3663 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003664 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003665
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003666 /**
fionaxu0152e512016-11-14 13:36:14 -08003667 * Sets the voice activation state of a given subId.
3668 */
3669 @Override
3670 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003671 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3672 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673
3674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 final Phone phone = getPhone(subId);
3677 if (phone != null) {
3678 phone.setVoiceActivationState(activationState);
3679 } else {
3680 loge("setVoiceActivationState fails with invalid subId: " + subId);
3681 }
3682 } finally {
3683 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003684 }
3685 }
3686
3687 /**
3688 * Sets the data activation state of a given subId.
3689 */
3690 @Override
3691 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3693 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694
3695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 final Phone phone = getPhone(subId);
3698 if (phone != null) {
3699 phone.setDataActivationState(activationState);
3700 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003701 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003702 }
3703 } finally {
3704 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003705 }
3706 }
3707
3708 /**
3709 * Returns the voice activation state of a given subId.
3710 */
3711 @Override
3712 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714
fionaxu0152e512016-11-14 13:36:14 -08003715 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 if (phone != null) {
3719 return phone.getVoiceActivationState();
3720 } else {
3721 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3722 }
3723 } finally {
3724 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003725 }
3726 }
3727
3728 /**
3729 * Returns the data activation state of a given subId.
3730 */
3731 @Override
3732 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003733 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
fionaxu0152e512016-11-14 13:36:14 -08003735 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 if (phone != null) {
3739 return phone.getDataActivationState();
3740 } else {
3741 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3742 }
3743 } finally {
3744 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003745 }
3746 }
3747
3748 /**
Wink Saville36469e72014-06-11 15:17:00 -07003749 * Returns the unread count of voicemails for a subId
3750 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003751 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003752 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3753 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003755 mApp, subId, callingPackage, callingFeatureId,
3756 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003757 return 0;
3758 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 final Phone phone = getPhone(subId);
3762 if (phone != null) {
3763 return phone.getVoiceMessageCount();
3764 } else {
3765 return 0;
3766 }
3767 } finally {
3768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003770 }
3771
3772 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003773 * returns true, if the device is in a state where both voice and data
3774 * are supported simultaneously. This can change based on location or network condition.
3775 */
3776 @Override
3777 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 final Phone phone = getPhone(subId);
3781 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3782 } finally {
3783 Binder.restoreCallingIdentity(identity);
3784 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003785 }
3786
3787 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003788 * Send the dialer code if called from the current default dialer or the caller has
3789 * carrier privilege.
3790 * @param inputCode The dialer code to send
3791 */
3792 @Override
3793 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003794 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003796 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3797 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003798 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003799 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003800 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802
3803 final long identity = Binder.clearCallingIdentity();
3804 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003805 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 } finally {
3807 Binder.restoreCallingIdentity(identity);
3808 }
fionaxu235cc5e2017-03-06 22:25:57 -08003809 }
3810
Pengquan Menga1bb6272018-09-06 09:59:22 -07003811 @Override
3812 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003813 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003814 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003815 mApp, subId, "getNetworkSelectionMode");
3816 final long identity = Binder.clearCallingIdentity();
3817 try {
3818 if (!isActiveSubscription(subId)) {
3819 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3820 }
3821 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003824 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003825 }
3826
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003828 public boolean isInEmergencySmsMode() {
3829 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3830 final long identity = Binder.clearCallingIdentity();
3831 try {
3832 for (Phone phone : PhoneFactory.getPhones()) {
3833 if (phone.isInEmergencySmsMode()) {
3834 return true;
3835 }
3836 }
3837 } finally {
3838 Binder.restoreCallingIdentity(identity);
3839 }
3840 return false;
3841 }
3842
shilu366312e2019-12-17 09:28:10 -08003843 /**
3844 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3845 * @param subId The subscription to use to check the configuration.
3846 * @param c The callback that will be used to send the result.
3847 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003848 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003849 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3850 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003851 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003852 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003853
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003854 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3855 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3856 "IMS not available on device.");
3857 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 final long token = Binder.clearCallingIdentity();
3859 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003860 int slotId = getSlotIndexOrException(subId);
3861 verifyImsMmTelConfiguredOrThrow(slotId);
3862 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003863 } catch (ImsException e) {
3864 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 } finally {
3866 Binder.restoreCallingIdentity(token);
3867 }
3868 }
3869
shilu366312e2019-12-17 09:28:10 -08003870 /**
3871 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3872 * @param subId The subscription to use to check the configuration.
3873 * @param c The callback that will be used to send the result.
3874 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003875 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003876 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003877 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003878 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003879 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3880 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3881 }
Meng Wangafbc5852019-09-19 17:37:13 -07003882 final long token = Binder.clearCallingIdentity();
3883 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003884 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3885 .removeRegistrationCallbackForSubscription(c, subId);
3886 } catch (ImsException e) {
3887 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3888 + "is inactive, ignoring unregister.");
3889 // If the subscription is no longer active, just return, since the callback
3890 // will already have been removed internally.
3891 } finally {
3892 Binder.restoreCallingIdentity(token);
3893 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003894 }
3895
Brad Ebingera34a6c22019-10-22 17:36:18 -07003896 /**
3897 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3898 */
3899 @Override
3900 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3901 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3902 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3903 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3904 "IMS not available on device.");
3905 }
3906 final long token = Binder.clearCallingIdentity();
3907 try {
3908 Phone phone = getPhone(subId);
3909 if (phone == null) {
3910 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3911 + subId + "'");
3912 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3913 }
3914 phone.getImsRegistrationState(regState -> {
3915 try {
3916 consumer.accept((regState == null)
3917 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3918 } catch (RemoteException e) {
3919 // Ignore if the remote process is no longer available to call back.
3920 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3921 }
3922 });
3923 } finally {
3924 Binder.restoreCallingIdentity(token);
3925 }
3926 }
3927
3928 /**
3929 * Get the transport type for the IMS service registration state.
3930 */
3931 @Override
3932 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003933 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003934 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003935 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3936 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3937 "IMS not available on device.");
3938 }
3939 final long token = Binder.clearCallingIdentity();
3940 try {
3941 Phone phone = getPhone(subId);
3942 if (phone == null) {
3943 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3944 + subId + "'");
3945 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3946 }
3947 phone.getImsRegistrationTech(regTech -> {
3948 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3949 int regTechConverted = (regTech == null)
3950 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3951 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3952 regTechConverted);
3953 try {
3954 consumer.accept(regTechConverted);
3955 } catch (RemoteException e) {
3956 // Ignore if the remote process is no longer available to call back.
3957 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3958 }
3959 });
3960 } finally {
3961 Binder.restoreCallingIdentity(token);
3962 }
3963 }
3964
shilu366312e2019-12-17 09:28:10 -08003965 /**
3966 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3967 * @param subId The subscription to use to check the configuration.
3968 * @param c The callback that will be used to send the result.
3969 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003971 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3972 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003973 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003974 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003975 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3976 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3977 "IMS not available on device.");
3978 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 final long token = Binder.clearCallingIdentity();
3980 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003981 int slotId = getSlotIndexOrException(subId);
3982 verifyImsMmTelConfiguredOrThrow(slotId);
3983 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003984 } catch (ImsException e) {
3985 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 } finally {
3987 Binder.restoreCallingIdentity(token);
3988 }
3989 }
3990
shilu366312e2019-12-17 09:28:10 -08003991 /**
3992 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3993 * @param subId The subscription to use to check the configuration.
3994 * @param c The callback that will be used to send the result.
3995 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003997 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003998 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003999 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004000 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4001 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4002 }
Meng Wangafbc5852019-09-19 17:37:13 -07004003
4004 final long token = Binder.clearCallingIdentity();
4005 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004006 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004007 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004008 } catch (ImsException e) {
4009 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4010 + "is inactive, ignoring unregister.");
4011 // If the subscription is no longer active, just return, since the callback
4012 // will already have been removed internally.
4013 } finally {
4014 Binder.restoreCallingIdentity(token);
4015 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 }
4017
4018 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004019 public boolean isCapable(int subId, int capability, int regTech) {
4020 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 final long token = Binder.clearCallingIdentity();
4022 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004023 int slotId = getSlotIndexOrException(subId);
4024 verifyImsMmTelConfiguredOrThrow(slotId);
4025 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004026 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004027 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4028 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004029 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004030 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4031 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 } finally {
4033 Binder.restoreCallingIdentity(token);
4034 }
4035 }
4036
4037 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004038 public boolean isAvailable(int subId, int capability, int regTech) {
4039 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 final long token = Binder.clearCallingIdentity();
4041 try {
4042 Phone phone = getPhone(subId);
4043 if (phone == null) return false;
4044 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004045 } catch (com.android.ims.ImsException e) {
4046 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4047 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 } finally {
4049 Binder.restoreCallingIdentity(token);
4050 }
4051 }
4052
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004053 /**
4054 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4055 * subscription.
4056 * @param subId The subscription to use to check the configuration.
4057 * @param callback The callback that will be used to send the result.
4058 * @param capability The MmTelFeature capability that will be used to send the result.
4059 * @param transportType The transport type of the MmTelFeature capability.
4060 */
4061 @Override
4062 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4063 int transportType) {
4064 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4065 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4066 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4067 "IMS not available on device.");
4068 }
4069 final long token = Binder.clearCallingIdentity();
4070 try {
4071 int slotId = getSlotIndex(subId);
4072 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4073 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4074 + subId + "'");
4075 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4076 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004077 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004078 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4079 transportType, aBoolean -> {
4080 try {
4081 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4082 } catch (RemoteException e) {
4083 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4084 + "running. Ignore");
4085 }
4086 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004087 } catch (ImsException e) {
4088 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004089 } finally {
4090 Binder.restoreCallingIdentity(token);
4091 }
4092 }
4093
shilu366312e2019-12-17 09:28:10 -08004094 /**
4095 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4096 * @param subId The subscription to use to check the configuration.
4097 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 @Override
4099 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004100 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004101 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004102
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 final long token = Binder.clearCallingIdentity();
4104 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004105 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004106 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004107 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004108 } catch (ImsException e) {
4109 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 } finally {
4111 Binder.restoreCallingIdentity(token);
4112 }
4113 }
4114
4115 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004116 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004118 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 final long identity = Binder.clearCallingIdentity();
4120 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004121 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004122 // This setting doesn't require an active ImsService connection, so do not verify. The
4123 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004124 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004125 } catch (ImsException e) {
4126 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
4130 }
4131
shilu366312e2019-12-17 09:28:10 -08004132 /**
4133 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4134 * @param subId The subscription to use to check the configuration.
4135 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004137 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004138 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004139 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 final long identity = Binder.clearCallingIdentity();
4141 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004142 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004143 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004144 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
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
4152 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004153 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004155 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004156 final long identity = Binder.clearCallingIdentity();
4157 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004158 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004159 // This setting doesn't require an active ImsService connection, so do not verify. The
4160 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004161 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004162 } catch (ImsException e) {
4163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
shilu366312e2019-12-17 09:28:10 -08004169 /**
4170 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4171 * @param subId The subscription to use to check the configuration.
4172 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 @Override
4174 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004175 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004176 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 final long identity = Binder.clearCallingIdentity();
4178 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004179 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004180 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004181 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004182 } catch (ImsException e) {
4183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
4187 }
4188
4189 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004190 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004192 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 final long identity = Binder.clearCallingIdentity();
4194 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004195 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004196 // This setting doesn't require an active ImsService connection, so do not verify. The
4197 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004198 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004199 } catch (ImsException e) {
4200 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 } finally {
4202 Binder.restoreCallingIdentity(identity);
4203 }
4204 }
4205
shilu366312e2019-12-17 09:28:10 -08004206 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004207 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4208 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4209 * @param subId The subscription to use to check the configuration.
4210 */
4211 @Override
4212 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004213 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004214 mApp, subId, "isCrossSimCallingEnabledByUser");
4215 final long identity = Binder.clearCallingIdentity();
4216 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004217 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004218 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004219 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004220 } catch (ImsException e) {
4221 throw new ServiceSpecificException(e.getCode());
4222 } finally {
4223 Binder.restoreCallingIdentity(identity);
4224 }
4225 }
4226
4227 /**
4228 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4229 * Requires MODIFY_PHONE_STATE permission.
4230 * @param subId The subscription to use to check the configuration.
4231 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4232 * false otherwise
4233 */
4234 @Override
4235 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4237 "setCrossSimCallingEnabled");
4238 final long identity = Binder.clearCallingIdentity();
4239 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004240 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004241 // This setting doesn't require an active ImsService connection, so do not verify. The
4242 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004243 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004244 } catch (ImsException e) {
4245 throw new ServiceSpecificException(e.getCode());
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
4249 }
4250
4251 /**
shilu366312e2019-12-17 09:28:10 -08004252 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4253 * @param subId The subscription to use to check the configuration.
4254 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004256
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004258 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004259 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 final long identity = Binder.clearCallingIdentity();
4261 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004262 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004263 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004264 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004265 } catch (ImsException e) {
4266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
4270 }
4271
4272 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004273 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004275 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 final long identity = Binder.clearCallingIdentity();
4277 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004278 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004279 // This setting doesn't require an active ImsService connection, so do not verify. The
4280 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004281 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004282 } catch (ImsException e) {
4283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
4287 }
4288
4289 @Override
4290 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4292 "setVoWiFiNonPersistent");
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004295 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004296 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004298 } catch (ImsException e) {
4299 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
4303 }
4304
shilu366312e2019-12-17 09:28:10 -08004305 /**
4306 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4307 * @param subId The subscription to use to check the configuration.
4308 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 @Override
4310 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004311 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004312 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 final long identity = Binder.clearCallingIdentity();
4314 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004316 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004317 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004318 } catch (ImsException e) {
4319 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 } finally {
4321 Binder.restoreCallingIdentity(identity);
4322 }
4323 }
4324
4325 @Override
4326 public void setVoWiFiModeSetting(int subId, int mode) {
4327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4328 "setVoWiFiModeSetting");
4329 final long identity = Binder.clearCallingIdentity();
4330 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004331 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004332 // This setting doesn't require an active ImsService connection, so do not verify. The
4333 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004334 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004335 } catch (ImsException e) {
4336 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
4340 }
4341
4342 @Override
4343 public int getVoWiFiRoamingModeSetting(int subId) {
4344 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004347 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004348 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004349 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004350 } catch (ImsException e) {
4351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 } finally {
4353 Binder.restoreCallingIdentity(identity);
4354 }
4355 }
4356
4357 @Override
4358 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4360 "setVoWiFiRoamingModeSetting");
4361 final long identity = Binder.clearCallingIdentity();
4362 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004363 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004364 // This setting doesn't require an active ImsService connection, so do not verify. The
4365 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004366 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004367 } catch (ImsException e) {
4368 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 } finally {
4370 Binder.restoreCallingIdentity(identity);
4371 }
4372 }
4373
4374 @Override
4375 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4377 "setRttCapabilityEnabled");
4378 final long identity = Binder.clearCallingIdentity();
4379 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004380 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004381 // This setting doesn't require an active ImsService connection, so do not verify. The
4382 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004383 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004384 } catch (ImsException e) {
4385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
4389 }
4390
shilu366312e2019-12-17 09:28:10 -08004391 /**
4392 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4393 * @param subId The subscription to use to check the configuration.
4394 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004395 @Override
4396 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004397 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004398 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004399 final long identity = Binder.clearCallingIdentity();
4400 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004401 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004402 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004403 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004404 } catch (ImsException e) {
4405 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
4409 }
4410
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004411 @Override
4412 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4413 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4414 final long identity = Binder.clearCallingIdentity();
4415 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004416 if (!isImsAvailableOnDevice()) {
4417 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4418 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004419 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004420 int slotId = getSlotIndexOrException(subId);
4421 verifyImsMmTelConfiguredOrThrow(slotId);
4422 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004423 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004424 } catch (ImsException e) {
4425 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
4429 }
4430
4431 @Override
4432 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4433 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4434 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004435 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4436 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4437 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004438 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004439 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004440 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004441 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004442 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4443 + "is inactive, ignoring unregister.");
4444 // If the subscription is no longer active, just return, since the callback will already
4445 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
4449 }
4450
allenwtsu99c623b2020-01-03 18:24:23 +08004451
4452 private void checkModifyPhoneStatePermission(int subId, String message) {
4453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4454 message);
4455 }
4456
4457 private boolean isImsProvisioningRequired(int subId, int capability,
4458 boolean isMmtelCapability) {
4459 Phone phone = getPhone(subId);
4460 if (phone == null) {
4461 loge("phone instance null for subid " + subId);
4462 return false;
4463 }
4464 if (isMmtelCapability) {
4465 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4466 return false;
4467 }
4468 } else {
4469 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4470 return false;
4471 }
4472 }
4473 return true;
4474 }
4475
4476 @Override
4477 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4478 boolean isProvisioned) {
4479 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4480
4481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4484 if (!isImsProvisioningRequired(subId, capability, false)) {
4485 return;
4486 }
4487
4488 // this capability requires provisioning, route to the correct API.
4489 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4490 switch (capability) {
4491 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4492 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4493 ims.setEabProvisioned(isProvisioned);
4494 break;
4495 default: {
4496 throw new IllegalArgumentException("Tried to set provisioning for "
4497 + "rcs capability '" + capability + "', which does not require "
4498 + "provisioning.");
4499 }
4500 }
4501 } finally {
4502 Binder.restoreCallingIdentity(identity);
4503 }
4504
4505 }
4506
4507
4508 @Override
4509 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4510 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4511 final long identity = Binder.clearCallingIdentity();
4512 try {
4513 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4514 if (!isImsProvisioningRequired(subId, capability, false)) {
4515 return true;
4516 }
4517
4518 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4519 switch (capability) {
4520 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4521 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4522 return ims.isEabProvisionedOnDevice();
4523
4524 default: {
4525 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4526 + "capability '" + capability + "', which does not require "
4527 + "provisioning.");
4528 }
4529 }
4530
4531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
4534 }
4535
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004536 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004537 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4538 boolean isProvisioned) {
4539 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004540 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4541 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4542 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004543 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4544 }
allenwtsu99c623b2020-01-03 18:24:23 +08004545 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004546 final long identity = Binder.clearCallingIdentity();
4547 try {
4548 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004549 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004550 return;
4551 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004552 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4553 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4554 loge("setImsProvisioningStatusForCapability: called for technology that does "
4555 + "not support provisioning - " + tech);
4556 return;
4557 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004558
4559 // this capability requires provisioning, route to the correct API.
4560 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4561 switch (capability) {
4562 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4563 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4564 ims.setVolteProvisioned(isProvisioned);
4565 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4566 ims.setWfcProvisioned(isProvisioned);
4567 }
4568 break;
4569 }
4570 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4571 // There is currently no difference in VT provisioning type.
4572 ims.setVtProvisioned(isProvisioned);
4573 break;
4574 }
4575 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4576 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4577 // change the capability of the feature instead if needed.
4578 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4579 == isProvisioned) {
4580 // No change in provisioning.
4581 return;
4582 }
4583 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4584 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004585 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004586 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004587 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4588 + ", Exception" + e.getMessage());
4589 }
4590 break;
4591 }
4592 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004593 throw new IllegalArgumentException("Tried to set provisioning for "
4594 + "MmTel capability '" + capability + "', which does not require "
4595 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004596 }
4597 }
4598
4599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
4602 }
4603
4604 @Override
4605 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4606 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004607 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4608 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4609 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004610 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4611 }
4612 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004616 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004617 return true;
4618 }
4619
Brad Ebinger0d79c572021-04-17 15:20:49 -07004620 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4621 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4622 loge("getImsProvisioningStatusForCapability: called for technology that does "
4623 + "not support provisioning - " + tech);
4624 return true;
4625 }
4626
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004627 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4628 switch (capability) {
4629 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4630 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4631 return ims.isVolteProvisionedOnDevice();
4632 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4633 return ims.isWfcProvisionedOnDevice();
4634 }
4635 // This should never happen, since we are checking tech above to make sure it
4636 // is either LTE or IWLAN.
4637 throw new IllegalArgumentException("Invalid radio technology for voice "
4638 + "capability.");
4639 }
4640 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4641 // There is currently no difference in VT provisioning type.
4642 return ims.isVtProvisionedOnDevice();
4643 }
4644 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4645 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4646 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4647 }
4648 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004649 throw new IllegalArgumentException(
4650 "Tried to get provisioning for MmTel capability '" + capability
4651 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004652 }
4653 }
4654
4655 } finally {
4656 Binder.restoreCallingIdentity(identity);
4657 }
4658 }
4659
4660 @Override
4661 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4662 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4663 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4664 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4665 }
4666 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4667 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4668 return (provisionedBits & capability) > 0;
4669 }
4670
4671 @Override
4672 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4673 boolean isProvisioned) {
4674 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4675 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4676 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4677 }
4678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4679 "setProvisioningStatusForCapability");
4680 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4681 // If the current provisioning status for capability already matches isProvisioned,
4682 // do nothing.
4683 if (((provisionedBits & capability) > 0) == isProvisioned) {
4684 return;
4685 }
4686 if (isProvisioned) {
4687 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4688 } else {
4689 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4690 }
4691 }
4692
4693 /**
4694 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4695 * technology. The bitfield should mirror the bitfield defined by
4696 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4697 */
4698 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4699 String key = getMmTelProvisioningKey(subId, tech);
4700 // Default is no capabilities are provisioned.
4701 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4702 }
4703
4704 /**
4705 * Sets the MmTel capability provisioning bitfield (defined by
4706 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4707 * technology specified.
4708 *
4709 * Note: This is a synchronous command and should not be called on UI thread.
4710 */
4711 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4712 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4713 String key = getMmTelProvisioningKey(subId, tech);
4714 editor.putInt(key, newField);
4715 editor.commit();
4716 }
4717
4718 private static String getMmTelProvisioningKey(int subId, int tech) {
4719 // resulting key is provision_ims_mmtel_{subId}_{tech}
4720 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4721 }
4722
4723 /**
4724 * Query CarrierConfig to see if the specified capability requires provisioning for the
4725 * carrier associated with the subscription id.
4726 */
4727 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4728 int capability) {
4729 CarrierConfigManager configManager = new CarrierConfigManager(context);
4730 PersistableBundle c = configManager.getConfigForSubId(subId);
4731 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004732 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004733 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4734 false);
4735 boolean requireVoiceVtProvisioning = c.getBoolean(
4736 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4737
4738 // First check to make sure that the capability requires provisioning.
4739 switch (capability) {
4740 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4741 // intentional fallthrough
4742 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4743 if (requireVoiceVtProvisioning) {
4744 // Voice and Video requires provisioning
4745 return true;
4746 }
4747 break;
4748 }
4749 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4750 if (requireUtProvisioning) {
4751 // UT requires provisioning
4752 return true;
4753 }
4754 break;
4755 }
4756 }
4757 return false;
4758 }
4759
allenwtsu99c623b2020-01-03 18:24:23 +08004760 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4761 int capability) {
4762 CarrierConfigManager configManager = new CarrierConfigManager(context);
4763 PersistableBundle c = configManager.getConfigForSubId(subId);
4764
4765 boolean requireRcsProvisioning = c.getBoolean(
4766 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4767
4768 // First check to make sure that the capability requires provisioning.
4769 switch (capability) {
4770 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4771 // intentional fallthrough
4772 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4773 if (requireRcsProvisioning) {
4774 // OPTION or PRESENCE requires provisioning
4775 return true;
4776 }
4777 break;
4778 }
4779 }
4780 return false;
4781 }
4782
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004783 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004784 public int getImsProvisioningInt(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("getImsProvisioningInt");
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, "getImsProvisioningInt: called with an inactive subscription '"
4795 + subId + "' for key:" + key);
4796 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4797 }
calvinpanb5a34062021-02-08 19:59:36 +08004798 return ImsManager.getInstance(mApp, slotId).getConfigInt(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, "getImsProvisioningInt: ImsService is not available for subscription '"
4801 + subId + "' for key:" + key);
4802 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
4806 }
4807
4808 @Override
4809 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004810 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4811 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4812 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004813 enforceReadPrivilegedPermission("getImsProvisioningString");
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004817 int slotId = getSlotIndex(subId);
4818 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4819 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4820 + subId + "' for key:" + key);
4821 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4822 }
calvinpanb5a34062021-02-08 19:59:36 +08004823 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004824 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004825 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4826 + subId + "' for key:" + key);
4827 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004828 } finally {
4829 Binder.restoreCallingIdentity(identity);
4830 }
4831 }
4832
4833 @Override
4834 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4836 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4837 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4839 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004840 final long identity = Binder.clearCallingIdentity();
4841 try {
4842 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004843 int slotId = getSlotIndex(subId);
4844 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4845 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4846 + subId + "' for key:" + key);
4847 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4848 }
calvinpanb5a34062021-02-08 19:59:36 +08004849 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4850 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004851 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004852 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004853 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
4857 }
4858
4859 @Override
4860 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004861 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4862 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4863 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4865 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004866 final long identity = Binder.clearCallingIdentity();
4867 try {
4868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004869 int slotId = getSlotIndex(subId);
4870 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4871 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4872 + subId + "' for key:" + key);
4873 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4874 }
calvinpanb5a34062021-02-08 19:59:36 +08004875 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4876 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004877 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004878 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
4883 }
4884
Brad Ebinger919631e2021-06-02 17:46:35 -07004885 /**
4886 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4887 * for the given slot ID or no ImsResolver instance has been created.
4888 * @param slotId The slot ID that the IMS service is created for.
4889 * @throws ImsException If there is no ImsService configured for this slot.
4890 */
4891 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4892 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4893 ImsFeature.FEATURE_MMTEL)) {
4894 throw new ImsException("This subscription does not support MMTEL over IMS",
4895 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4896 }
4897 }
4898
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004899 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004900 int slotId = SubscriptionManager.getSlotIndex(subId);
4901 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004902 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4903 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004904 }
4905 return slotId;
4906 }
4907
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004908 private int getSlotIndex(int subId) {
4909 int slotId = SubscriptionManager.getSlotIndex(subId);
4910 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4911 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4912 }
4913 return slotId;
4914 }
4915
Wink Saville36469e72014-06-11 15:17:00 -07004916 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004917 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004918 */
4919 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004920 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4921 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004922 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004923 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004924 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004925 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004926 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004927 mApp, subId, callingPackage, callingFeatureId,
4928 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004929 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4930 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 final Phone phone = getPhone(subId);
4935 if (phone != null) {
4936 return phone.getServiceState().getDataNetworkType();
4937 } else {
4938 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4939 }
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004943 }
4944
4945 /**
4946 * Returns the data network type
4947 */
4948 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004949 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004950 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4951 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004952 }
4953
4954 /**
4955 * Returns the data network type for a subId
4956 */
4957 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004958 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4959 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004961 mApp, subId, callingPackage, callingFeatureId,
4962 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004963 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4964 }
4965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 final long identity = Binder.clearCallingIdentity();
4967 try {
4968 final Phone phone = getPhone(subId);
4969 if (phone != null) {
4970 return phone.getServiceState().getDataNetworkType();
4971 } else {
4972 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4973 }
4974 } finally {
4975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004977 }
4978
4979 /**
Wink Saville36469e72014-06-11 15:17:00 -07004980 * Returns the Voice network type for a subId
4981 */
4982 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004983 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4984 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004985 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004986 mApp, subId, callingPackage, callingFeatureId,
4987 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004988 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4989 }
4990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 final Phone phone = getPhone(subId);
4994 if (phone != null) {
4995 return phone.getServiceState().getVoiceNetworkType();
4996 } else {
4997 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4998 }
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005002 }
5003
5004 /**
5005 * @return true if a ICC card is present
5006 */
5007 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005008 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005009 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5010 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005011 }
5012
5013 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005014 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005015 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005016 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005017 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 final long identity = Binder.clearCallingIdentity();
5019 try {
5020 final Phone phone = PhoneFactory.getPhone(slotIndex);
5021 if (phone != null) {
5022 return phone.getIccCard().hasIccCard();
5023 } else {
5024 return false;
5025 }
5026 } finally {
5027 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005029 }
5030
5031 /**
5032 * Return if the current radio is LTE on CDMA. This
5033 * is a tri-state return value as for a period of time
5034 * the mode may be unknown.
5035 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005036 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005037 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005038 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005039 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005040 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005041 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5042 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5043 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005044 }
5045
Sanket Padawe356d7632015-06-22 14:03:32 -07005046 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005047 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5048 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005049 try {
5050 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5051 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005052 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5053 }
5054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055 final long identity = Binder.clearCallingIdentity();
5056 try {
5057 final Phone phone = getPhone(subId);
5058 if (phone == null) {
5059 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5060 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005061 return TelephonyProperties.lte_on_cdma_device()
5062 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 }
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005066 }
Wink Saville36469e72014-06-11 15:17:00 -07005067 }
5068
Wink Saville36469e72014-06-11 15:17:00 -07005069 /**
5070 * {@hide}
5071 * Returns Default subId, 0 in the case of single standby.
5072 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005073 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005074 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005075 }
5076
Shishir Agrawala9f32182016-04-12 12:00:16 -07005077 private int getSlotForDefaultSubscription() {
5078 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5079 }
5080
Wink Savilleb564aae2014-10-23 10:18:09 -07005081 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005082 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005083 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005084
Pengquan Menge92a50d2018-09-21 15:54:48 -07005085 private boolean isActiveSubscription(int subId) {
5086 return mSubscriptionController.isActiveSubId(subId);
5087 }
5088
Ihab Awadf2177b72013-11-25 13:33:23 -08005089 /**
5090 * @see android.telephony.TelephonyManager.WifiCallingChoices
5091 */
5092 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 final long identity = Binder.clearCallingIdentity();
5094 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005095 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005096 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5097 getWhenToMakeWifiCallsDefaultPreference());
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005101 }
5102
5103 /**
5104 * @see android.telephony.TelephonyManager.WifiCallingChoices
5105 */
5106 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005110 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5112 } finally {
5113 Binder.restoreCallingIdentity(identity);
5114 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005115 }
5116
Sailesh Nepald1e68152013-12-12 19:08:02 -08005117 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005118 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005119 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005120 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005121
Jordan Liu4c733742019-02-28 12:03:40 -08005122 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5123 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5124 if (phoneId == -1) {
5125 throw new IllegalArgumentException("Given slot index: " + slotIndex
5126 + " does not correspond to an active phone");
5127 }
5128 return PhoneFactory.getPhone(phoneId);
5129 }
5130
Shishir Agrawal566b7612013-10-28 14:41:00 -07005131 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005132 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5133 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5135 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005137 if (DBG) {
5138 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5139 }
5140 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5141 p2);
5142 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005143
Jordan Liu4c733742019-02-28 12:03:40 -08005144
5145 @Override
5146 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5147 int slotIndex, String callingPackage, String aid, int p2) {
5148 enforceModifyPermission();
5149 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5150 if (DBG) {
5151 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5152 }
5153 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5154 callingPackage, aid, p2);
5155 }
5156
5157 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5158 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 if (TextUtils.equals(ISDR_AID, aid)) {
5162 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005163 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5164 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 if (bestComponent == null
5166 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5167 loge("The calling package is not allowed to access ISD-R.");
5168 throw new SecurityException(
5169 "The calling package is not allowed to access ISD-R.");
5170 }
Derek Tan740e1672017-06-27 14:56:27 -07005171 }
Derek Tan740e1672017-06-27 14:56:27 -07005172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005174 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5175 null /* workSource */);
5176 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 return response;
5178 } finally {
5179 Binder.restoreCallingIdentity(identity);
5180 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005181 }
5182
5183 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005184 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5186 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005187 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5188 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5189 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005190
Jordan Liu4c733742019-02-28 12:03:40 -08005191 @Override
5192 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5193 enforceModifyPermission();
5194 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5195 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5196 channel);
5197 }
5198
5199 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200 final long identity = Binder.clearCallingIdentity();
5201 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202 if (channel < 0) {
5203 return false;
5204 }
Jordan Liu4c733742019-02-28 12:03:40 -08005205 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5206 null /* workSource */);
5207 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 return success;
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005211 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005212 }
5213
5214 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005215 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005216 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5218 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005219 if (DBG) {
5220 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5221 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5222 + p3 + " data=" + data);
5223 }
5224 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5225 command, p1, p2, p3, data);
5226 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005227
Jordan Liu4c733742019-02-28 12:03:40 -08005228 @Override
5229 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5230 int command, int p1, int p2, int p3, String data) {
5231 enforceModifyPermission();
5232 if (DBG) {
5233 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5234 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5235 + p3 + " data=" + data);
5236 }
5237 return iccTransmitApduLogicalChannelWithPermission(
5238 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5239 data);
5240 }
5241
5242 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5243 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005246 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 return "";
5248 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005251 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5252 null /* workSource */);
5253 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 // Append the returned status code to the end of the response payload.
5256 String s = Integer.toHexString(
5257 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5258 if (response.payload != null) {
5259 s = IccUtils.bytesToHexString(response.payload) + s;
5260 }
5261 return s;
5262 } finally {
5263 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005264 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005265 }
Jake Hambye994d462014-02-03 13:10:13 -08005266
Evan Charltonc66da362014-05-16 14:06:40 -07005267 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005268 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5269 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5271 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005273 if (DBG) {
5274 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5275 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5276 }
5277 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5278 cla, command, p1, p2, p3, data);
5279 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005280
Jordan Liu4c733742019-02-28 12:03:40 -08005281 @Override
5282 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5283 int command, int p1, int p2, int p3, String data) {
5284 enforceModifyPermission();
5285 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5286 if (DBG) {
5287 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5288 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5289 + " data=" + data);
5290 }
5291
5292 return iccTransmitApduBasicChannelWithPermission(
5293 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5294 p2, p3, data);
5295 }
5296
5297 // open APDU basic channel assuming the caller has sufficient permissions
5298 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5299 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 final long identity = Binder.clearCallingIdentity();
5301 try {
5302 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5303 && TextUtils.equals(ISDR_AID, data)) {
5304 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005305 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5306 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 if (bestComponent == null
5308 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5309 loge("The calling package is not allowed to select ISD-R.");
5310 throw new SecurityException(
5311 "The calling package is not allowed to select ISD-R.");
5312 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005313 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005316 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5317 null /* workSource */);
5318 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005319
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 // Append the returned status code to the end of the response payload.
5321 String s = Integer.toHexString(
5322 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5323 if (response.payload != null) {
5324 s = IccUtils.bytesToHexString(response.payload) + s;
5325 }
5326 return s;
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005329 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005330 }
5331
5332 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005333 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005334 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005335 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5336 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 final long identity = Binder.clearCallingIdentity();
5339 try {
5340 if (DBG) {
5341 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5342 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5343 }
5344
5345 IccIoResult response =
5346 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5347 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5348 subId);
5349
5350 if (DBG) {
5351 log("Exchange SIM_IO [R]" + response);
5352 }
5353
5354 byte[] result = null;
5355 int length = 2;
5356 if (response.payload != null) {
5357 length = 2 + response.payload.length;
5358 result = new byte[length];
5359 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5360 } else {
5361 result = new byte[length];
5362 }
5363
5364 result[length - 1] = (byte) response.sw2;
5365 result[length - 2] = (byte) response.sw1;
5366 return result;
5367 } finally {
5368 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005369 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005370 }
5371
Nathan Haroldb3014052017-01-25 15:57:32 -08005372 /**
5373 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5374 * on a particular subscription
5375 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005376 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5377 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005378 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005379 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005380 return null;
5381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382
5383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 if (appType != TelephonyManager.APPTYPE_USIM
5386 && appType != TelephonyManager.APPTYPE_SIM) {
5387 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5388 return null;
5389 }
5390 Object response = sendRequest(
5391 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5392 if (response instanceof String[]) {
5393 return (String[]) response;
5394 }
yincheng zhao2737e882019-09-06 17:06:54 -07005395 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005397 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005398 } finally {
5399 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005400 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005401 }
5402
yincheng zhao2737e882019-09-06 17:06:54 -07005403 /**
5404 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5405 * subscription.
5406 *
5407 * @param subId the id of the subscription.
5408 * @param appType the uicc app type, must be USIM or SIM.
5409 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5410 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005411 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005412 * @return number of fplmns that is successfully written to the SIM.
5413 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005414 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5415 String callingFeatureId) {
5416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5417 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005418 if (DBG) logv("no permissions for setForbiddenplmns");
5419 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5420 }
5421 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5422 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5423 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5424 }
5425 if (fplmns == null) {
5426 throw new IllegalArgumentException("Fplmn List provided is null");
5427 }
5428 for (String fplmn : fplmns) {
5429 if (!CellIdentity.isValidPlmn(fplmn)) {
5430 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5431 }
5432 }
5433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 Object response = sendRequest(
5436 CMD_SET_FORBIDDEN_PLMNS,
5437 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5438 subId);
5439 return (int) response;
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
5442 }
5443 }
5444
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005445 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005446 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5448 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005449
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5453 if (response.payload == null) {
5454 return "";
5455 }
Evan Charltonc66da362014-05-16 14:06:40 -07005456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 // Append the returned status code to the end of the response payload.
5458 String s = Integer.toHexString(
5459 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5460 s = IccUtils.bytesToHexString(response.payload) + s;
5461 return s;
5462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
Evan Charltonc66da362014-05-16 14:06:40 -07005465 }
5466
Jake Hambye994d462014-02-03 13:10:13 -08005467 /**
5468 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5469 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5470 *
5471 * @param itemID the ID of the item to read
5472 * @return the NV item as a String, or null on error.
5473 */
5474 @Override
5475 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005476 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5478 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005479
5480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005483 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5485 return value;
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
5488 }
Jake Hambye994d462014-02-03 13:10:13 -08005489 }
5490
5491 /**
5492 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5493 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5494 *
5495 * @param itemID the ID of the item to read
5496 * @param itemValue the value to write, as a String
5497 * @return true on success; false on any failure
5498 */
5499 @Override
5500 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005501 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5503 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504
5505 final long identity = Binder.clearCallingIdentity();
5506 try {
5507 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5508 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005509 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5511 return success;
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
Jake Hambye994d462014-02-03 13:10:13 -08005515 }
5516
5517 /**
5518 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5519 * Used for device configuration by some CDMA operators.
5520 *
5521 * @param preferredRoamingList byte array containing the new PRL
5522 * @return true on success; false on any failure
5523 */
5524 @Override
5525 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5527 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528
5529 final long identity = Binder.clearCallingIdentity();
5530 try {
5531 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5532 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5533 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5534 return success;
5535 } finally {
5536 Binder.restoreCallingIdentity(identity);
5537 }
Jake Hambye994d462014-02-03 13:10:13 -08005538 }
5539
5540 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005541 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005542 * Used for device configuration by some CDMA operators.
5543 *
chen xu6dac5ab2018-10-26 17:39:23 -07005544 * @param slotIndex - device slot.
5545 *
Jake Hambye994d462014-02-03 13:10:13 -08005546 * @return true on success; false on any failure
5547 */
5548 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005549 public boolean resetModemConfig(int slotIndex) {
5550 Phone phone = PhoneFactory.getPhone(slotIndex);
5551 if (phone != null) {
5552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5553 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554
chen xu6dac5ab2018-10-26 17:39:23 -07005555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5558 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5559 return success;
5560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005563 }
chen xu6dac5ab2018-10-26 17:39:23 -07005564 return false;
5565 }
5566
5567 /**
5568 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5569 *
5570 * @param slotIndex - device slot.
5571 *
5572 * @return true on success; false on any failure
5573 */
5574 @Override
5575 public boolean rebootModem(int slotIndex) {
5576 Phone phone = PhoneFactory.getPhone(slotIndex);
5577 if (phone != null) {
5578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, phone.getSubId(), "rebootModem");
5580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5584 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5585 return success;
5586 } finally {
5587 Binder.restoreCallingIdentity(identity);
5588 }
5589 }
5590 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005591 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005592
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005593 public String[] getPcscfAddress(String apnType, String callingPackage,
5594 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005595 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5597 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005598 return new String[0];
5599 }
5600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601 final long identity = Binder.clearCallingIdentity();
5602 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005603 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
Wink Saville36469e72014-06-11 15:17:00 -07005607 }
5608
Brad Ebinger51f743a2017-01-23 13:50:20 -08005609 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005610 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5611 * {@link #disableIms(int)}.
5612 * @param slotIndex device slot.
5613 */
5614 public void resetIms(int slotIndex) {
5615 enforceModifyPermission();
5616
5617 final long identity = Binder.clearCallingIdentity();
5618 try {
5619 if (mImsResolver == null) {
5620 // may happen if the does not support IMS.
5621 return;
5622 }
5623 mImsResolver.disableIms(slotIndex);
5624 mImsResolver.enableIms(slotIndex);
5625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
5628 }
5629
5630 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005631 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5632 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005633 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005634 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -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 Ebinger9c0eb502019-01-23 15:06:19 -08005640 // may happen if the device does not support IMS.
5641 return;
5642 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005643 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005647 }
5648
5649 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005650 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5651 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005652 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005653 public void disableIms(int slotId) {
5654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005658 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005659 // may happen if the device does not support IMS.
5660 return;
5661 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005662 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005666 }
5667
5668 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005669 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5670 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005671 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005672 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005673 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005678 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005679 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5680 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005681 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005682 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005686 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005687 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005688 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5689 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005690 @Override
5691 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005692 enforceModifyPermission();
5693
5694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005697 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
5701 }
5702
5703 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005704 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005705 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005706 */
5707 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5708 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005712 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005713 // may happen if the device does not support IMS.
5714 return null;
5715 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005720 }
5721
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005722 /**
5723 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005724 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005725 */
5726 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5727 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728
5729 final long identity = Binder.clearCallingIdentity();
5730 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005731 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005732 // may happen if the device does not support IMS.
5733 return null;
5734 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005735 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005736 } finally {
5737 Binder.restoreCallingIdentity(identity);
5738 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005739 }
5740
Brad Ebinger884c07b2018-02-15 16:17:40 -08005741 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005742 * Sets the ImsService Package Name that Telephony will bind to.
5743 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005744 * @param slotIndex the slot ID that the ImsService should bind for.
5745 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005746 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005747 * @param featureTypes An integer array of feature types associated with a packageName.
5748 * @param packageName The name of the package that the current configuration will be replaced
5749 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005750 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005751 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005752 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5753 int[] featureTypes, String packageName) {
5754 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5755 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5757 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005758 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 final long identity = Binder.clearCallingIdentity();
5761 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005762 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005763 // may happen if the device does not support IMS.
5764 return false;
5765 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 Map<Integer, String> featureConfig = new HashMap<>();
5767 for (int featureType : featureTypes) {
5768 featureConfig.put(featureType, packageName);
5769 }
5770 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5771 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 } finally {
5773 Binder.restoreCallingIdentity(identity);
5774 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005775 }
5776
5777 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005778 * Clears any carrier ImsService overrides for the slot index specified that were previously
5779 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5780 *
5781 * This should only be used for testing.
5782 *
5783 * @param slotIndex the slot ID that the ImsService should bind for.
5784 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5785 */
5786 @Override
5787 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5788 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5790 "clearCarrierImsServiceOverride");
5791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5792 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5793 "clearCarrierImsServiceOverride");
5794
5795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 if (mImsResolver == null) {
5798 // may happen if the device does not support IMS.
5799 return false;
5800 }
5801 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5802 } finally {
5803 Binder.restoreCallingIdentity(identity);
5804 }
5805 }
5806
5807 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005808 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005809 *
5810 * @param slotId The slot that the ImsService is associated with.
5811 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5812 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005813 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005814 * @return the package name of the ImsService configuration.
5815 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005816 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5817 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005818 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005819 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005820 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005821 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5822 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 final long identity = Binder.clearCallingIdentity();
5825 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005827 // may happen if the device does not support IMS.
5828 return "";
5829 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005830 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005831 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5832 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005836 }
5837
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005838 /**
5839 * Get the MmTelFeature state associated with the requested subscription id.
5840 * @param subId The subscription that the MmTelFeature is associated with.
5841 * @param callback A callback with an integer containing the
5842 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5843 */
5844 @Override
5845 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5846 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5847 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5848 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5849 "IMS not available on device.");
5850 }
5851 final long token = Binder.clearCallingIdentity();
5852 try {
5853 int slotId = getSlotIndex(subId);
5854 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5855 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5856 + subId + "'");
5857 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5858 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005859 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005860 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5861 try {
5862 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5863 } catch (RemoteException e) {
5864 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5865 + "Ignore");
5866 }
5867 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005868 } catch (ImsException e) {
5869 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005870 } finally {
5871 Binder.restoreCallingIdentity(token);
5872 }
5873 }
5874
Daniel Brightbb5840b2021-01-12 15:48:18 -08005875 /**
5876 * Sets the ims registration state on all valid {@link Phone}s.
5877 */
5878 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005879 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880
5881 final long identity = Binder.clearCallingIdentity();
5882 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005883 // NOTE: Before S, this method only set the default phone.
5884 for (final Phone phone : PhoneFactory.getPhones()) {
5885 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5886 phone.setImsRegistrationState(registered);
5887 }
5888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
Wink Saville36469e72014-06-11 15:17:00 -07005892 }
5893
5894 /**
Stuart Scott54788802015-03-30 13:18:01 -07005895 * Set the network selection mode to automatic.
5896 *
5897 */
5898 @Override
5899 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5901 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902
5903 final long identity = Binder.clearCallingIdentity();
5904 try {
shilufc958392020-01-20 11:36:01 -08005905 if (!isActiveSubscription(subId)) {
5906 return;
5907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005909 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5910 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 } finally {
5912 Binder.restoreCallingIdentity(identity);
5913 }
Stuart Scott54788802015-03-30 13:18:01 -07005914 }
5915
Jack Yud10cdd42020-09-28 20:28:01 -07005916 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005917 * Ask the radio to connect to the input network and change selection mode to manual.
5918 *
5919 * @param subId the id of the subscription.
5920 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5921 * the operator to attach to.
5922 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5923 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5924 * normal network selection next time.
5925 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005926 */
5927 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005928 public boolean setNetworkSelectionModeManual(
5929 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5931 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005932
5933 if (!isActiveSubscription(subId)) {
5934 return false;
5935 }
5936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 final long identity = Binder.clearCallingIdentity();
5938 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005939 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005941 if (DBG) {
5942 log("setNetworkSelectionModeManual: subId: " + subId
5943 + " operator: " + operatorInfo);
5944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5946 } finally {
5947 Binder.restoreCallingIdentity(identity);
5948 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005949 }
shilu84f6e8b2019-12-19 13:58:01 -08005950 /**
5951 * Get the manual network selection
5952 *
5953 * @param subId the id of the subscription.
5954 *
5955 * @return the previously saved user selected PLMN
5956 */
5957 @Override
5958 public String getManualNetworkSelectionPlmn(int subId) {
5959 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005960 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005961 mApp, subId, "getManualNetworkSelectionPlmn");
5962
5963 final long identity = Binder.clearCallingIdentity();
5964 try {
5965 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005966 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005967 }
5968
5969 final Phone phone = getPhone(subId);
5970 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005971 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005972 }
5973 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5974 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5975 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5976 } finally {
5977 Binder.restoreCallingIdentity(identity);
5978 }
5979 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005980
5981 /**
5982 * Scans for available networks.
5983 */
5984 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005985 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5986 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5988 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005989 LocationAccessPolicy.LocationPermissionResult locationResult =
5990 LocationAccessPolicy.checkLocationPermission(mApp,
5991 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5992 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005993 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005994 .setCallingPid(Binder.getCallingPid())
5995 .setCallingUid(Binder.getCallingUid())
5996 .setMethod("getCellNetworkScanResults")
5997 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005998 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5999 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006000 .build());
6001 switch (locationResult) {
6002 case DENIED_HARD:
6003 throw new SecurityException("Not allowed to access scan results -- location");
6004 case DENIED_SOFT:
6005 return null;
6006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007
Pengquan Menga1bb6272018-09-06 09:59:22 -07006008 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 try {
6010 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006011 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006016 }
6017
6018 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006019 * Get the call forwarding info, given the call forwarding reason.
6020 */
6021 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006022 public void getCallForwarding(int subId, int callForwardingReason,
6023 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006024 enforceReadPrivilegedPermission("getCallForwarding");
6025 long identity = Binder.clearCallingIdentity();
6026 try {
6027 if (DBG) {
6028 log("getCallForwarding: subId " + subId
6029 + " callForwardingReason" + callForwardingReason);
6030 }
Hall Liu27d24262020-09-18 19:04:59 -07006031
6032 Phone phone = getPhone(subId);
6033 if (phone == null) {
6034 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006035 callback.onError(
6036 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006037 } catch (RemoteException e) {
6038 // ignore
6039 }
6040 return;
6041 }
6042
6043 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6044 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6045 @Override
6046 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6047 try {
6048 callback.onCallForwardingInfoAvailable(info);
6049 } catch (RemoteException e) {
6050 // ignore
6051 }
6052 }
6053
6054 @Override
6055 public void onError(int error) {
6056 try {
6057 callback.onError(error);
6058 } catch (RemoteException e) {
6059 // ignore
6060 }
6061 }
6062 });
6063 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006064 } finally {
6065 Binder.restoreCallingIdentity(identity);
6066 }
6067 }
6068
6069 /**
6070 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6071 * reason, the number to forward, and the timeout before the forwarding is attempted.
6072 */
6073 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006074 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6075 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006076 enforceModifyPermission();
6077 long identity = Binder.clearCallingIdentity();
6078 try {
6079 if (DBG) {
6080 log("setCallForwarding: subId " + subId
6081 + " callForwardingInfo" + callForwardingInfo);
6082 }
Hall Liu27d24262020-09-18 19:04:59 -07006083
6084 Phone phone = getPhone(subId);
6085 if (phone == null) {
6086 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006087 callback.accept(
6088 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006089 } catch (RemoteException e) {
6090 // ignore
6091 }
6092 return;
6093 }
6094
6095 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6096 FunctionalUtils.ignoreRemoteException(callback::accept));
6097
6098 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006099 } finally {
6100 Binder.restoreCallingIdentity(identity);
6101 }
6102 }
6103
6104 /**
Hall Liu27d24262020-09-18 19:04:59 -07006105 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006106 */
6107 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006108 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006109 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006110 long identity = Binder.clearCallingIdentity();
6111 try {
Hall Liu27d24262020-09-18 19:04:59 -07006112 Phone phone = getPhone(subId);
6113 if (phone == null) {
6114 try {
6115 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6116 } catch (RemoteException e) {
6117 // ignore
6118 }
6119 return;
6120 }
SongFerngWang0e767992021-03-31 22:08:45 +08006121 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6122 PersistableBundle c = configManager.getConfigForSubId(subId);
6123 boolean requireUssd = c.getBoolean(
6124 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006125
Shuo Qian4a594052020-01-23 11:59:30 -08006126 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006127 if (requireUssd) {
6128 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6129 getSubscriptionCarrierId(subId));
6130 String newUssdCommand = "";
6131 try {
6132 newUssdCommand = carrierXmlParser.getFeature(
6133 CarrierXmlParser.FEATURE_CALL_WAITING)
6134 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6135 } catch (NullPointerException e) {
6136 loge("Failed to generate USSD number" + e);
6137 }
6138 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6139 mMainThreadHandler, callback, carrierXmlParser,
6140 CarrierXmlParser.SsEntry.SSAction.QUERY);
6141 final String ussdCommand = newUssdCommand;
6142 Executors.newSingleThreadExecutor().execute(() -> {
6143 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6144 });
6145 } else {
6146 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6147 callback::accept);
6148 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6149 }
Shuo Qian4a594052020-01-23 11:59:30 -08006150 } finally {
6151 Binder.restoreCallingIdentity(identity);
6152 }
6153 }
6154
6155 /**
Hall Liu27d24262020-09-18 19:04:59 -07006156 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006157 */
6158 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006159 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006160 enforceModifyPermission();
6161 long identity = Binder.clearCallingIdentity();
6162 try {
Hall Liu27d24262020-09-18 19:04:59 -07006163 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6164
6165 Phone phone = getPhone(subId);
6166 if (phone == null) {
6167 try {
6168 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6169 } catch (RemoteException e) {
6170 // ignore
6171 }
6172 return;
6173 }
6174
SongFerngWang0e767992021-03-31 22:08:45 +08006175 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6176 PersistableBundle c = configManager.getConfigForSubId(subId);
6177 boolean requireUssd = c.getBoolean(
6178 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006179
SongFerngWang0e767992021-03-31 22:08:45 +08006180 if (DBG) log("getCallWaitingStatus: subId " + subId);
6181 if (requireUssd) {
6182 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6183 getSubscriptionCarrierId(subId));
6184 CarrierXmlParser.SsEntry.SSAction ssAction =
6185 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6186 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6187 String newUssdCommand = "";
6188 try {
6189 newUssdCommand = carrierXmlParser.getFeature(
6190 CarrierXmlParser.FEATURE_CALL_WAITING)
6191 .makeCommand(ssAction, null);
6192 } catch (NullPointerException e) {
6193 loge("Failed to generate USSD number" + e);
6194 }
6195 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6196 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6197 final String ussdCommand = newUssdCommand;
6198 Executors.newSingleThreadExecutor().execute(() -> {
6199 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6200 });
6201 } else {
6202 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6203 FunctionalUtils.ignoreRemoteException(callback::accept));
6204
6205 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6206 }
Shuo Qian4a594052020-01-23 11:59:30 -08006207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
6210 }
6211
6212 /**
yinxub1bed742017-04-17 11:45:04 -07006213 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006214 *
yinxub1bed742017-04-17 11:45:04 -07006215 * @param subId id of the subscription
6216 * @param request contains the radio access networks with bands/channels to scan
6217 * @param messenger callback messenger for scan results or errors
6218 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006219 * @return the id of the requested scan which can be used to stop the scan.
6220 */
6221 @Override
6222 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006223 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6225 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006226 LocationAccessPolicy.LocationPermissionResult locationResult =
6227 LocationAccessPolicy.checkLocationPermission(mApp,
6228 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6229 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006230 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006231 .setCallingPid(Binder.getCallingPid())
6232 .setCallingUid(Binder.getCallingUid())
6233 .setMethod("requestNetworkScan")
6234 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006235 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6236 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006237 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006238 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006239 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6240 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006241 if (e != null) {
6242 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6243 throw e;
6244 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006245 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006246 return TelephonyScanManager.INVALID_SCAN_ID;
6247 }
6248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 }
Hall Liu912dfd32019-04-25 14:02:26 -07006250 int callingUid = Binder.getCallingUid();
6251 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006252 final long identity = Binder.clearCallingIdentity();
6253 try {
6254 return mNetworkScanRequestTracker.startNetworkScan(
6255 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006256 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006257 } finally {
6258 Binder.restoreCallingIdentity(identity);
6259 }
yinxu504e1392017-04-12 16:03:22 -07006260 }
6261
Hall Liub2ac8ef2019-02-28 15:56:23 -08006262 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006263 NetworkScanRequest request, int subId, String callingPackage) {
6264 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006265 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6266 boolean hasNetworkScanPermission =
6267 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6268 == PERMISSION_GRANTED;
6269
6270 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6271 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6272 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006273 }
6274
6275 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6276 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006277 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6278 return new SecurityException("Specific channels must not be"
6279 + " scanned without location access.");
6280 }
6281 }
6282 }
6283
Hall Liub2ac8ef2019-02-28 15:56:23 -08006284 return null;
6285 }
6286
yinxu504e1392017-04-12 16:03:22 -07006287 /**
6288 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006289 *
6290 * @param subId id of the subscription
6291 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006292 */
6293 @Override
6294 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6296 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297
Hall Liu912dfd32019-04-25 14:02:26 -07006298 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006299 final long identity = Binder.clearCallingIdentity();
6300 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006301 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 } finally {
6303 Binder.restoreCallingIdentity(identity);
6304 }
yinxu504e1392017-04-12 16:03:22 -07006305 }
6306
6307 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006308 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006309 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006310 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006311 */
6312 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006313 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006314 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006315 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006316 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317
6318 final long identity = Binder.clearCallingIdentity();
6319 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006320 if (DBG) log("getAllowedNetworkTypesBitmask");
6321 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6322 int networkTypesBitmask = (result != null ? result[0] : -1);
6323 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6324 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006328 }
6329
6330 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006331 * Get the allowed network types for certain reason.
6332 *
6333 * @param subId the id of the subscription.
6334 * @param reason the reason the allowed network type change is taking place
6335 * @return the allowed network types.
6336 */
6337 @Override
6338 public long getAllowedNetworkTypesForReason(int subId,
6339 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006340 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006341 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006342 final long identity = Binder.clearCallingIdentity();
6343 try {
6344 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
6348 }
6349
6350 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006351 * Enable/Disable E-UTRA-NR Dual Connectivity
6352 * @param subId subscription id of the sim card
6353 * @param nrDualConnectivityState expected NR dual connectivity state
6354 * This can be passed following states
6355 * <ol>
6356 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6357 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6358 * <li>Disable NR dual connectivity and force secondary cell to be released
6359 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6360 * </ol>
6361 * @return operation result.
6362 */
6363 @Override
6364 public int setNrDualConnectivityState(int subId,
6365 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6367 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006368 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006369 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6370 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6371 }
6372
Sooraj Sasindran37444802020-08-11 10:40:43 -07006373 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6374 final long identity = Binder.clearCallingIdentity();
6375 try {
6376 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6377 nrDualConnectivityState, subId,
6378 workSource);
6379 if (DBG) log("enableNRDualConnectivity result: " + result);
6380 return result;
6381 } finally {
6382 Binder.restoreCallingIdentity(identity);
6383 }
6384 }
6385
6386 /**
6387 * Is E-UTRA-NR Dual Connectivity enabled
6388 * @return true if dual connectivity is enabled else false
6389 */
6390 @Override
6391 public boolean isNrDualConnectivityEnabled(int subId) {
6392 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006393 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006394 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006395 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006396 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6397 return false;
6398 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006399 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
6402 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6403 null, subId, workSource);
6404 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6405 return isEnabled;
6406 } finally {
6407 Binder.restoreCallingIdentity(identity);
6408 }
6409 }
6410
6411 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006412 * Set the allowed network types of the device and
6413 * provide the reason triggering the allowed network change.
6414 *
6415 * @param subId the id of the subscription.
6416 * @param reason the reason the allowed network type change is taking place
6417 * @param allowedNetworkTypes the allowed network types.
6418 * @return true on success; false on any failure.
6419 */
6420 @Override
6421 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006422 @TelephonyManager.AllowedNetworkTypesReason int reason,
6423 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6425 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006426 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006427 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6428 return false;
6429 }
6430 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6431 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006432 return false;
6433 }
6434
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006435 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6436 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6437
6438
6439 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6440 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6441 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006442 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006443
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006444 final long identity = Binder.clearCallingIdentity();
6445 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006446 Boolean success = (Boolean) sendRequest(
6447 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6448 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6449
6450 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6451 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006452 } finally {
6453 Binder.restoreCallingIdentity(identity);
6454 }
6455 }
6456
6457 /**
Miaoa84611c2019-03-15 09:21:10 +08006458 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006459 *
Miaoa84611c2019-03-15 09:21:10 +08006460 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006461 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006462 * @hide
6463 */
6464 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006465 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006466 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006468 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 try {
Miaoa84611c2019-03-15 09:21:10 +08006470 if (phone != null) {
6471 return phone.hasMatchedTetherApnSetting();
6472 } else {
6473 return false;
6474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475 } finally {
6476 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006477 }
Junda Liu475951f2014-11-07 16:45:03 -08006478 }
6479
6480 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006481 * Enable or disable always reporting signal strength changes from radio.
6482 *
6483 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6484 */
6485 @Override
6486 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6487 enforceModifyPermission();
6488 enforceSystemCaller();
6489
6490 final long identity = Binder.clearCallingIdentity();
6491 final Phone phone = getPhone(subId);
6492 try {
6493 if (phone != null) {
6494 if (DBG) {
6495 log("setAlwaysReportSignalStrength: subId=" + subId
6496 + " isEnable=" + isEnable);
6497 }
6498 phone.setAlwaysReportSignalStrength(isEnable);
6499 } else {
6500 loge("setAlwaysReportSignalStrength: no phone found for subId="
6501 + subId);
6502 }
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
6508 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006509 * Get the user enabled state of Mobile Data.
6510 *
6511 * TODO: remove and use isUserDataEnabled.
6512 * This can't be removed now because some vendor codes
6513 * calls through ITelephony directly while they should
6514 * use TelephonyManager.
6515 *
6516 * @return true on enabled
6517 */
6518 @Override
6519 public boolean getDataEnabled(int subId) {
6520 return isUserDataEnabled(subId);
6521 }
6522
6523 /**
6524 * Get whether mobile data is enabled per user setting.
6525 *
6526 * There are other factors deciding whether mobile data is actually enabled, but they are
6527 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006528 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006529 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006530 *
6531 * @return {@code true} if data is enabled else {@code false}
6532 */
6533 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006534 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006535 try {
6536 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6537 null);
6538 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6540 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542
6543 final long identity = Binder.clearCallingIdentity();
6544 try {
6545 int phoneId = mSubscriptionController.getPhoneId(subId);
6546 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6547 Phone phone = PhoneFactory.getPhone(phoneId);
6548 if (phone != null) {
6549 boolean retVal = phone.isUserDataEnabled();
6550 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6551 return retVal;
6552 } else {
6553 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6554 return false;
6555 }
6556 } finally {
6557 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006558 }
6559 }
6560
6561 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006562 * Checks if the device is capable of mobile data by considering whether whether the
6563 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6564 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006565 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006566 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006567 */
6568 @Override
6569 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006570 try {
6571 try {
6572 mApp.enforceCallingOrSelfPermission(
6573 android.Manifest.permission.ACCESS_NETWORK_STATE,
6574 null);
6575 } catch (Exception e) {
6576 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6577 "isDataEnabled");
6578 }
6579 } catch (Exception e) {
6580 enforceReadPrivilegedPermission("isDataEnabled");
6581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582
6583 final long identity = Binder.clearCallingIdentity();
6584 try {
6585 int phoneId = mSubscriptionController.getPhoneId(subId);
6586 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6587 Phone phone = PhoneFactory.getPhone(phoneId);
6588 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006589 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6591 return retVal;
6592 } else {
6593 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6594 return false;
6595 }
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006598 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006599 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006600
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006601 /**
6602 * Check if data is enabled for a specific reason
6603 * @param subId Subscription index
6604 * @param reason the reason the data enable change is taking place
6605 * @return {@code true} if the overall data is enabled; {@code false} if not.
6606 */
6607 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006608 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006609 @TelephonyManager.DataEnabledReason int reason) {
6610 try {
6611 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6612 null);
6613 } catch (Exception e) {
6614 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006615 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006616 }
6617
6618
6619 final long identity = Binder.clearCallingIdentity();
6620 try {
6621 int phoneId = mSubscriptionController.getPhoneId(subId);
6622 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006623 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006624 + " reason=" + reason);
6625 }
6626 Phone phone = PhoneFactory.getPhone(phoneId);
6627 if (phone != null) {
6628 boolean retVal;
6629 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6630 retVal = phone.isUserDataEnabled();
6631 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006632 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006633 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006634 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006635 return retVal;
6636 } else {
6637 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006638 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006639 + subId + " retVal=false");
6640 }
6641 return false;
6642 }
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
6646 }
6647
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006648 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006649 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006650 if (uid == Process.PHONE_UID) {
6651 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6652 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006653 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6654 }
6655
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006656 //load access rules from carrier configs, and check those as well: b/139133814
6657 SubscriptionController subController = SubscriptionController.getInstance();
6658 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6659 || subController == null) return privilegeFromSim;
6660
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006661 PackageManager pkgMgr = phone.getContext().getPackageManager();
6662 String[] packages = pkgMgr.getPackagesForUid(uid);
6663
6664 final long identity = Binder.clearCallingIdentity();
6665 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006666 int subId = phone.getSubId();
6667 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6668 // A test override is in place for the privileges for this subId, so don't try to
6669 // read the subscription privileges.
6670 return privilegeFromSim;
6671 }
6672 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006673 SubscriptionManager subManager = (SubscriptionManager)
6674 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6675 for (String pkg : packages) {
6676 if (subManager.canManageSubscription(subInfo, pkg)) {
6677 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6678 }
6679 }
6680 return privilegeFromSim;
6681 } finally {
6682 Binder.restoreCallingIdentity(identity);
6683 }
6684 }
6685
6686 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6687 String pkgName) {
6688 //load access rules from carrier configs, and check those as well: b/139133814
6689 SubscriptionController subController = SubscriptionController.getInstance();
6690 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6691 || subController == null) return privilegeFromSim;
6692
6693 final long identity = Binder.clearCallingIdentity();
6694 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006695 int subId = phone.getSubId();
6696 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6697 // A test override is in place for the privileges for this subId, so don't try to
6698 // read the subscription privileges.
6699 return privilegeFromSim;
6700 }
6701 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006702 SubscriptionManager subManager = (SubscriptionManager)
6703 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6704 return subManager.canManageSubscription(subInfo, pkgName)
6705 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6706 } finally {
6707 Binder.restoreCallingIdentity(identity);
6708 }
6709 }
6710
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006711 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006712 public int getCarrierPrivilegeStatus(int subId) {
6713 final Phone phone = getPhone(subId);
6714 if (phone == null) {
6715 loge("getCarrierPrivilegeStatus: Invalid subId");
6716 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6717 }
6718 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006719 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006720 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006721 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6722 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006723
6724 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6725 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006726 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006727 }
Junda Liu29340342014-07-10 15:23:27 -07006728
6729 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006730 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006731 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006732 final Phone phone = getPhone(subId);
6733 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006734 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006735 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6736 }
6737 UiccProfile profile =
6738 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6739 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006740 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006741 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6742 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006743 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006744 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006745 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006746 }
6747
6748 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006749 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006750 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006751 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006753 }
6754
6755 int phoneId = SubscriptionManager.getPhoneId(subId);
6756 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006757 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006758 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006759 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6760 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006761 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6762 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6763 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006764 }
6765
6766 @Override
6767 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006768 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006769 if (TextUtils.isEmpty(pkgName))
6770 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006771 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6772 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6773 UiccCard card = UiccController.getInstance().getUiccCard(i);
6774 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006775 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006776 continue;
6777 }
6778
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006779 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6780 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6781 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006782 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6783 break;
6784 }
6785 }
6786
6787 return result;
Junda Liu29340342014-07-10 15:23:27 -07006788 }
Derek Tan89e89d42014-07-08 17:00:10 -07006789
6790 @Override
Junda Liue64de782015-04-16 17:19:16 -07006791 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006792 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006793 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6794 loge("phoneId " + phoneId + " is not valid.");
6795 return null;
6796 }
6797 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006798 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006799 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006800 return null ;
6801 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006802 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006803 }
6804
Amith Yamasani6e118872016-02-19 12:53:51 -08006805 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006806 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006807 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006808 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006809 List<String> privilegedPackages = new ArrayList<>();
6810 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006811 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6812 // has UICC in that slot.
6813 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006814 if (card.hasCarrierPrivilegeRules()) {
6815 if (packages == null) {
6816 // Only check packages in user 0 for now
6817 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006818 PackageManager.MATCH_DISABLED_COMPONENTS
6819 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006820 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006821 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006822 }
6823 for (int p = packages.size() - 1; p >= 0; p--) {
6824 PackageInfo pkgInfo = packages.get(p);
6825 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006826 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6827 card.getCarrierPrivilegeStatus(pkgInfo),
6828 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006829 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006830 privilegedPackages.add(pkgInfo.packageName);
6831 }
6832 }
6833 }
6834 }
6835 return privilegedPackages;
6836 }
6837
chen xuf7e9fe82019-05-09 19:31:02 -07006838 @Override
6839 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006840 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6841
6842 final long identity = Binder.clearCallingIdentity();
6843
chen xuf7e9fe82019-05-09 19:31:02 -07006844 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006845 try {
6846 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6847 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6848 }
6849 } finally {
6850 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006851 }
6852 return privilegedPackages;
6853 }
6854
Wink Savilleb564aae2014-10-23 10:18:09 -07006855 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006856 final Phone phone = getPhone(subId);
6857 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006858 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006859 return null;
6860 }
6861 String iccId = card.getIccId();
6862 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006863 return null;
6864 }
6865 return iccId;
6866 }
6867
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006868 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006869 public void setCallComposerStatus(int subId, int status) {
6870 enforceModifyPermission();
6871
6872 final long identity = Binder.clearCallingIdentity();
6873 try {
6874 Phone phone = getPhone(subId);
6875 if (phone != null) {
6876 Phone defaultPhone = phone.getImsPhone();
6877 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6878 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6879 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006880 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6881 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006882 }
6883 }
Shuo Qian284ae752020-12-22 19:10:14 -08006884 } catch (ImsException e) {
6885 throw new ServiceSpecificException(e.getCode());
6886 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006887 Binder.restoreCallingIdentity(identity);
6888 }
6889 }
6890
6891 @Override
6892 public int getCallComposerStatus(int subId) {
6893 enforceReadPrivilegedPermission("getCallComposerStatus");
6894
6895 final long identity = Binder.clearCallingIdentity();
6896 try {
6897 Phone phone = getPhone(subId);
6898 if (phone != null) {
6899 Phone defaultPhone = phone.getImsPhone();
6900 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6901 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6902 return imsPhone.getCallComposerStatus();
6903 }
6904 }
6905 } finally {
6906 Binder.restoreCallingIdentity(identity);
6907 }
6908 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6909 }
6910
6911 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006912 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6913 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006914 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006915 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006917 final long identity = Binder.clearCallingIdentity();
6918 try {
6919 final String iccId = getIccId(subId);
6920 final Phone phone = getPhone(subId);
6921 if (phone == null) {
6922 return false;
6923 }
6924 final String subscriberId = phone.getSubscriberId();
6925
6926 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006927 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 + subscriberId + " to " + number);
6929 }
6930
6931 if (TextUtils.isEmpty(iccId)) {
6932 return false;
6933 }
6934
6935 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6936
6937 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6938 if (alphaTag == null) {
6939 editor.remove(alphaTagPrefKey);
6940 } else {
6941 editor.putString(alphaTagPrefKey, alphaTag);
6942 }
6943
6944 // Record both the line number and IMSI for this ICCID, since we need to
6945 // track all merged IMSIs based on line number
6946 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6947 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6948 if (number == null) {
6949 editor.remove(numberPrefKey);
6950 editor.remove(subscriberPrefKey);
6951 } else {
6952 editor.putString(numberPrefKey, number);
6953 editor.putString(subscriberPrefKey, subscriberId);
6954 }
6955
6956 editor.commit();
6957 return true;
6958 } finally {
6959 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006960 }
Derek Tan7226c842014-07-02 17:42:23 -07006961 }
6962
6963 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006964 public String getLine1NumberForDisplay(int subId, String callingPackage,
6965 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006966 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006968 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006969 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006970 return null;
6971 }
Derek Tan97ebb422014-09-05 16:55:38 -07006972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 final long identity = Binder.clearCallingIdentity();
6974 try {
6975 String iccId = getIccId(subId);
6976 if (iccId != null) {
6977 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6978 if (DBG_MERGE) {
6979 log("getLine1NumberForDisplay returning "
6980 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6981 }
6982 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6985 return null;
6986 } finally {
6987 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006988 }
Derek Tan7226c842014-07-02 17:42:23 -07006989 }
6990
6991 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006992 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6993 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006995 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006996 return null;
6997 }
Derek Tan97ebb422014-09-05 16:55:38 -07006998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 final long identity = Binder.clearCallingIdentity();
7000 try {
7001 String iccId = getIccId(subId);
7002 if (iccId != null) {
7003 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7004 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7005 }
7006 return null;
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007009 }
Derek Tan7226c842014-07-02 17:42:23 -07007010 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007011
7012 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007013 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7014 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007015 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7016 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007018 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007019 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007020 return null;
7021 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007022
Jordan Liub49b04b2019-05-06 14:45:15 -07007023 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7024 // the process, where TelephonyManager was instantiated.
7025 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007026 final long identity = Binder.clearCallingIdentity();
7027 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007028 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 final TelephonyManager tele = TelephonyManager.from(context);
7030 final SubscriptionManager sub = SubscriptionManager.from(context);
7031
7032 // Figure out what subscribers are currently active
7033 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034
Jordan Liub49b04b2019-05-06 14:45:15 -07007035 // Only consider subs which match the current subId
7036 // This logic can be simplified. See b/131189269 for progress.
7037 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007038 activeSubscriberIds.add(tele.getSubscriberId(subId));
7039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040
7041 // First pass, find a number override for an active subscriber
7042 String mergeNumber = null;
7043 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7044 for (String key : prefs.keySet()) {
7045 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7046 final String subscriberId = (String) prefs.get(key);
7047 if (activeSubscriberIds.contains(subscriberId)) {
7048 final String iccId = key.substring(
7049 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7050 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7051 mergeNumber = (String) prefs.get(numberKey);
7052 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007053 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 + " for active subscriber " + subscriberId);
7055 }
7056 if (!TextUtils.isEmpty(mergeNumber)) {
7057 break;
7058 }
7059 }
7060 }
7061 }
7062
7063 // Shortcut when no active merged subscribers
7064 if (TextUtils.isEmpty(mergeNumber)) {
7065 return null;
7066 }
7067
7068 // Second pass, find all subscribers under that line override
7069 final ArraySet<String> result = new ArraySet<>();
7070 for (String key : prefs.keySet()) {
7071 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7072 final String number = (String) prefs.get(key);
7073 if (mergeNumber.equals(number)) {
7074 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7075 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7076 final String subscriberId = (String) prefs.get(subscriberKey);
7077 if (!TextUtils.isEmpty(subscriberId)) {
7078 result.add(subscriberId);
7079 }
7080 }
7081 }
7082 }
7083
7084 final String[] resultArray = result.toArray(new String[result.size()]);
7085 Arrays.sort(resultArray);
7086 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007087 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7089 }
7090 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007091 } finally {
7092 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007093 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007094 }
7095
7096 @Override
zoey chen38003472019-12-13 17:16:31 +08007097 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7098 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007099
7100 final long identity = Binder.clearCallingIdentity();
7101 try {
7102 final TelephonyManager telephonyManager = mApp.getSystemService(
7103 TelephonyManager.class);
7104 String subscriberId = telephonyManager.getSubscriberId(subId);
7105 if (subscriberId == null) {
7106 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007107 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007108 + subId);
7109 }
7110 return null;
7111 }
7112
7113 final SubscriptionInfo info = SubscriptionController.getInstance()
7114 .getSubscriptionInfo(subId);
7115 final ParcelUuid groupUuid = info.getGroupUuid();
7116 // If it doesn't belong to any group, return just subscriberId of itself.
7117 if (groupUuid == null) {
7118 return new String[]{subscriberId};
7119 }
7120
7121 // Get all subscriberIds from the group.
7122 final List<String> mergedSubscriberIds = new ArrayList<>();
7123 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007124 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007125 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007126 for (SubscriptionInfo subInfo : groupInfos) {
7127 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7128 if (subscriberId != null) {
7129 mergedSubscriberIds.add(subscriberId);
7130 }
7131 }
7132
7133 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7134 } finally {
7135 Binder.restoreCallingIdentity(identity);
7136
7137 }
7138 }
7139
7140 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007141 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007142 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007143 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007144
7145 final long identity = Binder.clearCallingIdentity();
7146 try {
7147 final Phone phone = getPhone(subId);
7148 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7149 } finally {
7150 Binder.restoreCallingIdentity(identity);
7151 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007152 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007153
7154 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007155 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007156 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7157 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007158 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7159 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007160
7161 final long identity = Binder.clearCallingIdentity();
7162 try {
7163 final Phone phone = getPhone(subId);
7164 if (phone == null) {
7165 return false;
7166 }
7167 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7168 cdmaNonRoamingList);
7169 } finally {
7170 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007171 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007172 }
7173
7174 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007175 @Deprecated
7176 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7177 enforceModifyPermission();
7178
7179 int returnValue = 0;
7180 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007181 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007182 if(result.exception == null) {
7183 if (result.result != null) {
7184 byte[] responseData = (byte[])(result.result);
7185 if(responseData.length > oemResp.length) {
7186 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7187 responseData.length + "bytes. Buffer Size is " +
7188 oemResp.length + "bytes.");
7189 }
7190 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7191 returnValue = responseData.length;
7192 }
7193 } else {
7194 CommandException ex = (CommandException) result.exception;
7195 returnValue = ex.getCommandError().ordinal();
7196 if(returnValue > 0) returnValue *= -1;
7197 }
7198 } catch (RuntimeException e) {
7199 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7200 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7201 if(returnValue > 0) returnValue *= -1;
7202 }
7203
7204 return returnValue;
7205 }
7206
7207 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007208 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007209 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007210 try {
7211 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007212 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007213 mApp, phone.getSubId(), "getRadioAccessFamily");
7214 } catch (SecurityException e) {
7215 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7216 throw e;
7217 }
chen xub97461a2018-10-26 14:17:57 -07007218 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007219 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007220 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007221 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222 final long identity = Binder.clearCallingIdentity();
7223 try {
chen xub97461a2018-10-26 14:17:57 -07007224 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007225 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007226 mApp, phone.getSubId(), "getRadioAccessFamily");
7227 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 } finally {
7229 Binder.restoreCallingIdentity(identity);
7230 }
chen xub97461a2018-10-26 14:17:57 -07007231 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007232 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007233
7234 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007235 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007236 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007237 try {
7238 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7239 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007240 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007241 }
7242 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007243 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007244 }
7245 RoleManager rm = mApp.getSystemService(RoleManager.class);
7246 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7247 if (!dialerRoleHolders.contains(callingPackage)) {
7248 throw new SecurityException("App must be the dialer role holder to"
7249 + " upload a call composer pic");
7250 }
7251
7252 Executors.newSingleThreadExecutor().execute(() -> {
7253 ByteArrayOutputStream output = new ByteArrayOutputStream(
7254 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7255 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7256 boolean readUntilEnd = false;
7257 int totalBytesRead = 0;
7258 byte[] buffer = new byte[16 * 1024];
7259 while (true) {
7260 int numRead;
7261 try {
7262 numRead = input.read(buffer);
7263 } catch (IOException e) {
7264 try {
7265 fd.checkError();
7266 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7267 null);
7268 } catch (IOException e1) {
7269 // This means that the other side closed explicitly with an error. If this
7270 // happens, log and ignore.
7271 loge("Remote end of call composer picture pipe closed: " + e1);
7272 }
7273 break;
7274 }
7275 if (numRead == -1) {
7276 readUntilEnd = true;
7277 break;
7278 }
7279 totalBytesRead += numRead;
7280 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7281 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7282 try {
7283 input.close();
7284 } catch (IOException e) {
7285 // ignore
7286 }
7287 break;
7288 }
7289 output.write(buffer, 0, numRead);
7290 }
7291 // Generally, the remote end will close the file descriptors. The only case where we
7292 // close is above, where the picture size is too big.
7293
7294 try {
7295 fd.checkError();
7296 } catch (IOException e) {
7297 loge("Remote end for call composer closed with an error: " + e);
7298 return;
7299 }
7300
Hall Liuaa4211e2021-01-20 15:43:39 -08007301 if (!readUntilEnd) {
7302 loge("Did not finish reading entire image; aborting");
7303 return;
7304 }
Hall Liu82694d52020-12-11 18:22:04 -08007305
Hall Liuaa4211e2021-01-20 15:43:39 -08007306 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7307 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7308 new CallComposerPictureTransfer.Factory() {},
7309 imageData,
7310 (result) -> {
7311 if (result.first != null) {
7312 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7313 Bundle outputResult = new Bundle();
7314 outputResult.putParcelable(
7315 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7316 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7317 outputResult);
7318 } else {
7319 callback.send(result.second, null);
7320 }
7321 }
7322 );
Hall Liu82694d52020-12-11 18:22:04 -08007323 });
7324 }
7325
7326 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007327 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007328 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007329 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330
7331 final long identity = Binder.clearCallingIdentity();
7332 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007333 ImsManager.getInstance(defaultPhone.getContext(),
7334 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 } finally {
7336 Binder.restoreCallingIdentity(identity);
7337 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007338 }
7339
7340 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007341 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007342 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7344 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007345 return false;
7346 }
Svet Ganovb320e182015-04-16 12:30:10 -07007347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 // Check the user preference and the system-level IMS setting. Even if the user has
7351 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7352 // In the long run, we may instead need to check if there exists a connection service
7353 // which can support video calling.
7354 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007355 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 return imsManager.isVtEnabledByPlatform()
7357 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7358 && imsManager.isVtEnabledByUser();
7359 } finally {
7360 Binder.restoreCallingIdentity(identity);
7361 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007362 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007363
Andrew Leea1239f22015-03-02 17:44:07 -08007364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007365 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7366 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007368 mApp, subId, callingPackage, callingFeatureId,
7369 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 return false;
7371 }
7372
7373 final long identity = Binder.clearCallingIdentity();
7374 try {
7375 CarrierConfigManager configManager =
7376 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007377 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7379 } finally {
7380 Binder.restoreCallingIdentity(identity);
7381 }
Andrew Leea1239f22015-03-02 17:44:07 -08007382 }
7383
7384 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007385 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007387 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 return false;
7389 }
7390
7391 final long identity = Binder.clearCallingIdentity();
7392 try {
7393 CarrierConfigManager configManager =
7394 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007395 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7397 } finally {
7398 Binder.restoreCallingIdentity(identity);
7399 }
Andrew Leea1239f22015-03-02 17:44:07 -08007400 }
7401
Andrew Lee9431b832015-03-09 18:46:45 -07007402 @Override
7403 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007404 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007405 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007406 }
7407
7408 @Override
7409 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007410 final long identity = Binder.clearCallingIdentity();
7411 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007412 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
Andrew Lee9431b832015-03-09 18:46:45 -07007416 }
7417
Hall Liuf6668912018-10-31 17:05:23 -07007418 /**
7419 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7420 * support for the feature and device firmware support.
7421 *
7422 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7423 */
7424 @Override
7425 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007427 final Phone phone = getPhone(subscriptionId);
7428 if (phone == null) {
7429 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7430 return false;
7431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007433 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7435 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007436 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 return isCarrierSupported && isDeviceSupported;
7438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
Hall Liu98187582018-01-22 19:15:32 -08007441 }
7442
Hall Liuf6668912018-10-31 17:05:23 -07007443 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007444 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7445 * RTT setting, will return true if the device and carrier both support RTT.
7446 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007447 */
7448 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 final long identity = Binder.clearCallingIdentity();
7450 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007451 boolean isRttSupported = isRttSupported(subscriptionId);
7452 boolean isUserRttSettingOn = Settings.Secure.getInt(
7453 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7454 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7455 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7456 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007460 }
7461
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007462 @Deprecated
7463 @Override
7464 public String getDeviceId(String callingPackage) {
7465 return getDeviceIdWithFeature(callingPackage, null);
7466 }
7467
Sanket Padawe7310cc72015-01-14 09:53:20 -08007468 /**
7469 * Returns the unique device ID of phone, for example, the IMEI for
7470 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7471 *
7472 * <p>Requires Permission:
7473 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7474 */
7475 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007476 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007477 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007478 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007479 return null;
7480 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007481 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007482 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007483 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007484 return null;
7485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
7489 return phone.getDeviceId();
7490 } finally {
7491 Binder.restoreCallingIdentity(identity);
7492 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007493 }
7494
Ping Sunc67b7c22016-03-02 19:16:45 +08007495 /**
7496 * {@hide}
7497 * Returns the IMS Registration Status on a particular subid
7498 *
7499 * @param subId
7500 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007501 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007502 Phone phone = getPhone(subId);
7503 if (phone != null) {
7504 return phone.isImsRegistered();
7505 } else {
7506 return false;
7507 }
7508 }
7509
Santos Cordon7a1885b2015-02-03 11:15:19 -08007510 @Override
7511 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 final long identity = Binder.clearCallingIdentity();
7513 try {
7514 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007518 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007519
Tyler Gunnf70ed162019-04-03 15:28:53 -07007520 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007521 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007522 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007524 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007525 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7526 }
7527 final long identity = Binder.clearCallingIdentity();
7528 try {
7529 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
7533 }
7534
7535 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007536 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007537 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007538 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007539 mApp,
7540 subscriptionId,
7541 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007542 final long identity = Binder.clearCallingIdentity();
7543 try {
7544 Phone phone = getPhone(subscriptionId);
7545 if (phone == null) {
7546 return null;
7547 }
7548 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7549 } finally {
7550 Binder.restoreCallingIdentity(identity);
7551 }
7552 }
7553
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007554 /**
7555 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007556 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007557 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 Phone phone = getPhone(subId);
7561 if (phone != null) {
7562 return phone.isWifiCallingEnabled();
7563 } else {
7564 return false;
7565 }
7566 } finally {
7567 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007568 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007569 }
7570
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007571 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007572 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007573 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007574 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 final long identity = Binder.clearCallingIdentity();
7576 try {
7577 Phone phone = getPhone(subId);
7578 if (phone != null) {
7579 return phone.isVideoEnabled();
7580 } else {
7581 return false;
7582 }
7583 } finally {
7584 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007585 }
7586 }
7587
7588 /**
7589 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7590 * defined in {@link ImsRegistrationImplBase}.
7591 */
7592 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 final long identity = Binder.clearCallingIdentity();
7594 try {
7595 Phone phone = getPhone(subId);
7596 if (phone != null) {
7597 return phone.getImsRegistrationTech();
7598 } else {
7599 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7600 }
7601 } finally {
7602 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007603 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007604 }
7605
Stuart Scott8eef64f2015-04-08 15:13:54 -07007606 @Override
7607 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007608 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007609 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7610 return;
7611 }
Kai Shif70f46f2021-03-03 13:59:46 -08007612 Phone defaultPhone = getDefaultPhone();
7613 if (defaultPhone != null) {
7614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7615 mApp, getDefaultPhone().getSubId(), "factoryReset");
7616 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007617 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007618
Svet Ganovcc087f82015-05-12 20:35:54 -07007619 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007620 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7621 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007622 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007623 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007624 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007625 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007626 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007627 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007628 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007629 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007630 // There has been issues when Sms raw table somehow stores orphan
7631 // fragments. They lead to garbled message when new fragments come
7632 // in and combined with those stale ones. In case this happens again,
7633 // user can reset all network settings which will clean up this table.
7634 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007635 // Clean up IMS settings as well here.
7636 int slotId = getSlotIndex(subId);
7637 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7638 ImsManager.getInstance(mApp, slotId).factoryReset();
7639 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007640
Kai Shif70f46f2021-03-03 13:59:46 -08007641 if (defaultPhone == null) {
7642 return;
7643 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007644 // Erase modem config if erase modem on network setting is enabled.
7645 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7646 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7647 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007648 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007649 }
Kai Shif70f46f2021-03-03 13:59:46 -08007650
7651 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007652 } finally {
7653 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007654 }
7655 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007656
SongFerngWangfd89b102021-05-27 22:44:54 +08007657 @VisibleForTesting
7658 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7659 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7660 return;
7661 }
7662 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7663 RILConstants.PREFERRED_NETWORK_MODE);
7664 SubscriptionManager.setSubscriptionProperty(subId,
7665 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7666 "user=" + defaultNetworkType);
7667 phone.loadAllowedNetworksFromSubscriptionDatabase();
7668 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7669 defaultNetworkType, null);
7670 }
7671
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007672 private void cleanUpSmsRawTable(Context context) {
7673 ContentResolver resolver = context.getContentResolver();
7674 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7675 resolver.delete(uri, null, null);
7676 }
7677
Narayan Kamath1c496c22015-04-16 14:40:19 +01007678 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007679 public String getSimLocaleForSubscriber(int subId) {
7680 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7681 final Phone phone = getPhone(subId);
7682 if (phone == null) {
7683 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007684 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007686 final long identity = Binder.clearCallingIdentity();
7687 try {
chen xu5d3637b2019-01-21 23:31:38 -08007688 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007689 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007690 if (info == null) {
7691 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7692 return null;
7693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 // Try and fetch the locale from the carrier properties or from the SIM language
7695 // preferences (EF-PL and EF-LI)...
7696 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007698 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7699 if (localeFromDefaultSim != null) {
7700 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7701 if (DBG) log("Using locale from subId: " + subId + " locale: "
7702 + localeFromDefaultSim);
7703 return localeFromDefaultSim.toLanguageTag();
7704 } else {
7705 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706 }
7707 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709 // The SIM language preferences only store a language (e.g. fr = French), not an
7710 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7711 // the SIM and carrier preferences does not include a country we add the country
7712 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007713 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007715 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716 return mccLocale.toLanguageTag();
7717 }
7718
7719 if (DBG) log("No locale found - returning null");
7720 return null;
7721 } finally {
7722 Binder.restoreCallingIdentity(identity);
7723 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007724 }
7725
7726 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007727 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007728 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007729 }
7730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 /**
7732 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7733 */
7734 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007735 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007736 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007737 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007738
Chenjie Yu1ba97252018-01-11 18:16:20 -08007739 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007740 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007741
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007742 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007743 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7744 * representing the state of the modem.
7745 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007746 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7747 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007748 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007749 */
7750 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007751 public void requestModemActivityInfo(ResultReceiver result) {
7752 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007753 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007754
7755 final long identity = Binder.clearCallingIdentity();
7756 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007757 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 } finally {
7759 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007760 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007761 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007762
Siddharth Rayb8114062018-06-17 15:02:38 -07007763 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7764 // less than total activity duration.
7765 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7766 if (info == null) {
7767 return false;
7768 }
7769 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007770 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7771 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7772
Siddharth Rayb8114062018-06-17 15:02:38 -07007773 return (info.isValid()
7774 && (info.getSleepTimeMillis() <= activityDurationMs)
7775 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007776 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007777 && (totalTxTimeMs <= activityDurationMs));
7778 }
7779
Jack Yu85bd38a2015-11-09 11:34:32 -08007780 /**
7781 * {@hide}
7782 * Returns the service state information on specified subscription.
7783 */
7784 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007785 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7786 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007788 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007789 return null;
7790 }
7791
Hall Liuf19c44f2018-11-27 14:38:17 -08007792 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7793 LocationAccessPolicy.checkLocationPermission(mApp,
7794 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7795 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007796 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007797 .setCallingPid(Binder.getCallingPid())
7798 .setCallingUid(Binder.getCallingUid())
7799 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007800 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007801 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007802 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7803 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007804 .build());
7805
7806 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7807 LocationAccessPolicy.checkLocationPermission(mApp,
7808 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7809 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007810 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007811 .setCallingPid(Binder.getCallingPid())
7812 .setCallingUid(Binder.getCallingUid())
7813 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007814 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007815 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007816 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7817 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007818 .build());
7819 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7820 boolean hasFinePermission =
7821 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7822 boolean hasCoarsePermission =
7823 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7824
Jack Yu479f40e2020-10-27 21:29:25 -07007825 final Phone phone = getPhone(subId);
7826 if (phone == null) {
7827 return null;
7828 }
7829
Jordan Liu0f2bc442020-11-18 16:47:37 -08007830 final long identity = Binder.clearCallingIdentity();
7831
Jack Yu479f40e2020-10-27 21:29:25 -07007832 boolean isCallingPackageDataService = phone.getDataServicePackages()
7833 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007834 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007835 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7836 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7837 Rlog.d(LOG_TAG,
7838 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7839 return null;
7840 }
7841
Hall Liuf19c44f2018-11-27 14:38:17 -08007842 ServiceState ss = phone.getServiceState();
7843
7844 // Scrub out the location info in ServiceState depending on what level of access
7845 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007846 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007847 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7848 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849 } finally {
7850 Binder.restoreCallingIdentity(identity);
7851 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007852 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007853
7854 /**
7855 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7856 *
7857 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7858 * voicemail ringtone.
7859 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7860 * PhoneAccount.
7861 */
7862 @Override
7863 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007864 final long identity = Binder.clearCallingIdentity();
7865 try {
7866 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7867 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007868 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007869 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7872 } finally {
7873 Binder.restoreCallingIdentity(identity);
7874 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007875 }
7876
7877 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007878 * Sets the per-account voicemail ringtone.
7879 *
7880 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7881 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7882 *
7883 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7884 * voicemail ringtone.
7885 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7886 * PhoneAccount.
7887 */
7888 @Override
7889 public void setVoicemailRingtoneUri(String callingPackage,
7890 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007891 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007892 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007893 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7894 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7896 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7897 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007898 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007899
7900 final long identity = Binder.clearCallingIdentity();
7901 try {
7902 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7903 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007904 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 }
7906 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7907 } finally {
7908 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007909 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007910 }
7911
7912 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007913 * Returns whether vibration is set for voicemail notification in Phone settings.
7914 *
7915 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7916 * voicemail vibration setting.
7917 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7918 */
7919 @Override
7920 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921 final long identity = Binder.clearCallingIdentity();
7922 try {
7923 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7924 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007925 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007928 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7929 } finally {
7930 Binder.restoreCallingIdentity(identity);
7931 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007932 }
7933
Youhan Wange64578a2016-05-02 15:32:42 -07007934 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007935 * Sets the per-account voicemail vibration.
7936 *
7937 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7938 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7939 *
7940 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7941 * voicemail vibration setting.
7942 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7943 * specific PhoneAccount.
7944 */
7945 @Override
7946 public void setVoicemailVibrationEnabled(String callingPackage,
7947 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007948 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007949 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007950 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7951 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7953 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7954 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007955 }
7956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7960 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007961 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 }
7963 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7964 } finally {
7965 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007966 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007967 }
7968
7969 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007970 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7971 *
7972 * @throws SecurityException if the caller does not have the required permission
7973 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007974 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007975 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007976 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007977 }
7978
7979 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007980 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7981 * permission.
7982 *
7983 * @throws SecurityException if the caller does not have the required permission
7984 */
7985 private void enforceSendSmsPermission() {
7986 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7987 }
7988
7989 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007990 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007991 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007992 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007993 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007994 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007995 final long identity = Binder.clearCallingIdentity();
7996 try {
7997 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007998 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007999 if (componentName == null) {
8000 throw new SecurityException(
8001 "Caller not current active visual voicemail package[null]");
8002 }
8003 String vvmPackage = componentName.getPackageName();
8004 if (!callingPackage.equals(vvmPackage)) {
8005 throw new SecurityException("Caller not current active visual voicemail package["
8006 + vvmPackage + "]");
8007 }
8008 } finally {
8009 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008010 }
8011 }
8012
8013 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008014 * Return the application ID for the app type.
8015 *
8016 * @param subId the subscription ID that this request applies to.
8017 * @param appType the uicc app type.
8018 * @return Application ID for specificied app type, or null if no uicc.
8019 */
8020 @Override
8021 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008022 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008023 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024
8025 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008026 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008027 if (phone == null) {
8028 return null;
8029 }
8030 String aid = null;
8031 try {
8032 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8033 .getApplicationByType(appType).getAid();
8034 } catch (Exception e) {
8035 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8036 }
8037 return aid;
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008040 }
Youhan Wange64578a2016-05-02 15:32:42 -07008041 }
8042
Youhan Wang4001d252016-05-11 10:29:41 -07008043 /**
8044 * Return the Electronic Serial Number.
8045 *
8046 * @param subId the subscription ID that this request applies to.
8047 * @return ESN or null if error.
8048 */
8049 @Override
8050 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008051 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008052 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053
8054 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008055 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 if (phone == null) {
8057 return null;
8058 }
8059 String esn = null;
8060 try {
8061 esn = phone.getEsn();
8062 } catch (Exception e) {
8063 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8064 }
8065 return esn;
8066 } finally {
8067 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008068 }
Youhan Wang4001d252016-05-11 10:29:41 -07008069 }
8070
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008071 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008072 * Return the Preferred Roaming List Version.
8073 *
8074 * @param subId the subscription ID that this request applies to.
8075 * @return PRLVersion or null if error.
8076 */
8077 @Override
8078 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008079 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008080 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008081
8082 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008083 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 if (phone == null) {
8085 return null;
8086 }
8087 String cdmaPrlVersion = null;
8088 try {
8089 cdmaPrlVersion = phone.getCdmaPrlVersion();
8090 } catch (Exception e) {
8091 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8092 }
8093 return cdmaPrlVersion;
8094 } finally {
8095 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008096 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008097 }
8098
8099 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008100 * Get snapshot of Telephony histograms
8101 * @return List of Telephony histograms
8102 * @hide
8103 */
8104 @Override
8105 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8107 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108
8109 final long identity = Binder.clearCallingIdentity();
8110 try {
8111 return RIL.getTelephonyRILTimingHistograms();
8112 } finally {
8113 Binder.restoreCallingIdentity(identity);
8114 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008115 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008116
8117 /**
8118 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008119 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8120 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008121 * Require system privileges. In the future we may add this to carrier APIs.
8122 *
Michele Berionne482f8202018-11-27 18:57:59 -08008123 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008124 */
8125 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008126 @TelephonyManager.SetCarrierRestrictionResult
8127 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008128 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008129 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008130
Michele Berionne482f8202018-11-27 18:57:59 -08008131 if (carrierRestrictionRules == null) {
8132 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008133 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 final long identity = Binder.clearCallingIdentity();
8136 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008137 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008138 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 } finally {
8140 Binder.restoreCallingIdentity(identity);
8141 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008142 }
8143
8144 /**
8145 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008146 * Get the allowed carrier list and the excluded carrier list, including the priority between
8147 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008148 * Require system privileges. In the future we may add this to carrier APIs.
8149 *
Michele Berionne482f8202018-11-27 18:57:59 -08008150 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008151 */
8152 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008153 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008154 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008155 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008156
8157 final long identity = Binder.clearCallingIdentity();
8158 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008159 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8160 if (response instanceof CarrierRestrictionRules) {
8161 return (CarrierRestrictionRules) response;
8162 }
8163 // Response is an Exception of some kind,
8164 // which is signalled to the user as a NULL retval
8165 return null;
8166 } catch (Exception e) {
8167 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8168 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008169 } finally {
8170 Binder.restoreCallingIdentity(identity);
8171 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008172 }
8173
fionaxu59545b42016-05-25 15:53:37 -07008174 /**
fionaxu59545b42016-05-25 15:53:37 -07008175 * Action set from carrier signalling broadcast receivers to enable/disable radio
8176 * @param subId the subscription ID that this action applies to.
8177 * @param enabled control enable or disable radio.
8178 * {@hide}
8179 */
8180 @Override
8181 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8182 enforceModifyPermission();
8183 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008184
8185 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008186 if (phone == null) {
8187 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8188 return;
8189 }
8190 try {
8191 phone.carrierActionSetRadioEnabled(enabled);
8192 } catch (Exception e) {
8193 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008194 } finally {
8195 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008196 }
8197 }
8198
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008199 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008200 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8201 * network status based on which carrier apps could apply actions accordingly,
8202 * enable/disable default url handler for example.
8203 *
8204 * @param subId the subscription ID that this action applies to.
8205 * @param report control start/stop reporting the default network status.
8206 * {@hide}
8207 */
8208 @Override
8209 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8210 enforceModifyPermission();
8211 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008212
8213 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008214 if (phone == null) {
8215 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8216 return;
8217 }
8218 try {
8219 phone.carrierActionReportDefaultNetworkStatus(report);
8220 } catch (Exception e) {
8221 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222 } finally {
8223 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008224 }
8225 }
8226
8227 /**
fionaxud9622282017-07-17 17:51:30 -07008228 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8229 * @param subId the subscription ID that this action applies to.
8230 * {@hide}
8231 */
8232 @Override
8233 public void carrierActionResetAll(int subId) {
8234 enforceModifyPermission();
8235 final Phone phone = getPhone(subId);
8236 if (phone == null) {
8237 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8238 return;
8239 }
8240 try {
8241 phone.carrierActionResetAll();
8242 } catch (Exception e) {
8243 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8244 }
8245 }
8246
8247 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008248 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8249 * bug report is being generated.
8250 */
8251 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008252 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008253 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8254 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008255 writer.println("Permission Denial: can't dump Phone from pid="
8256 + Binder.getCallingPid()
8257 + ", uid=" + Binder.getCallingUid()
8258 + "without permission "
8259 + android.Manifest.permission.DUMP);
8260 return;
8261 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008262 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008263 }
Jack Yueb89b242016-06-22 13:27:47 -07008264
Brad Ebingerdac2f002018-04-03 15:17:52 -07008265 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008266 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8267 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8268 @NonNull String[] args) {
8269 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8270 this, in.getFileDescriptor(), out.getFileDescriptor(),
8271 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008272 }
8273
Jack Yueb89b242016-06-22 13:27:47 -07008274 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008275 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008276 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008277 * @param reason the reason the data enable change is taking place
8278 * @param enabled True if enabling the data, otherwise disabling.
8279 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008280 */
8281 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008282 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008283 boolean enabled) {
8284 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8285 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8286 try {
8287 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008288 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008289 } catch (SecurityException se) {
8290 enforceModifyPermission();
8291 }
8292 } else {
8293 enforceModifyPermission();
8294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295
8296 final long identity = Binder.clearCallingIdentity();
8297 try {
8298 Phone phone = getPhone(subId);
8299 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008300 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8301 phone.carrierActionSetMeteredApnsEnabled(enabled);
8302 } else {
8303 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008305 }
8306 } finally {
8307 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008308 }
8309 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008310
8311 /**
8312 * Get Client request stats
8313 * @return List of Client Request Stats
8314 * @hide
8315 */
8316 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008317 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8318 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008320 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008321 return null;
8322 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008323 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008325 final long identity = Binder.clearCallingIdentity();
8326 try {
8327 if (phone != null) {
8328 return phone.getClientRequestStats();
8329 }
8330
8331 return null;
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008335 }
8336
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008337 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008338 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008339 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008340 }
Jack Yueb4124c2017-02-16 15:32:43 -08008341
8342 /**
Grace Chen70990072017-03-24 17:21:30 -07008343 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008344 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008345 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008346 * @param state State of SIM (power down, power up, pass through)
8347 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8348 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8349 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008350 *
8351 **/
8352 @Override
Grace Chen70990072017-03-24 17:21:30 -07008353 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008354 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008355 Phone phone = PhoneFactory.getPhone(slotIndex);
8356
vagdeviaf9a5b92018-08-15 16:01:53 -07008357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008359 final long identity = Binder.clearCallingIdentity();
8360 try {
8361 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008362 phone.setSimPowerState(state, null, workSource);
8363 }
8364 } finally {
8365 Binder.restoreCallingIdentity(identity);
8366 }
8367 }
8368
8369 /**
8370 * Set SIM card power state.
8371 *
8372 * @param slotIndex SIM slot id.
8373 * @param state State of SIM (power down, power up, pass through)
8374 * @param callback callback to trigger after success or failure
8375 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8376 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8377 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8378 *
8379 **/
8380 @Override
8381 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8382 IIntegerConsumer callback) {
8383 enforceModifyPermission();
8384 Phone phone = PhoneFactory.getPhone(slotIndex);
8385
8386 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8387
8388 final long identity = Binder.clearCallingIdentity();
8389 try {
8390 if (phone != null) {
8391 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8392 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008393 }
8394 } finally {
8395 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008396 }
8397 }
Shuo Qiandd210312017-04-12 22:11:33 +00008398
Tyler Gunn65d45c22017-06-05 11:22:26 -07008399 private boolean isUssdApiAllowed(int subId) {
8400 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008401 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008402 if (configManager == null) {
8403 return false;
8404 }
8405 PersistableBundle pb = configManager.getConfigForSubId(subId);
8406 if (pb == null) {
8407 return false;
8408 }
8409 return pb.getBoolean(
8410 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8411 }
8412
Shuo Qiandd210312017-04-12 22:11:33 +00008413 /**
8414 * Check if phone is in emergency callback mode
8415 * @return true if phone is in emergency callback mode
8416 * @param subId sub id
8417 */
goneil9c5f4872017-12-05 14:07:56 -08008418 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008419 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008420 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008421 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008422
8423 final long identity = Binder.clearCallingIdentity();
8424 try {
8425 if (phone != null) {
8426 return phone.isInEcm();
8427 } else {
8428 return false;
8429 }
8430 } finally {
8431 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008432 }
8433 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008434
8435 /**
8436 * Get the current signal strength information for the given subscription.
8437 * Because this information is not updated when the device is in a low power state
8438 * it should not be relied-upon to be current.
8439 * @param subId Subscription index
8440 * @return the most recent cached signal strength info from the modem
8441 */
8442 @Override
8443 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444 final long identity = Binder.clearCallingIdentity();
8445 try {
8446 Phone p = getPhone(subId);
8447 if (p == null) {
8448 return null;
8449 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008450
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451 return p.getSignalStrength();
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
8454 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008455 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008456
Pengquan Meng77b7f132018-08-22 14:49:57 -07008457 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008458 * Get the current modem radio state for the given slot.
8459 * @param slotIndex slot index.
8460 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008461 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008462 * @return the current radio power state from the modem
8463 */
8464 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008466 Phone phone = PhoneFactory.getPhone(slotIndex);
8467 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8469 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008470 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8471 }
8472
8473 final long identity = Binder.clearCallingIdentity();
8474 try {
8475 return phone.getRadioPowerState();
8476 } finally {
8477 Binder.restoreCallingIdentity(identity);
8478 }
8479 }
8480 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8481 }
8482
8483 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008484 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8485 *
8486 * <p>Requires one of the following permissions:
8487 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8488 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8489 * privileges.
8490 *
8491 * @param subId subscription id
8492 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8493 * {@code false}.
8494 */
8495 @Override
8496 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008497 try {
8498 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8499 null);
8500 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008501 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008502 mApp, subId, "isDataRoamingEnabled");
8503 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008504
Pengquan Menga1bb6272018-09-06 09:59:22 -07008505 boolean isEnabled = false;
8506 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008507 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008508 Phone phone = getPhone(subId);
8509 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008510 } finally {
8511 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008512 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008513 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008514 }
8515
8516
8517 /**
8518 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8519 *
8520 * <p> Requires permission:
8521 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8522 * privileges.
8523 *
8524 * @param subId subscription id
8525 * @param isEnabled {@code true} means enable, {@code false} means disable.
8526 */
8527 @Override
8528 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8530 mApp, subId, "setDataRoamingEnabled");
8531
Pengquan Menga1bb6272018-09-06 09:59:22 -07008532 final long identity = Binder.clearCallingIdentity();
8533 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008534 Phone phone = getPhone(subId);
8535 if (phone != null) {
8536 phone.setDataRoamingEnabled(isEnabled);
8537 }
8538 } finally {
8539 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008540 }
8541 }
8542
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008543 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008544 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008545 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008546 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008547 mApp, subId, "isManualNetworkSelectionAllowed");
8548
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008549 boolean isAllowed = true;
8550 final long identity = Binder.clearCallingIdentity();
8551 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008552 Phone phone = getPhone(subId);
8553 if (phone != null) {
8554 isAllowed = phone.isCspPlmnEnabled();
8555 }
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
8559 return isAllowed;
8560 }
8561
8562 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008563 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008564 // Verify that tha callingPackage belongs to the calling UID
8565 mApp.getSystemService(AppOpsManager.class)
8566 .checkPackage(Binder.getCallingUid(), callingPackage);
8567
Jordan Liu1e142fc2019-04-22 15:10:43 -07008568 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008569 try {
8570 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008571 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008572 } catch (SecurityException e) {
8573 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8574 // has carrier privileges on an active UICC
8575 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8576 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008577 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008578 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008579 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008580
8581 final long identity = Binder.clearCallingIdentity();
8582 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008583 UiccController uiccController = UiccController.getInstance();
8584 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008585 if (hasReadPermission) {
8586 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008587 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008588
8589 // Remove private info if the caller doesn't have access
8590 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8591 for (UiccCardInfo cardInfo : cardInfos) {
8592 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8593 // is available
8594 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8595 if (card == null || card.getUiccProfile() == null) {
8596 // assume no access if the card or profile is unavailable
8597 filteredInfos.add(cardInfo.getUnprivileged());
8598 continue;
8599 }
8600 UiccProfile profile = card.getUiccProfile();
8601 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8602 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8603 filteredInfos.add(cardInfo);
8604 } else {
8605 filteredInfos.add(cardInfo.getUnprivileged());
8606 }
8607 }
8608 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008609 } finally {
8610 Binder.restoreCallingIdentity(identity);
8611 }
8612 }
8613
8614 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008615 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008616 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008617
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8621 if (slots == null) {
8622 Rlog.i(LOG_TAG, "slots is null.");
8623 return null;
8624 }
8625
8626 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8627 for (int i = 0; i < slots.length; i++) {
8628 UiccSlot slot = slots[i];
8629 if (slot == null) {
8630 continue;
8631 }
8632
Jordan Liu7be7e652019-05-06 18:55:02 +00008633 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008634 UiccCard card = slot.getUiccCard();
8635 if (card != null) {
8636 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008637 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008638 cardId = slot.getEid();
8639 if (TextUtils.isEmpty(cardId)) {
8640 cardId = slot.getIccId();
8641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008642 }
8643
Jordan Liu857451f2019-05-09 16:35:35 -07008644 if (cardId != null) {
8645 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8646 // if cardId is an EID, it's all digits so this is fine
8647 cardId = IccUtils.stripTrailingFs(cardId);
8648 }
8649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008650 int cardState = 0;
8651 switch (slot.getCardState()) {
8652 case CARDSTATE_ABSENT:
8653 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8654 break;
8655 case CARDSTATE_PRESENT:
8656 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8657 break;
8658 case CARDSTATE_ERROR:
8659 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8660 break;
8661 case CARDSTATE_RESTRICTED:
8662 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8663 break;
8664 default:
8665 break;
8666
8667 }
8668
8669 infos[i] = new UiccSlotInfo(
8670 slot.isActive(),
8671 slot.isEuicc(),
8672 cardId,
8673 cardState,
8674 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008675 slot.isExtendedApduSupported(),
8676 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008677 }
8678 return infos;
8679 } finally {
8680 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008681 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008682 }
8683
8684 @Override
8685 public boolean switchSlots(int[] physicalSlots) {
8686 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008687
8688 final long identity = Binder.clearCallingIdentity();
8689 try {
8690 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8691 } finally {
8692 Binder.restoreCallingIdentity(identity);
8693 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008694 }
Jack Yu4c988042018-02-27 15:30:01 -08008695
8696 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008697 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008698 final long identity = Binder.clearCallingIdentity();
8699 try {
8700 return UiccController.getInstance().getCardIdForDefaultEuicc();
8701 } finally {
8702 Binder.restoreCallingIdentity(identity);
8703 }
8704 }
8705
Pengquan Meng85728fb2018-03-12 16:31:21 -07008706 /**
goneil47ffb6e2018-04-06 15:40:58 -07008707 * A test API to reload the UICC profile.
8708 *
8709 * <p>Requires that the calling app has permission
8710 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8711 * @hide
8712 */
8713 @Override
8714 public void refreshUiccProfile(int subId) {
8715 enforceModifyPermission();
8716
8717 final long identity = Binder.clearCallingIdentity();
8718 try {
8719 Phone phone = getPhone(subId);
8720 if (phone == null) {
8721 return;
8722 }
8723 UiccCard uiccCard = phone.getUiccCard();
8724 if (uiccCard == null) {
8725 return;
8726 }
8727 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8728 if (uiccProfile == null) {
8729 return;
8730 }
8731 uiccProfile.refresh();
8732 } finally {
8733 Binder.restoreCallingIdentity(identity);
8734 }
8735 }
8736
8737 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008738 * Returns false if the mobile data is disabled by default, otherwise return true.
8739 */
8740 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008741 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008742 }
8743
8744 /**
8745 * Returns true if the data roaming is enabled by default, i.e the system property
8746 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8747 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8748 */
8749 private boolean getDefaultDataRoamingEnabled(int subId) {
8750 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008751 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008752 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008753 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8754 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8755 return isDataRoamingEnabled;
8756 }
8757
8758 /**
8759 * Returns the default network type for the given {@code subId}, if the default network type is
8760 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8761 */
8762 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008763 List<Integer> list = TelephonyProperties.default_network();
8764 int phoneId = mSubscriptionController.getPhoneId(subId);
8765 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8766 return list.get(phoneId);
8767 }
8768 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008769 }
fionaxua13278b2018-03-21 00:08:13 -07008770
8771 @Override
8772 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008773 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008775
8776 final long identity = Binder.clearCallingIdentity();
8777 try {
8778 final Phone phone = getPhone(subId);
8779 if (phone == null) {
8780 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8781 return;
8782 }
chen xueaba88a2019-03-15 13:15:10 -07008783 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8784 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008785 if (carrierPrivilegeRules == null) {
8786 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8787 } else {
8788 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008790 } finally {
8791 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008792 }
fionaxua13278b2018-03-21 00:08:13 -07008793 }
8794
8795 @Override
8796 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008797 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008798
8799 final long identity = Binder.clearCallingIdentity();
8800 try {
8801 final Phone phone = getPhone(subId);
8802 if (phone == null) {
8803 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8804 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8805 }
8806 return phone.getCarrierIdListVersion();
8807 } finally {
8808 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008809 }
fionaxua13278b2018-03-21 00:08:13 -07008810 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008811
8812 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008813 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8814 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008816 mApp, subId, callingPackage, callingFeatureId,
8817 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008818 return -1;
8819 }
8820
8821 final long identity = Binder.clearCallingIdentity();
8822 try {
8823 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8824 } finally {
8825 Binder.restoreCallingIdentity(identity);
8826 }
8827 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008828
8829 @Override
8830 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008831 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008832 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008833 mApp, subId, "getCdmaRoamingMode");
8834
8835 final long identity = Binder.clearCallingIdentity();
8836 try {
8837 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8838 } finally {
8839 Binder.restoreCallingIdentity(identity);
8840 }
8841 }
8842
8843 @Override
8844 public boolean setCdmaRoamingMode(int subId, int mode) {
8845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8846 mApp, subId, "setCdmaRoamingMode");
8847
8848 final long identity = Binder.clearCallingIdentity();
8849 try {
8850 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8851 } finally {
8852 Binder.restoreCallingIdentity(identity);
8853 }
8854 }
8855
8856 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008857 public int getCdmaSubscriptionMode(int subId) {
8858 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008859 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008860 mApp, subId, "getCdmaSubscriptionMode");
8861
8862 final long identity = Binder.clearCallingIdentity();
8863 try {
8864 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8865 } finally {
8866 Binder.restoreCallingIdentity(identity);
8867 }
8868 }
8869
8870 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008871 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8873 mApp, subId, "setCdmaSubscriptionMode");
8874
8875 final long identity = Binder.clearCallingIdentity();
8876 try {
8877 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8878 } finally {
8879 Binder.restoreCallingIdentity(identity);
8880 }
8881 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008882
sqianc5eccab2018-10-19 18:46:41 -07008883 @Override
sqian8c685422019-02-22 15:55:18 -08008884 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008885 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008886 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008887 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8888 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008889 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8890 }
8891 final long identity = Binder.clearCallingIdentity();
8892 try {
sqian854d44b2018-12-12 16:48:18 -08008893 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8894 for (Phone phone: PhoneFactory.getPhones()) {
8895 if (phone.getEmergencyNumberTracker() != null
8896 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8897 emergencyNumberListInternal.put(
8898 phone.getSubId(),
8899 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8900 }
sqian11b7a0e2018-12-05 18:48:28 -08008901 }
sqian854d44b2018-12-12 16:48:18 -08008902 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008903 } finally {
8904 Binder.restoreCallingIdentity(identity);
8905 }
sqianc5eccab2018-10-19 18:46:41 -07008906 }
8907
8908 @Override
sqian8c685422019-02-22 15:55:18 -08008909 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008910 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008911 if (!exactMatch) {
8912 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008913 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008914 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008915 }
8916 final long identity = Binder.clearCallingIdentity();
8917 try {
sqian854d44b2018-12-12 16:48:18 -08008918 for (Phone phone: PhoneFactory.getPhones()) {
8919 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008920 && phone.getEmergencyNumberTracker()
8921 .isEmergencyNumber(number, exactMatch)) {
8922 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008923 }
sqian11b7a0e2018-12-05 18:48:28 -08008924 }
8925 return false;
8926 } finally {
8927 Binder.restoreCallingIdentity(identity);
8928 }
8929 }
8930
sqianf4ca7ed2019-01-15 18:32:07 -08008931 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008932 * Start emergency callback mode for GsmCdmaPhone for testing.
8933 */
8934 @Override
8935 public void startEmergencyCallbackMode() {
8936 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8937 "startEmergencyCallbackMode");
8938 enforceModifyPermission();
8939 final long identity = Binder.clearCallingIdentity();
8940 try {
8941 for (Phone phone : PhoneFactory.getPhones()) {
8942 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8943 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8944 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8945 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8946 gsmCdmaPhone.obtainMessage(
8947 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8948 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8949 }
8950 }
8951 } finally {
8952 Binder.restoreCallingIdentity(identity);
8953 }
8954 }
8955
8956 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008957 * Update emergency number list for test mode.
8958 */
8959 @Override
8960 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8961 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8962 "updateEmergencyNumberListTestMode");
8963
8964 final long identity = Binder.clearCallingIdentity();
8965 try {
8966 for (Phone phone: PhoneFactory.getPhones()) {
8967 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8968 if (tracker != null) {
8969 tracker.executeEmergencyNumberTestModeCommand(action, num);
8970 }
8971 }
8972 } finally {
8973 Binder.restoreCallingIdentity(identity);
8974 }
8975 }
8976
8977 /**
8978 * Get the full emergency number list for test mode.
8979 */
8980 @Override
8981 public List<String> getEmergencyNumberListTestMode() {
8982 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8983 "getEmergencyNumberListTestMode");
8984
8985 final long identity = Binder.clearCallingIdentity();
8986 try {
8987 Set<String> emergencyNumbers = new HashSet<>();
8988 for (Phone phone: PhoneFactory.getPhones()) {
8989 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8990 if (tracker != null) {
8991 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8992 emergencyNumbers.add(num.getNumber());
8993 }
8994 }
8995 }
8996 return new ArrayList<>(emergencyNumbers);
8997 } finally {
8998 Binder.restoreCallingIdentity(identity);
8999 }
9000 }
9001
chen xud6b45bd2018-10-30 22:27:10 -07009002 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009003 public int getEmergencyNumberDbVersion(int subId) {
9004 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9005
9006 final long identity = Binder.clearCallingIdentity();
9007 try {
9008 final Phone phone = getPhone(subId);
9009 if (phone == null) {
9010 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9011 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9012 }
9013 return phone.getEmergencyNumberDbVersion();
9014 } finally {
9015 Binder.restoreCallingIdentity(identity);
9016 }
9017 }
9018
9019 @Override
9020 public void notifyOtaEmergencyNumberDbInstalled() {
9021 enforceModifyPermission();
9022
9023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 for (Phone phone: PhoneFactory.getPhones()) {
9026 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9027 if (tracker != null) {
9028 tracker.updateOtaEmergencyNumberDatabase();
9029 }
9030 }
9031 } finally {
9032 Binder.restoreCallingIdentity(identity);
9033 }
9034 }
9035
9036 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009037 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009038 enforceActiveEmergencySessionPermission();
9039
9040 final long identity = Binder.clearCallingIdentity();
9041 try {
9042 for (Phone phone: PhoneFactory.getPhones()) {
9043 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9044 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009045 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9046 }
9047 }
9048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
9051 }
9052
9053 @Override
9054 public void resetOtaEmergencyNumberDbFilePath() {
9055 enforceActiveEmergencySessionPermission();
9056
9057 final long identity = Binder.clearCallingIdentity();
9058 try {
9059 for (Phone phone: PhoneFactory.getPhones()) {
9060 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9061 if (tracker != null) {
9062 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009063 }
9064 }
9065 } finally {
9066 Binder.restoreCallingIdentity(identity);
9067 }
9068 }
9069
9070 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009071 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9072 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9073 Phone phone = getPhone(subId);
9074 if (phone == null) {
9075 return null;
9076 }
9077 final long identity = Binder.clearCallingIdentity();
9078 try {
9079 UiccProfile profile = UiccController.getInstance()
9080 .getUiccProfileForPhone(phone.getPhoneId());
9081 if (profile != null) {
9082 return profile.getCertsFromCarrierPrivilegeAccessRules();
9083 }
9084 } finally {
9085 Binder.restoreCallingIdentity(identity);
9086 }
9087 return null;
9088 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009089
9090 /**
9091 * Enable or disable a modem stack.
9092 */
9093 @Override
9094 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9095 enforceModifyPermission();
9096
9097 final long identity = Binder.clearCallingIdentity();
9098 try {
9099 Phone phone = PhoneFactory.getPhone(slotIndex);
9100 if (phone == null) {
9101 return false;
9102 } else {
9103 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9104 }
9105 } finally {
9106 Binder.restoreCallingIdentity(identity);
9107 }
9108 }
Michelecea4cf22018-12-21 15:00:11 -08009109
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009110 /**
9111 * Whether a modem stack is enabled or not.
9112 */
9113 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009114 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9115 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009116 Phone phone = PhoneFactory.getPhone(slotIndex);
9117 if (phone == null) return false;
9118
9119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009120 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9121 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009122 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9123 }
9124
9125 final long identity = Binder.clearCallingIdentity();
9126 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009127 try {
9128 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9129 } catch (NoSuchElementException ex) {
9130 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9131 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
9136
Michelecea4cf22018-12-21 15:00:11 -08009137 @Override
Michele0ea7d782019-03-19 14:58:42 -07009138 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009139 enforceModifyPermission();
9140
9141 final long identity = Binder.clearCallingIdentity();
9142 try {
9143 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009144 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009145 .commit();
9146 } finally {
9147 Binder.restoreCallingIdentity(identity);
9148 }
9149 }
9150
9151 @Override
Michele0ea7d782019-03-19 14:58:42 -07009152 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009153 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009154 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009155 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9156 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009157 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009158 }
Michelecea4cf22018-12-21 15:00:11 -08009159
9160 final long identity = Binder.clearCallingIdentity();
9161 try {
Michele0ea7d782019-03-19 14:58:42 -07009162 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009163 } finally {
9164 Binder.restoreCallingIdentity(identity);
9165 }
9166 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009167
Michele0ea7d782019-03-19 14:58:42 -07009168 @TelephonyManager.IsMultiSimSupportedResult
9169 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009170 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9171 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9172 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009173 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9174 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009175 }
9176 // Check if the hardware supports multisim functionality. If usage of multisim is not
9177 // supported by the modem, indicate that it is restricted.
9178 PhoneCapability staticCapability =
9179 mPhoneConfigurationManager.getStaticPhoneCapability();
9180 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009181 loge("isMultiSimSupportedInternal: no static configuration available");
9182 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009183 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009184 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009185 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9186 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009187 }
9188 // Check if support of multiple SIMs is restricted by carrier
9189 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009190 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009191 }
9192
Michele0ea7d782019-03-19 14:58:42 -07009193 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009194 }
9195
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009196 /**
9197 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009198 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9199 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9200 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009201 * @param numOfSims number of active sims we want to switch to
9202 */
9203 @Override
9204 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009205 if (numOfSims == 1) {
9206 enforceModifyPermission();
9207 } else {
9208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9209 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9210 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009211 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009212
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009213 try {
Michele30b57b22019-03-01 12:01:14 -08009214 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009215 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009216 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9217 return;
9218 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009219 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9220 } finally {
9221 Binder.restoreCallingIdentity(identity);
9222 }
9223 }
9224
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009225 @Override
9226 public boolean isApplicationOnUicc(int subId, int appType) {
9227 enforceReadPrivilegedPermission("isApplicationOnUicc");
9228 Phone phone = getPhone(subId);
9229 if (phone == null) {
9230 return false;
9231 }
9232 final long identity = Binder.clearCallingIdentity();
9233 try {
9234 UiccCard uiccCard = phone.getUiccCard();
9235 if (uiccCard == null) {
9236 return false;
9237 }
9238 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9239 if (uiccProfile == null) {
9240 return false;
9241 }
9242 if (TelephonyManager.APPTYPE_SIM <= appType
9243 && appType <= TelephonyManager.APPTYPE_ISIM) {
9244 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9245 }
9246 return false;
9247 } finally {
9248 Binder.restoreCallingIdentity(identity);
9249 }
9250 }
9251
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009252 /**
chen xub4baa772019-04-03 10:23:41 -07009253 * Get whether making changes to modem configurations will trigger reboot.
9254 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009255 */
9256 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009257 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9258 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009260 mApp, subId, callingPackage, callingFeatureId,
9261 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009262 return false;
9263 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009264 final long identity = Binder.clearCallingIdentity();
9265 try {
9266 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 }
9271
Nathan Harold29f5f052019-02-15 13:41:57 -08009272 private void updateModemStateMetrics() {
9273 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9274 // TODO: check the state for each modem if the api is ready.
9275 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9276 }
9277
Pengquan Meng3889a572019-01-23 11:16:29 -08009278 @Override
9279 public int[] getSlotsMapping() {
9280 enforceReadPrivilegedPermission("getSlotsMapping");
9281
9282 final long identity = Binder.clearCallingIdentity();
9283 try {
9284 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9285 // All logical slots should have a mapping to a physical slot.
9286 int[] logicalSlotsMapping = new int[phoneCount];
9287 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9288 for (int i = 0; i < slotInfos.length; i++) {
9289 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9290 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9291 }
9292 }
9293 return logicalSlotsMapping;
9294 } finally {
9295 Binder.restoreCallingIdentity(identity);
9296 }
9297 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009298
9299 /**
9300 * Get the IRadio HAL Version
9301 */
9302 @Override
9303 public int getRadioHalVersion() {
9304 Phone phone = getDefaultPhone();
9305 if (phone == null) return -1;
9306 HalVersion hv = phone.getHalVersion();
9307 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9308 return hv.major * 100 + hv.minor;
9309 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009310
9311 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009312 * Get the current calling package name.
9313 * @return the current calling package name
9314 */
9315 @Override
9316 public String getCurrentPackageName() {
9317 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9318 }
9319
9320 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009321 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9322 * corresponding network requests on a subId.
9323 *
9324 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009325 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009326 * 2) APN is un-metered for this subscription, or
9327 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009328 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009329 *
9330 * @return whether data is allowed for a apn type.
9331 *
9332 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009333 */
9334 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009335 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009336 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9337 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009338
9339 // Now that all security checks passes, perform the operation as ourselves.
9340 final long identity = Binder.clearCallingIdentity();
9341 try {
9342 Phone phone = getPhone(subId);
9343 if (phone == null) return false;
9344
Jack Yu41407ee2019-05-13 16:54:09 -07009345 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009346 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9347 } finally {
9348 Binder.restoreCallingIdentity(identity);
9349 }
9350 }
9351
9352 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009353 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009354 enforceReadPrivilegedPermission("isApnMetered");
9355
9356 // Now that all security checks passes, perform the operation as ourselves.
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
9359 Phone phone = getPhone(subId);
9360 if (phone == null) return true; // By default return true.
9361
Jack Yu41407ee2019-05-13 16:54:09 -07009362 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009363 } finally {
9364 Binder.restoreCallingIdentity(identity);
9365 }
9366 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009367
9368 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009369 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9370 int subscriptionId, IBooleanConsumer resultCallback) {
9371 enforceModifyPermission();
9372 long token = Binder.clearCallingIdentity();
9373 try {
9374 Phone phone = getPhone(subscriptionId);
9375 if (phone == null) {
9376 try {
9377 if (resultCallback != null) {
9378 resultCallback.accept(false);
9379 }
9380 } catch (RemoteException e) {
9381 // ignore
9382 }
9383 return;
9384 }
9385 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9386 Pair.create(specifiers, (x) -> {
9387 try {
9388 if (resultCallback != null) {
9389 resultCallback.accept(x);
9390 }
9391 } catch (RemoteException e) {
9392 // ignore
9393 }
9394 });
9395 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9396 } finally {
9397 Binder.restoreCallingIdentity(token);
9398 }
9399 }
9400
9401 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009402 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9403 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009404 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009405 mApp, subId, "getSystemSelectionChannels");
9406 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9407 final long identity = Binder.clearCallingIdentity();
9408 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009409 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9410 if (result instanceof IllegalStateException) {
9411 throw (IllegalStateException) result;
9412 }
9413 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009414 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9415 return specifiers;
9416 } finally {
9417 Binder.restoreCallingIdentity(identity);
9418 }
9419 }
9420
9421 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009422 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009423 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009424 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9425 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9426 if (iccRecords == null) {
9427 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9428 return false;
9429 }
9430 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9431 }
9432
9433 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009434 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9435 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009436 if (callingPackage == null) {
9437 callingPackage = getCurrentPackageName();
9438 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009439 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9440 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009441 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9442 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009443 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9444 }
9445 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9446 Intent intent = new Intent();
9447 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9448 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9449 // Bring up choose default SMS subscription dialog right now
9450 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9451 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9452 mApp.startActivity(intent);
9453 }
chen xud5ca2d52019-05-28 15:20:57 -07009454
9455 @Override
9456 public String getMmsUAProfUrl(int subId) {
9457 //TODO investigate if this API should require proper permission check in R b/133791609
9458 final long identity = Binder.clearCallingIdentity();
9459 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009460 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9461 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9462 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9463 return carrierUAProfUrl;
9464 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009465 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9466 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009467 } finally {
9468 Binder.restoreCallingIdentity(identity);
9469 }
9470 }
9471
9472 @Override
9473 public String getMmsUserAgent(int subId) {
9474 //TODO investigate if this API should require proper permission check in R b/133791609
9475 final long identity = Binder.clearCallingIdentity();
9476 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009477 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9478 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9479 if (!TextUtils.isEmpty(carrierUserAgent)) {
9480 return carrierUserAgent;
9481 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009482 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9483 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009484 } finally {
9485 Binder.restoreCallingIdentity(identity);
9486 }
9487 }
Jack Yub07d4972019-05-28 16:12:25 -07009488
9489 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009490 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9491 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009492
Jack Yub07d4972019-05-28 16:12:25 -07009493 final long identity = Binder.clearCallingIdentity();
9494 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009495 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009496 if (phone == null) return false;
9497
Hall Liua62f5da2020-09-25 10:42:19 -07009498 switch (policy) {
9499 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9500 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9501 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9502 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9503 default:
9504 throw new IllegalArgumentException(policy + " is not a valid policy");
9505 }
Jack Yub07d4972019-05-28 16:12:25 -07009506 } finally {
9507 Binder.restoreCallingIdentity(identity);
9508 }
9509 }
9510
9511 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009512 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009513 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009514 enforceModifyPermission();
9515
changbettyd5c246e2019-12-24 15:40:37 +08009516 final long identity = Binder.clearCallingIdentity();
9517 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009518 Phone phone = getPhone(subscriptionId);
9519 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009520
Hall Liua62f5da2020-09-25 10:42:19 -07009521 switch (policy) {
9522 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9523 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9524 break;
9525 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9526 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9527 break;
9528 default:
9529 throw new IllegalArgumentException(policy + " is not a valid policy");
9530 }
changbettyd5c246e2019-12-24 15:40:37 +08009531 } finally {
9532 Binder.restoreCallingIdentity(identity);
9533 }
9534 }
9535
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009536 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009537 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009538 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9539 * otherwise.
9540 */
9541 @Override
9542 public void setCepEnabled(boolean isCepEnabled) {
9543 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9544
9545 final long identity = Binder.clearCallingIdentity();
9546 try {
9547 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9548 for (Phone phone : PhoneFactory.getPhones()) {
9549 Phone defaultPhone = phone.getImsPhone();
9550 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9551 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9552 ImsPhoneCallTracker imsPhoneCallTracker =
9553 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9554 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9555 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9556 + imsPhone.getMsisdn());
9557 }
9558 }
9559 } finally {
9560 Binder.restoreCallingIdentity(identity);
9561 }
9562 }
allenwtsu46dcc572020-01-08 18:24:03 +08009563
9564 /**
9565 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9566 *
9567 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9568 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9569 * before being read.
9570 */
9571 @Override
9572 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9573 isCompressed) {
9574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9575 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009576 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9577 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9578 }
9579 if (!isImsAvailableOnDevice()) {
9580 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9581 "IMS not available on device.");
9582 }
9583
9584 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009585 try {
Hui Wang761a6682020-10-31 05:12:53 +00009586 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9587 } finally {
9588 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009589 }
9590 }
zoey chene02881a2019-12-30 16:11:23 +08009591
9592 @Override
9593 public boolean isIccLockEnabled(int subId) {
9594 enforceReadPrivilegedPermission("isIccLockEnabled");
9595
9596 // Now that all security checks passes, perform the operation as ourselves.
9597 final long identity = Binder.clearCallingIdentity();
9598 try {
9599 Phone phone = getPhone(subId);
9600 if (phone != null && phone.getIccCard() != null) {
9601 return phone.getIccCard().getIccLockEnabled();
9602 } else {
9603 return false;
9604 }
9605 } finally {
9606 Binder.restoreCallingIdentity(identity);
9607 }
9608 }
9609
9610 /**
9611 * Set the ICC pin lock enabled or disabled.
9612 *
9613 * @return an integer representing the status of IccLock enabled or disabled in the following
9614 * three cases:
9615 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9616 * successfully.
9617 * - Positive number and zero for remaining password attempts.
9618 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9619 *
9620 */
9621 @Override
9622 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9623 enforceModifyPermission();
9624
9625 Phone phone = getPhone(subId);
9626 if (phone == null) {
9627 return 0;
9628 }
9629 // Now that all security checks passes, perform the operation as ourselves.
9630 final long identity = Binder.clearCallingIdentity();
9631 try {
9632 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9633 new Pair<Boolean, String>(enabled, password), phone, null);
9634 return attemptsRemaining;
9635
9636 } catch (Exception e) {
9637 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 return 0;
9642 }
9643
9644 /**
9645 * Change the ICC password used in ICC pin lock.
9646 *
9647 * @return an integer representing the status of IccLock changed in the following three cases:
9648 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9649 * - Positive number and zero for remaining password attempts.
9650 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9651 *
9652 */
9653 @Override
9654 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9655 enforceModifyPermission();
9656
9657 Phone phone = getPhone(subId);
9658 if (phone == null) {
9659 return 0;
9660 }
9661 // Now that all security checks passes, perform the operation as ourselves.
9662 final long identity = Binder.clearCallingIdentity();
9663 try {
9664 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9665 new Pair<String, String>(oldPassword, newPassword), phone, null);
9666 return attemptsRemaining;
9667
9668 } catch (Exception e) {
9669 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9670 } finally {
9671 Binder.restoreCallingIdentity(identity);
9672 }
9673 return 0;
9674 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009675
9676 /**
9677 * Request for receiving user activity notification
9678 */
9679 @Override
9680 public void requestUserActivityNotification() {
9681 if (!mNotifyUserActivity.get()
9682 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9683 mNotifyUserActivity.set(true);
9684 }
9685 }
9686
9687 /**
9688 * Called when userActivity is signalled in the power manager.
9689 * This is safe to call from any thread, with any window manager locks held or not.
9690 */
9691 @Override
9692 public void userActivity() {
9693 // ***************************************
9694 // * Inherited from PhoneWindowManager *
9695 // ***************************************
9696 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9697 // WITH ITS LOCKS HELD.
9698 //
9699 // This code must be VERY careful about the locks
9700 // it acquires.
9701 // In fact, the current code acquires way too many,
9702 // and probably has lurking deadlocks.
9703
9704 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9705 throw new SecurityException("Only the OS may call notifyUserActivity()");
9706 }
9707
9708 if (mNotifyUserActivity.getAndSet(false)) {
9709 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9710 USER_ACTIVITY_NOTIFICATION_DELAY);
9711 }
9712 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009713
9714 @Override
9715 public boolean canConnectTo5GInDsdsMode() {
9716 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9717 }
Jack Yud10cdd42020-09-28 20:28:01 -07009718
9719 @Override
9720 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9721 String callingFeatureId) {
9722 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9723 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9724 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9725 }
9726
9727 Phone phone = getPhone(subId);
9728 if (phone == null) {
9729 throw new RuntimeException("phone is not available");
9730 }
9731 // Now that all security checks passes, perform the operation as ourselves.
9732 final long identity = Binder.clearCallingIdentity();
9733 try {
9734 return phone.getEquivalentHomePlmns();
9735 } finally {
9736 Binder.restoreCallingIdentity(identity);
9737 }
9738 }
Daniel Bright59e67312020-11-13 11:49:37 -08009739
9740 @Override
9741 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009742 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9743 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009744 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009745 if (radioInterfaceCapabilities == null) {
9746 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009747 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009748 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009749 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009750
Hui Wang641e81c2020-10-12 12:14:23 -07009751 @Override
9752 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9753 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009754 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9755 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9756 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9757 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9758 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009759 if (DBG) {
9760 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9761 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9762 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9763 }
9764
9765 if (!SubscriptionManager.isValidSubscriptionId(subId)
9766 || appType < TelephonyManager.APPTYPE_UNKNOWN
9767 || appType > TelephonyManager.APPTYPE_ISIM
9768 || nafUrl == null || securityProtocol == null || callback == null) {
9769 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9770 if (callback != null) {
9771 try {
9772 callback.onAuthenticationFailure(
9773 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9774 } catch (RemoteException exception) {
9775 log("Fail to notify onAuthenticationFailure due to " + exception);
9776 }
9777 return;
9778 }
9779 }
9780
9781 final long token = Binder.clearCallingIdentity();
9782 try {
9783 getGbaManager(subId).bootstrapAuthenticationRequest(
9784 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9785 forceBootStrapping, callback));
9786 } finally {
9787 Binder.restoreCallingIdentity(token);
9788 }
9789 }
9790
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009791 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009792 * Attempts to set the radio power state for all phones for thermal reason.
9793 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009794 * requested radio power state will actually be set. See {@link
9795 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9796 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009797 * @param enable {@code true} if trying to turn radio on.
9798 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9799 * false}.
9800 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009801 private boolean setRadioPowerForThermal(boolean enable) {
9802 boolean isPhoneAvailable = false;
9803 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9804 Phone phone = PhoneFactory.getPhone(i);
9805 if (phone != null) {
9806 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9807 isPhoneAvailable = true;
9808 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009809 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009810
9811 // return true if successfully informed the phone object about the thermal radio power
9812 // request.
9813 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009814 }
9815
9816 private int handleDataThrottlingRequest(int subId,
9817 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009818 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9819 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9820 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9821 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9822 throw new IllegalArgumentException("modem does not support data throttling");
9823 }
9824
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009825 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9826 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009827 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009828 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9829 }
9830
9831 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9832
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009833 if (isDataThrottlingSupported) {
9834 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009835 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009836 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9837 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9838 } else if (thermalMitigationResult
9839 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009840 log("Modem likely does not support data throttling on secondary carrier. Data " +
9841 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9842 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009843 }
9844 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009845 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009846
9847 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009848 }
9849
Jack Nudelman644b91a2021-03-12 14:09:48 -08009850 private static List<String> getThermalMitigationAllowlist(Context context) {
9851 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9852 for (String pckg : context.getResources()
9853 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9854 sThermalMitigationAllowlistedPackages.add(pckg);
9855 }
9856 }
9857
9858 return sThermalMitigationAllowlistedPackages;
9859 }
9860
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009861 private boolean isAnyPhoneInEmergencyState() {
9862 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
9863 if (tm.isInEmergencyCall()) {
9864 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
9865 return true;
9866 }
9867 for (Phone phone : PhoneFactory.getPhones()) {
9868 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
9869 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
9870 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
9871 + phone.isInEcm());
9872 return true;
9873 }
9874 }
9875
9876 return false;
9877 }
9878
Jack Nudelman644b91a2021-03-12 14:09:48 -08009879 /**
9880 * Used by shell commands to add an authorized package name for thermal mitigation.
9881 * @param packageName name of package to be allowlisted
9882 * @param context
9883 */
9884 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9885 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9886 sThermalMitigationAllowlistedPackages.add(packageName);
9887 }
9888
9889 /**
9890 * Used by shell commands to remove an authorized package name for thermal mitigation.
9891 * @param packageName name of package to remove from allowlist
9892 * @param context
9893 */
9894 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9895 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9896 sThermalMitigationAllowlistedPackages.remove(packageName);
9897 }
9898
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009899 /**
9900 * Thermal mitigation request to control functionalities at modem.
9901 *
9902 * @param subId the id of the subscription.
9903 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009904 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009905 *
9906 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9907 */
9908 @Override
9909 @ThermalMitigationResult
9910 public int sendThermalMitigationRequest(
9911 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009912 ThermalMitigationRequest thermalMitigationRequest,
9913 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009914 enforceModifyPermission();
9915
Jack Nudelman644b91a2021-03-12 14:09:48 -08009916 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9917 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9918 .contains(callingPackage)) {
9919 throw new SecurityException("Calling package must be configured in the device config. "
9920 + "calling package: " + callingPackage);
9921 }
9922
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9924 final long identity = Binder.clearCallingIdentity();
9925
9926 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9927 try {
9928 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9929 switch (thermalMitigationAction) {
9930 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9931 thermalMitigationResult =
9932 handleDataThrottlingRequest(subId,
9933 thermalMitigationRequest.getDataThrottlingRequest());
9934 break;
9935 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9936 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9937 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9938 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9939 }
9940
9941 // Ensure that radio is on. If not able to power on due to phone being
9942 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009943 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009944 thermalMitigationResult =
9945 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9946 break;
9947 }
9948
9949 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9950 false);
9951 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9952 break;
9953 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9954 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9955 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9956 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9957 }
9958
9959 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9960 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009961 Phone phone = getPhone(subId);
9962 if (phone == null) {
9963 thermalMitigationResult =
9964 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9965 break;
9966 }
9967
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009968 TelephonyConnectionService service =
9969 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -07009970 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -07009971 Log.e(LOG_TAG, "An emergency call is pending");
9972 thermalMitigationResult =
9973 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9974 break;
9975 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009976 thermalMitigationResult =
9977 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9978 break;
9979 }
9980 } else {
9981 thermalMitigationResult =
9982 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9983 break;
9984 }
9985
9986 // Turn radio off. If not able to power off due to phone being unavailable,
9987 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009988 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009989 thermalMitigationResult =
9990 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9991 break;
9992 }
9993 thermalMitigationResult =
9994 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9995 break;
9996 default:
9997 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9998 + "not exist. Requested action: " + thermalMitigationAction);
9999 }
10000 } catch (IllegalArgumentException e) {
10001 throw e;
10002 } catch (Exception e) {
10003 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10004 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10005 } finally {
10006 Binder.restoreCallingIdentity(identity);
10007 }
10008
10009 if (DBG) {
10010 log("thermalMitigationRequest returning with thermalMitigationResult: "
10011 + thermalMitigationResult);
10012 }
10013
10014 return thermalMitigationResult;
10015 }
Hui Wang641e81c2020-10-12 12:14:23 -070010016
10017 /**
10018 * Set the GbaService Package Name that Telephony will bind to.
10019 *
10020 * @param subId The sim that the GbaService is associated with.
10021 * @param packageName The name of the package to be replaced with.
10022 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10023 */
10024 @Override
10025 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10026 enforceModifyPermission();
10027
10028 final long identity = Binder.clearCallingIdentity();
10029 try {
10030 return getGbaManager(subId).overrideServicePackage(packageName);
10031 } finally {
10032 Binder.restoreCallingIdentity(identity);
10033 }
10034 }
10035
10036 /**
10037 * Return the package name of the currently bound GbaService.
10038 *
10039 * @param subId The sim that the GbaService is associated with.
10040 * @return the package name of the GbaService configuration, null if GBA is not supported.
10041 */
10042 @Override
10043 public String getBoundGbaService(int subId) {
10044 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10045
10046 final long identity = Binder.clearCallingIdentity();
10047 try {
10048 return getGbaManager(subId).getServicePackage();
10049 } finally {
10050 Binder.restoreCallingIdentity(identity);
10051 }
10052 }
10053
10054 /**
10055 * Set the release time for telephony to unbind GbaService.
10056 *
10057 * @param subId The sim that the GbaService is associated with.
10058 * @param interval The release time to unbind GbaService by millisecond.
10059 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10060 */
10061 @Override
10062 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10063 enforceModifyPermission();
10064
10065 final long identity = Binder.clearCallingIdentity();
10066 try {
10067 return getGbaManager(subId).overrideReleaseTime(interval);
10068 } finally {
10069 Binder.restoreCallingIdentity(identity);
10070 }
10071 }
10072
10073 /**
10074 * Return the release time for telephony to unbind GbaService.
10075 *
10076 * @param subId The sim that the GbaService is associated with.
10077 * @return The release time to unbind GbaService by millisecond.
10078 */
10079 @Override
10080 public int getGbaReleaseTime(int subId) {
10081 enforceReadPrivilegedPermission("getGbaReleaseTime");
10082
10083 final long identity = Binder.clearCallingIdentity();
10084 try {
10085 return getGbaManager(subId).getReleaseTime();
10086 } finally {
10087 Binder.restoreCallingIdentity(identity);
10088 }
10089 }
10090
10091 private GbaManager getGbaManager(int subId) {
10092 GbaManager instance = GbaManager.getInstance(subId);
10093 if (instance == null) {
10094 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10095 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10096 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10097 }
10098 return instance;
10099 }
Hui Wang761a6682020-10-31 05:12:53 +000010100
10101 /**
10102 * indicate whether the device and the carrier can support
10103 * RCS VoLTE single registration.
10104 */
10105 @Override
10106 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010107 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10108 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10109 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10110 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010111
10112 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10113 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10114 }
10115
10116 final long identity = Binder.clearCallingIdentity();
10117 try {
10118 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10119 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010120 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10121 if (isCapable != null) {
10122 return isCapable;
10123 }
Hui Wang761a6682020-10-31 05:12:53 +000010124 }
Hui Wang67af90e2021-06-04 16:57:15 -070010125 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10126 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010127 } finally {
10128 Binder.restoreCallingIdentity(identity);
10129 }
10130 }
10131
10132 /**
10133 * Register RCS provisioning callback.
10134 */
10135 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010136 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010137 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010138 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010139 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010140 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10141 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010142
10143 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10144 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10145 }
10146 if (!isImsAvailableOnDevice()) {
10147 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10148 "IMS not available on device.");
10149 }
10150
10151 final long identity = Binder.clearCallingIdentity();
10152 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010153 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010154 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010155 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10156 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010157 }
Hui Wang761a6682020-10-31 05:12:53 +000010158 } finally {
10159 Binder.restoreCallingIdentity(identity);
10160 }
10161 }
10162
10163 /**
10164 * Unregister RCS provisioning callback.
10165 */
10166 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010167 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010168 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010169 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010170 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010171 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10172 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010173
10174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10175 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10176 }
10177 if (!isImsAvailableOnDevice()) {
10178 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10179 "IMS not available on device.");
10180 }
10181
10182 final long identity = Binder.clearCallingIdentity();
10183 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010184 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010185 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010186 } finally {
10187 Binder.restoreCallingIdentity(identity);
10188 }
10189 }
10190
10191 /**
10192 * trigger RCS reconfiguration.
10193 */
10194 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010195 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10196 "triggerRcsReconfiguration",
10197 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010198
10199 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10200 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10201 }
10202 if (!isImsAvailableOnDevice()) {
10203 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10204 "IMS not available on device.");
10205 }
10206
10207 final long identity = Binder.clearCallingIdentity();
10208 try {
10209 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10210 } finally {
10211 Binder.restoreCallingIdentity(identity);
10212 }
10213 }
10214
10215 /**
10216 * Provide the client configuration parameters of the RCS application.
10217 */
10218 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010219 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10220 "setRcsClientConfiguration",
10221 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010222
10223 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10224 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10225 }
10226 if (!isImsAvailableOnDevice()) {
10227 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10228 "IMS not available on device.");
10229 }
10230
10231 final long identity = Binder.clearCallingIdentity();
10232
10233 try {
10234 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10235 if (configBinder == null) {
10236 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010237 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10238 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010239 } else {
10240 configBinder.setRcsClientConfiguration(rcc);
10241 }
10242 } catch (RemoteException e) {
10243 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010244 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10245 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010246 } finally {
10247 Binder.restoreCallingIdentity(identity);
10248 }
10249 }
10250
10251 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010252 * Enables or disables the test mode for RCS VoLTE single registration.
10253 */
10254 @Override
10255 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10256 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10257 "setRcsSingleRegistrationTestModeEnabled");
10258
10259 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10260 }
10261
10262 /**
10263 * Gets the test mode for RCS VoLTE single registration.
10264 */
10265 @Override
10266 public boolean getRcsSingleRegistrationTestModeEnabled() {
10267 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10268 "getRcsSingleRegistrationTestModeEnabled");
10269
10270 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10271 }
10272
10273 /**
Hui Wang761a6682020-10-31 05:12:53 +000010274 * Overrides the config of RCS VoLTE single registration enabled for the device.
10275 */
10276 @Override
10277 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10278 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10279 "setDeviceSingleRegistrationEnabledOverride");
10280 enforceModifyPermission();
10281
10282 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10283 : Boolean.parseBoolean(enabledStr);
10284 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010285 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010286 }
10287
10288 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010289 * Sends a device to device communication message. Only usable via shell.
10290 * @param message message to send.
10291 * @param value message value.
10292 */
10293 @Override
10294 public void sendDeviceToDeviceMessage(int message, int value) {
10295 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010296 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010297 enforceModifyPermission();
10298
10299 final long identity = Binder.clearCallingIdentity();
10300 try {
10301 TelephonyConnectionService service =
10302 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10303 if (service == null) {
10304 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10305 return;
10306 }
10307 service.sendTestDeviceToDeviceMessage(message, value);
10308 } finally {
10309 Binder.restoreCallingIdentity(identity);
10310 }
10311 }
10312
Tyler Gunnbabbda02021-02-10 11:05:02 -080010313 /**
10314 * Sets the specified device to device transport active.
10315 * @param transport The transport to set active.
10316 */
10317 @Override
10318 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10319 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10320 "setActiveDeviceToDeviceTransport");
10321 enforceModifyPermission();
10322
10323 final long identity = Binder.clearCallingIdentity();
10324 try {
10325 TelephonyConnectionService service =
10326 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10327 if (service == null) {
10328 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10329 return;
10330 }
10331 service.setActiveDeviceToDeviceTransport(transport);
10332 } finally {
10333 Binder.restoreCallingIdentity(identity);
10334 }
10335 }
Tyler Gunn92479152021-01-20 16:30:10 -080010336
Tyler Gunnd4575212021-05-03 14:46:49 -070010337 @Override
10338 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10339 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10340 "setDeviceToDeviceForceEnabled");
10341
10342 final long identity = Binder.clearCallingIdentity();
10343 try {
10344 Arrays.stream(PhoneFactory.getPhones()).forEach(
10345 p -> {
10346 Phone thePhone = p.getImsPhone();
10347 if (thePhone != null && thePhone instanceof ImsPhone) {
10348 ImsPhone imsPhone = (ImsPhone) thePhone;
10349 CallTracker tracker = imsPhone.getCallTracker();
10350 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10351 ImsPhoneCallTracker imsPhoneCallTracker =
10352 (ImsPhoneCallTracker) tracker;
10353 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10354 }
10355 }
10356 }
10357 );
10358 } finally {
10359 Binder.restoreCallingIdentity(identity);
10360 }
10361 }
10362
Tyler Gunn92479152021-01-20 16:30:10 -080010363 /**
Hui Wang761a6682020-10-31 05:12:53 +000010364 * Gets the config of RCS VoLTE single registration enabled for the device.
10365 */
10366 @Override
10367 public boolean getDeviceSingleRegistrationEnabled() {
10368 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10369 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10370 }
10371
10372 /**
10373 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10374 */
10375 @Override
10376 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10377 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10378 "setCarrierSingleRegistrationEnabledOverride");
10379 enforceModifyPermission();
10380
10381 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10382 : Boolean.parseBoolean(enabledStr);
10383 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10384 subId, enabled);
10385 }
10386
10387 /**
10388 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10389 */
10390 @Override
10391 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10392 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10393 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10394 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010395
10396 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010397 * Overrides the ims feature validation result
10398 */
10399 @Override
10400 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10401 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10402 "setImsFeatureValidationOverride");
10403
10404 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10405 : Boolean.parseBoolean(enabledStr);
10406 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10407 subId, enabled);
10408 }
10409
10410 /**
10411 * Gets the ims feature validation override value
10412 */
10413 @Override
10414 public boolean getImsFeatureValidationOverride(int subId) {
10415 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10416 "getImsFeatureValidationOverride");
10417 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10418 }
10419
10420 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010421 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10422 * their mobile plan.
10423 */
10424 @Override
10425 public String getMobileProvisioningUrl() {
10426 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10427 final long identity = Binder.clearCallingIdentity();
10428 try {
10429 return getDefaultPhone().getMobileProvisioningUrl();
10430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010434
James.cf Linbcdf8b32021-01-14 16:44:13 +080010435 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010436 * Get the EAB contact from the EAB database.
10437 */
10438 @Override
10439 public String getContactFromEab(String contact) {
10440 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10441 enforceModifyPermission();
10442 final long identity = Binder.clearCallingIdentity();
10443 try {
10444 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10445 } finally {
10446 Binder.restoreCallingIdentity(identity);
10447 }
10448 }
10449
10450 /**
Calvin Pana1434322021-07-01 19:27:01 +080010451 * Get the EAB capability from the EAB database.
10452 */
10453 @Override
10454 public String getCapabilityFromEab(String contact) {
10455 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10456 enforceModifyPermission();
10457 final long identity = Binder.clearCallingIdentity();
10458 try {
10459 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10460 } finally {
10461 Binder.restoreCallingIdentity(identity);
10462 }
10463 }
10464
10465 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010466 * Remove the EAB contacts from the EAB database.
10467 */
10468 @Override
10469 public int removeContactFromEab(int subId, String contacts) {
10470 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10471 enforceModifyPermission();
10472 final long identity = Binder.clearCallingIdentity();
10473 try {
10474 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10475 } finally {
10476 Binder.restoreCallingIdentity(identity);
10477 }
10478 }
10479
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010480 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010481 public boolean getDeviceUceEnabled() {
10482 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10483 final long identity = Binder.clearCallingIdentity();
10484 try {
10485 return mApp.getDeviceUceEnabled();
10486 } finally {
10487 Binder.restoreCallingIdentity(identity);
10488 }
10489 }
10490
10491 @Override
10492 public void setDeviceUceEnabled(boolean isEnabled) {
10493 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10494 final long identity = Binder.clearCallingIdentity();
10495 try {
10496 mApp.setDeviceUceEnabled(isEnabled);
10497 } finally {
10498 Binder.restoreCallingIdentity(identity);
10499 }
10500 }
10501
Brad Ebinger14d467f2021-02-12 06:18:28 +000010502 /**
10503 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10504 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10505 */
10506 // Used for SHELL command only right now.
10507 @Override
10508 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10509 List<String> featureTags) {
10510 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10511 "addUceRegistrationOverrideShell");
10512 final long identity = Binder.clearCallingIdentity();
10513 try {
10514 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10515 new ArraySet<>(featureTags));
10516 } catch (ImsException e) {
10517 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10518 } finally {
10519 Binder.restoreCallingIdentity(identity);
10520 }
10521 }
10522
10523 /**
10524 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10525 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10526 */
10527 // Used for SHELL command only right now.
10528 @Override
10529 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10530 List<String> featureTags) {
10531 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10532 "removeUceRegistrationOverrideShell");
10533 final long identity = Binder.clearCallingIdentity();
10534 try {
10535 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10536 new ArraySet<>(featureTags));
10537 } catch (ImsException e) {
10538 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10539 } finally {
10540 Binder.restoreCallingIdentity(identity);
10541 }
10542 }
10543
10544 /**
10545 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10546 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10547 */
10548 // Used for SHELL command only right now.
10549 @Override
10550 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10552 "clearUceRegistrationOverrideShell");
10553 final long identity = Binder.clearCallingIdentity();
10554 try {
10555 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10556 } catch (ImsException e) {
10557 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10558 } finally {
10559 Binder.restoreCallingIdentity(identity);
10560 }
10561 }
10562
10563 /**
10564 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10565 */
10566 // Used for SHELL command only right now.
10567 @Override
10568 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10569 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10570 "getLatestRcsContactUceCapabilityShell");
10571 final long identity = Binder.clearCallingIdentity();
10572 try {
10573 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10574 } catch (ImsException e) {
10575 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10576 } finally {
10577 Binder.restoreCallingIdentity(identity);
10578 }
10579 }
10580
10581 /**
10582 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10583 * device does not have an active PUBLISH.
10584 */
10585 // Used for SHELL command only right now.
10586 @Override
10587 public String getLastUcePidfXmlShell(int subId) {
10588 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10589 final long identity = Binder.clearCallingIdentity();
10590 try {
10591 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10592 } catch (ImsException e) {
10593 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10594 } finally {
10595 Binder.restoreCallingIdentity(identity);
10596 }
10597 }
10598
James.cf Line8713a42021-04-29 16:04:26 +080010599 /**
10600 * Remove UCE requests cannot be sent to the network status.
10601 */
10602 // Used for SHELL command only right now.
10603 @Override
10604 public boolean removeUceRequestDisallowedStatus(int subId) {
10605 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10606 final long identity = Binder.clearCallingIdentity();
10607 try {
10608 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10609 } catch (ImsException e) {
10610 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10611 } finally {
10612 Binder.restoreCallingIdentity(identity);
10613 }
10614 }
10615
James.cf Lin0fc71b02021-05-25 01:37:38 +080010616 /**
10617 * Remove UCE requests cannot be sent to the network status.
10618 */
10619 // Used for SHELL command only.
10620 @Override
10621 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10623 final long identity = Binder.clearCallingIdentity();
10624 try {
10625 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10626 } catch (ImsException e) {
10627 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10628 } finally {
10629 Binder.restoreCallingIdentity(identity);
10630 }
10631 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010632
James.cf Lin4b784aa2021-01-31 03:25:15 +080010633 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010634 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10635 String callingPackage) {
10636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10637 mApp, subId, "setSignalStrengthUpdateRequest");
10638
10639 final int callingUid = Binder.getCallingUid();
10640 // Verify that tha callingPackage belongs to the calling UID
10641 mApp.getSystemService(AppOpsManager.class)
10642 .checkPackage(callingUid, callingPackage);
10643
10644 validateSignalStrengthUpdateRequest(request, callingUid);
10645
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
10648 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10649 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10650
10651 if (result instanceof IllegalStateException) {
10652 throw (IllegalStateException) result;
10653 }
10654 } finally {
10655 Binder.restoreCallingIdentity(identity);
10656 }
10657 }
10658
10659 @Override
10660 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10661 String callingPackage) {
10662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10663 mApp, subId, "clearSignalStrengthUpdateRequest");
10664
10665 final int callingUid = Binder.getCallingUid();
10666 // Verify that tha callingPackage belongs to the calling UID
10667 mApp.getSystemService(AppOpsManager.class)
10668 .checkPackage(callingUid, callingPackage);
10669
10670 final long identity = Binder.clearCallingIdentity();
10671 try {
10672 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10673 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10674
10675 if (result instanceof IllegalStateException) {
10676 throw (IllegalStateException) result;
10677 }
10678 } finally {
10679 Binder.restoreCallingIdentity(identity);
10680 }
10681 }
10682
10683 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10684 int callingUid) {
10685 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10686 // phone/system process do not have further restriction on request
10687 return;
10688 }
10689
10690 // Applications has restrictions on how to use the request:
10691 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10692 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10693 // This is not system caller which has been checked above
10694 throw new IllegalArgumentException(
10695 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10696 }
10697
10698 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10699 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10700 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10701 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10702 || info.isEnabled()) {
10703 throw new IllegalArgumentException(
10704 "Only system can set hide fields in SignalThresholdInfo");
10705 }
10706
10707 // Thresholds length for each RAN need in range. This has been validated in
10708 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10709 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10710 final int[] thresholds = info.getThresholds();
10711 Objects.requireNonNull(thresholds);
10712 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10713 || thresholds.length
10714 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10715 throw new IllegalArgumentException(
10716 "thresholds length is out of range: " + thresholds.length);
10717 }
10718 }
10719 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010720
10721 /**
10722 * Gets the current phone capability.
10723 *
10724 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10725 * @return the PhoneCapability which describes the data connection capability of modem.
10726 * It's used to evaluate possible phone config change, for example from single
10727 * SIM device to multi-SIM device.
10728 */
10729 @Override
10730 public PhoneCapability getPhoneCapability() {
10731 enforceReadPrivilegedPermission("getPhoneCapability");
10732 final long identity = Binder.clearCallingIdentity();
10733 try {
10734 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10735 } finally {
10736 Binder.restoreCallingIdentity(identity);
10737 }
10738 }
Michele Berionne5e411512020-11-13 02:36:59 +000010739
10740 /**
10741 * Prepare TelephonyManager for an unattended reboot. The reboot is
10742 * required to be done shortly after the API is invoked.
10743 */
10744 @Override
10745 @TelephonyManager.PrepareUnattendedRebootResult
10746 public int prepareForUnattendedReboot() {
10747 enforceRebootPermission();
10748
10749 final long identity = Binder.clearCallingIdentity();
10750 try {
10751 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10752 } finally {
10753 Binder.restoreCallingIdentity(identity);
10754 }
10755 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010756
10757 /**
10758 * Request to get the current slicing configuration including URSP rules and
10759 * NSSAIs (configured, allowed and rejected).
10760 *
10761 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10762 */
10763 @Override
10764 public void getSlicingConfig(ResultReceiver callback) {
10765 enforceReadPrivilegedPermission("getSlicingConfig");
10766
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 Phone phone = getDefaultPhone();
10770 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10771 } finally {
10772 Binder.restoreCallingIdentity(identity);
10773 }
10774 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010775}