blob: 3b4e189503c9a00ad867f9d56ac4835adb1ff392 [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 Gunnd4339262021-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;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700344 private static final int CMD_ENABLE_VONR = 113;
345 private static final int EVENT_ENABLE_VONR_DONE = 114;
346 private static final int CMD_IS_VONR_ENABLED = 115;
347 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800349 // Parameters of select command.
350 private static final int SELECT_COMMAND = 0xA4;
351 private static final int SELECT_P1 = 0x04;
352 private static final int SELECT_P2 = 0;
353 private static final int SELECT_P3 = 0x10;
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 /** The singleton instance. */
356 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800357 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800361 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700362 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700364 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800365 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800366 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700368 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800369 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Peter Wangdafb9ac2020-01-15 14:13:38 -0800371 /** User Activity */
372 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
374
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700375 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
376
Derek Tan97ebb422014-09-05 16:55:38 -0700377 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
378 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800379 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800380 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700381
Michelecea4cf22018-12-21 15:00:11 -0800382 // String to store multi SIM allowed
383 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
384
Derek Tan740e1672017-06-27 14:56:27 -0700385 // The AID of ISD-R.
386 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
387
yinxub1bed742017-04-17 11:45:04 -0700388 private NetworkScanRequestTracker mNetworkScanRequestTracker;
389
David Kelly5e06a7f2018-03-12 14:10:59 +0000390 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
391 private static final int MANUFACTURER_CODE_LENGTH = 8;
392
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800393 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800394 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395
Derek Tan89e89d42014-07-08 17:00:10 -0700396 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700397 * Experiment flag to enable erase modem config on reset network, default value is false
398 */
399 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
400 "reset_network_erase_modem_config_enabled";
401
Rambo Wang0f050d82021-02-12 11:43:36 -0800402 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
403
Naina Nallurid63128d2019-09-17 14:10:30 -0700404 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 * A request object to use for transmitting data to an ICC.
406 */
407 private static final class IccAPDUArgument {
408 public int channel, cla, command, p1, p2, p3;
409 public String data;
410
411 public IccAPDUArgument(int channel, int cla, int command,
412 int p1, int p2, int p3, String data) {
413 this.channel = channel;
414 this.cla = cla;
415 this.command = command;
416 this.p1 = p1;
417 this.p2 = p2;
418 this.p3 = p3;
419 this.data = data;
420 }
421 }
422
423 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700424 * A request object to use for transmitting data to an ICC.
425 */
426 private static final class ManualNetworkSelectionArgument {
427 public OperatorInfo operatorInfo;
428 public boolean persistSelection;
429
430 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
431 this.operatorInfo = operatorInfo;
432 this.persistSelection = persistSelection;
433 }
434 }
435
436 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
438 * request after sending. The main thread will notify the request when it is complete.
439 */
440 private static final class MainThreadRequest {
441 /** The argument to use for the request */
442 public Object argument;
443 /** The result of the request that is run on the main thread */
444 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800445 // The subscriber id that this request applies to. Defaults to
446 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
447 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Nathan Harold92bed182018-10-12 18:16:49 -0700449 // In cases where subId is unavailable, the caller needs to specify the phone.
450 public Phone phone;
451
vagdeviaf9a5b92018-08-15 16:01:53 -0700452 public WorkSource workSource;
453
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 public MainThreadRequest(Object argument) {
455 this.argument = argument;
456 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800457
Nathan Harold92bed182018-10-12 18:16:49 -0700458 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
459 this.argument = argument;
460 if (phone != null) {
461 this.phone = phone;
462 }
463 this.workSource = workSource;
464 }
465
vagdeviaf9a5b92018-08-15 16:01:53 -0700466 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800467 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800468 if (subId != null) {
469 this.subId = subId;
470 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700471 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 }
474
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800475 private static final class IncomingThirdPartyCallArgs {
476 public final ComponentName component;
477 public final String callId;
478 public final String callerDisplayName;
479
480 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
481 String callerDisplayName) {
482 this.component = component;
483 this.callId = callId;
484 this.callerDisplayName = callerDisplayName;
485 }
486 }
487
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 /**
489 * A handler that processes messages on the main thread in the phone process. Since many
490 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
491 * inbound binder threads to the main thread in the phone process. The Binder thread
492 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
493 * on, which will be notified when the operation completes and will contain the result of the
494 * request.
495 *
496 * <p>If a MainThreadRequest object is provided in the msg.obj field,
497 * note that request.result must be set to something non-null for the calling thread to
498 * unblock.
499 */
500 private final class MainThreadHandler extends Handler {
501 @Override
502 public void handleMessage(Message msg) {
503 MainThreadRequest request;
504 Message onCompleted;
505 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800508 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509
510 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 case CMD_HANDLE_USSD_REQUEST: {
512 request = (MainThreadRequest) msg.obj;
513 final Phone phone = getPhoneFromRequest(request);
514 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
515 String ussdRequest = ussdObject.first;
516 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700517
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 if (!isUssdApiAllowed(request.subId)) {
519 // Carrier does not support use of this API, return failure.
520 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
521 UssdResponse response = new UssdResponse(ussdRequest, null);
522 Bundle returnData = new Bundle();
523 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
524 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700525
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 request.result = true;
527 notifyRequester(request);
528 return;
529 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700530
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 try {
532 request.result = phone != null
533 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
534 } catch (CallStateException cse) {
535 request.result = false;
536 }
537 // Wake up the requesting thread
538 notifyRequester(request);
539 break;
pkanwar32d516d2016-10-14 19:37:38 -0700540 }
541
Yorke Lee716f67e2015-06-17 15:39:16 -0700542 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 final Phone phone = getPhoneFromRequest(request);
545 request.result = phone != null ?
546 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
547 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("iccTransmitApduLogicalChannel: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
563 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 iccArgument.channel, iccArgument.cla, iccArgument.command,
566 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 break;
570
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
574 if (ar.exception == null && ar.result != null) {
575 request.result = ar.result;
576 } else {
577 request.result = new IccIoResult(0x6F, 0, (byte[])null);
578 if (ar.result == null) {
579 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800580 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800582 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
584 loge("iccTransmitApduLogicalChannel: Unknown exception");
585 }
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
591 request = (MainThreadRequest) msg.obj;
592 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 if (uiccCard == null) {
595 loge("iccTransmitApduBasicChannel: No UICC");
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 } else {
599 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
600 request);
601 uiccCard.iccTransmitApduBasicChannel(
602 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
603 iccArgument.p3, iccArgument.data, onCompleted);
604 }
605 break;
606
607 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
610 if (ar.exception == null && ar.result != null) {
611 request.result = ar.result;
612 } else {
613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
614 if (ar.result == null) {
615 loge("iccTransmitApduBasicChannel: Empty response");
616 } else if (ar.exception instanceof CommandException) {
617 loge("iccTransmitApduBasicChannel: CommandException: " +
618 ar.exception);
619 } else {
620 loge("iccTransmitApduBasicChannel: Unknown exception");
621 }
622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 break;
625
626 case CMD_EXCHANGE_SIM_IO:
627 request = (MainThreadRequest) msg.obj;
628 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (uiccCard == null) {
631 loge("iccExchangeSimIO: No UICC");
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
636 request);
637 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
638 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
639 iccArgument.data, onCompleted);
640 }
641 break;
642
643 case EVENT_EXCHANGE_SIM_IO_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
648 } else {
649 request.result = new IccIoResult(0x6f, 0, (byte[])null);
650 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 break;
653
Derek Tan4d5e5c12014-02-04 11:54:58 -0800654 case CMD_SEND_ENVELOPE:
655 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800656 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 if (uiccCard == null) {
658 loge("sendEnvelopeWithStatus: No UICC");
659 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 } else {
662 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
663 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
664 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 break;
666
667 case EVENT_SEND_ENVELOPE_DONE:
668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800672 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700673 request.result = new IccIoResult(0x6F, 0, (byte[])null);
674 if (ar.result == null) {
675 loge("sendEnvelopeWithStatus: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("sendEnvelopeWithStatus: CommandException: " +
678 ar.exception);
679 } else {
680 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
681 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 break;
685
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 case CMD_OPEN_CHANNEL:
687 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800688 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800689 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 if (uiccCard == null) {
691 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800692 request.result = new IccOpenLogicalChannelResponse(-1,
693 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800697 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
698 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 break;
701
702 case EVENT_OPEN_CHANNEL_DONE:
703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 int[] result = (int[]) ar.result;
708 int channelId = result[0];
709 byte[] selectResponse = null;
710 if (result.length > 1) {
711 selectResponse = new byte[result.length - 1];
712 for (int i = 1; i < result.length; ++i) {
713 selectResponse[i - 1] = (byte) result[i];
714 }
715 }
716 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 if (ar.result == null) {
720 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 if (ar.exception != null) {
723 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
724 }
725
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700726 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700727 if (ar.exception instanceof CommandException) {
728 CommandException.Error error =
729 ((CommandException) (ar.exception)).getCommandError();
730 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700731 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700732 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700733 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 }
735 }
736 openChannelResp = new IccOpenLogicalChannelResponse(
737 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700739 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 break;
742
743 case CMD_CLOSE_CHANNEL:
744 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800745 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 if (uiccCard == null) {
747 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900748 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
752 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
753 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 break;
755
756 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800757 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
758 break;
759
760 case CMD_NV_READ_ITEM:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
764 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800765 break;
766
767 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 ar = (AsyncResult) msg.obj;
769 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800770 if (ar.exception == null && ar.result != null) {
771 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800773 request.result = "";
774 if (ar.result == null) {
775 loge("nvReadItem: Empty response");
776 } else if (ar.exception instanceof CommandException) {
777 loge("nvReadItem: CommandException: " +
778 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800780 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 }
782 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700783 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
Jake Hambye994d462014-02-03 13:10:13 -0800786 case CMD_NV_WRITE_ITEM:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
789 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700791 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800792 break;
793
794 case EVENT_NV_WRITE_ITEM_DONE:
795 handleNullReturnEvent(msg, "nvWriteItem");
796 break;
797
798 case CMD_NV_WRITE_CDMA_PRL:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800801 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800802 break;
803
804 case EVENT_NV_WRITE_CDMA_PRL_DONE:
805 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
806 break;
807
chen xu6dac5ab2018-10-26 17:39:23 -0700808 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800809 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700810 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800811 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
chen xu6dac5ab2018-10-26 17:39:23 -0700814 case EVENT_RESET_MODEM_CONFIG_DONE:
815 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
Sooraj Sasindran37444802020-08-11 10:40:43 -0700818 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
821 request);
822 Phone phone = getPhoneFromRequest(request);
823 if (phone != null) {
824 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
825 } else {
826 loge("isNRDualConnectivityEnabled: No phone object");
827 request.result = false;
828 notifyRequester(request);
829 }
830 break;
831 }
832
833 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 // request.result must be set to something non-null
840 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700841 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700842 request.result = ar.result;
843 } else {
844 request.result = false;
845 }
846 if (ar.result == null) {
847 loge("isNRDualConnectivityEnabled: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("isNRDualConnectivityEnabled: CommandException: "
850 + ar.exception);
851 } else {
852 loge("isNRDualConnectivityEnabled: Unknown exception");
853 }
854 }
855 notifyRequester(request);
856 break;
857
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700858 case CMD_IS_VONR_ENABLED: {
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
861 request);
862 Phone phone = getPhoneFromRequest(request);
863 if (phone != null) {
864 phone.isVoNrEnabled(onCompleted, request.workSource);
865 } else {
866 loge("isVoNrEnabled: No phone object");
867 request.result = false;
868 notifyRequester(request);
869 }
870 break;
871 }
872
873 case EVENT_IS_VONR_ENABLED_DONE:
874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null && ar.result != null) {
877 request.result = ar.result;
878 } else {
879 // request.result must be set to something non-null
880 // for the calling thread to unblock
881 if (ar.result != null) {
882 request.result = ar.result;
883 } else {
884 request.result = false;
885 }
886 if (ar.result == null) {
887 loge("isVoNrEnabled: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("isVoNrEnabled: CommandException: "
890 + ar.exception);
891 } else {
892 loge("isVoNrEnabled: Unknown exception");
893 }
894 }
895 notifyRequester(request);
896 break;
897
Sooraj Sasindran37444802020-08-11 10:40:43 -0700898 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
901 Phone phone = getPhoneFromRequest(request);
902 if (phone != null) {
903 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
904 request.workSource);
905 } else {
906 loge("enableNrDualConnectivity: No phone object");
907 request.result =
908 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
909 notifyRequester(request);
910 }
911 break;
912 }
913
914 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
917 if (ar.exception == null) {
918 request.result =
919 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
920 } else {
921 request.result =
922 TelephonyManager
923 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
924 if (ar.exception instanceof CommandException) {
925 CommandException.Error error =
926 ((CommandException) (ar.exception)).getCommandError();
927 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
928 request.result =
929 TelephonyManager
930 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000931 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
932 request.result =
933 TelephonyManager
934 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700935 }
936 loge("enableNrDualConnectivity" + ": CommandException: "
937 + ar.exception);
938 } else {
939 loge("enableNrDualConnectivity" + ": Unknown exception");
940 }
941 }
942 notifyRequester(request);
943 break;
944 }
945
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700946 case CMD_ENABLE_VONR: {
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
949 Phone phone = getPhoneFromRequest(request);
950 if (phone != null) {
951 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
952 request.workSource);
953 } else {
954 loge("setVoNrEnabled: No phone object");
955 request.result =
956 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
957 notifyRequester(request);
958 }
959 break;
960 }
961
962 case EVENT_ENABLE_VONR_DONE: {
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null) {
966 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
967 } else {
968 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
969 if (ar.exception instanceof CommandException) {
970 CommandException.Error error =
971 ((CommandException) (ar.exception)).getCommandError();
972 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
973 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
974 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
975 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
976 } else {
977 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
978 }
979 loge("setVoNrEnabled" + ": CommandException: "
980 + ar.exception);
981 } else {
982 loge("setVoNrEnabled" + ": Unknown exception");
983 }
984 }
985 notifyRequester(request);
986 break;
987 }
988
SongFerngWang3ef3e072020-12-21 16:41:52 +0800989 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800990 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800991 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
992 request);
993 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800994 break;
995
SongFerngWang3ef3e072020-12-21 16:41:52 +0800996 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception == null && ar.result != null) {
1000 request.result = ar.result; // Integer
1001 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301002 // request.result must be set to something non-null
1003 // for the calling thread to unblock
1004 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001005 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001006 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001007 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 loge("getAllowedNetworkTypesBitmask: CommandException: "
1009 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001010 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 }
1013 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001014 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 break;
1016
SongFerngWang3ef3e072020-12-21 16:41:52 +08001017 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001019 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1020 request);
1021 Pair<Integer, Long> reasonWithNetworkTypes =
1022 (Pair<Integer, Long>) request.argument;
1023 getPhoneFromRequest(request).setAllowedNetworkTypes(
1024 reasonWithNetworkTypes.first,
1025 reasonWithNetworkTypes.second,
1026 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 break;
1028
SongFerngWang3ef3e072020-12-21 16:41:52 +08001029 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1030 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 break;
1032
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001033 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1034 request = (MainThreadRequest)msg.obj;
1035 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001036 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001037 break;
1038
1039 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1040 ar = (AsyncResult)msg.obj;
1041 request = (MainThreadRequest)ar.userObj;
1042 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001043 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001044 break;
1045
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001046 case CMD_SET_VOICEMAIL_NUMBER:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1049 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001050 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1051 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001052 break;
1053
1054 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1055 handleNullReturnEvent(msg, "setVoicemailNumber");
1056 break;
1057
Stuart Scott54788802015-03-30 13:18:01 -07001058 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1061 request);
1062 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1063 break;
1064
1065 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1066 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1067 break;
1068
Shishir Agrawal302c8692015-06-19 13:49:39 -07001069 case CMD_PERFORM_NETWORK_SCAN:
1070 request = (MainThreadRequest) msg.obj;
1071 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1072 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1073 break;
1074
Hall Liu27d24262020-09-18 19:04:59 -07001075 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001078 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1079 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1080 request.argument;
1081 int callForwardingReason = args.first;
1082 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001083 break;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
1085 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001088 TelephonyManager.CallForwardingInfoCallback callback =
1089 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1090 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001091 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001092 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1094 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1095 // Service Class is a bit mask per 3gpp 27.007. Search for
1096 // any service for voice call.
1097 if ((callForwardInfo.serviceClass
1098 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001099 callForwardingInfo = new CallForwardingInfo(true,
1100 callForwardInfo.reason,
1101 callForwardInfo.number,
1102 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001103 break;
1104 }
1105 }
1106 // Didn't find a call forward info for voice call.
1107 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001108 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1109 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001110 }
Hall Liu27d24262020-09-18 19:04:59 -07001111 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001112 } else {
1113 if (ar.result == null) {
1114 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1115 }
1116 if (ar.exception != null) {
1117 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1118 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001119 int errorCode = TelephonyManager
1120 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001121 if (ar.exception instanceof CommandException) {
1122 CommandException.Error error =
1123 ((CommandException) (ar.exception)).getCommandError();
1124 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001125 errorCode = TelephonyManager
1126 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001128 errorCode = TelephonyManager
1129 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001130 }
1131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
Shuo Qian4a594052020-01-23 11:59:30 -08001134 break;
Hall Liu27d24262020-09-18 19:04:59 -07001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136
Hall Liu27d24262020-09-18 19:04:59 -07001137 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001140 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001141 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001142 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1143 request.argument).first;
1144 request.phone.setCallForwardingOption(
1145 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001146 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001147 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001148 callForwardingInfoToSet.getReason(),
1149 callForwardingInfoToSet.getNumber(),
1150 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1151 break;
Hall Liu27d24262020-09-18 19:04:59 -07001152 }
Shuo Qian4a594052020-01-23 11:59:30 -08001153
Hall Liu27d24262020-09-18 19:04:59 -07001154 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001157 Consumer<Integer> callback =
1158 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1159 request.argument).second;
1160 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001162 int errorCode = TelephonyManager.CallForwardingInfoCallback
1163 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001164 if (ar.exception instanceof CommandException) {
1165 CommandException.Error error =
1166 ((CommandException) (ar.exception)).getCommandError();
1167 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001168 errorCode = TelephonyManager.CallForwardingInfoCallback
1169 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001170 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001171 errorCode = TelephonyManager.CallForwardingInfoCallback
1172 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001173 }
1174 }
1175 callback.accept(errorCode);
1176 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001177 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001178 }
Shuo Qian4a594052020-01-23 11:59:30 -08001179 break;
Hall Liu27d24262020-09-18 19:04:59 -07001180 }
Shuo Qian4a594052020-01-23 11:59:30 -08001181
Hall Liu27d24262020-09-18 19:04:59 -07001182 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001183 request = (MainThreadRequest) msg.obj;
1184 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1185 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1186 break;
Hall Liu27d24262020-09-18 19:04:59 -07001187 }
Shuo Qian4a594052020-01-23 11:59:30 -08001188
Hall Liu27d24262020-09-18 19:04:59 -07001189 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001190 ar = (AsyncResult) msg.obj;
1191 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001192 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001193 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1194 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001195 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 // Service Class is a bit mask per 3gpp 27.007.
1197 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001198 if (callForwardResults.length > 1
1199 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001200 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001201 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001202 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1203 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001205 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 }
1207 } else {
1208 if (ar.result == null) {
1209 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1210 }
1211 if (ar.exception != null) {
1212 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1213 }
1214 if (ar.exception instanceof CommandException) {
1215 CommandException.Error error =
1216 ((CommandException) (ar.exception)).getCommandError();
1217 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1218 callForwardingStatus =
1219 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1220 }
1221 }
1222 }
Hall Liu27d24262020-09-18 19:04:59 -07001223 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001224 break;
Hall Liu27d24262020-09-18 19:04:59 -07001225 }
Shuo Qian4a594052020-01-23 11:59:30 -08001226
Hall Liu27d24262020-09-18 19:04:59 -07001227 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001230 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1231 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001232 break;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234
Hall Liu27d24262020-09-18 19:04:59 -07001235 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001238 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1239 Consumer<Integer> callback =
1240 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1241 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001242 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001243 if (ar.exception instanceof CommandException) {
1244 CommandException.Error error =
1245 ((CommandException) (ar.exception)).getCommandError();
1246 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1247 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1248 } else {
1249 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1250 }
1251 } else {
1252 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1253 }
1254 } else {
1255 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1256 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001260 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
1263 CellNetworkScanResult cellScanResult;
1264 if (ar.exception == null && ar.result != null) {
1265 cellScanResult = new CellNetworkScanResult(
1266 CellNetworkScanResult.STATUS_SUCCESS,
1267 (List<OperatorInfo>) ar.result);
1268 } else {
1269 if (ar.result == null) {
1270 loge("getCellNetworkScanResults: Empty response");
1271 }
1272 if (ar.exception != null) {
1273 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1274 }
1275 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1276 if (ar.exception instanceof CommandException) {
1277 CommandException.Error error =
1278 ((CommandException) (ar.exception)).getCommandError();
1279 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1280 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1281 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1282 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1283 }
1284 }
1285 cellScanResult = new CellNetworkScanResult(errorCode, null);
1286 }
1287 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001288 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001289 break;
1290
1291 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1292 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001293 ManualNetworkSelectionArgument selArg =
1294 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001295 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1296 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001297 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1298 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001299 break;
1300
1301 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null) {
1305 request.result = true;
1306 } else {
1307 request.result = false;
1308 loge("setNetworkSelectionModeManual " + ar.exception);
1309 }
1310 notifyRequester(request);
1311 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001312 break;
1313
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001314 case CMD_GET_MODEM_ACTIVITY_INFO:
1315 request = (MainThreadRequest) msg.obj;
1316 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001317 if (defaultPhone != null) {
1318 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001319 } else {
1320 ResultReceiver result = (ResultReceiver) request.argument;
1321 Bundle bundle = new Bundle();
1322 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001323 new ModemActivityInfo(0, 0, 0,
1324 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001325 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001326 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001327 break;
1328
Hall Liud0f208c2020-10-14 16:54:44 -07001329 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001332 ResultReceiver result = (ResultReceiver) request.argument;
1333
Hall Liud0f208c2020-10-14 16:54:44 -07001334 ModemActivityInfo ret = null;
1335 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001336 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001337 // Update the last modem activity info and the result of the request.
1338 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1339 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001340 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001341 int[] txTimeMs = info.getTransmitTimeMillis();
1342 int[] lastModemTxTimeMs = mLastModemActivityInfo
1343 .getTransmitTimeMillis();
1344 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1345 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1346 }
Hall Liu49656c02020-10-09 19:00:11 -07001347 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001348 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1349 + mLastModemActivityInfo.getSleepTimeMillis());
1350 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1351 + mLastModemActivityInfo.getIdleTimeMillis());
1352 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1353 mLastModemActivityInfo.setReceiveTimeMillis(
1354 info.getReceiveTimeMillis()
1355 + mLastModemActivityInfo.getReceiveTimeMillis());
1356 }
Hall Liu49656c02020-10-09 19:00:11 -07001357 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 mLastModemActivityInfo.getSleepTimeMillis(),
1359 mLastModemActivityInfo.getIdleTimeMillis(),
1360 mLastModemActivityInfo.getTransmitTimeMillis(),
1361 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001362 } else {
1363 if (ar.result == null) {
1364 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001365 error = TelephonyManager.ModemActivityInfoException
1366 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001367 } else if (ar.exception instanceof CommandException) {
1368 loge("queryModemActivityInfo: CommandException: " +
1369 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001370 error = TelephonyManager.ModemActivityInfoException
1371 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001372 } else {
1373 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001374 error = TelephonyManager.ModemActivityInfoException
1375 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001376 }
1377 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001378 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001379 if (ret != null) {
1380 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1381 } else {
1382 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1383 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001384 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001385 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001386 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001387 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388
Meng Wang1a7c35a2016-05-05 20:56:15 -07001389 case CMD_SET_ALLOWED_CARRIERS:
1390 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001391 CarrierRestrictionRules argument =
1392 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001393 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001394 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001395 break;
1396
1397 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 if (ar.exception == null && ar.result != null) {
1401 request.result = ar.result;
1402 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001403 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1404 if (ar.exception instanceof CommandException) {
1405 loge("setAllowedCarriers: CommandException: " + ar.exception);
1406 CommandException.Error error =
1407 ((CommandException) (ar.exception)).getCommandError();
1408 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1409 request.result =
1410 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1411 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001412 } else {
1413 loge("setAllowedCarriers: Unknown exception");
1414 }
1415 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001416 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001417 break;
1418
1419 case CMD_GET_ALLOWED_CARRIERS:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001422 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001423 break;
1424
1425 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 if (ar.exception == null && ar.result != null) {
1429 request.result = ar.result;
1430 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001431 request.result = new IllegalStateException(
1432 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001433 if (ar.result == null) {
1434 loge("getAllowedCarriers: Empty response");
1435 } else if (ar.exception instanceof CommandException) {
1436 loge("getAllowedCarriers: CommandException: " +
1437 ar.exception);
1438 } else {
1439 loge("getAllowedCarriers: Unknown exception");
1440 }
1441 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001442 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001443 break;
1444
Nathan Haroldb3014052017-01-25 15:57:32 -08001445 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 if (ar.exception == null && ar.result != null) {
1449 request.result = ar.result;
1450 } else {
1451 request.result = new IllegalArgumentException(
1452 "Failed to retrieve Forbidden Plmns");
1453 if (ar.result == null) {
1454 loge("getForbiddenPlmns: Empty response");
1455 } else {
1456 loge("getForbiddenPlmns: Unknown exception");
1457 }
1458 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001459 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001460 break;
1461
1462 case CMD_GET_FORBIDDEN_PLMNS:
1463 request = (MainThreadRequest) msg.obj;
1464 uiccCard = getUiccCardFromRequest(request);
1465 if (uiccCard == null) {
1466 loge("getForbiddenPlmns() UiccCard is null");
1467 request.result = new IllegalArgumentException(
1468 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001469 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001470 break;
1471 }
1472 Integer appType = (Integer) request.argument;
1473 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1474 if (uiccApp == null) {
1475 loge("getForbiddenPlmns() no app with specified type -- "
1476 + appType);
1477 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001478 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001479 break;
1480 } else {
1481 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1482 + " specified type -- " + appType);
1483 }
1484 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1485 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1486 onCompleted);
1487 break;
1488
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001489 case CMD_SWITCH_SLOTS:
1490 request = (MainThreadRequest) msg.obj;
1491 int[] physicalSlots = (int[]) request.argument;
1492 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1493 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1494 break;
1495
1496 case EVENT_SWITCH_SLOTS_DONE:
1497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
1499 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 notifyRequester(request);
1501 break;
1502 case CMD_GET_NETWORK_SELECTION_MODE:
1503 request = (MainThreadRequest) msg.obj;
1504 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1505 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1506 break;
1507
1508 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 if (ar.exception != null) {
1512 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1513 } else {
1514 int mode = ((int[]) ar.result)[0];
1515 if (mode == 0) {
1516 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1517 } else {
1518 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1519 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
1522 break;
1523 case CMD_GET_CDMA_ROAMING_MODE:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1526 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1527 break;
1528 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 if (ar.exception != null) {
1532 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1533 } else {
1534 request.result = ((int[]) ar.result)[0];
1535 }
1536 notifyRequester(request);
1537 break;
1538 case CMD_SET_CDMA_ROAMING_MODE:
1539 request = (MainThreadRequest) msg.obj;
1540 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1541 int mode = (int) request.argument;
1542 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1543 break;
1544 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1545 ar = (AsyncResult) msg.obj;
1546 request = (MainThreadRequest) ar.userObj;
1547 request.result = ar.exception == null;
1548 notifyRequester(request);
1549 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001550 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1551 request = (MainThreadRequest) msg.obj;
1552 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1553 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1554 break;
1555 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1556 ar = (AsyncResult) msg.obj;
1557 request = (MainThreadRequest) ar.userObj;
1558 if (ar.exception != null) {
1559 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1560 } else {
1561 request.result = ((int[]) ar.result)[0];
1562 }
1563 notifyRequester(request);
1564 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001565 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1566 request = (MainThreadRequest) msg.obj;
1567 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1568 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001569 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1570 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 break;
1572 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 request.result = ar.exception == null;
1576 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001577 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001578 case CMD_GET_ALL_CELL_INFO:
1579 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001580 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001581 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001583 case EVENT_GET_ALL_CELL_INFO_DONE:
1584 ar = (AsyncResult) msg.obj;
1585 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001586 // If a timeout occurs, the response will be null
1587 request.result = (ar.exception == null && ar.result != null)
1588 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001589 synchronized (request) {
1590 request.notifyAll();
1591 }
1592 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001593 case CMD_REQUEST_CELL_INFO_UPDATE:
1594 request = (MainThreadRequest) msg.obj;
1595 request.phone.requestCellInfoUpdate(request.workSource,
1596 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1597 break;
1598 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1602 try {
1603 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001604 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001605 cb.onError(
1606 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1607 ar.exception.getClass().getName(),
1608 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001609 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001611 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 } else {
1613 // use the result as returned
1614 cb.onCellInfo((List<CellInfo>) ar.result);
1615 }
1616 } catch (RemoteException re) {
1617 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1618 }
1619 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001620 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001621 request = (MainThreadRequest) msg.obj;
1622 WorkSource ws = (WorkSource) request.argument;
1623 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001624 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001625 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001626 }
1627 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001628 ar = (AsyncResult) msg.obj;
1629 request = (MainThreadRequest) ar.userObj;
1630 if (ar.exception == null) {
1631 request.result = ar.result;
1632 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001633 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001634 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001635 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001636 }
1637
1638 synchronized (request) {
1639 request.notifyAll();
1640 }
1641 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001642 }
chen xu6dac5ab2018-10-26 17:39:23 -07001643 case CMD_MODEM_REBOOT:
1644 request = (MainThreadRequest) msg.obj;
1645 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001646 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001647 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001648 case EVENT_CMD_MODEM_REBOOT_DONE:
1649 handleNullReturnEvent(msg, "rebootModem");
1650 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001651 case CMD_REQUEST_ENABLE_MODEM:
1652 request = (MainThreadRequest) msg.obj;
1653 boolean enable = (boolean) request.argument;
1654 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001655 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001656 PhoneConfigurationManager.getInstance()
1657 .enablePhone(request.phone, enable, onCompleted);
1658 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001659 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
1662 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001663 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001664 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001665 if ((boolean) request.result) {
1666 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1667 updateModemStateMetrics();
1668 } else {
1669 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1670 + ar.exception);
1671 }
1672 notifyRequester(request);
1673 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001674 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001675 case CMD_GET_MODEM_STATUS:
1676 request = (MainThreadRequest) msg.obj;
1677 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1678 PhoneConfigurationManager.getInstance()
1679 .getPhoneStatusFromModem(request.phone, onCompleted);
1680 break;
1681 case EVENT_GET_MODEM_STATUS_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 int id = request.phone.getPhoneId();
1685 if (ar.exception == null && ar.result != null) {
1686 request.result = ar.result;
1687 //update the cache as modem status has changed
1688 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1689 (boolean) request.result);
1690 } else {
1691 // Return true if modem status cannot be retrieved. For most cases,
1692 // modem status is on. And for older version modems, GET_MODEM_STATUS
1693 // and disable modem are not supported. Modem is always on.
1694 // TODO: this should be fixed in R to support a third
1695 // status UNKNOWN b/131631629
1696 request.result = true;
1697 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1698 + ar.exception);
1699 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001700 notifyRequester(request);
1701 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001702 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1705 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1706 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1707 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1708 break;
1709 }
1710 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1711 ar = (AsyncResult) msg.obj;
1712 request = (MainThreadRequest) ar.userObj;
1713 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1714 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1715 args.second.accept(ar.exception == null);
1716 notifyRequester(request);
1717 break;
1718 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001719 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1722 Phone phone = getPhoneFromRequest(request);
1723 if (phone != null) {
1724 phone.getSystemSelectionChannels(onCompleted);
1725 } else {
1726 loge("getSystemSelectionChannels: No phone object");
1727 request.result = new ArrayList<RadioAccessSpecifier>();
1728 notifyRequester(request);
1729 }
1730 break;
1731 }
1732 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception == null && ar.result != null) {
1736 request.result = ar.result;
1737 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001738 request.result = new IllegalStateException(
1739 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 if (ar.result == null) {
1741 loge("getSystemSelectionChannels: Empty response");
1742 } else {
1743 loge("getSystemSelectionChannels: Unknown exception");
1744 }
1745 }
1746 notifyRequester(request);
1747 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001748 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
1751 if (ar.exception == null && ar.result != null) {
1752 request.result = ar.result;
1753 } else {
1754 request.result = -1;
1755 loge("Failed to set Forbidden Plmns");
1756 if (ar.result == null) {
1757 loge("setForbidenPlmns: Empty response");
1758 } else if (ar.exception != null) {
1759 loge("setForbiddenPlmns: Exception: " + ar.exception);
1760 request.result = -1;
1761 } else {
1762 loge("setForbiddenPlmns: Unknown exception");
1763 }
1764 }
1765 notifyRequester(request);
1766 break;
1767 case CMD_SET_FORBIDDEN_PLMNS:
1768 request = (MainThreadRequest) msg.obj;
1769 uiccCard = getUiccCardFromRequest(request);
1770 if (uiccCard == null) {
1771 loge("setForbiddenPlmns: UiccCard is null");
1772 request.result = -1;
1773 notifyRequester(request);
1774 break;
1775 }
1776 Pair<Integer, List<String>> setFplmnsArgs =
1777 (Pair<Integer, List<String>>) request.argument;
1778 appType = setFplmnsArgs.first;
1779 List<String> fplmns = setFplmnsArgs.second;
1780 uiccApp = uiccCard.getApplicationByType(appType);
1781 if (uiccApp == null) {
1782 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1783 request.result = -1;
1784 loge("Failed to get UICC App");
1785 notifyRequester(request);
1786 } else {
1787 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1788 ((SIMRecords) uiccApp.getIccRecords())
1789 .setForbiddenPlmns(onCompleted, fplmns);
1790 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001791 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001792 case CMD_ERASE_MODEM_CONFIG:
1793 request = (MainThreadRequest) msg.obj;
1794 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1795 defaultPhone.eraseModemConfig(onCompleted);
1796 break;
1797 case EVENT_ERASE_MODEM_CONFIG_DONE:
1798 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001799 break;
zoey chene02881a2019-12-30 16:11:23 +08001800
Kai Shif70f46f2021-03-03 13:59:46 -08001801 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1802 request = (MainThreadRequest) msg.obj;
1803 request.result = defaultPhone.eraseDataInSharedPreferences();
1804 notifyRequester(request);
1805 break;
1806
zoey chene02881a2019-12-30 16:11:23 +08001807 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1808 request = (MainThreadRequest) msg.obj;
1809 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1810 Pair<String, String> changed = (Pair<String, String>) request.argument;
1811 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1812 changed.first, changed.second, onCompleted);
1813 break;
1814 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 if (ar.exception == null) {
1818 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001819 // If the operation is successful, update the PIN storage
1820 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1821 int phoneId = getPhoneFromRequest(request).getPhoneId();
1822 UiccController.getInstance().getPinStorage()
1823 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001824 } else {
1825 request.result = msg.arg1;
1826 }
1827 notifyRequester(request);
1828 break;
1829
Michele Berionne5e411512020-11-13 02:36:59 +00001830 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1833 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1834 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1835 enabled.first, enabled.second, onCompleted);
1836 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001837 }
zoey chene02881a2019-12-30 16:11:23 +08001838 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 if (ar.exception == null) {
1842 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001843 // If the operation is successful, update the PIN storage
1844 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1845 int phoneId = getPhoneFromRequest(request).getPhoneId();
1846 if (enabled.first) {
1847 UiccController.getInstance().getPinStorage()
1848 .storePin(enabled.second, phoneId);
1849 } else {
1850 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1851 }
zoey chene02881a2019-12-30 16:11:23 +08001852 } else {
1853 request.result = msg.arg1;
1854 }
Michele Berionne5e411512020-11-13 02:36:59 +00001855
1856
zoey chene02881a2019-12-30 16:11:23 +08001857 notifyRequester(request);
1858 break;
1859
Peter Wangdafb9ac2020-01-15 14:13:38 -08001860 case MSG_NOTIFY_USER_ACTIVITY:
1861 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001862 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001863 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1864 getDefaultPhone().getContext().sendBroadcastAsUser(
1865 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1866 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001867
1868 case CMD_SET_DATA_THROTTLING: {
1869 request = (MainThreadRequest) msg.obj;
1870 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1871 DataThrottlingRequest dataThrottlingRequest =
1872 (DataThrottlingRequest) request.argument;
1873 Phone phone = getPhoneFromRequest(request);
1874 if (phone != null) {
1875 phone.setDataThrottling(onCompleted,
1876 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1877 dataThrottlingRequest.getCompletionDurationMillis());
1878 } else {
1879 loge("setDataThrottling: No phone object");
1880 request.result =
1881 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1882 notifyRequester(request);
1883 }
1884
1885 break;
1886 }
1887 case EVENT_SET_DATA_THROTTLING_DONE:
1888 ar = (AsyncResult) msg.obj;
1889 request = (MainThreadRequest) ar.userObj;
1890
1891 if (ar.exception == null) {
1892 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1893 } else if (ar.exception instanceof CommandException) {
1894 loge("setDataThrottling: CommandException: " + ar.exception);
1895 CommandException.Error error =
1896 ((CommandException) (ar.exception)).getCommandError();
1897
1898 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1899 request.result = TelephonyManager
1900 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1901 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1902 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001903 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1904 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001905 } else {
1906 request.result =
1907 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1908 }
1909 } else {
1910 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1911 }
1912 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1913 notifyRequester(request);
1914 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001915
1916 case CMD_SET_SIM_POWER: {
1917 request = (MainThreadRequest) msg.obj;
1918 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1919 request = (MainThreadRequest) msg.obj;
1920 int stateToSet =
1921 ((Pair<Integer, IIntegerConsumer>)
1922 request.argument).first;
1923 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1924 break;
1925 }
1926 case EVENT_SET_SIM_POWER_DONE: {
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 IIntegerConsumer callback =
1930 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1931 if (ar.exception != null) {
1932 loge("setSimPower exception: " + ar.exception);
1933 int errorCode = TelephonyManager.CallForwardingInfoCallback
1934 .RESULT_ERROR_UNKNOWN;
1935 if (ar.exception instanceof CommandException) {
1936 CommandException.Error error =
1937 ((CommandException) (ar.exception)).getCommandError();
1938 if (error == CommandException.Error.SIM_ERR) {
1939 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1940 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1941 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1942 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1943 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1944 } else {
1945 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1946 }
1947 }
1948 try {
1949 callback.accept(errorCode);
1950 } catch (RemoteException e) {
1951 // Ignore if the remote process is no longer available to call back.
1952 Log.w(LOG_TAG, "setSimPower: callback not available.");
1953 }
1954 } else {
1955 try {
1956 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1957 } catch (RemoteException e) {
1958 // Ignore if the remote process is no longer available to call back.
1959 Log.w(LOG_TAG, "setSimPower: callback not available.");
1960 }
1961 }
1962 break;
1963 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001964 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1965 request = (MainThreadRequest) msg.obj;
1966
1967 final Phone phone = getPhoneFromRequest(request);
1968 if (phone == null || phone.getServiceStateTracker() == null) {
1969 request.result = new IllegalStateException("Phone or SST is null");
1970 notifyRequester(request);
1971 break;
1972 }
1973
1974 Pair<Integer, SignalStrengthUpdateRequest> pair =
1975 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1976 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1977 request);
1978 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1979 request.subId, pair.first /*callingUid*/,
1980 pair.second /*request*/, onCompleted);
1981 break;
1982 }
1983 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1984 ar = (AsyncResult) msg.obj;
1985 request = (MainThreadRequest) ar.userObj;
1986 // request.result will be the exception of ar if present, true otherwise.
1987 // Be cautious not to leave result null which will wait() forever
1988 request.result = ar.exception != null ? ar.exception : true;
1989 notifyRequester(request);
1990 break;
1991 }
1992 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1993 request = (MainThreadRequest) msg.obj;
1994
1995 Phone phone = getPhoneFromRequest(request);
1996 if (phone == null || phone.getServiceStateTracker() == null) {
1997 request.result = new IllegalStateException("Phone or SST is null");
1998 notifyRequester(request);
1999 break;
2000 }
2001
2002 Pair<Integer, SignalStrengthUpdateRequest> pair =
2003 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2004 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2005 request);
2006 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
2007 request.subId, pair.first /*callingUid*/,
2008 pair.second /*request*/, onCompleted);
2009 break;
2010 }
2011 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2012 ar = (AsyncResult) msg.obj;
2013 request = (MainThreadRequest) ar.userObj;
2014 request.result = ar.exception != null ? ar.exception : true;
2015 notifyRequester(request);
2016 break;
2017 }
Jordan Liu109698e2020-11-24 14:50:34 -08002018
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002019 case CMD_GET_SLICING_CONFIG: {
2020 request = (MainThreadRequest) msg.obj;
2021 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2022 request.phone.getSlicingConfig(onCompleted);
2023 break;
2024 }
2025 case EVENT_GET_SLICING_CONFIG_DONE: {
2026 ar = (AsyncResult) msg.obj;
2027 request = (MainThreadRequest) ar.userObj;
2028 ResultReceiver result = (ResultReceiver) request.argument;
2029
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002030 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002031 Bundle bundle = new Bundle();
2032 int resultCode = 0;
2033 if (ar.exception != null) {
2034 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2035 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002036 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002037 } else if (ar.result == null) {
2038 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002039 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 } else {
2041 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002042 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2043 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002044 }
2045
2046 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002047 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002048 }
2049 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2050 result.send(resultCode, bundle);
2051 notifyRequester(request);
2052 break;
2053 }
2054
Michele Berionne5e411512020-11-13 02:36:59 +00002055 case CMD_PREPARE_UNATTENDED_REBOOT:
2056 request = (MainThreadRequest) msg.obj;
2057 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002058 UiccController.getInstance().getPinStorage()
2059 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002060 notifyRequester(request);
2061 break;
2062
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 default:
2064 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2065 break;
2066 }
2067 }
Jake Hambye994d462014-02-03 13:10:13 -08002068
Pengquan Menga1bb6272018-09-06 09:59:22 -07002069 private void notifyRequester(MainThreadRequest request) {
2070 synchronized (request) {
2071 request.notifyAll();
2072 }
2073 }
2074
Jake Hambye994d462014-02-03 13:10:13 -08002075 private void handleNullReturnEvent(Message msg, String command) {
2076 AsyncResult ar = (AsyncResult) msg.obj;
2077 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2078 if (ar.exception == null) {
2079 request.result = true;
2080 } else {
2081 request.result = false;
2082 if (ar.exception instanceof CommandException) {
2083 loge(command + ": CommandException: " + ar.exception);
2084 } else {
2085 loge(command + ": Unknown exception");
2086 }
2087 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002088 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 }
2091
2092 /**
2093 * Posts the specified command to be executed on the main thread,
2094 * waits for the request to complete, and returns the result.
2095 * @see #sendRequestAsync
2096 */
2097 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002098 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2099 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002100 }
2101
2102 /**
2103 * Posts the specified command to be executed on the main thread,
2104 * waits for the request to complete, and returns the result.
2105 * @see #sendRequestAsync
2106 */
2107 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2108 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002109 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002110 }
2111
2112 /**
2113 * Posts the specified command to be executed on the main thread,
2114 * waits for the request to complete, and returns the result.
2115 * @see #sendRequestAsync
2116 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002117 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002118 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2119 }
2120
2121 /**
2122 * Posts the specified command to be executed on the main thread,
2123 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2124 * if not timeout or null otherwise.
2125 * @see #sendRequestAsync
2126 */
2127 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2128 long timeoutInMs) {
2129 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002130 }
2131
2132 /**
2133 * Posts the specified command to be executed on the main thread,
2134 * waits for the request to complete, and returns the result.
2135 * @see #sendRequestAsync
2136 */
Nathan Harold92bed182018-10-12 18:16:49 -07002137 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002138 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002139 }
2140
2141 /**
2142 * Posts the specified command to be executed on the main thread,
2143 * waits for the request to complete, and returns the result.
2144 * @see #sendRequestAsync
2145 */
2146 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002147 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2148 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002149 }
2150
2151 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002152 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2153 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2154 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002155 * @see #sendRequestAsync
2156 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002157 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2158 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2160 throw new RuntimeException("This method will deadlock if called from the main thread.");
2161 }
2162
Nathan Harold92bed182018-10-12 18:16:49 -07002163 MainThreadRequest request = null;
2164 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2165 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2166 } else if (phone != null) {
2167 request = new MainThreadRequest(argument, phone, workSource);
2168 } else {
2169 request = new MainThreadRequest(argument, subId, workSource);
2170 }
2171
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 Message msg = mMainThreadHandler.obtainMessage(command, request);
2173 msg.sendToTarget();
2174
Rambo Wang0f050d82021-02-12 11:43:36 -08002175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002177 if (timeoutInMs >= 0) {
2178 // Wait for at least timeoutInMs before returning null request result
2179 long now = SystemClock.elapsedRealtime();
2180 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002181 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002182 try {
2183 request.wait(deadline - now);
2184 } catch (InterruptedException e) {
2185 // Do nothing, go back and check if request is completed or timeout
2186 } finally {
2187 now = SystemClock.elapsedRealtime();
2188 }
2189 }
2190 } else {
2191 // Wait for the request to complete
2192 while (request.result == null) {
2193 try {
2194 request.wait();
2195 } catch (InterruptedException e) {
2196 // Do nothing, go back and wait until the request is complete
2197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 }
2199 }
2200 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002201 if (request.result == null) {
2202 Log.wtf(LOG_TAG,
2203 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 return request.result;
2206 }
2207
2208 /**
2209 * Asynchronous ("fire and forget") version of sendRequest():
2210 * Posts the specified command to be executed on the main thread, and
2211 * returns immediately.
2212 * @see #sendRequest
2213 */
2214 private void sendRequestAsync(int command) {
2215 mMainThreadHandler.sendEmptyMessage(command);
2216 }
2217
2218 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002219 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002220 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002221 */
2222 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002223 sendRequestAsync(command, argument, null, null);
2224 }
2225
2226 /**
2227 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2228 * @see {@link #sendRequest(int,Object)}
2229 */
2230 private void sendRequestAsync(
2231 int command, Object argument, Phone phone, WorkSource workSource) {
2232 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002233 Message msg = mMainThreadHandler.obtainMessage(command, request);
2234 msg.sendToTarget();
2235 }
2236
2237 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 * Initialize the singleton PhoneInterfaceManager instance.
2239 * This is only done once, at startup, from PhoneApp.onCreate().
2240 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002241 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 synchronized (PhoneInterfaceManager.class) {
2243 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002244 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 } else {
2246 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2247 }
2248 return sInstance;
2249 }
2250 }
2251
2252 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002253 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002256 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002257 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002259 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002261 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002262 mTelephonySharedPreferences =
2263 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002264 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002265 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002266 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002267 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002268
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 publish();
2270 }
2271
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002272 private Phone getDefaultPhone() {
2273 Phone thePhone = getPhone(getDefaultSubscription());
2274 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2275 }
2276
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 private void publish() {
2278 if (DBG) log("publish: " + this);
2279
Peter Wangc035ce42020-01-08 21:00:22 -08002280 TelephonyFrameworkInitializer
2281 .getTelephonyServiceManager()
2282 .getTelephonyServiceRegisterer()
2283 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 }
2285
Stuart Scott584921c2015-01-15 17:10:34 -08002286 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002287 if (request.phone != null) {
2288 return request.phone;
2289 } else {
2290 return getPhoneFromSubId(request.subId);
2291 }
2292 }
2293
2294 private Phone getPhoneFromSubId(int subId) {
2295 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2296 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002297 }
2298
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002299 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2300 Phone phone = getPhoneFromRequest(request);
2301 return phone == null ? null :
2302 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2303 }
2304
Wink Saville36469e72014-06-11 15:17:00 -07002305 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002306 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002307 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309
Kai Shif70f46f2021-03-03 13:59:46 -08002310 private void sendEraseModemConfig(@NonNull Phone phone) {
2311 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2312 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2313 }
2314
2315 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2316 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2317 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002318 }
2319
Peter Wang44b186e2020-01-13 23:33:09 -08002320 private boolean isImsAvailableOnDevice() {
2321 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2322 if (pm == null) {
2323 // For some reason package manger is not available.. This will fail internally anyway,
2324 // so do not throw error and allow.
2325 return true;
2326 }
2327 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2328 }
2329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002331 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002332 }
2333
Wink Savilleb564aae2014-10-23 10:18:09 -07002334 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 if (DBG) log("dial: " + number);
2336 // No permission check needed here: This is just a wrapper around the
2337 // ACTION_DIAL intent, which is available to any app since it puts up
2338 // the UI before it does anything.
2339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340 final long identity = Binder.clearCallingIdentity();
2341 try {
2342 String url = createTelUrl(number);
2343 if (url == null) {
2344 return;
2345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347 // PENDING: should we just silently fail if phone is offhook or ringing?
2348 PhoneConstants.State state = mCM.getState(subId);
2349 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2350 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2351 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2352 mApp.startActivity(intent);
2353 }
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 }
2357 }
2358
2359 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002360 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002361 }
2362
Wink Savilleb564aae2014-10-23 10:18:09 -07002363 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 if (DBG) log("call: " + number);
2365
2366 // This is just a wrapper around the ACTION_CALL intent, but we still
2367 // need to do a permission check since we're calling startActivity()
2368 // from the context of the phone app.
2369 enforceCallPermission();
2370
Jordan Liu1617b712019-07-10 15:06:26 -07002371 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 != AppOpsManager.MODE_ALLOWED) {
2373 return;
2374 }
2375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 String url = createTelUrl(number);
2379 if (url == null) {
2380 return;
2381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002383 boolean isValid = false;
2384 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2385 if (slist != null) {
2386 for (SubscriptionInfo subInfoRecord : slist) {
2387 if (subInfoRecord.getSubscriptionId() == subId) {
2388 isValid = true;
2389 break;
2390 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002391 }
Wink Saville08874612014-08-31 19:19:58 -07002392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393 if (!isValid) {
2394 return;
2395 }
Wink Saville08874612014-08-31 19:19:58 -07002396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2398 intent.putExtra(SUBSCRIPTION_KEY, subId);
2399 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2400 mApp.startActivity(intent);
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 }
2405
Wink Savilleb564aae2014-10-23 10:18:09 -07002406 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002407 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002408 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2409 }
2410
Wink Savilleb564aae2014-10-23 10:18:09 -07002411 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002412 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002413 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2414 }
2415
Wink Savilleb564aae2014-10-23 10:18:09 -07002416 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418
2419 final long identity = Binder.clearCallingIdentity();
2420 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002421 Phone phone = getPhone(subId);
2422 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423 checkSimPin.start();
2424 return checkSimPin.unlockSim(null, pin);
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
2427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
Wink Savilleb564aae2014-10-23 10:18:09 -07002430 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002435 Phone phone = getPhone(subId);
2436 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437 checkSimPuk.start();
2438 return checkSimPuk.unlockSim(puk, pin);
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
2441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 }
2443
2444 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002445 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 * a synchronous one.
2447 */
2448 private static class UnlockSim extends Thread {
2449
2450 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002451 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452
2453 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002454 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2455 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456
2457 // For replies from SimCard interface
2458 private Handler mHandler;
2459
2460 // For async handler to identify request type
2461 private static final int SUPPLY_PIN_COMPLETE = 100;
2462
Michele Berionne5e411512020-11-13 02:36:59 +00002463 UnlockSim(int phoneId, IccCard simCard) {
2464 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 mSimCard = simCard;
2466 }
2467
2468 @Override
2469 public void run() {
2470 Looper.prepare();
2471 synchronized (UnlockSim.this) {
2472 mHandler = new Handler() {
2473 @Override
2474 public void handleMessage(Message msg) {
2475 AsyncResult ar = (AsyncResult) msg.obj;
2476 switch (msg.what) {
2477 case SUPPLY_PIN_COMPLETE:
2478 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2479 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002480 mRetryCount = msg.arg1;
2481 if (ar.exception != null) {
2482 if (ar.exception instanceof CommandException &&
2483 ((CommandException)(ar.exception)).getCommandError()
2484 == CommandException.Error.PASSWORD_INCORRECT) {
2485 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002486 } //When UiccCardApp dispose,handle message and return exception
2487 else if (ar.exception instanceof CommandException &&
2488 ((CommandException) (ar.exception)).getCommandError()
2489 == CommandException.Error.ABORTED) {
2490 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002491 } else {
2492 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2493 }
2494 } else {
2495 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 mDone = true;
2498 UnlockSim.this.notifyAll();
2499 }
2500 break;
2501 }
2502 }
2503 };
2504 UnlockSim.this.notifyAll();
2505 }
2506 Looper.loop();
2507 }
2508
2509 /*
2510 * Use PIN or PUK to unlock SIM card
2511 *
2512 * If PUK is null, unlock SIM card with PIN
2513 *
2514 * If PUK is not null, unlock SIM card with PUK and set PIN code
2515 */
Wink Saville9de0f752013-10-22 19:04:03 -07002516 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517
2518 while (mHandler == null) {
2519 try {
2520 wait();
2521 } catch (InterruptedException e) {
2522 Thread.currentThread().interrupt();
2523 }
2524 }
2525 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2526
2527 if (puk == null) {
2528 mSimCard.supplyPin(pin, callback);
2529 } else {
2530 mSimCard.supplyPuk(puk, pin, callback);
2531 }
2532
2533 while (!mDone) {
2534 try {
2535 Log.d(LOG_TAG, "wait for done");
2536 wait();
2537 } catch (InterruptedException e) {
2538 // Restore the interrupted status
2539 Thread.currentThread().interrupt();
2540 }
2541 }
2542 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002543 int[] resultArray = new int[2];
2544 resultArray[0] = mResult;
2545 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002546
2547 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2548 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2549 }
2550
Wink Saville9de0f752013-10-22 19:04:03 -07002551 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 }
2553 }
2554
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002555 /**
2556 * This method has been removed due to privacy and stability concerns.
2557 */
2558 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002559 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002560 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2561 return;
Wink Saville36469e72014-06-11 15:17:00 -07002562 }
2563
Nathan Harold1f889d82020-06-04 17:05:26 -07002564 @Override
2565 public void updateServiceLocationWithPackageName(String callingPackage) {
2566 mApp.getSystemService(AppOpsManager.class)
2567 .checkPackage(Binder.getCallingUid(), callingPackage);
2568
Nathan Haroldf096d982020-11-18 17:18:06 -08002569 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002570 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2571 // Callers targeting S have no business invoking this method.
2572 return;
2573 }
2574
2575 LocationAccessPolicy.LocationPermissionResult locationResult =
2576 LocationAccessPolicy.checkLocationPermission(mApp,
2577 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2578 .setCallingPackage(callingPackage)
2579 .setCallingFeatureId(null)
2580 .setCallingPid(Binder.getCallingPid())
2581 .setCallingUid(Binder.getCallingUid())
2582 .setMethod("updateServiceLocation")
2583 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2584 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2585 .build());
2586 // Apps that lack location permission have no business calling this method;
2587 // however, because no permission was declared in the public API, denials must
2588 // all be "soft".
2589 switch (locationResult) {
2590 case DENIED_HARD: /* fall through */
2591 case DENIED_SOFT:
2592 return;
2593 }
2594
2595 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 final long identity = Binder.clearCallingIdentity();
2597 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002598 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002600 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 }
2606
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002607 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002608 @Override
2609 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002610 return isRadioOnWithFeature(callingPackage, null);
2611 }
2612
2613
2614 @Override
2615 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2616 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2617 callingFeatureId);
2618 }
2619
2620 @Deprecated
2621 @Override
2622 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2623 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002624 }
2625
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002626 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002627 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2628 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 return false;
2632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633
2634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 return isRadioOnForSubscriber(subId);
2637 } finally {
2638 Binder.restoreCallingIdentity(identity);
2639 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002640 }
2641
2642 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 final Phone phone = getPhone(subId);
2646 if (phone != null) {
2647 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2648 } else {
2649 return false;
2650 }
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
2656 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002657 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
Wink Saville36469e72014-06-11 15:17:00 -07002659
Wink Savilleb564aae2014-10-23 10:18:09 -07002660 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662
2663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
2667 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002671 }
Wink Saville36469e72014-06-11 15:17:00 -07002672 }
2673
2674 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002675 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002676 }
2677
Wink Savilleb564aae2014-10-23 10:18:09 -07002678 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002679 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 final Phone phone = getPhone(subId);
2684 if (phone == null) {
2685 return false;
2686 }
2687 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2688 toggleRadioOnOffForSubscriber(subId);
2689 }
2690 return true;
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
Wink Saville36469e72014-06-11 15:17:00 -07002695
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002696 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002697 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002698 /*
2699 * If any of the Radios are available, it will need to be
2700 * shutdown. So return true if any Radio is available.
2701 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2705 Phone phone = PhoneFactory.getPhone(i);
2706 if (phone != null && phone.isRadioAvailable()) return true;
2707 }
2708 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2709 return false;
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002712 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002713 }
2714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 enforceModifyPermission();
2718
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2722 logv("Shutting down Phone " + i);
2723 shutdownRadioUsingPhoneId(i);
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002727 }
2728 }
2729
2730 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002731 Phone phone = PhoneFactory.getPhone(phoneId);
2732 if (phone != null && phone.isRadioAvailable()) {
2733 phone.shutdownRadio();
2734 }
2735 }
2736
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002738 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739
2740 final long identity = Binder.clearCallingIdentity();
2741 try {
2742 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2743 if (defaultPhone != null) {
2744 defaultPhone.setRadioPower(turnOn);
2745 return true;
2746 } else {
2747 loge("There's no default phone.");
2748 return false;
2749 }
2750 } finally {
2751 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002752 }
Wink Saville36469e72014-06-11 15:17:00 -07002753 }
2754
Wink Savilleb564aae2014-10-23 10:18:09 -07002755 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757
2758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 final Phone phone = getPhone(subId);
2761 if (phone != null) {
2762 phone.setRadioPower(turnOn);
2763 return true;
2764 } else {
2765 return false;
2766 }
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
Wink Saville36469e72014-06-11 15:17:00 -07002772 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 public boolean enableDataConnectivity() {
2775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776
2777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 int subId = mSubscriptionController.getDefaultDataSubId();
2780 final Phone phone = getPhone(subId);
2781 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002782 phone.getDataEnabledSettings().setDataEnabled(
2783 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784 return true;
2785 } else {
2786 return false;
2787 }
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002791 }
2792
Wink Saville36469e72014-06-11 15:17:00 -07002793 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 public boolean disableDataConnectivity() {
2796 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797
2798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 int subId = mSubscriptionController.getDefaultDataSubId();
2801 final Phone phone = getPhone(subId);
2802 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002803 phone.getDataEnabledSettings().setDataEnabled(
2804 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 return true;
2806 } else {
2807 return false;
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 }
2813
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002815 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone phone = getPhone(subId);
2819 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002820 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821 } else {
2822 return false;
2823 }
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 }
2828
2829 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002830 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002831 }
2832
pkanwarae03a6b2016-11-06 20:37:09 -08002833 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 enforceCallPermission();
2835
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2839 return;
2840 }
2841 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2842 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
pkanwar32d516d2016-10-14 19:37:38 -07002846 };
2847
Wink Savilleb564aae2014-10-23 10:18:09 -07002848 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2854 return false;
2855 }
2856 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002862 /**
2863 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2864 * tag on getCallState Binder call.
2865 */
2866 @Deprecated
2867 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002869 if (CompatChanges.isChangeEnabled(
2870 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2871 Binder.getCallingUid())) {
2872 // Do not allow this API to be called on API version 31+, it should only be
2873 // called on old apps using this Binder call directly.
2874 throw new SecurityException("This method can only be used for applications "
2875 + "targeting API version 30 or less.");
2876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877 final long identity = Binder.clearCallingIdentity();
2878 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002879 Phone phone = getPhone(getDefaultSubscription());
2880 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2881 PhoneConstantConversions.convertCallState(phone.getState());
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
2885 }
2886
2887 @Override
2888 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2889 if (CompatChanges.isChangeEnabled(
2890 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2891 Binder.getCallingUid())) {
2892 // Check READ_PHONE_STATE for API version 31+
2893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2894 featureId, "getCallStateForSubscription")) {
2895 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2896 + "targeting API level 31+.");
2897 }
2898 }
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2903 PhoneConstantConversions.convertCallState(phone.getState());
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002907 }
2908
Sanket Padawe356d7632015-06-22 14:03:32 -07002909 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002910 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002911 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2912 }
2913
2914 @Override
2915 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 final long identity = Binder.clearCallingIdentity();
2917 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002918 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 if (phone != null) {
2920 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2921 } else {
2922 return PhoneConstantConversions.convertDataState(
2923 PhoneConstants.DataState.DISCONNECTED);
2924 }
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 }
2929
Sanket Padawe356d7632015-06-22 14:03:32 -07002930 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002931 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002932 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2933 }
2934
2935 @Override
2936 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002939 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 if (phone != null) {
2941 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2942 } else {
2943 return TelephonyManager.DATA_ACTIVITY_NONE;
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
2950 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002951 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002952 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002953 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002954
2955 LocationAccessPolicy.LocationPermissionResult locationResult =
2956 LocationAccessPolicy.checkLocationPermission(mApp,
2957 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2958 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002959 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002960 .setCallingPid(Binder.getCallingPid())
2961 .setCallingUid(Binder.getCallingUid())
2962 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002963 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002964 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2965 .build());
2966 switch (locationResult) {
2967 case DENIED_HARD:
2968 throw new SecurityException("Not allowed to access cell location");
2969 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002970 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2971 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002972 }
2973
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002978 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002979 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
Svetoslav64fad262015-04-14 14:35:21 -07002983 }
2984
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002985 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002986 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002987 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2988 // registered cell info, so return a NULL country instead.
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002991 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2992 // Get default phone in this case.
2993 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2994 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002995 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002997 if (phone == null) return "";
2998 ServiceStateTracker sst = phone.getServiceStateTracker();
2999 if (sst == null) return "";
3000 LocaleTracker lt = sst.getLocaleTracker();
3001 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003002 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003003 } finally {
3004 Binder.restoreCallingIdentity(identity);
3005 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003006 }
3007
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003008 /**
3009 * This method was removed due to potential issues caused by performing partial
3010 * updates of service state, and lack of a credible use case.
3011 *
3012 * This has the ability to break the telephony implementation by disabling notification of
3013 * changes in device connectivity. DO NOT USE THIS!
3014 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003015 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 public void enableLocationUpdates() {
3017 mApp.enforceCallingOrSelfPermission(
3018 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 }
3020
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003021 /**
3022 * This method was removed due to potential issues caused by performing partial
3023 * updates of service state, and lack of a credible use case.
3024 *
3025 * This has the ability to break the telephony implementation by disabling notification of
3026 * changes in device connectivity. DO NOT USE THIS!
3027 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 @Override
3029 public void disableLocationUpdates() {
3030 mApp.enforceCallingOrSelfPermission(
3031 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003032 }
3033
3034 @Override
3035 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003036 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3037 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003038 try {
3039 mApp.getSystemService(AppOpsManager.class)
3040 .checkPackage(Binder.getCallingUid(), callingPackage);
3041 } catch (SecurityException e) {
3042 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3043 throw e;
3044 }
3045
Nathan Haroldf096d982020-11-18 17:18:06 -08003046 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003047 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3048 throw new SecurityException(
3049 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3050 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003051
Jordan Liu1617b712019-07-10 15:06:26 -07003052 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3054 return null;
3055 }
Svetoslav64fad262015-04-14 14:35:21 -07003056
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003057 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003059 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003060 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061
Nathan Haroldf180aac2018-06-01 18:43:55 -07003062 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3063 for (CellInfo ci : info) {
3064 if (ci instanceof CellInfoGsm) {
3065 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3066 } else if (ci instanceof CellInfoWcdma) {
3067 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003069 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003070 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 }
3072
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003073 private List<CellInfo> getCachedCellInfo() {
3074 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3075 for (Phone phone : PhoneFactory.getPhones()) {
3076 List<CellInfo> info = phone.getAllCellInfo();
3077 if (info != null) cellInfos.addAll(info);
3078 }
3079 return cellInfos;
3080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081
3082 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003083 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003084 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003085 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003086
3087 LocationAccessPolicy.LocationPermissionResult locationResult =
3088 LocationAccessPolicy.checkLocationPermission(mApp,
3089 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3090 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003091 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003092 .setCallingPid(Binder.getCallingPid())
3093 .setCallingUid(Binder.getCallingUid())
3094 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003095 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003096 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3097 .build());
3098 switch (locationResult) {
3099 case DENIED_HARD:
3100 throw new SecurityException("Not allowed to access cell info");
3101 case DENIED_SOFT:
3102 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 }
3104
Nathan Haroldf096d982020-11-18 17:18:06 -08003105 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003106 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3107 return getCachedCellInfo();
3108 }
3109
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003110 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3115 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003116 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003117 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 if (info != null) cellInfos.addAll(info);
3119 }
3120 return cellInfos;
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 }
3124 }
3125
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003126 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003127 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3128 String callingFeatureId) {
3129 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3130 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003131 }
3132
3133 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003134 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3135 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003136 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003137 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003138 }
3139
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003140 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3141 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003142 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003143 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003144
3145 LocationAccessPolicy.LocationPermissionResult locationResult =
3146 LocationAccessPolicy.checkLocationPermission(mApp,
3147 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3148 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003149 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003150 .setCallingPid(Binder.getCallingPid())
3151 .setCallingUid(Binder.getCallingUid())
3152 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003153 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3154 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003155 .build());
3156 switch (locationResult) {
3157 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003158 if (TelephonyPermissions
3159 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003160 // Safetynet logging for b/154934934
3161 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3162 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003163 throw new SecurityException("Not allowed to access cell info");
3164 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003165 if (TelephonyPermissions
3166 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003167 // Safetynet logging for b/154934934
3168 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3169 }
Nathan Harold5320c422019-05-09 10:26:08 -07003170 try {
3171 cb.onCellInfo(new ArrayList<CellInfo>());
3172 } catch (RemoteException re) {
3173 // Drop without consequences
3174 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003175 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003176 }
3177
Nathan Harolda939a962019-05-09 10:13:47 -07003178
3179 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003180 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3181
3182 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3183 }
3184
3185 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003187 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003188 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
Shishir Agrawala9f32182016-04-12 12:00:16 -07003198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003199 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003200 Phone phone = PhoneFactory.getPhone(slotIndex);
3201 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003202 return null;
3203 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003204 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003205 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003206 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003207 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003208 return null;
3209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210
3211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 return phone.getImei();
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003217 }
3218
3219 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003220 public String getTypeAllocationCodeForSlot(int slotIndex) {
3221 Phone phone = PhoneFactory.getPhone(slotIndex);
3222 String tac = null;
3223 if (phone != null) {
3224 String imei = phone.getImei();
3225 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3226 }
3227 return tac;
3228 }
3229
3230 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003231 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003232 try {
3233 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3234 } catch (SecurityException se) {
3235 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3236 throw new SecurityException("Package " + callingPackage + " does not belong to "
3237 + Binder.getCallingUid());
3238 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003239 Phone phone = PhoneFactory.getPhone(slotIndex);
3240 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003241 return null;
3242 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003243
Jeff Davidson913390f2018-02-23 17:11:49 -08003244 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003245 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003246 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003247 return null;
3248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003249
3250 final long identity = Binder.clearCallingIdentity();
3251 try {
3252 return phone.getMeid();
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
Jack Yu2af8d712017-03-15 17:14:14 -07003256 }
3257
3258 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003259 public String getManufacturerCodeForSlot(int slotIndex) {
3260 Phone phone = PhoneFactory.getPhone(slotIndex);
3261 String manufacturerCode = null;
3262 if (phone != null) {
3263 String meid = phone.getMeid();
3264 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3265 }
3266 return manufacturerCode;
3267 }
3268
3269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003270 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3271 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003272 Phone phone = PhoneFactory.getPhone(slotIndex);
3273 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003274 return null;
3275 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003276 int subId = phone.getSubId();
3277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003278 mApp, subId, callingPackage, callingFeatureId,
3279 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003280 return null;
3281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282
3283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 return phone.getDeviceSvn();
3286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003289 }
3290
fionaxu43304da2017-11-27 22:51:16 -08003291 @Override
3292 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 final Phone phone = getPhone(subId);
3296 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3297 } finally {
3298 Binder.restoreCallingIdentity(identity);
3299 }
fionaxu43304da2017-11-27 22:51:16 -08003300 }
3301
3302 @Override
3303 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 final Phone phone = getPhone(subId);
3307 return phone == null ? null : phone.getCarrierName();
3308 } finally {
3309 Binder.restoreCallingIdentity(identity);
3310 }
fionaxu43304da2017-11-27 22:51:16 -08003311 }
3312
calvinpanffe225e2018-11-01 19:43:06 +08003313 @Override
chen xu0026ca62019-03-06 15:28:50 -08003314 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 final Phone phone = getPhone(subId);
3318 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003319 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003320 } finally {
3321 Binder.restoreCallingIdentity(identity);
3322 }
3323 }
3324
3325 @Override
chen xu0026ca62019-03-06 15:28:50 -08003326 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003330 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
3334 }
3335
chen xu651eec72018-11-11 19:03:44 -08003336 @Override
chen xu864e11c2018-12-06 22:10:03 -08003337 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3338 if (!isSubscriptionMccMnc) {
3339 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3340 }
chen xu651eec72018-11-11 19:03:44 -08003341 final Phone phone = PhoneFactory.getPhone(slotIndex);
3342 if (phone == null) {
3343 return TelephonyManager.UNKNOWN_CARRIER_ID;
3344 }
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3348 } finally {
3349 Binder.restoreCallingIdentity(identity);
3350 }
3351 }
3352
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003353 //
3354 // Internal helper methods.
3355 //
3356
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003357 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003358 * Make sure the caller is the calling package itself
3359 *
3360 * @throws SecurityException if the caller is not the calling package
3361 */
3362 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3363 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003364 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3365 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003366 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003367 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003368 } catch (PackageManager.NameNotFoundException e) {
3369 // packageUid is -1
3370 }
3371 if (packageUid != callingUid) {
3372 throw new SecurityException(message + ": Package " + callingPackage
3373 + " does not belong to " + callingUid);
3374 }
3375 }
3376
3377 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003378 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3379 *
3380 * @throws SecurityException if the caller does not have the required permission
3381 */
3382 private void enforceModifyPermission() {
3383 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3384 }
3385
Shuo Qiancd19c462020-01-16 20:51:11 -08003386 /**
3387 * Make sure the caller is system.
3388 *
3389 * @throws SecurityException if the caller is not system.
3390 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003391 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003392 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3393 throw new SecurityException("Caller must be system");
3394 }
3395 }
3396
Shuo Qian3b6ee772019-11-13 17:43:31 -08003397 private void enforceActiveEmergencySessionPermission() {
3398 mApp.enforceCallingOrSelfPermission(
3399 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3400 }
3401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003402 /**
3403 * Make sure the caller has the CALL_PHONE permission.
3404 *
3405 * @throws SecurityException if the caller does not have the required permission
3406 */
3407 private void enforceCallPermission() {
3408 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3409 }
3410
paulhu5a773602019-08-23 19:17:33 +08003411 private void enforceSettingsPermission() {
3412 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003413 }
3414
Michele Berionne5e411512020-11-13 02:36:59 +00003415 private void enforceRebootPermission() {
3416 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3417 }
3418
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003419 private String createTelUrl(String number) {
3420 if (TextUtils.isEmpty(number)) {
3421 return null;
3422 }
3423
Jake Hambye994d462014-02-03 13:10:13 -08003424 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 }
3426
Ihab Awadf9e92732013-12-05 18:02:52 -08003427 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3429 }
3430
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003431 private static void logv(String msg) {
3432 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3433 }
3434
Ihab Awadf9e92732013-12-05 18:02:52 -08003435 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003436 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3437 }
3438
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003439 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003441 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003442 }
3443
Sanket Padawe356d7632015-06-22 14:03:32 -07003444 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003445 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 final Phone phone = PhoneFactory.getPhone(slotIndex);
3449 if (phone == null) {
3450 return PhoneConstants.PHONE_TYPE_NONE;
3451 } else {
3452 return phone.getPhoneType();
3453 }
3454 } finally {
3455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003457 }
3458
3459 /**
3460 * Returns the CDMA ERI icon index to display
3461 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003462 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003463 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3464 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3465 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003466 }
3467
Sanket Padawe356d7632015-06-22 14:03:32 -07003468 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003469 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3470 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003472 mApp, subId, callingPackage, callingFeatureId,
3473 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003474 return -1;
3475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 final Phone phone = getPhone(subId);
3480 if (phone != null) {
3481 return phone.getCdmaEriIconIndex();
3482 } else {
3483 return -1;
3484 }
3485 } finally {
3486 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003488 }
3489
3490 /**
3491 * Returns the CDMA ERI icon mode,
3492 * 0 - ON
3493 * 1 - FLASHING
3494 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003495 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003496 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3497 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3498 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003499 }
3500
Sanket Padawe356d7632015-06-22 14:03:32 -07003501 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003502 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3503 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003505 mApp, subId, callingPackage, callingFeatureId,
3506 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003507 return -1;
3508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509
3510 final long identity = Binder.clearCallingIdentity();
3511 try {
3512 final Phone phone = getPhone(subId);
3513 if (phone != null) {
3514 return phone.getCdmaEriIconMode();
3515 } else {
3516 return -1;
3517 }
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 }
3522
3523 /**
3524 * Returns the CDMA ERI text,
3525 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003526 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003527 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3528 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3529 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003530 }
3531
Sanket Padawe356d7632015-06-22 14:03:32 -07003532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003533 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3534 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003536 mApp, subId, callingPackage, callingFeatureId,
3537 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003538 return null;
3539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003540
3541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 final Phone phone = getPhone(subId);
3544 if (phone != null) {
3545 return phone.getCdmaEriText();
3546 } else {
3547 return null;
3548 }
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003552 }
3553
3554 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003555 * Returns the CDMA MDN.
3556 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003558 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3560 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003565 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566 return phone.getLine1Number();
3567 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003568 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569 return null;
3570 }
3571 } finally {
3572 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003573 }
3574 }
3575
3576 /**
3577 * Returns the CDMA MIN.
3578 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003579 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003580 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3582 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583
3584 final long identity = Binder.clearCallingIdentity();
3585 try {
3586 final Phone phone = getPhone(subId);
3587 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3588 return phone.getCdmaMin();
3589 } else {
3590 return null;
3591 }
3592 } finally {
3593 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003594 }
3595 }
3596
Hall Liud892bec2018-11-30 14:51:45 -08003597 @Override
3598 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3599 INumberVerificationCallback callback, String callingPackage) {
3600 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3601 != PERMISSION_GRANTED) {
3602 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3603 }
3604 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3605
3606 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3607 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003608 throw new SecurityException("Calling package must be configured in the device config: "
3609 + "calling package: " + callingPackage
3610 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003611 }
3612
3613 if (range == null) {
3614 throw new NullPointerException("Range must be non-null");
3615 }
3616
3617 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003618 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003619
3620 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3621 }
3622
Junda Liuca05d5d2014-08-14 22:36:34 -07003623 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003624 * Returns true if CDMA provisioning needs to run.
3625 */
3626 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003627 final long identity = Binder.clearCallingIdentity();
3628 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003629 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003633 }
3634
3635 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003636 * Sets the voice mail number of a given subId.
3637 */
3638 @Override
3639 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003640 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3641 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642
3643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3646 new Pair<String, String>(alphaTag, number), new Integer(subId));
3647 return success;
3648 } finally {
3649 Binder.restoreCallingIdentity(identity);
3650 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003651 }
3652
Ta-wei Yen87c49842016-05-13 21:19:52 -07003653 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003654 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3655 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003656 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3657 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003658 if (!TextUtils.equals(callingPackage, systemDialer)) {
3659 throw new SecurityException("caller must be system dialer");
3660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661
3662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3665 if (phoneAccountHandle == null) {
3666 return null;
3667 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003668 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003669 } finally {
3670 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003671 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003672 }
3673
3674 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003675 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3676 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003677 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003679 mApp, subId, callingPackage, callingFeatureId,
3680 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003681 return null;
3682 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003683
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003684 final long identity = Binder.clearCallingIdentity();
3685 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003686 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003690 }
3691
3692 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003693 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3694 VisualVoicemailSmsFilterSettings settings) {
3695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696
3697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003700 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003704 }
3705
3706 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003707 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3708 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003709
3710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003717 }
3718
3719 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003720 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3721 String callingPackage, int subId) {
3722 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723
3724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003727 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 } finally {
3729 Binder.restoreCallingIdentity(identity);
3730 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003731 }
3732
3733 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003734 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003735 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736
3737 final long identity = Binder.clearCallingIdentity();
3738 try {
3739 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003740 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741 } finally {
3742 Binder.restoreCallingIdentity(identity);
3743 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003744 }
3745
3746 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003747 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3748 String callingAttributionTag, int subId, String number, int port, String text,
3749 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003751 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003752 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003753 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003754 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3755 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003756 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003757
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003758 /**
fionaxu0152e512016-11-14 13:36:14 -08003759 * Sets the voice activation state of a given subId.
3760 */
3761 @Override
3762 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3764 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765
3766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 final Phone phone = getPhone(subId);
3769 if (phone != null) {
3770 phone.setVoiceActivationState(activationState);
3771 } else {
3772 loge("setVoiceActivationState fails with invalid subId: " + subId);
3773 }
3774 } finally {
3775 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003776 }
3777 }
3778
3779 /**
3780 * Sets the data activation state of a given subId.
3781 */
3782 @Override
3783 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3785 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786
3787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 final Phone phone = getPhone(subId);
3790 if (phone != null) {
3791 phone.setDataActivationState(activationState);
3792 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003793 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 }
3795 } finally {
3796 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003797 }
3798 }
3799
3800 /**
3801 * Returns the voice activation state of a given subId.
3802 */
3803 @Override
3804 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003805 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806
fionaxu0152e512016-11-14 13:36:14 -08003807 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 final long identity = Binder.clearCallingIdentity();
3809 try {
3810 if (phone != null) {
3811 return phone.getVoiceActivationState();
3812 } else {
3813 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3814 }
3815 } finally {
3816 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003817 }
3818 }
3819
3820 /**
3821 * Returns the data activation state of a given subId.
3822 */
3823 @Override
3824 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826
fionaxu0152e512016-11-14 13:36:14 -08003827 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 if (phone != null) {
3831 return phone.getDataActivationState();
3832 } else {
3833 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3834 }
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003837 }
3838 }
3839
3840 /**
Wink Saville36469e72014-06-11 15:17:00 -07003841 * Returns the unread count of voicemails for a subId
3842 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003843 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003844 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3845 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003846 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003847 mApp, subId, callingPackage, callingFeatureId,
3848 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003849 return 0;
3850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 final Phone phone = getPhone(subId);
3854 if (phone != null) {
3855 return phone.getVoiceMessageCount();
3856 } else {
3857 return 0;
3858 }
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003862 }
3863
3864 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003865 * returns true, if the device is in a state where both voice and data
3866 * are supported simultaneously. This can change based on location or network condition.
3867 */
3868 @Override
3869 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 final Phone phone = getPhone(subId);
3873 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3874 } finally {
3875 Binder.restoreCallingIdentity(identity);
3876 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003877 }
3878
3879 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003880 * Send the dialer code if called from the current default dialer or the caller has
3881 * carrier privilege.
3882 * @param inputCode The dialer code to send
3883 */
3884 @Override
3885 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003886 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003887 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003888 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3889 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003890 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003891 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003892 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003893 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003894
3895 final long identity = Binder.clearCallingIdentity();
3896 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003897 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898 } finally {
3899 Binder.restoreCallingIdentity(identity);
3900 }
fionaxu235cc5e2017-03-06 22:25:57 -08003901 }
3902
Pengquan Menga1bb6272018-09-06 09:59:22 -07003903 @Override
3904 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003905 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003906 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003907 mApp, subId, "getNetworkSelectionMode");
3908 final long identity = Binder.clearCallingIdentity();
3909 try {
3910 if (!isActiveSubscription(subId)) {
3911 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3912 }
3913 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3914 } finally {
3915 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003916 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003917 }
3918
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003920 public boolean isInEmergencySmsMode() {
3921 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 for (Phone phone : PhoneFactory.getPhones()) {
3925 if (phone.isInEmergencySmsMode()) {
3926 return true;
3927 }
3928 }
3929 } finally {
3930 Binder.restoreCallingIdentity(identity);
3931 }
3932 return false;
3933 }
3934
shilu366312e2019-12-17 09:28:10 -08003935 /**
3936 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3937 * @param subId The subscription to use to check the configuration.
3938 * @param c The callback that will be used to send the result.
3939 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003940 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003941 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3942 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003943 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003944 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003945
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003946 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3947 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3948 "IMS not available on device.");
3949 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 final long token = Binder.clearCallingIdentity();
3951 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003952 int slotId = getSlotIndexOrException(subId);
3953 verifyImsMmTelConfiguredOrThrow(slotId);
3954 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003955 } catch (ImsException e) {
3956 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 } finally {
3958 Binder.restoreCallingIdentity(token);
3959 }
3960 }
3961
shilu366312e2019-12-17 09:28:10 -08003962 /**
3963 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3964 * @param subId The subscription to use to check the configuration.
3965 * @param c The callback that will be used to send the result.
3966 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003968 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003969 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003970 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003971 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3972 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3973 }
Meng Wangafbc5852019-09-19 17:37:13 -07003974 final long token = Binder.clearCallingIdentity();
3975 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003976 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3977 .removeRegistrationCallbackForSubscription(c, subId);
3978 } catch (ImsException e) {
3979 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3980 + "is inactive, ignoring unregister.");
3981 // If the subscription is no longer active, just return, since the callback
3982 // will already have been removed internally.
3983 } finally {
3984 Binder.restoreCallingIdentity(token);
3985 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 }
3987
Brad Ebingera34a6c22019-10-22 17:36:18 -07003988 /**
3989 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3990 */
3991 @Override
3992 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3993 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3994 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3995 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3996 "IMS not available on device.");
3997 }
3998 final long token = Binder.clearCallingIdentity();
3999 try {
4000 Phone phone = getPhone(subId);
4001 if (phone == null) {
4002 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4003 + subId + "'");
4004 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4005 }
4006 phone.getImsRegistrationState(regState -> {
4007 try {
4008 consumer.accept((regState == null)
4009 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4010 } catch (RemoteException e) {
4011 // Ignore if the remote process is no longer available to call back.
4012 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4013 }
4014 });
4015 } finally {
4016 Binder.restoreCallingIdentity(token);
4017 }
4018 }
4019
4020 /**
4021 * Get the transport type for the IMS service registration state.
4022 */
4023 @Override
4024 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004025 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004026 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004027 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4028 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4029 "IMS not available on device.");
4030 }
4031 final long token = Binder.clearCallingIdentity();
4032 try {
4033 Phone phone = getPhone(subId);
4034 if (phone == null) {
4035 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4036 + subId + "'");
4037 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4038 }
4039 phone.getImsRegistrationTech(regTech -> {
4040 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4041 int regTechConverted = (regTech == null)
4042 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4043 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4044 regTechConverted);
4045 try {
4046 consumer.accept(regTechConverted);
4047 } catch (RemoteException e) {
4048 // Ignore if the remote process is no longer available to call back.
4049 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4050 }
4051 });
4052 } finally {
4053 Binder.restoreCallingIdentity(token);
4054 }
4055 }
4056
shilu366312e2019-12-17 09:28:10 -08004057 /**
4058 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4059 * @param subId The subscription to use to check the configuration.
4060 * @param c The callback that will be used to send the result.
4061 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004063 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4064 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004065 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004066 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004067 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4068 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4069 "IMS not available on device.");
4070 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 final long token = Binder.clearCallingIdentity();
4072 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004073 int slotId = getSlotIndexOrException(subId);
4074 verifyImsMmTelConfiguredOrThrow(slotId);
4075 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004076 } catch (ImsException e) {
4077 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 } finally {
4079 Binder.restoreCallingIdentity(token);
4080 }
4081 }
4082
shilu366312e2019-12-17 09:28:10 -08004083 /**
4084 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4085 * @param subId The subscription to use to check the configuration.
4086 * @param c The callback that will be used to send the result.
4087 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004089 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004090 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004091 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004092 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4093 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4094 }
Meng Wangafbc5852019-09-19 17:37:13 -07004095
4096 final long token = Binder.clearCallingIdentity();
4097 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004098 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004099 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004100 } catch (ImsException e) {
4101 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4102 + "is inactive, ignoring unregister.");
4103 // If the subscription is no longer active, just return, since the callback
4104 // will already have been removed internally.
4105 } finally {
4106 Binder.restoreCallingIdentity(token);
4107 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 }
4109
4110 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004111 public boolean isCapable(int subId, int capability, int regTech) {
4112 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004113 final long token = Binder.clearCallingIdentity();
4114 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004115 int slotId = getSlotIndexOrException(subId);
4116 verifyImsMmTelConfiguredOrThrow(slotId);
4117 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004118 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4120 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004121 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004122 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4123 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 } finally {
4125 Binder.restoreCallingIdentity(token);
4126 }
4127 }
4128
4129 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004130 public boolean isAvailable(int subId, int capability, int regTech) {
4131 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004132 final long token = Binder.clearCallingIdentity();
4133 try {
4134 Phone phone = getPhone(subId);
4135 if (phone == null) return false;
4136 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004137 } catch (com.android.ims.ImsException e) {
4138 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4139 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 } finally {
4141 Binder.restoreCallingIdentity(token);
4142 }
4143 }
4144
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004145 /**
4146 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4147 * subscription.
4148 * @param subId The subscription to use to check the configuration.
4149 * @param callback The callback that will be used to send the result.
4150 * @param capability The MmTelFeature capability that will be used to send the result.
4151 * @param transportType The transport type of the MmTelFeature capability.
4152 */
4153 @Override
4154 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4155 int transportType) {
4156 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4157 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4158 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4159 "IMS not available on device.");
4160 }
4161 final long token = Binder.clearCallingIdentity();
4162 try {
4163 int slotId = getSlotIndex(subId);
4164 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4165 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4166 + subId + "'");
4167 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4168 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004169 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004170 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4171 transportType, aBoolean -> {
4172 try {
4173 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4174 } catch (RemoteException e) {
4175 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4176 + "running. Ignore");
4177 }
4178 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004179 } catch (ImsException e) {
4180 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004181 } finally {
4182 Binder.restoreCallingIdentity(token);
4183 }
4184 }
4185
shilu366312e2019-12-17 09:28:10 -08004186 /**
4187 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4188 * @param subId The subscription to use to check the configuration.
4189 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 @Override
4191 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004192 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004193 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004194
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 final long token = Binder.clearCallingIdentity();
4196 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004197 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004198 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004199 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004200 } catch (ImsException e) {
4201 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 } finally {
4203 Binder.restoreCallingIdentity(token);
4204 }
4205 }
4206
4207 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004208 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004210 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004211 final long identity = Binder.clearCallingIdentity();
4212 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004213 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004214 // This setting doesn't require an active ImsService connection, so do not verify. The
4215 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004216 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 } catch (ImsException e) {
4218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222 }
4223
shilu366312e2019-12-17 09:28:10 -08004224 /**
4225 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4226 * @param subId The subscription to use to check the configuration.
4227 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004229 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004230 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004231 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 final long identity = Binder.clearCallingIdentity();
4233 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004234 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004235 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004236 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004237 } catch (ImsException e) {
4238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
4242 }
4243
4244 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004245 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004247 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004248 final long identity = Binder.clearCallingIdentity();
4249 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004250 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004251 // This setting doesn't require an active ImsService connection, so do not verify. The
4252 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004253 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004254 } catch (ImsException e) {
4255 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
4259 }
4260
shilu366312e2019-12-17 09:28:10 -08004261 /**
4262 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4263 * @param subId The subscription to use to check the configuration.
4264 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 @Override
4266 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004267 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004268 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 final long identity = Binder.clearCallingIdentity();
4270 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004271 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004272 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004273 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004274 } catch (ImsException e) {
4275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
4279 }
4280
4281 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004282 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004284 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 final long identity = Binder.clearCallingIdentity();
4286 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004287 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004288 // This setting doesn't require an active ImsService connection, so do not verify. The
4289 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004290 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004291 } catch (ImsException e) {
4292 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
4296 }
4297
shilu366312e2019-12-17 09:28:10 -08004298 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004299 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4300 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4301 * @param subId The subscription to use to check the configuration.
4302 */
4303 @Override
4304 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004305 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004306 mApp, subId, "isCrossSimCallingEnabledByUser");
4307 final long identity = Binder.clearCallingIdentity();
4308 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004309 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004310 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004311 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004312 } catch (ImsException e) {
4313 throw new ServiceSpecificException(e.getCode());
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
4316 }
4317 }
4318
4319 /**
4320 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4321 * Requires MODIFY_PHONE_STATE permission.
4322 * @param subId The subscription to use to check the configuration.
4323 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4324 * false otherwise
4325 */
4326 @Override
4327 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4329 "setCrossSimCallingEnabled");
4330 final long identity = Binder.clearCallingIdentity();
4331 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004332 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004333 // This setting doesn't require an active ImsService connection, so do not verify. The
4334 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004335 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004336 } catch (ImsException e) {
4337 throw new ServiceSpecificException(e.getCode());
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
4341 }
4342
4343 /**
shilu366312e2019-12-17 09:28:10 -08004344 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4345 * @param subId The subscription to use to check the configuration.
4346 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004348
Brad Ebinger35c841c2018-10-01 10:40:55 -07004349 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004350 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004351 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004352 final long identity = Binder.clearCallingIdentity();
4353 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004354 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004355 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004356 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004357 } catch (ImsException e) {
4358 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 } finally {
4360 Binder.restoreCallingIdentity(identity);
4361 }
4362 }
4363
4364 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004365 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004367 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004368 final long identity = Binder.clearCallingIdentity();
4369 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004370 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004371 // This setting doesn't require an active ImsService connection, so do not verify. The
4372 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004373 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004374 } catch (ImsException e) {
4375 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
4379 }
4380
4381 @Override
4382 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4384 "setVoWiFiNonPersistent");
4385 final long identity = Binder.clearCallingIdentity();
4386 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004387 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004388 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004389 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004390 } catch (ImsException e) {
4391 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004392 } finally {
4393 Binder.restoreCallingIdentity(identity);
4394 }
4395 }
4396
shilu366312e2019-12-17 09:28:10 -08004397 /**
4398 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4399 * @param subId The subscription to use to check the configuration.
4400 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004401 @Override
4402 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004403 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004404 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004405 final long identity = Binder.clearCallingIdentity();
4406 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004407 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004408 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004409 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004410 } catch (ImsException e) {
4411 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004412 } finally {
4413 Binder.restoreCallingIdentity(identity);
4414 }
4415 }
4416
4417 @Override
4418 public void setVoWiFiModeSetting(int subId, int mode) {
4419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4420 "setVoWiFiModeSetting");
4421 final long identity = Binder.clearCallingIdentity();
4422 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004423 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004424 // This setting doesn't require an active ImsService connection, so do not verify. The
4425 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004426 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004427 } catch (ImsException e) {
4428 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
4432 }
4433
4434 @Override
4435 public int getVoWiFiRoamingModeSetting(int subId) {
4436 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4437 final long identity = Binder.clearCallingIdentity();
4438 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004439 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004440 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004442 } catch (ImsException e) {
4443 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004444 } finally {
4445 Binder.restoreCallingIdentity(identity);
4446 }
4447 }
4448
4449 @Override
4450 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4451 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4452 "setVoWiFiRoamingModeSetting");
4453 final long identity = Binder.clearCallingIdentity();
4454 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004455 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004456 // This setting doesn't require an active ImsService connection, so do not verify. The
4457 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004458 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004459 } catch (ImsException e) {
4460 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004461 } finally {
4462 Binder.restoreCallingIdentity(identity);
4463 }
4464 }
4465
4466 @Override
4467 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4469 "setRttCapabilityEnabled");
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004472 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004473 // This setting doesn't require an active ImsService connection, so do not verify. The
4474 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004475 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004476 } catch (ImsException e) {
4477 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
4481 }
4482
shilu366312e2019-12-17 09:28:10 -08004483 /**
4484 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4485 * @param subId The subscription to use to check the configuration.
4486 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004487 @Override
4488 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004489 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004490 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 final long identity = Binder.clearCallingIdentity();
4492 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004493 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004494 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004495 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004496 } catch (ImsException e) {
4497 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
4501 }
4502
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004503 @Override
4504 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4505 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4506 final long identity = Binder.clearCallingIdentity();
4507 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004508 if (!isImsAvailableOnDevice()) {
4509 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4510 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004511 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004512 int slotId = getSlotIndexOrException(subId);
4513 verifyImsMmTelConfiguredOrThrow(slotId);
4514 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004515 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004516 } catch (ImsException e) {
4517 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
4523 @Override
4524 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4525 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4526 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004527 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4528 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4529 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004530 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004531 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004532 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004533 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004534 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4535 + "is inactive, ignoring unregister.");
4536 // If the subscription is no longer active, just return, since the callback will already
4537 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
4541 }
4542
allenwtsu99c623b2020-01-03 18:24:23 +08004543
4544 private void checkModifyPhoneStatePermission(int subId, String message) {
4545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4546 message);
4547 }
4548
4549 private boolean isImsProvisioningRequired(int subId, int capability,
4550 boolean isMmtelCapability) {
4551 Phone phone = getPhone(subId);
4552 if (phone == null) {
4553 loge("phone instance null for subid " + subId);
4554 return false;
4555 }
4556 if (isMmtelCapability) {
4557 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4558 return false;
4559 }
4560 } else {
4561 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4562 return false;
4563 }
4564 }
4565 return true;
4566 }
4567
4568 @Override
4569 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4570 boolean isProvisioned) {
4571 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4572
4573 final long identity = Binder.clearCallingIdentity();
4574 try {
4575 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4576 if (!isImsProvisioningRequired(subId, capability, false)) {
4577 return;
4578 }
4579
4580 // this capability requires provisioning, route to the correct API.
4581 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4582 switch (capability) {
4583 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4584 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4585 ims.setEabProvisioned(isProvisioned);
4586 break;
4587 default: {
4588 throw new IllegalArgumentException("Tried to set provisioning for "
4589 + "rcs capability '" + capability + "', which does not require "
4590 + "provisioning.");
4591 }
4592 }
4593 } finally {
4594 Binder.restoreCallingIdentity(identity);
4595 }
4596
4597 }
4598
4599
4600 @Override
4601 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4602 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4603 final long identity = Binder.clearCallingIdentity();
4604 try {
4605 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4606 if (!isImsProvisioningRequired(subId, capability, false)) {
4607 return true;
4608 }
4609
4610 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4611 switch (capability) {
4612 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4613 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4614 return ims.isEabProvisionedOnDevice();
4615
4616 default: {
4617 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4618 + "capability '" + capability + "', which does not require "
4619 + "provisioning.");
4620 }
4621 }
4622
4623 } finally {
4624 Binder.restoreCallingIdentity(identity);
4625 }
4626 }
4627
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004628 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004629 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4630 boolean isProvisioned) {
4631 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004632 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4633 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4634 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004635 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4636 }
allenwtsu99c623b2020-01-03 18:24:23 +08004637 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004638 final long identity = Binder.clearCallingIdentity();
4639 try {
4640 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004641 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004642 return;
4643 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004644 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4645 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4646 loge("setImsProvisioningStatusForCapability: called for technology that does "
4647 + "not support provisioning - " + tech);
4648 return;
4649 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004650
4651 // this capability requires provisioning, route to the correct API.
4652 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4653 switch (capability) {
4654 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4655 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4656 ims.setVolteProvisioned(isProvisioned);
4657 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4658 ims.setWfcProvisioned(isProvisioned);
4659 }
4660 break;
4661 }
4662 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4663 // There is currently no difference in VT provisioning type.
4664 ims.setVtProvisioned(isProvisioned);
4665 break;
4666 }
4667 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4668 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4669 // change the capability of the feature instead if needed.
4670 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4671 == isProvisioned) {
4672 // No change in provisioning.
4673 return;
4674 }
4675 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4676 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004677 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004678 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004679 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4680 + ", Exception" + e.getMessage());
4681 }
4682 break;
4683 }
4684 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004685 throw new IllegalArgumentException("Tried to set provisioning for "
4686 + "MmTel capability '" + capability + "', which does not require "
4687 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004688 }
4689 }
4690
4691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
4694 }
4695
4696 @Override
4697 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4698 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004699 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4700 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4701 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004702 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4703 }
4704 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004708 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004709 return true;
4710 }
4711
Brad Ebinger0d79c572021-04-17 15:20:49 -07004712 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4713 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4714 loge("getImsProvisioningStatusForCapability: called for technology that does "
4715 + "not support provisioning - " + tech);
4716 return true;
4717 }
4718
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004719 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4720 switch (capability) {
4721 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4722 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4723 return ims.isVolteProvisionedOnDevice();
4724 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4725 return ims.isWfcProvisionedOnDevice();
4726 }
4727 // This should never happen, since we are checking tech above to make sure it
4728 // is either LTE or IWLAN.
4729 throw new IllegalArgumentException("Invalid radio technology for voice "
4730 + "capability.");
4731 }
4732 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4733 // There is currently no difference in VT provisioning type.
4734 return ims.isVtProvisionedOnDevice();
4735 }
4736 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4737 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4738 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4739 }
4740 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004741 throw new IllegalArgumentException(
4742 "Tried to get provisioning for MmTel capability '" + capability
4743 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 }
4745 }
4746
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
4750 }
4751
4752 @Override
4753 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4754 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4755 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4756 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4757 }
4758 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4759 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4760 return (provisionedBits & capability) > 0;
4761 }
4762
4763 @Override
4764 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4765 boolean isProvisioned) {
4766 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4767 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4768 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4769 }
4770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4771 "setProvisioningStatusForCapability");
4772 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4773 // If the current provisioning status for capability already matches isProvisioned,
4774 // do nothing.
4775 if (((provisionedBits & capability) > 0) == isProvisioned) {
4776 return;
4777 }
4778 if (isProvisioned) {
4779 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4780 } else {
4781 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4782 }
4783 }
4784
4785 /**
4786 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4787 * technology. The bitfield should mirror the bitfield defined by
4788 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4789 */
4790 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4791 String key = getMmTelProvisioningKey(subId, tech);
4792 // Default is no capabilities are provisioned.
4793 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4794 }
4795
4796 /**
4797 * Sets the MmTel capability provisioning bitfield (defined by
4798 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4799 * technology specified.
4800 *
4801 * Note: This is a synchronous command and should not be called on UI thread.
4802 */
4803 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4804 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4805 String key = getMmTelProvisioningKey(subId, tech);
4806 editor.putInt(key, newField);
4807 editor.commit();
4808 }
4809
4810 private static String getMmTelProvisioningKey(int subId, int tech) {
4811 // resulting key is provision_ims_mmtel_{subId}_{tech}
4812 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4813 }
4814
4815 /**
4816 * Query CarrierConfig to see if the specified capability requires provisioning for the
4817 * carrier associated with the subscription id.
4818 */
4819 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4820 int capability) {
4821 CarrierConfigManager configManager = new CarrierConfigManager(context);
4822 PersistableBundle c = configManager.getConfigForSubId(subId);
4823 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004824 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004825 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4826 false);
4827 boolean requireVoiceVtProvisioning = c.getBoolean(
4828 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4829
4830 // First check to make sure that the capability requires provisioning.
4831 switch (capability) {
4832 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4833 // intentional fallthrough
4834 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4835 if (requireVoiceVtProvisioning) {
4836 // Voice and Video requires provisioning
4837 return true;
4838 }
4839 break;
4840 }
4841 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4842 if (requireUtProvisioning) {
4843 // UT requires provisioning
4844 return true;
4845 }
4846 break;
4847 }
4848 }
4849 return false;
4850 }
4851
allenwtsu99c623b2020-01-03 18:24:23 +08004852 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4853 int capability) {
4854 CarrierConfigManager configManager = new CarrierConfigManager(context);
4855 PersistableBundle c = configManager.getConfigForSubId(subId);
4856
4857 boolean requireRcsProvisioning = c.getBoolean(
4858 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4859
4860 // First check to make sure that the capability requires provisioning.
4861 switch (capability) {
4862 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4863 // intentional fallthrough
4864 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4865 if (requireRcsProvisioning) {
4866 // OPTION or PRESENCE requires provisioning
4867 return true;
4868 }
4869 break;
4870 }
4871 }
4872 return false;
4873 }
4874
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004875 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004876 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004877 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4878 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4879 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004880 enforceReadPrivilegedPermission("getImsProvisioningInt");
4881 final long identity = Binder.clearCallingIdentity();
4882 try {
4883 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004884 int slotId = getSlotIndex(subId);
4885 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4886 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4887 + subId + "' for key:" + key);
4888 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4889 }
calvinpanb5a34062021-02-08 19:59:36 +08004890 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004891 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4893 + subId + "' for key:" + key);
4894 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004895 } finally {
4896 Binder.restoreCallingIdentity(identity);
4897 }
4898 }
4899
4900 @Override
4901 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4903 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4904 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004905 enforceReadPrivilegedPermission("getImsProvisioningString");
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004909 int slotId = getSlotIndex(subId);
4910 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4911 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4912 + subId + "' for key:" + key);
4913 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4914 }
calvinpanb5a34062021-02-08 19:59:36 +08004915 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004916 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4918 + subId + "' for key:" + key);
4919 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
4922 }
4923 }
4924
4925 @Override
4926 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4928 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4929 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4931 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004935 int slotId = getSlotIndex(subId);
4936 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4937 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4938 + subId + "' for key:" + key);
4939 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4940 }
calvinpanb5a34062021-02-08 19:59:36 +08004941 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4942 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004943 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004944 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004945 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
4949 }
4950
4951 @Override
4952 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004953 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4954 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4955 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4957 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004961 int slotId = getSlotIndex(subId);
4962 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4963 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4964 + subId + "' for key:" + key);
4965 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4966 }
calvinpanb5a34062021-02-08 19:59:36 +08004967 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4968 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004969 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004970 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004971 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
4975 }
4976
Brad Ebinger919631e2021-06-02 17:46:35 -07004977 /**
4978 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4979 * for the given slot ID or no ImsResolver instance has been created.
4980 * @param slotId The slot ID that the IMS service is created for.
4981 * @throws ImsException If there is no ImsService configured for this slot.
4982 */
4983 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4984 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4985 ImsFeature.FEATURE_MMTEL)) {
4986 throw new ImsException("This subscription does not support MMTEL over IMS",
4987 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4988 }
4989 }
4990
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004991 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004992 int slotId = SubscriptionManager.getSlotIndex(subId);
4993 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004994 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4995 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004996 }
4997 return slotId;
4998 }
4999
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005000 private int getSlotIndex(int subId) {
5001 int slotId = SubscriptionManager.getSlotIndex(subId);
5002 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5003 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5004 }
5005 return slotId;
5006 }
5007
Wink Saville36469e72014-06-11 15:17:00 -07005008 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005009 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005010 */
5011 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005012 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5013 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005014 try {
5015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5016 } catch (SecurityException se) {
5017 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5018 throw new SecurityException("Package " + callingPackage + " does not belong to "
5019 + Binder.getCallingUid());
5020 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005021 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005022 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005023 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005024 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005025 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005026 mApp, subId, callingPackage, callingFeatureId,
5027 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005028 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5029 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 final long identity = Binder.clearCallingIdentity();
5032 try {
5033 final Phone phone = getPhone(subId);
5034 if (phone != null) {
5035 return phone.getServiceState().getDataNetworkType();
5036 } else {
5037 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5038 }
5039 } finally {
5040 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005041 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005042 }
5043
5044 /**
5045 * Returns the data network type
5046 */
5047 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005048 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005049 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5050 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005051 }
5052
5053 /**
5054 * Returns the data network type for a subId
5055 */
5056 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005057 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5058 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005059 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005060 mApp, subId, callingPackage, callingFeatureId,
5061 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005062 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5063 }
5064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 final Phone phone = getPhone(subId);
5068 if (phone != null) {
5069 return phone.getServiceState().getDataNetworkType();
5070 } else {
5071 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5072 }
5073 } finally {
5074 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005075 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005076 }
5077
5078 /**
Wink Saville36469e72014-06-11 15:17:00 -07005079 * Returns the Voice network type for a subId
5080 */
5081 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005082 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5083 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005084 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005085 mApp, subId, callingPackage, callingFeatureId,
5086 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005087 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5088 }
5089
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 final long identity = Binder.clearCallingIdentity();
5091 try {
5092 final Phone phone = getPhone(subId);
5093 if (phone != null) {
5094 return phone.getServiceState().getVoiceNetworkType();
5095 } else {
5096 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5097 }
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005101 }
5102
5103 /**
5104 * @return true if a ICC card is present
5105 */
5106 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005107 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005108 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5109 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005110 }
5111
5112 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005113 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005114 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005115 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005116 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 final long identity = Binder.clearCallingIdentity();
5118 try {
5119 final Phone phone = PhoneFactory.getPhone(slotIndex);
5120 if (phone != null) {
5121 return phone.getIccCard().hasIccCard();
5122 } else {
5123 return false;
5124 }
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005128 }
5129
5130 /**
5131 * Return if the current radio is LTE on CDMA. This
5132 * is a tri-state return value as for a period of time
5133 * the mode may be unknown.
5134 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005135 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005136 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005137 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005138 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005139 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005140 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5141 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5142 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005143 }
5144
Sanket Padawe356d7632015-06-22 14:03:32 -07005145 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005146 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5147 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005148 try {
5149 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5150 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005151 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5152 }
5153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 final long identity = Binder.clearCallingIdentity();
5155 try {
5156 final Phone phone = getPhone(subId);
5157 if (phone == null) {
5158 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5159 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005160 return TelephonyProperties.lte_on_cdma_device()
5161 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 }
5163 } finally {
5164 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005165 }
Wink Saville36469e72014-06-11 15:17:00 -07005166 }
5167
Wink Saville36469e72014-06-11 15:17:00 -07005168 /**
5169 * {@hide}
5170 * Returns Default subId, 0 in the case of single standby.
5171 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005172 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005173 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005174 }
5175
Shishir Agrawala9f32182016-04-12 12:00:16 -07005176 private int getSlotForDefaultSubscription() {
5177 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5178 }
5179
Wink Savilleb564aae2014-10-23 10:18:09 -07005180 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005181 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005182 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005183
Pengquan Menge92a50d2018-09-21 15:54:48 -07005184 private boolean isActiveSubscription(int subId) {
5185 return mSubscriptionController.isActiveSubId(subId);
5186 }
5187
Ihab Awadf2177b72013-11-25 13:33:23 -08005188 /**
5189 * @see android.telephony.TelephonyManager.WifiCallingChoices
5190 */
5191 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 final long identity = Binder.clearCallingIdentity();
5193 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005194 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5196 getWhenToMakeWifiCallsDefaultPreference());
5197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005200 }
5201
5202 /**
5203 * @see android.telephony.TelephonyManager.WifiCallingChoices
5204 */
5205 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 final long identity = Binder.clearCallingIdentity();
5207 try {
5208 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005209 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005214 }
5215
Sailesh Nepald1e68152013-12-12 19:08:02 -08005216 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005217 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005218 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005219 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005220
Jordan Liu4c733742019-02-28 12:03:40 -08005221 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5222 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5223 if (phoneId == -1) {
5224 throw new IllegalArgumentException("Given slot index: " + slotIndex
5225 + " does not correspond to an active phone");
5226 }
5227 return PhoneFactory.getPhone(phoneId);
5228 }
5229
Shishir Agrawal566b7612013-10-28 14:41:00 -07005230 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005231 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5232 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5234 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005236 if (DBG) {
5237 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5238 }
5239 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5240 p2);
5241 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005242
Jordan Liu4c733742019-02-28 12:03:40 -08005243
5244 @Override
5245 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5246 int slotIndex, String callingPackage, String aid, int p2) {
5247 enforceModifyPermission();
5248 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5249 if (DBG) {
5250 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5251 }
5252 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5253 callingPackage, aid, p2);
5254 }
5255
5256 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5257 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 final long identity = Binder.clearCallingIdentity();
5259 try {
5260 if (TextUtils.equals(ISDR_AID, aid)) {
5261 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005262 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5263 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 if (bestComponent == null
5265 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5266 loge("The calling package is not allowed to access ISD-R.");
5267 throw new SecurityException(
5268 "The calling package is not allowed to access ISD-R.");
5269 }
Derek Tan740e1672017-06-27 14:56:27 -07005270 }
Derek Tan740e1672017-06-27 14:56:27 -07005271
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005273 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5274 null /* workSource */);
5275 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 return response;
5277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005280 }
5281
5282 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005283 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5285 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005286 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5287 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5288 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005289
Jordan Liu4c733742019-02-28 12:03:40 -08005290 @Override
5291 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5292 enforceModifyPermission();
5293 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5294 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5295 channel);
5296 }
5297
5298 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 final long identity = Binder.clearCallingIdentity();
5300 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 if (channel < 0) {
5302 return false;
5303 }
Jordan Liu4c733742019-02-28 12:03:40 -08005304 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5305 null /* workSource */);
5306 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 return success;
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005310 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005311 }
5312
5313 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005314 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005315 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5317 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005318 if (DBG) {
5319 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5320 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5321 + p3 + " data=" + data);
5322 }
5323 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5324 command, p1, p2, p3, data);
5325 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326
Jordan Liu4c733742019-02-28 12:03:40 -08005327 @Override
5328 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5329 int command, int p1, int p2, int p3, String data) {
5330 enforceModifyPermission();
5331 if (DBG) {
5332 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5333 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5334 + p3 + " data=" + data);
5335 }
5336 return iccTransmitApduLogicalChannelWithPermission(
5337 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5338 data);
5339 }
5340
5341 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5342 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 final long identity = Binder.clearCallingIdentity();
5344 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005345 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 return "";
5347 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005348
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005350 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5351 null /* workSource */);
5352 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 // Append the returned status code to the end of the response payload.
5355 String s = Integer.toHexString(
5356 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5357 if (response.payload != null) {
5358 s = IccUtils.bytesToHexString(response.payload) + s;
5359 }
5360 return s;
5361 } finally {
5362 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005363 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005364 }
Jake Hambye994d462014-02-03 13:10:13 -08005365
Evan Charltonc66da362014-05-16 14:06:40 -07005366 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005367 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5368 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5370 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005372 if (DBG) {
5373 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5374 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5375 }
5376 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5377 cla, command, p1, p2, p3, data);
5378 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005379
Jordan Liu4c733742019-02-28 12:03:40 -08005380 @Override
5381 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5382 int command, int p1, int p2, int p3, String data) {
5383 enforceModifyPermission();
5384 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5385 if (DBG) {
5386 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5387 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5388 + " data=" + data);
5389 }
5390
5391 return iccTransmitApduBasicChannelWithPermission(
5392 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5393 p2, p3, data);
5394 }
5395
5396 // open APDU basic channel assuming the caller has sufficient permissions
5397 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5398 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 final long identity = Binder.clearCallingIdentity();
5400 try {
5401 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5402 && TextUtils.equals(ISDR_AID, data)) {
5403 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005404 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5405 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 if (bestComponent == null
5407 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5408 loge("The calling package is not allowed to select ISD-R.");
5409 throw new SecurityException(
5410 "The calling package is not allowed to select ISD-R.");
5411 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005412 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005413
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005415 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5416 null /* workSource */);
5417 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 // Append the returned status code to the end of the response payload.
5420 String s = Integer.toHexString(
5421 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5422 if (response.payload != null) {
5423 s = IccUtils.bytesToHexString(response.payload) + s;
5424 }
5425 return s;
5426 } finally {
5427 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005428 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005429 }
5430
5431 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005432 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005433 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5435 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437 final long identity = Binder.clearCallingIdentity();
5438 try {
5439 if (DBG) {
5440 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5441 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5442 }
5443
5444 IccIoResult response =
5445 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5446 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5447 subId);
5448
5449 if (DBG) {
5450 log("Exchange SIM_IO [R]" + response);
5451 }
5452
5453 byte[] result = null;
5454 int length = 2;
5455 if (response.payload != null) {
5456 length = 2 + response.payload.length;
5457 result = new byte[length];
5458 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5459 } else {
5460 result = new byte[length];
5461 }
5462
5463 result[length - 1] = (byte) response.sw2;
5464 result[length - 2] = (byte) response.sw1;
5465 return result;
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005468 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005469 }
5470
Nathan Haroldb3014052017-01-25 15:57:32 -08005471 /**
5472 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5473 * on a particular subscription
5474 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005475 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5476 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005478 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005479 return null;
5480 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481
5482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 if (appType != TelephonyManager.APPTYPE_USIM
5485 && appType != TelephonyManager.APPTYPE_SIM) {
5486 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5487 return null;
5488 }
5489 Object response = sendRequest(
5490 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5491 if (response instanceof String[]) {
5492 return (String[]) response;
5493 }
yincheng zhao2737e882019-09-06 17:06:54 -07005494 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005496 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 } finally {
5498 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005499 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005500 }
5501
yincheng zhao2737e882019-09-06 17:06:54 -07005502 /**
5503 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5504 * subscription.
5505 *
5506 * @param subId the id of the subscription.
5507 * @param appType the uicc app type, must be USIM or SIM.
5508 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5509 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005510 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005511 * @return number of fplmns that is successfully written to the SIM.
5512 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005513 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5514 String callingFeatureId) {
5515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5516 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005517 if (DBG) logv("no permissions for setForbiddenplmns");
5518 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5519 }
5520 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5521 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5522 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5523 }
5524 if (fplmns == null) {
5525 throw new IllegalArgumentException("Fplmn List provided is null");
5526 }
5527 for (String fplmn : fplmns) {
5528 if (!CellIdentity.isValidPlmn(fplmn)) {
5529 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5530 }
5531 }
5532 final long identity = Binder.clearCallingIdentity();
5533 try {
5534 Object response = sendRequest(
5535 CMD_SET_FORBIDDEN_PLMNS,
5536 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5537 subId);
5538 return (int) response;
5539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
5542 }
5543
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005544 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005545 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5547 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 final long identity = Binder.clearCallingIdentity();
5550 try {
5551 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5552 if (response.payload == null) {
5553 return "";
5554 }
Evan Charltonc66da362014-05-16 14:06:40 -07005555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556 // Append the returned status code to the end of the response payload.
5557 String s = Integer.toHexString(
5558 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5559 s = IccUtils.bytesToHexString(response.payload) + s;
5560 return s;
5561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Evan Charltonc66da362014-05-16 14:06:40 -07005564 }
5565
Jake Hambye994d462014-02-03 13:10:13 -08005566 /**
5567 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5568 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5569 *
5570 * @param itemID the ID of the item to read
5571 * @return the NV item as a String, or null on error.
5572 */
5573 @Override
5574 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005575 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5577 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578
5579 final long identity = Binder.clearCallingIdentity();
5580 try {
5581 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005582 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5584 return value;
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
Jake Hambye994d462014-02-03 13:10:13 -08005588 }
5589
5590 /**
5591 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5592 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5593 *
5594 * @param itemID the ID of the item to read
5595 * @param itemValue the value to write, as a String
5596 * @return true on success; false on any failure
5597 */
5598 @Override
5599 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005600 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5607 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005608 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5610 return success;
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Jake Hambye994d462014-02-03 13:10:13 -08005614 }
5615
5616 /**
5617 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5618 * Used for device configuration by some CDMA operators.
5619 *
5620 * @param preferredRoamingList byte array containing the new PRL
5621 * @return true on success; false on any failure
5622 */
5623 @Override
5624 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5626 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005627
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5631 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5632 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5633 return success;
5634 } finally {
5635 Binder.restoreCallingIdentity(identity);
5636 }
Jake Hambye994d462014-02-03 13:10:13 -08005637 }
5638
5639 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005640 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005641 * Used for device configuration by some CDMA operators.
5642 *
chen xu6dac5ab2018-10-26 17:39:23 -07005643 * @param slotIndex - device slot.
5644 *
Jake Hambye994d462014-02-03 13:10:13 -08005645 * @return true on success; false on any failure
5646 */
5647 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005648 public boolean resetModemConfig(int slotIndex) {
5649 Phone phone = PhoneFactory.getPhone(slotIndex);
5650 if (phone != null) {
5651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5652 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653
chen xu6dac5ab2018-10-26 17:39:23 -07005654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5657 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5658 return success;
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662 }
chen xu6dac5ab2018-10-26 17:39:23 -07005663 return false;
5664 }
5665
5666 /**
5667 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5668 *
5669 * @param slotIndex - device slot.
5670 *
5671 * @return true on success; false on any failure
5672 */
5673 @Override
5674 public boolean rebootModem(int slotIndex) {
5675 Phone phone = PhoneFactory.getPhone(slotIndex);
5676 if (phone != null) {
5677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5678 mApp, phone.getSubId(), "rebootModem");
5679
5680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5683 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5684 return success;
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
5688 }
5689 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005690 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005691
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005692 public String[] getPcscfAddress(String apnType, String callingPackage,
5693 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005694 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5696 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005697 return new String[0];
5698 }
5699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 final long identity = Binder.clearCallingIdentity();
5701 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005702 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 } finally {
5704 Binder.restoreCallingIdentity(identity);
5705 }
Wink Saville36469e72014-06-11 15:17:00 -07005706 }
5707
Brad Ebinger51f743a2017-01-23 13:50:20 -08005708 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005709 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5710 * {@link #disableIms(int)}.
5711 * @param slotIndex device slot.
5712 */
5713 public void resetIms(int slotIndex) {
5714 enforceModifyPermission();
5715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 if (mImsResolver == null) {
5719 // may happen if the does not support IMS.
5720 return;
5721 }
5722 mImsResolver.disableIms(slotIndex);
5723 mImsResolver.enableIms(slotIndex);
5724 } finally {
5725 Binder.restoreCallingIdentity(identity);
5726 }
5727 }
5728
5729 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005730 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5731 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005732 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005733 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005734 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005738 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005739 // may happen if the device does not support IMS.
5740 return;
5741 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005746 }
5747
5748 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005749 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5750 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005751 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005752 public void disableIms(int slotId) {
5753 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005757 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005758 // may happen if the device does not support IMS.
5759 return;
5760 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005761 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005765 }
5766
5767 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005768 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5769 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005770 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005771 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005772 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005773 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005777 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005778 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5779 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005780 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005781 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 } finally {
5783 Binder.restoreCallingIdentity(identity);
5784 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005785 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005786 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005787 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5788 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005789 @Override
5790 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005791 enforceModifyPermission();
5792
5793 final long identity = Binder.clearCallingIdentity();
5794 try {
5795 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005796 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
5800 }
5801
5802 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005803 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005804 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005805 */
5806 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5807 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808
5809 final long identity = Binder.clearCallingIdentity();
5810 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005811 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005812 // may happen if the device does not support IMS.
5813 return null;
5814 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005815 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 } finally {
5817 Binder.restoreCallingIdentity(identity);
5818 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005819 }
5820
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005821 /**
5822 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005823 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005824 */
5825 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5826 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827
5828 final long identity = Binder.clearCallingIdentity();
5829 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005830 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005831 // may happen if the device does not support IMS.
5832 return null;
5833 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 } finally {
5836 Binder.restoreCallingIdentity(identity);
5837 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005838 }
5839
Brad Ebinger884c07b2018-02-15 16:17:40 -08005840 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005841 * Sets the ImsService Package Name that Telephony will bind to.
5842 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005843 * @param slotIndex the slot ID that the ImsService should bind for.
5844 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005845 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005846 * @param featureTypes An integer array of feature types associated with a packageName.
5847 * @param packageName The name of the package that the current configuration will be replaced
5848 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005849 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005850 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005851 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5852 int[] featureTypes, String packageName) {
5853 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5856 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005858
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 final long identity = Binder.clearCallingIdentity();
5860 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005861 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005862 // may happen if the device does not support IMS.
5863 return false;
5864 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005865 Map<Integer, String> featureConfig = new HashMap<>();
5866 for (int featureType : featureTypes) {
5867 featureConfig.put(featureType, packageName);
5868 }
5869 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5870 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 } finally {
5872 Binder.restoreCallingIdentity(identity);
5873 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005874 }
5875
5876 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005877 * Clears any carrier ImsService overrides for the slot index specified that were previously
5878 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5879 *
5880 * This should only be used for testing.
5881 *
5882 * @param slotIndex the slot ID that the ImsService should bind for.
5883 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5884 */
5885 @Override
5886 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5887 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5889 "clearCarrierImsServiceOverride");
5890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5891 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5892 "clearCarrierImsServiceOverride");
5893
5894 final long identity = Binder.clearCallingIdentity();
5895 try {
5896 if (mImsResolver == null) {
5897 // may happen if the device does not support IMS.
5898 return false;
5899 }
5900 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
5904 }
5905
5906 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005907 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005908 *
5909 * @param slotId The slot that the ImsService is associated with.
5910 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5911 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005912 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005913 * @return the package name of the ImsService configuration.
5914 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005915 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5916 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005917 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005918 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005919 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005920 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5921 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005922
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005923 final long identity = Binder.clearCallingIdentity();
5924 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005925 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005926 // may happen if the device does not support IMS.
5927 return "";
5928 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005929 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5931 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 } finally {
5933 Binder.restoreCallingIdentity(identity);
5934 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005935 }
5936
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005937 /**
5938 * Get the MmTelFeature state associated with the requested subscription id.
5939 * @param subId The subscription that the MmTelFeature is associated with.
5940 * @param callback A callback with an integer containing the
5941 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5942 */
5943 @Override
5944 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5945 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5946 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5947 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5948 "IMS not available on device.");
5949 }
5950 final long token = Binder.clearCallingIdentity();
5951 try {
5952 int slotId = getSlotIndex(subId);
5953 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5954 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5955 + subId + "'");
5956 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5957 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005958 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005959 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5960 try {
5961 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5962 } catch (RemoteException e) {
5963 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5964 + "Ignore");
5965 }
5966 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005967 } catch (ImsException e) {
5968 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005969 } finally {
5970 Binder.restoreCallingIdentity(token);
5971 }
5972 }
5973
Daniel Brightbb5840b2021-01-12 15:48:18 -08005974 /**
5975 * Sets the ims registration state on all valid {@link Phone}s.
5976 */
5977 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005978 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005979
5980 final long identity = Binder.clearCallingIdentity();
5981 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005982 // NOTE: Before S, this method only set the default phone.
5983 for (final Phone phone : PhoneFactory.getPhones()) {
5984 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5985 phone.setImsRegistrationState(registered);
5986 }
5987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
Wink Saville36469e72014-06-11 15:17:00 -07005991 }
5992
5993 /**
Stuart Scott54788802015-03-30 13:18:01 -07005994 * Set the network selection mode to automatic.
5995 *
5996 */
5997 @Override
5998 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6000 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001
6002 final long identity = Binder.clearCallingIdentity();
6003 try {
shilufc958392020-01-20 11:36:01 -08006004 if (!isActiveSubscription(subId)) {
6005 return;
6006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006008 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6009 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
Stuart Scott54788802015-03-30 13:18:01 -07006013 }
6014
Jack Yud10cdd42020-09-28 20:28:01 -07006015 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006016 * Ask the radio to connect to the input network and change selection mode to manual.
6017 *
6018 * @param subId the id of the subscription.
6019 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6020 * the operator to attach to.
6021 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6022 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6023 * normal network selection next time.
6024 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006025 */
6026 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006027 public boolean setNetworkSelectionModeManual(
6028 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6030 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006031
6032 if (!isActiveSubscription(subId)) {
6033 return false;
6034 }
6035
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 final long identity = Binder.clearCallingIdentity();
6037 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006038 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006040 if (DBG) {
6041 log("setNetworkSelectionModeManual: subId: " + subId
6042 + " operator: " + operatorInfo);
6043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6045 } finally {
6046 Binder.restoreCallingIdentity(identity);
6047 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006048 }
shilu84f6e8b2019-12-19 13:58:01 -08006049 /**
6050 * Get the manual network selection
6051 *
6052 * @param subId the id of the subscription.
6053 *
6054 * @return the previously saved user selected PLMN
6055 */
6056 @Override
6057 public String getManualNetworkSelectionPlmn(int subId) {
6058 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006059 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006060 mApp, subId, "getManualNetworkSelectionPlmn");
6061
6062 final long identity = Binder.clearCallingIdentity();
6063 try {
6064 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006065 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006066 }
6067
6068 final Phone phone = getPhone(subId);
6069 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006070 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006071 }
6072 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6073 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6074 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6075 } finally {
6076 Binder.restoreCallingIdentity(identity);
6077 }
6078 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006079
6080 /**
6081 * Scans for available networks.
6082 */
6083 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006084 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6085 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6087 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006088 LocationAccessPolicy.LocationPermissionResult locationResult =
6089 LocationAccessPolicy.checkLocationPermission(mApp,
6090 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6091 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006092 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006093 .setCallingPid(Binder.getCallingPid())
6094 .setCallingUid(Binder.getCallingUid())
6095 .setMethod("getCellNetworkScanResults")
6096 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006097 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6098 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006099 .build());
6100 switch (locationResult) {
6101 case DENIED_HARD:
6102 throw new SecurityException("Not allowed to access scan results -- location");
6103 case DENIED_SOFT:
6104 return null;
6105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106
Pengquan Menga1bb6272018-09-06 09:59:22 -07006107 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 try {
6109 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006110 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006115 }
6116
6117 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006118 * Get the call forwarding info, given the call forwarding reason.
6119 */
6120 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006121 public void getCallForwarding(int subId, int callForwardingReason,
6122 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006123 enforceReadPrivilegedPermission("getCallForwarding");
6124 long identity = Binder.clearCallingIdentity();
6125 try {
6126 if (DBG) {
6127 log("getCallForwarding: subId " + subId
6128 + " callForwardingReason" + callForwardingReason);
6129 }
Hall Liu27d24262020-09-18 19:04:59 -07006130
6131 Phone phone = getPhone(subId);
6132 if (phone == null) {
6133 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006134 callback.onError(
6135 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006136 } catch (RemoteException e) {
6137 // ignore
6138 }
6139 return;
6140 }
6141
6142 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6143 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6144 @Override
6145 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6146 try {
6147 callback.onCallForwardingInfoAvailable(info);
6148 } catch (RemoteException e) {
6149 // ignore
6150 }
6151 }
6152
6153 @Override
6154 public void onError(int error) {
6155 try {
6156 callback.onError(error);
6157 } catch (RemoteException e) {
6158 // ignore
6159 }
6160 }
6161 });
6162 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006163 } finally {
6164 Binder.restoreCallingIdentity(identity);
6165 }
6166 }
6167
6168 /**
6169 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6170 * reason, the number to forward, and the timeout before the forwarding is attempted.
6171 */
6172 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006173 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6174 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006175 enforceModifyPermission();
6176 long identity = Binder.clearCallingIdentity();
6177 try {
6178 if (DBG) {
6179 log("setCallForwarding: subId " + subId
6180 + " callForwardingInfo" + callForwardingInfo);
6181 }
Hall Liu27d24262020-09-18 19:04:59 -07006182
6183 Phone phone = getPhone(subId);
6184 if (phone == null) {
6185 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006186 callback.accept(
6187 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006188 } catch (RemoteException e) {
6189 // ignore
6190 }
6191 return;
6192 }
6193
6194 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6195 FunctionalUtils.ignoreRemoteException(callback::accept));
6196
6197 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006198 } finally {
6199 Binder.restoreCallingIdentity(identity);
6200 }
6201 }
6202
6203 /**
Hall Liu27d24262020-09-18 19:04:59 -07006204 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006205 */
6206 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006207 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006208 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006209 long identity = Binder.clearCallingIdentity();
6210 try {
Hall Liu27d24262020-09-18 19:04:59 -07006211 Phone phone = getPhone(subId);
6212 if (phone == null) {
6213 try {
6214 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6215 } catch (RemoteException e) {
6216 // ignore
6217 }
6218 return;
6219 }
SongFerngWang0e767992021-03-31 22:08:45 +08006220 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6221 PersistableBundle c = configManager.getConfigForSubId(subId);
6222 boolean requireUssd = c.getBoolean(
6223 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006224
Shuo Qian4a594052020-01-23 11:59:30 -08006225 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006226 if (requireUssd) {
6227 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6228 getSubscriptionCarrierId(subId));
6229 String newUssdCommand = "";
6230 try {
6231 newUssdCommand = carrierXmlParser.getFeature(
6232 CarrierXmlParser.FEATURE_CALL_WAITING)
6233 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6234 } catch (NullPointerException e) {
6235 loge("Failed to generate USSD number" + e);
6236 }
6237 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6238 mMainThreadHandler, callback, carrierXmlParser,
6239 CarrierXmlParser.SsEntry.SSAction.QUERY);
6240 final String ussdCommand = newUssdCommand;
6241 Executors.newSingleThreadExecutor().execute(() -> {
6242 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6243 });
6244 } else {
6245 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6246 callback::accept);
6247 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6248 }
Shuo Qian4a594052020-01-23 11:59:30 -08006249 } finally {
6250 Binder.restoreCallingIdentity(identity);
6251 }
6252 }
6253
6254 /**
Hall Liu27d24262020-09-18 19:04:59 -07006255 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006256 */
6257 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006258 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006259 enforceModifyPermission();
6260 long identity = Binder.clearCallingIdentity();
6261 try {
Hall Liu27d24262020-09-18 19:04:59 -07006262 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6263
6264 Phone phone = getPhone(subId);
6265 if (phone == null) {
6266 try {
6267 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6268 } catch (RemoteException e) {
6269 // ignore
6270 }
6271 return;
6272 }
6273
SongFerngWang0e767992021-03-31 22:08:45 +08006274 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6275 PersistableBundle c = configManager.getConfigForSubId(subId);
6276 boolean requireUssd = c.getBoolean(
6277 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006278
SongFerngWang0e767992021-03-31 22:08:45 +08006279 if (DBG) log("getCallWaitingStatus: subId " + subId);
6280 if (requireUssd) {
6281 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6282 getSubscriptionCarrierId(subId));
6283 CarrierXmlParser.SsEntry.SSAction ssAction =
6284 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6285 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6286 String newUssdCommand = "";
6287 try {
6288 newUssdCommand = carrierXmlParser.getFeature(
6289 CarrierXmlParser.FEATURE_CALL_WAITING)
6290 .makeCommand(ssAction, null);
6291 } catch (NullPointerException e) {
6292 loge("Failed to generate USSD number" + e);
6293 }
6294 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6295 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6296 final String ussdCommand = newUssdCommand;
6297 Executors.newSingleThreadExecutor().execute(() -> {
6298 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6299 });
6300 } else {
6301 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6302 FunctionalUtils.ignoreRemoteException(callback::accept));
6303
6304 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6305 }
Shuo Qian4a594052020-01-23 11:59:30 -08006306 } finally {
6307 Binder.restoreCallingIdentity(identity);
6308 }
6309 }
6310
6311 /**
yinxub1bed742017-04-17 11:45:04 -07006312 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006313 *
yinxub1bed742017-04-17 11:45:04 -07006314 * @param subId id of the subscription
6315 * @param request contains the radio access networks with bands/channels to scan
6316 * @param messenger callback messenger for scan results or errors
6317 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006318 * @return the id of the requested scan which can be used to stop the scan.
6319 */
6320 @Override
6321 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006322 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6324 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006325 LocationAccessPolicy.LocationPermissionResult locationResult =
6326 LocationAccessPolicy.checkLocationPermission(mApp,
6327 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6328 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006329 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006330 .setCallingPid(Binder.getCallingPid())
6331 .setCallingUid(Binder.getCallingUid())
6332 .setMethod("requestNetworkScan")
6333 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006334 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6335 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006336 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006337 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006338 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6339 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006340 if (e != null) {
6341 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6342 throw e;
6343 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006344 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006345 return TelephonyScanManager.INVALID_SCAN_ID;
6346 }
6347 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348 }
Hall Liu912dfd32019-04-25 14:02:26 -07006349 int callingUid = Binder.getCallingUid();
6350 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006351 final long identity = Binder.clearCallingIdentity();
6352 try {
6353 return mNetworkScanRequestTracker.startNetworkScan(
6354 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006355 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
yinxu504e1392017-04-12 16:03:22 -07006359 }
6360
Hall Liub2ac8ef2019-02-28 15:56:23 -08006361 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006362 NetworkScanRequest request, int subId, String callingPackage) {
6363 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006364 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6365 boolean hasNetworkScanPermission =
6366 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6367 == PERMISSION_GRANTED;
6368
6369 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6370 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6371 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006372 }
6373
6374 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6375 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006376 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6377 return new SecurityException("Specific channels must not be"
6378 + " scanned without location access.");
6379 }
6380 }
6381 }
6382
Hall Liub2ac8ef2019-02-28 15:56:23 -08006383 return null;
6384 }
6385
yinxu504e1392017-04-12 16:03:22 -07006386 /**
6387 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006388 *
6389 * @param subId id of the subscription
6390 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006391 */
6392 @Override
6393 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6395 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396
Hall Liu912dfd32019-04-25 14:02:26 -07006397 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398 final long identity = Binder.clearCallingIdentity();
6399 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006400 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
yinxu504e1392017-04-12 16:03:22 -07006404 }
6405
6406 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006407 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006408 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006409 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006410 */
6411 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006412 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006413 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006414 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006415 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416
6417 final long identity = Binder.clearCallingIdentity();
6418 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006419 if (DBG) log("getAllowedNetworkTypesBitmask");
6420 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6421 int networkTypesBitmask = (result != null ? result[0] : -1);
6422 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6423 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006427 }
6428
6429 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006430 * Get the allowed network types for certain reason.
6431 *
6432 * @param subId the id of the subscription.
6433 * @param reason the reason the allowed network type change is taking place
6434 * @return the allowed network types.
6435 */
6436 @Override
6437 public long getAllowedNetworkTypesForReason(int subId,
6438 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006439 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006440 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006441 final long identity = Binder.clearCallingIdentity();
6442 try {
6443 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6444 } finally {
6445 Binder.restoreCallingIdentity(identity);
6446 }
6447 }
6448
6449 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006450 * Enable/Disable E-UTRA-NR Dual Connectivity
6451 * @param subId subscription id of the sim card
6452 * @param nrDualConnectivityState expected NR dual connectivity state
6453 * This can be passed following states
6454 * <ol>
6455 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6456 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6457 * <li>Disable NR dual connectivity and force secondary cell to be released
6458 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6459 * </ol>
6460 * @return operation result.
6461 */
6462 @Override
6463 public int setNrDualConnectivityState(int subId,
6464 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6466 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006467 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006468 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6469 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6470 }
6471
Sooraj Sasindran37444802020-08-11 10:40:43 -07006472 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6476 nrDualConnectivityState, subId,
6477 workSource);
6478 if (DBG) log("enableNRDualConnectivity result: " + result);
6479 return result;
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
6483 }
6484
6485 /**
6486 * Is E-UTRA-NR Dual Connectivity enabled
6487 * @return true if dual connectivity is enabled else false
6488 */
6489 @Override
6490 public boolean isNrDualConnectivityEnabled(int subId) {
6491 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006492 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006493 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006494 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006495 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6496 return false;
6497 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006498 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6499 final long identity = Binder.clearCallingIdentity();
6500 try {
6501 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6502 null, subId, workSource);
6503 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6504 return isEnabled;
6505 } finally {
6506 Binder.restoreCallingIdentity(identity);
6507 }
6508 }
6509
6510 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006511 * Set the allowed network types of the device and
6512 * provide the reason triggering the allowed network change.
6513 *
6514 * @param subId the id of the subscription.
6515 * @param reason the reason the allowed network type change is taking place
6516 * @param allowedNetworkTypes the allowed network types.
6517 * @return true on success; false on any failure.
6518 */
6519 @Override
6520 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006521 @TelephonyManager.AllowedNetworkTypesReason int reason,
6522 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6524 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006525 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006526 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6527 return false;
6528 }
6529 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6530 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006531 return false;
6532 }
6533
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006534 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6535 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6536
6537
6538 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6539 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6540 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006541 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006542
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006543 final long identity = Binder.clearCallingIdentity();
6544 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 Boolean success = (Boolean) sendRequest(
6546 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6547 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6548
6549 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6550 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
6554 }
6555
6556 /**
Miaoa84611c2019-03-15 09:21:10 +08006557 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006558 *
Miaoa84611c2019-03-15 09:21:10 +08006559 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006560 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006561 * @hide
6562 */
6563 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006564 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006565 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006567 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 try {
Miaoa84611c2019-03-15 09:21:10 +08006569 if (phone != null) {
6570 return phone.hasMatchedTetherApnSetting();
6571 } else {
6572 return false;
6573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 } finally {
6575 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006576 }
Junda Liu475951f2014-11-07 16:45:03 -08006577 }
6578
6579 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006580 * Enable or disable always reporting signal strength changes from radio.
6581 *
6582 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6583 */
6584 @Override
6585 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6586 enforceModifyPermission();
6587 enforceSystemCaller();
6588
6589 final long identity = Binder.clearCallingIdentity();
6590 final Phone phone = getPhone(subId);
6591 try {
6592 if (phone != null) {
6593 if (DBG) {
6594 log("setAlwaysReportSignalStrength: subId=" + subId
6595 + " isEnable=" + isEnable);
6596 }
6597 phone.setAlwaysReportSignalStrength(isEnable);
6598 } else {
6599 loge("setAlwaysReportSignalStrength: no phone found for subId="
6600 + subId);
6601 }
6602 } finally {
6603 Binder.restoreCallingIdentity(identity);
6604 }
6605 }
6606
6607 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006608 * Get the user enabled state of Mobile Data.
6609 *
6610 * TODO: remove and use isUserDataEnabled.
6611 * This can't be removed now because some vendor codes
6612 * calls through ITelephony directly while they should
6613 * use TelephonyManager.
6614 *
6615 * @return true on enabled
6616 */
6617 @Override
6618 public boolean getDataEnabled(int subId) {
6619 return isUserDataEnabled(subId);
6620 }
6621
6622 /**
6623 * Get whether mobile data is enabled per user setting.
6624 *
6625 * There are other factors deciding whether mobile data is actually enabled, but they are
6626 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006627 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006628 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006629 *
6630 * @return {@code true} if data is enabled else {@code false}
6631 */
6632 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006633 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006634 try {
6635 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6636 null);
6637 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6639 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006640 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006641
6642 final long identity = Binder.clearCallingIdentity();
6643 try {
6644 int phoneId = mSubscriptionController.getPhoneId(subId);
6645 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6646 Phone phone = PhoneFactory.getPhone(phoneId);
6647 if (phone != null) {
6648 boolean retVal = phone.isUserDataEnabled();
6649 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6650 return retVal;
6651 } else {
6652 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6653 return false;
6654 }
6655 } finally {
6656 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006657 }
6658 }
6659
6660 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006661 * Checks if the device is capable of mobile data by considering whether whether the
6662 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6663 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006664 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006665 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006666 */
6667 @Override
6668 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006669 try {
6670 try {
6671 mApp.enforceCallingOrSelfPermission(
6672 android.Manifest.permission.ACCESS_NETWORK_STATE,
6673 null);
6674 } catch (Exception e) {
6675 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6676 "isDataEnabled");
6677 }
6678 } catch (Exception e) {
6679 enforceReadPrivilegedPermission("isDataEnabled");
6680 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681
6682 final long identity = Binder.clearCallingIdentity();
6683 try {
6684 int phoneId = mSubscriptionController.getPhoneId(subId);
6685 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6686 Phone phone = PhoneFactory.getPhone(phoneId);
6687 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006688 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6690 return retVal;
6691 } else {
6692 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6693 return false;
6694 }
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006697 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006698 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006699
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006700 /**
6701 * Check if data is enabled for a specific reason
6702 * @param subId Subscription index
6703 * @param reason the reason the data enable change is taking place
6704 * @return {@code true} if the overall data is enabled; {@code false} if not.
6705 */
6706 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006707 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006708 @TelephonyManager.DataEnabledReason int reason) {
6709 try {
6710 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6711 null);
6712 } catch (Exception e) {
6713 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006714 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 }
6716
6717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 int phoneId = mSubscriptionController.getPhoneId(subId);
6721 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006722 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006723 + " reason=" + reason);
6724 }
6725 Phone phone = PhoneFactory.getPhone(phoneId);
6726 if (phone != null) {
6727 boolean retVal;
6728 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6729 retVal = phone.isUserDataEnabled();
6730 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006731 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006732 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006733 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 return retVal;
6735 } else {
6736 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006737 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006738 + subId + " retVal=false");
6739 }
6740 return false;
6741 }
6742 } finally {
6743 Binder.restoreCallingIdentity(identity);
6744 }
6745 }
6746
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006747 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006748 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006749 if (uid == Process.PHONE_UID) {
6750 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6751 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6753 }
6754
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006755 //load access rules from carrier configs, and check those as well: b/139133814
6756 SubscriptionController subController = SubscriptionController.getInstance();
6757 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6758 || subController == null) return privilegeFromSim;
6759
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006760 PackageManager pkgMgr = phone.getContext().getPackageManager();
6761 String[] packages = pkgMgr.getPackagesForUid(uid);
6762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006765 int subId = phone.getSubId();
6766 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6767 // A test override is in place for the privileges for this subId, so don't try to
6768 // read the subscription privileges.
6769 return privilegeFromSim;
6770 }
6771 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006772 SubscriptionManager subManager = (SubscriptionManager)
6773 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6774 for (String pkg : packages) {
6775 if (subManager.canManageSubscription(subInfo, pkg)) {
6776 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6777 }
6778 }
6779 return privilegeFromSim;
6780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
6783 }
6784
6785 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6786 String pkgName) {
6787 //load access rules from carrier configs, and check those as well: b/139133814
6788 SubscriptionController subController = SubscriptionController.getInstance();
6789 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6790 || subController == null) return privilegeFromSim;
6791
6792 final long identity = Binder.clearCallingIdentity();
6793 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006794 int subId = phone.getSubId();
6795 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6796 // A test override is in place for the privileges for this subId, so don't try to
6797 // read the subscription privileges.
6798 return privilegeFromSim;
6799 }
6800 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006801 SubscriptionManager subManager = (SubscriptionManager)
6802 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6803 return subManager.canManageSubscription(subInfo, pkgName)
6804 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
6807 }
6808 }
6809
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006810 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006811 public int getCarrierPrivilegeStatus(int subId) {
6812 final Phone phone = getPhone(subId);
6813 if (phone == null) {
6814 loge("getCarrierPrivilegeStatus: Invalid subId");
6815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6816 }
6817 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006818 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006819 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006820 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6821 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006822
6823 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6824 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006825 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006826 }
Junda Liu29340342014-07-10 15:23:27 -07006827
6828 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006829 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006830 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006831 final Phone phone = getPhone(subId);
6832 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006833 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006834 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6835 }
6836 UiccProfile profile =
6837 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6838 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006839 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006840 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6841 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006842 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006843 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006844 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 }
6846
6847 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006848 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006849 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006850 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006851 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006852 }
6853
6854 int phoneId = SubscriptionManager.getPhoneId(subId);
6855 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006856 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006857 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006858 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6859 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006860 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6861 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6862 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006863 }
6864
6865 @Override
6866 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006867 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006868 if (TextUtils.isEmpty(pkgName))
6869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006870 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6871 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6872 UiccCard card = UiccController.getInstance().getUiccCard(i);
6873 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006874 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006875 continue;
6876 }
6877
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006878 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6879 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6880 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006881 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6882 break;
6883 }
6884 }
6885
6886 return result;
Junda Liu29340342014-07-10 15:23:27 -07006887 }
Derek Tan89e89d42014-07-08 17:00:10 -07006888
6889 @Override
Junda Liue64de782015-04-16 17:19:16 -07006890 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006891 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006892 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6893 loge("phoneId " + phoneId + " is not valid.");
6894 return null;
6895 }
6896 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006897 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006898 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006899 return null ;
6900 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006901 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006902 }
6903
Amith Yamasani6e118872016-02-19 12:53:51 -08006904 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006905 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006906 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006907 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006908 List<String> privilegedPackages = new ArrayList<>();
6909 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006910 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6911 // has UICC in that slot.
6912 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006913 if (card.hasCarrierPrivilegeRules()) {
6914 if (packages == null) {
6915 // Only check packages in user 0 for now
6916 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006917 PackageManager.MATCH_DISABLED_COMPONENTS
6918 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006919 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006920 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006921 }
6922 for (int p = packages.size() - 1; p >= 0; p--) {
6923 PackageInfo pkgInfo = packages.get(p);
6924 if (pkgInfo != null && pkgInfo.packageName != null
6925 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006926 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006927 privilegedPackages.add(pkgInfo.packageName);
6928 }
6929 }
6930 }
6931 }
6932 return privilegedPackages;
6933 }
6934
chen xuf7e9fe82019-05-09 19:31:02 -07006935 @Override
6936 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006937 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6938
6939 final long identity = Binder.clearCallingIdentity();
6940
chen xuf7e9fe82019-05-09 19:31:02 -07006941 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006942 try {
6943 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6944 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6945 }
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006948 }
6949 return privilegedPackages;
6950 }
6951
Wink Savilleb564aae2014-10-23 10:18:09 -07006952 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006953 final Phone phone = getPhone(subId);
6954 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006955 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006956 return null;
6957 }
6958 String iccId = card.getIccId();
6959 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006960 return null;
6961 }
6962 return iccId;
6963 }
6964
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006965 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006966 public void setCallComposerStatus(int subId, int status) {
6967 enforceModifyPermission();
6968
6969 final long identity = Binder.clearCallingIdentity();
6970 try {
6971 Phone phone = getPhone(subId);
6972 if (phone != null) {
6973 Phone defaultPhone = phone.getImsPhone();
6974 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6975 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6976 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006977 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6978 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006979 }
6980 }
Shuo Qian284ae752020-12-22 19:10:14 -08006981 } catch (ImsException e) {
6982 throw new ServiceSpecificException(e.getCode());
6983 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006984 Binder.restoreCallingIdentity(identity);
6985 }
6986 }
6987
6988 @Override
6989 public int getCallComposerStatus(int subId) {
6990 enforceReadPrivilegedPermission("getCallComposerStatus");
6991
6992 final long identity = Binder.clearCallingIdentity();
6993 try {
6994 Phone phone = getPhone(subId);
6995 if (phone != null) {
6996 Phone defaultPhone = phone.getImsPhone();
6997 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6998 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6999 return imsPhone.getCallComposerStatus();
7000 }
7001 }
7002 } finally {
7003 Binder.restoreCallingIdentity(identity);
7004 }
7005 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7006 }
7007
7008 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007009 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7010 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007011 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007012 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007013
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007014 final long identity = Binder.clearCallingIdentity();
7015 try {
7016 final String iccId = getIccId(subId);
7017 final Phone phone = getPhone(subId);
7018 if (phone == null) {
7019 return false;
7020 }
7021 final String subscriberId = phone.getSubscriberId();
7022
7023 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007024 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 + subscriberId + " to " + number);
7026 }
7027
7028 if (TextUtils.isEmpty(iccId)) {
7029 return false;
7030 }
7031
7032 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7033
7034 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7035 if (alphaTag == null) {
7036 editor.remove(alphaTagPrefKey);
7037 } else {
7038 editor.putString(alphaTagPrefKey, alphaTag);
7039 }
7040
7041 // Record both the line number and IMSI for this ICCID, since we need to
7042 // track all merged IMSIs based on line number
7043 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7044 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7045 if (number == null) {
7046 editor.remove(numberPrefKey);
7047 editor.remove(subscriberPrefKey);
7048 } else {
7049 editor.putString(numberPrefKey, number);
7050 editor.putString(subscriberPrefKey, subscriberId);
7051 }
7052
7053 editor.commit();
7054 return true;
7055 } finally {
7056 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007057 }
Derek Tan7226c842014-07-02 17:42:23 -07007058 }
7059
7060 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007061 public String getLine1NumberForDisplay(int subId, String callingPackage,
7062 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007063 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007065 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007066 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007067 return null;
7068 }
Derek Tan97ebb422014-09-05 16:55:38 -07007069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 final long identity = Binder.clearCallingIdentity();
7071 try {
7072 String iccId = getIccId(subId);
7073 if (iccId != null) {
7074 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7075 if (DBG_MERGE) {
7076 log("getLine1NumberForDisplay returning "
7077 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7078 }
7079 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7082 return null;
7083 } finally {
7084 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007085 }
Derek Tan7226c842014-07-02 17:42:23 -07007086 }
7087
7088 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007089 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7090 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007092 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007093 return null;
7094 }
Derek Tan97ebb422014-09-05 16:55:38 -07007095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 String iccId = getIccId(subId);
7099 if (iccId != null) {
7100 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7101 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7102 }
7103 return null;
7104 } finally {
7105 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007106 }
Derek Tan7226c842014-07-02 17:42:23 -07007107 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007108
7109 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007110 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7111 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007112 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7113 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007114 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007115 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007116 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007117 return null;
7118 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007119
Jordan Liub49b04b2019-05-06 14:45:15 -07007120 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7121 // the process, where TelephonyManager was instantiated.
7122 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007123 final long identity = Binder.clearCallingIdentity();
7124 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007125 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 final TelephonyManager tele = TelephonyManager.from(context);
7127 final SubscriptionManager sub = SubscriptionManager.from(context);
7128
7129 // Figure out what subscribers are currently active
7130 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131
Jordan Liub49b04b2019-05-06 14:45:15 -07007132 // Only consider subs which match the current subId
7133 // This logic can be simplified. See b/131189269 for progress.
7134 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007135 activeSubscriberIds.add(tele.getSubscriberId(subId));
7136 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137
7138 // First pass, find a number override for an active subscriber
7139 String mergeNumber = null;
7140 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7141 for (String key : prefs.keySet()) {
7142 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7143 final String subscriberId = (String) prefs.get(key);
7144 if (activeSubscriberIds.contains(subscriberId)) {
7145 final String iccId = key.substring(
7146 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7147 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7148 mergeNumber = (String) prefs.get(numberKey);
7149 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007150 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 + " for active subscriber " + subscriberId);
7152 }
7153 if (!TextUtils.isEmpty(mergeNumber)) {
7154 break;
7155 }
7156 }
7157 }
7158 }
7159
7160 // Shortcut when no active merged subscribers
7161 if (TextUtils.isEmpty(mergeNumber)) {
7162 return null;
7163 }
7164
7165 // Second pass, find all subscribers under that line override
7166 final ArraySet<String> result = new ArraySet<>();
7167 for (String key : prefs.keySet()) {
7168 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7169 final String number = (String) prefs.get(key);
7170 if (mergeNumber.equals(number)) {
7171 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7172 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7173 final String subscriberId = (String) prefs.get(subscriberKey);
7174 if (!TextUtils.isEmpty(subscriberId)) {
7175 result.add(subscriberId);
7176 }
7177 }
7178 }
7179 }
7180
7181 final String[] resultArray = result.toArray(new String[result.size()]);
7182 Arrays.sort(resultArray);
7183 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007184 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007185 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7186 }
7187 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007188 } finally {
7189 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007190 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007191 }
7192
7193 @Override
zoey chen38003472019-12-13 17:16:31 +08007194 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7195 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007196
7197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 final TelephonyManager telephonyManager = mApp.getSystemService(
7200 TelephonyManager.class);
7201 String subscriberId = telephonyManager.getSubscriberId(subId);
7202 if (subscriberId == null) {
7203 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007204 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007205 + subId);
7206 }
7207 return null;
7208 }
7209
7210 final SubscriptionInfo info = SubscriptionController.getInstance()
7211 .getSubscriptionInfo(subId);
7212 final ParcelUuid groupUuid = info.getGroupUuid();
7213 // If it doesn't belong to any group, return just subscriberId of itself.
7214 if (groupUuid == null) {
7215 return new String[]{subscriberId};
7216 }
7217
7218 // Get all subscriberIds from the group.
7219 final List<String> mergedSubscriberIds = new ArrayList<>();
7220 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007221 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007222 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007223 for (SubscriptionInfo subInfo : groupInfos) {
7224 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7225 if (subscriberId != null) {
7226 mergedSubscriberIds.add(subscriberId);
7227 }
7228 }
7229
7230 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7231 } finally {
7232 Binder.restoreCallingIdentity(identity);
7233
7234 }
7235 }
7236
7237 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007238 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007239 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007240 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007241
7242 final long identity = Binder.clearCallingIdentity();
7243 try {
7244 final Phone phone = getPhone(subId);
7245 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007249 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007250
7251 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007252 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007253 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7254 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007255 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7256 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257
7258 final long identity = Binder.clearCallingIdentity();
7259 try {
7260 final Phone phone = getPhone(subId);
7261 if (phone == null) {
7262 return false;
7263 }
7264 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7265 cdmaNonRoamingList);
7266 } finally {
7267 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007268 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007269 }
7270
7271 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007272 @Deprecated
7273 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7274 enforceModifyPermission();
7275
7276 int returnValue = 0;
7277 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007278 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007279 if(result.exception == null) {
7280 if (result.result != null) {
7281 byte[] responseData = (byte[])(result.result);
7282 if(responseData.length > oemResp.length) {
7283 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7284 responseData.length + "bytes. Buffer Size is " +
7285 oemResp.length + "bytes.");
7286 }
7287 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7288 returnValue = responseData.length;
7289 }
7290 } else {
7291 CommandException ex = (CommandException) result.exception;
7292 returnValue = ex.getCommandError().ordinal();
7293 if(returnValue > 0) returnValue *= -1;
7294 }
7295 } catch (RuntimeException e) {
7296 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7297 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7298 if(returnValue > 0) returnValue *= -1;
7299 }
7300
7301 return returnValue;
7302 }
7303
7304 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007305 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007306 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007307 try {
7308 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007309 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007310 mApp, phone.getSubId(), "getRadioAccessFamily");
7311 } catch (SecurityException e) {
7312 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7313 throw e;
7314 }
chen xub97461a2018-10-26 14:17:57 -07007315 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007316 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007317 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007318 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 final long identity = Binder.clearCallingIdentity();
7320 try {
chen xub97461a2018-10-26 14:17:57 -07007321 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007322 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007323 mApp, phone.getSubId(), "getRadioAccessFamily");
7324 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
chen xub97461a2018-10-26 14:17:57 -07007328 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007329 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007330
7331 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007332 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007333 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007334 try {
7335 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7336 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007337 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007338 }
7339 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007340 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007341 }
7342 RoleManager rm = mApp.getSystemService(RoleManager.class);
7343 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7344 if (!dialerRoleHolders.contains(callingPackage)) {
7345 throw new SecurityException("App must be the dialer role holder to"
7346 + " upload a call composer pic");
7347 }
7348
7349 Executors.newSingleThreadExecutor().execute(() -> {
7350 ByteArrayOutputStream output = new ByteArrayOutputStream(
7351 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7352 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7353 boolean readUntilEnd = false;
7354 int totalBytesRead = 0;
7355 byte[] buffer = new byte[16 * 1024];
7356 while (true) {
7357 int numRead;
7358 try {
7359 numRead = input.read(buffer);
7360 } catch (IOException e) {
7361 try {
7362 fd.checkError();
7363 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7364 null);
7365 } catch (IOException e1) {
7366 // This means that the other side closed explicitly with an error. If this
7367 // happens, log and ignore.
7368 loge("Remote end of call composer picture pipe closed: " + e1);
7369 }
7370 break;
7371 }
7372 if (numRead == -1) {
7373 readUntilEnd = true;
7374 break;
7375 }
7376 totalBytesRead += numRead;
7377 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7378 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7379 try {
7380 input.close();
7381 } catch (IOException e) {
7382 // ignore
7383 }
7384 break;
7385 }
7386 output.write(buffer, 0, numRead);
7387 }
7388 // Generally, the remote end will close the file descriptors. The only case where we
7389 // close is above, where the picture size is too big.
7390
7391 try {
7392 fd.checkError();
7393 } catch (IOException e) {
7394 loge("Remote end for call composer closed with an error: " + e);
7395 return;
7396 }
7397
Hall Liuaa4211e2021-01-20 15:43:39 -08007398 if (!readUntilEnd) {
7399 loge("Did not finish reading entire image; aborting");
7400 return;
7401 }
Hall Liu82694d52020-12-11 18:22:04 -08007402
Hall Liuaa4211e2021-01-20 15:43:39 -08007403 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7404 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7405 new CallComposerPictureTransfer.Factory() {},
7406 imageData,
7407 (result) -> {
7408 if (result.first != null) {
7409 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7410 Bundle outputResult = new Bundle();
7411 outputResult.putParcelable(
7412 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7413 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7414 outputResult);
7415 } else {
7416 callback.send(result.second, null);
7417 }
7418 }
7419 );
Hall Liu82694d52020-12-11 18:22:04 -08007420 });
7421 }
7422
7423 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007424 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007425 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007426 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427
7428 final long identity = Binder.clearCallingIdentity();
7429 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007430 ImsManager.getInstance(defaultPhone.getContext(),
7431 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 } finally {
7433 Binder.restoreCallingIdentity(identity);
7434 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007435 }
7436
7437 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007438 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007439 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7441 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007442 return false;
7443 }
Svet Ganovb320e182015-04-16 12:30:10 -07007444
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 final long identity = Binder.clearCallingIdentity();
7446 try {
7447 // Check the user preference and the system-level IMS setting. Even if the user has
7448 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7449 // In the long run, we may instead need to check if there exists a connection service
7450 // which can support video calling.
7451 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007452 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007453 return imsManager.isVtEnabledByPlatform()
7454 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7455 && imsManager.isVtEnabledByUser();
7456 } finally {
7457 Binder.restoreCallingIdentity(identity);
7458 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007459 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007460
Andrew Leea1239f22015-03-02 17:44:07 -08007461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007462 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7463 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007465 mApp, subId, callingPackage, callingFeatureId,
7466 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 return false;
7468 }
7469
7470 final long identity = Binder.clearCallingIdentity();
7471 try {
7472 CarrierConfigManager configManager =
7473 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007474 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478 }
Andrew Leea1239f22015-03-02 17:44:07 -08007479 }
7480
7481 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007482 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007484 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 return false;
7486 }
7487
7488 final long identity = Binder.clearCallingIdentity();
7489 try {
7490 CarrierConfigManager configManager =
7491 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007492 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
Andrew Leea1239f22015-03-02 17:44:07 -08007497 }
7498
Andrew Lee9431b832015-03-09 18:46:45 -07007499 @Override
7500 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007501 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007502 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007503 }
7504
7505 @Override
7506 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007507 final long identity = Binder.clearCallingIdentity();
7508 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007509 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
Andrew Lee9431b832015-03-09 18:46:45 -07007513 }
7514
Hall Liuf6668912018-10-31 17:05:23 -07007515 /**
7516 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7517 * support for the feature and device firmware support.
7518 *
7519 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7520 */
7521 @Override
7522 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007524 final Phone phone = getPhone(subscriptionId);
7525 if (phone == null) {
7526 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7527 return false;
7528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007530 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7532 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007533 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 return isCarrierSupported && isDeviceSupported;
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
Hall Liu98187582018-01-22 19:15:32 -08007538 }
7539
Hall Liuf6668912018-10-31 17:05:23 -07007540 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007541 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7542 * RTT setting, will return true if the device and carrier both support RTT.
7543 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007544 */
7545 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546 final long identity = Binder.clearCallingIdentity();
7547 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007548 boolean isRttSupported = isRttSupported(subscriptionId);
7549 boolean isUserRttSettingOn = Settings.Secure.getInt(
7550 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7551 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7552 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7553 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 } finally {
7555 Binder.restoreCallingIdentity(identity);
7556 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007557 }
7558
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007559 @Deprecated
7560 @Override
7561 public String getDeviceId(String callingPackage) {
7562 return getDeviceIdWithFeature(callingPackage, null);
7563 }
7564
Sanket Padawe7310cc72015-01-14 09:53:20 -08007565 /**
7566 * Returns the unique device ID of phone, for example, the IMEI for
7567 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7568 *
7569 * <p>Requires Permission:
7570 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7571 */
7572 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007573 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007574 try {
7575 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7576 } catch (SecurityException se) {
7577 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7578 throw new SecurityException("Package " + callingPackage + " does not belong to "
7579 + Binder.getCallingUid());
7580 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007581 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007582 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007583 return null;
7584 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007585 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007586 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007587 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007588 return null;
7589 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590
7591 final long identity = Binder.clearCallingIdentity();
7592 try {
7593 return phone.getDeviceId();
7594 } finally {
7595 Binder.restoreCallingIdentity(identity);
7596 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007597 }
7598
Ping Sunc67b7c22016-03-02 19:16:45 +08007599 /**
7600 * {@hide}
7601 * Returns the IMS Registration Status on a particular subid
7602 *
7603 * @param subId
7604 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007605 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007606 Phone phone = getPhone(subId);
7607 if (phone != null) {
7608 return phone.isImsRegistered();
7609 } else {
7610 return false;
7611 }
7612 }
7613
Santos Cordon7a1885b2015-02-03 11:15:19 -08007614 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007615 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007616 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007618 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007619 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7620 }
7621 final long identity = Binder.clearCallingIdentity();
7622 try {
7623 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7624 } finally {
7625 Binder.restoreCallingIdentity(identity);
7626 }
7627 }
7628
7629 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007630 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007631 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007632 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007633 mApp,
7634 subscriptionId,
7635 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007636 final long identity = Binder.clearCallingIdentity();
7637 try {
7638 Phone phone = getPhone(subscriptionId);
7639 if (phone == null) {
7640 return null;
7641 }
7642 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7643 } finally {
7644 Binder.restoreCallingIdentity(identity);
7645 }
7646 }
7647
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007648 /**
7649 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007650 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007651 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 Phone phone = getPhone(subId);
7655 if (phone != null) {
7656 return phone.isWifiCallingEnabled();
7657 } else {
7658 return false;
7659 }
7660 } finally {
7661 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007662 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007663 }
7664
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007665 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007666 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007667 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007668 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669 final long identity = Binder.clearCallingIdentity();
7670 try {
7671 Phone phone = getPhone(subId);
7672 if (phone != null) {
7673 return phone.isVideoEnabled();
7674 } else {
7675 return false;
7676 }
7677 } finally {
7678 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007679 }
7680 }
7681
7682 /**
7683 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7684 * defined in {@link ImsRegistrationImplBase}.
7685 */
7686 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 Phone phone = getPhone(subId);
7690 if (phone != null) {
7691 return phone.getImsRegistrationTech();
7692 } else {
7693 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7694 }
7695 } finally {
7696 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007697 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007698 }
7699
Stuart Scott8eef64f2015-04-08 15:13:54 -07007700 @Override
7701 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007702 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007703 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7704 return;
7705 }
Kai Shif70f46f2021-03-03 13:59:46 -08007706 Phone defaultPhone = getDefaultPhone();
7707 if (defaultPhone != null) {
7708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7709 mApp, getDefaultPhone().getSubId(), "factoryReset");
7710 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007711 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007712
Svet Ganovcc087f82015-05-12 20:35:54 -07007713 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007714 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7715 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007716 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007717 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007718 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007719 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007720 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007721 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007722 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007723 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007724 // There has been issues when Sms raw table somehow stores orphan
7725 // fragments. They lead to garbled message when new fragments come
7726 // in and combined with those stale ones. In case this happens again,
7727 // user can reset all network settings which will clean up this table.
7728 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007729 // Clean up IMS settings as well here.
7730 int slotId = getSlotIndex(subId);
7731 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7732 ImsManager.getInstance(mApp, slotId).factoryReset();
7733 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007734
Kai Shif70f46f2021-03-03 13:59:46 -08007735 if (defaultPhone == null) {
7736 return;
7737 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007738 // Erase modem config if erase modem on network setting is enabled.
7739 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7740 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7741 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007742 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007743 }
Kai Shif70f46f2021-03-03 13:59:46 -08007744
7745 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007746 } finally {
7747 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007748 }
7749 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007750
SongFerngWangfd89b102021-05-27 22:44:54 +08007751 @VisibleForTesting
7752 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7753 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7754 return;
7755 }
7756 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7757 RILConstants.PREFERRED_NETWORK_MODE);
7758 SubscriptionManager.setSubscriptionProperty(subId,
7759 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7760 "user=" + defaultNetworkType);
7761 phone.loadAllowedNetworksFromSubscriptionDatabase();
7762 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7763 defaultNetworkType, null);
7764 }
7765
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007766 private void cleanUpSmsRawTable(Context context) {
7767 ContentResolver resolver = context.getContentResolver();
7768 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7769 resolver.delete(uri, null, null);
7770 }
7771
Narayan Kamath1c496c22015-04-16 14:40:19 +01007772 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007773 public String getSimLocaleForSubscriber(int subId) {
7774 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7775 final Phone phone = getPhone(subId);
7776 if (phone == null) {
7777 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007778 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780 final long identity = Binder.clearCallingIdentity();
7781 try {
chen xu5d3637b2019-01-21 23:31:38 -08007782 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007783 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007784 if (info == null) {
7785 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7786 return null;
7787 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788 // Try and fetch the locale from the carrier properties or from the SIM language
7789 // preferences (EF-PL and EF-LI)...
7790 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007792 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7793 if (localeFromDefaultSim != null) {
7794 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7795 if (DBG) log("Using locale from subId: " + subId + " locale: "
7796 + localeFromDefaultSim);
7797 return localeFromDefaultSim.toLanguageTag();
7798 } else {
7799 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 }
7801 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007802
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 // The SIM language preferences only store a language (e.g. fr = French), not an
7804 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7805 // the SIM and carrier preferences does not include a country we add the country
7806 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007807 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007809 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 return mccLocale.toLanguageTag();
7811 }
7812
7813 if (DBG) log("No locale found - returning null");
7814 return null;
7815 } finally {
7816 Binder.restoreCallingIdentity(identity);
7817 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007818 }
7819
7820 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007821 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007822 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007823 }
7824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 /**
7826 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7827 */
7828 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007829 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007830 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007831 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007832
Chenjie Yu1ba97252018-01-11 18:16:20 -08007833 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007834 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007835
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007836 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007837 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7838 * representing the state of the modem.
7839 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007840 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7841 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007842 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007843 */
7844 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007845 public void requestModemActivityInfo(ResultReceiver result) {
7846 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007847 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007848
7849 final long identity = Binder.clearCallingIdentity();
7850 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007851 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007852 } finally {
7853 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007854 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007855 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007856
Siddharth Rayb8114062018-06-17 15:02:38 -07007857 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7858 // less than total activity duration.
7859 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7860 if (info == null) {
7861 return false;
7862 }
7863 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007864 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7865 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7866
Siddharth Rayb8114062018-06-17 15:02:38 -07007867 return (info.isValid()
7868 && (info.getSleepTimeMillis() <= activityDurationMs)
7869 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007870 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007871 && (totalTxTimeMs <= activityDurationMs));
7872 }
7873
Jack Yu85bd38a2015-11-09 11:34:32 -08007874 /**
7875 * {@hide}
7876 * Returns the service state information on specified subscription.
7877 */
7878 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007879 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7880 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007882 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007883 return null;
7884 }
7885
Hall Liuf19c44f2018-11-27 14:38:17 -08007886 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7887 LocationAccessPolicy.checkLocationPermission(mApp,
7888 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7889 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007890 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007891 .setCallingPid(Binder.getCallingPid())
7892 .setCallingUid(Binder.getCallingUid())
7893 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007894 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007895 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007896 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7897 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007898 .build());
7899
7900 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7901 LocationAccessPolicy.checkLocationPermission(mApp,
7902 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7903 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007904 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007905 .setCallingPid(Binder.getCallingPid())
7906 .setCallingUid(Binder.getCallingUid())
7907 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007908 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007909 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007910 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7911 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007912 .build());
7913 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7914 boolean hasFinePermission =
7915 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7916 boolean hasCoarsePermission =
7917 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7918
Jack Yu479f40e2020-10-27 21:29:25 -07007919 final Phone phone = getPhone(subId);
7920 if (phone == null) {
7921 return null;
7922 }
7923
Jordan Liu0f2bc442020-11-18 16:47:37 -08007924 final long identity = Binder.clearCallingIdentity();
7925
Jack Yu479f40e2020-10-27 21:29:25 -07007926 boolean isCallingPackageDataService = phone.getDataServicePackages()
7927 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007928 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007929 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7930 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7931 Rlog.d(LOG_TAG,
7932 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7933 return null;
7934 }
7935
Hall Liuf19c44f2018-11-27 14:38:17 -08007936 ServiceState ss = phone.getServiceState();
7937
7938 // Scrub out the location info in ServiceState depending on what level of access
7939 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007940 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007941 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7942 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943 } finally {
7944 Binder.restoreCallingIdentity(identity);
7945 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007946 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007947
7948 /**
7949 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7950 *
7951 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7952 * voicemail ringtone.
7953 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7954 * PhoneAccount.
7955 */
7956 @Override
7957 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 final long identity = Binder.clearCallingIdentity();
7959 try {
7960 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7961 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007962 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7966 } finally {
7967 Binder.restoreCallingIdentity(identity);
7968 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007969 }
7970
7971 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007972 * Sets the per-account voicemail ringtone.
7973 *
7974 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7975 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7976 *
7977 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7978 * voicemail ringtone.
7979 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7980 * PhoneAccount.
7981 */
7982 @Override
7983 public void setVoicemailRingtoneUri(String callingPackage,
7984 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007985 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007986 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007987 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7988 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7990 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7991 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993
7994 final long identity = Binder.clearCallingIdentity();
7995 try {
7996 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7997 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007998 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007999 }
8000 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8001 } finally {
8002 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008003 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008004 }
8005
8006 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008007 * Returns whether vibration is set for voicemail notification in Phone settings.
8008 *
8009 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8010 * voicemail vibration setting.
8011 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8012 */
8013 @Override
8014 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015 final long identity = Binder.clearCallingIdentity();
8016 try {
8017 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8018 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008019 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008020 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8023 } finally {
8024 Binder.restoreCallingIdentity(identity);
8025 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008026 }
8027
Youhan Wange64578a2016-05-02 15:32:42 -07008028 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008029 * Sets the per-account voicemail vibration.
8030 *
8031 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8032 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8033 *
8034 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8035 * voicemail vibration setting.
8036 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8037 * specific PhoneAccount.
8038 */
8039 @Override
8040 public void setVoicemailVibrationEnabled(String callingPackage,
8041 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008042 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008044 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8045 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8047 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8048 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008049 }
8050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 final long identity = Binder.clearCallingIdentity();
8052 try {
8053 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8054 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008055 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008056 }
8057 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008060 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008061 }
8062
8063 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008064 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8065 *
8066 * @throws SecurityException if the caller does not have the required permission
8067 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008068 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008069 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008070 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008071 }
8072
8073 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008074 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8075 * permission.
8076 *
8077 * @throws SecurityException if the caller does not have the required permission
8078 */
8079 private void enforceSendSmsPermission() {
8080 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8081 }
8082
8083 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008084 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008085 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008086 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008087 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008088 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008089 final long identity = Binder.clearCallingIdentity();
8090 try {
8091 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008092 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093 if (componentName == null) {
8094 throw new SecurityException(
8095 "Caller not current active visual voicemail package[null]");
8096 }
8097 String vvmPackage = componentName.getPackageName();
8098 if (!callingPackage.equals(vvmPackage)) {
8099 throw new SecurityException("Caller not current active visual voicemail package["
8100 + vvmPackage + "]");
8101 }
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008104 }
8105 }
8106
8107 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008108 * Return the application ID for the app type.
8109 *
8110 * @param subId the subscription ID that this request applies to.
8111 * @param appType the uicc app type.
8112 * @return Application ID for specificied app type, or null if no uicc.
8113 */
8114 @Override
8115 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008116 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008117 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008118
8119 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008120 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 if (phone == null) {
8122 return null;
8123 }
8124 String aid = null;
8125 try {
8126 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8127 .getApplicationByType(appType).getAid();
8128 } catch (Exception e) {
8129 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8130 }
8131 return aid;
8132 } finally {
8133 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008134 }
Youhan Wange64578a2016-05-02 15:32:42 -07008135 }
8136
Youhan Wang4001d252016-05-11 10:29:41 -07008137 /**
8138 * Return the Electronic Serial Number.
8139 *
8140 * @param subId the subscription ID that this request applies to.
8141 * @return ESN or null if error.
8142 */
8143 @Override
8144 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008145 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008146 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008147
8148 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008149 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 if (phone == null) {
8151 return null;
8152 }
8153 String esn = null;
8154 try {
8155 esn = phone.getEsn();
8156 } catch (Exception e) {
8157 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8158 }
8159 return esn;
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008162 }
Youhan Wang4001d252016-05-11 10:29:41 -07008163 }
8164
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008165 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008166 * Return the Preferred Roaming List Version.
8167 *
8168 * @param subId the subscription ID that this request applies to.
8169 * @return PRLVersion or null if error.
8170 */
8171 @Override
8172 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008173 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008174 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008175
8176 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008177 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178 if (phone == null) {
8179 return null;
8180 }
8181 String cdmaPrlVersion = null;
8182 try {
8183 cdmaPrlVersion = phone.getCdmaPrlVersion();
8184 } catch (Exception e) {
8185 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8186 }
8187 return cdmaPrlVersion;
8188 } finally {
8189 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008190 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008191 }
8192
8193 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008194 * Get snapshot of Telephony histograms
8195 * @return List of Telephony histograms
8196 * @hide
8197 */
8198 @Override
8199 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8201 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008202
8203 final long identity = Binder.clearCallingIdentity();
8204 try {
8205 return RIL.getTelephonyRILTimingHistograms();
8206 } finally {
8207 Binder.restoreCallingIdentity(identity);
8208 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008209 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008210
8211 /**
8212 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008213 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8214 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008215 * Require system privileges. In the future we may add this to carrier APIs.
8216 *
Michele Berionne482f8202018-11-27 18:57:59 -08008217 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008218 */
8219 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008220 @TelephonyManager.SetCarrierRestrictionResult
8221 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008222 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008223 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008224
Michele Berionne482f8202018-11-27 18:57:59 -08008225 if (carrierRestrictionRules == null) {
8226 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008227 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008229 final long identity = Binder.clearCallingIdentity();
8230 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008231 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008232 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 } finally {
8234 Binder.restoreCallingIdentity(identity);
8235 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008236 }
8237
8238 /**
8239 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008240 * Get the allowed carrier list and the excluded carrier list, including the priority between
8241 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008242 * Require system privileges. In the future we may add this to carrier APIs.
8243 *
Michele Berionne482f8202018-11-27 18:57:59 -08008244 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008245 */
8246 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008247 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008248 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008249 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250
8251 final long identity = Binder.clearCallingIdentity();
8252 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008253 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8254 if (response instanceof CarrierRestrictionRules) {
8255 return (CarrierRestrictionRules) response;
8256 }
8257 // Response is an Exception of some kind,
8258 // which is signalled to the user as a NULL retval
8259 return null;
8260 } catch (Exception e) {
8261 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8262 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008263 } finally {
8264 Binder.restoreCallingIdentity(identity);
8265 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008266 }
8267
fionaxu59545b42016-05-25 15:53:37 -07008268 /**
fionaxu59545b42016-05-25 15:53:37 -07008269 * Action set from carrier signalling broadcast receivers to enable/disable radio
8270 * @param subId the subscription ID that this action applies to.
8271 * @param enabled control enable or disable radio.
8272 * {@hide}
8273 */
8274 @Override
8275 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8276 enforceModifyPermission();
8277 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278
8279 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008280 if (phone == null) {
8281 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8282 return;
8283 }
8284 try {
8285 phone.carrierActionSetRadioEnabled(enabled);
8286 } catch (Exception e) {
8287 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288 } finally {
8289 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008290 }
8291 }
8292
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008293 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008294 * Enable or disable Voice over NR (VoNR)
8295 * @param subId the subscription ID that this action applies to.
8296 * @param enabled enable or disable VoNR.
8297 * @return operation result.
8298 */
8299 @Override
8300 public int setVoNrEnabled(int subId, boolean enabled) {
8301 enforceModifyPermission();
8302 final Phone phone = getPhone(subId);
8303
8304 final long identity = Binder.clearCallingIdentity();
8305 if (phone == null) {
8306 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8307 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8308 }
8309
8310 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8311 try {
8312 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8313 workSource);
8314 if (DBG) log("setVoNrEnabled result: " + result);
8315 return result;
8316 } finally {
8317 Binder.restoreCallingIdentity(identity);
8318 }
8319 }
8320
8321 /**
8322 * Is voice over NR enabled
8323 * @return true if VoNR is enabled else false
8324 */
8325 @Override
8326 public boolean isVoNrEnabled(int subId) {
8327 enforceReadPrivilegedPermission("isVoNrEnabled");
8328 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8329 final long identity = Binder.clearCallingIdentity();
8330 try {
8331 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8332 null, subId, workSource);
8333 if (DBG) log("isVoNrEnabled: " + isEnabled);
8334 return isEnabled;
8335 } finally {
8336 Binder.restoreCallingIdentity(identity);
8337 }
8338 }
8339
8340 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008341 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8342 * network status based on which carrier apps could apply actions accordingly,
8343 * enable/disable default url handler for example.
8344 *
8345 * @param subId the subscription ID that this action applies to.
8346 * @param report control start/stop reporting the default network status.
8347 * {@hide}
8348 */
8349 @Override
8350 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8351 enforceModifyPermission();
8352 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008353
8354 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008355 if (phone == null) {
8356 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8357 return;
8358 }
8359 try {
8360 phone.carrierActionReportDefaultNetworkStatus(report);
8361 } catch (Exception e) {
8362 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008363 } finally {
8364 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008365 }
8366 }
8367
8368 /**
fionaxud9622282017-07-17 17:51:30 -07008369 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8370 * @param subId the subscription ID that this action applies to.
8371 * {@hide}
8372 */
8373 @Override
8374 public void carrierActionResetAll(int subId) {
8375 enforceModifyPermission();
8376 final Phone phone = getPhone(subId);
8377 if (phone == null) {
8378 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8379 return;
8380 }
8381 try {
8382 phone.carrierActionResetAll();
8383 } catch (Exception e) {
8384 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8385 }
8386 }
8387
8388 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008389 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8390 * bug report is being generated.
8391 */
8392 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008393 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008394 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8395 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008396 writer.println("Permission Denial: can't dump Phone from pid="
8397 + Binder.getCallingPid()
8398 + ", uid=" + Binder.getCallingUid()
8399 + "without permission "
8400 + android.Manifest.permission.DUMP);
8401 return;
8402 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008403 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008404 }
Jack Yueb89b242016-06-22 13:27:47 -07008405
Brad Ebingerdac2f002018-04-03 15:17:52 -07008406 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008407 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8408 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8409 @NonNull String[] args) {
8410 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8411 this, in.getFileDescriptor(), out.getFileDescriptor(),
8412 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008413 }
8414
Jack Yueb89b242016-06-22 13:27:47 -07008415 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008416 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008417 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008418 * @param reason the reason the data enable change is taking place
8419 * @param enabled True if enabling the data, otherwise disabling.
8420 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008421 */
8422 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008423 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008424 boolean enabled) {
8425 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8426 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8427 try {
8428 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008429 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008430 } catch (SecurityException se) {
8431 enforceModifyPermission();
8432 }
8433 } else {
8434 enforceModifyPermission();
8435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008436
8437 final long identity = Binder.clearCallingIdentity();
8438 try {
8439 Phone phone = getPhone(subId);
8440 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008441 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8442 phone.carrierActionSetMeteredApnsEnabled(enabled);
8443 } else {
8444 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446 }
8447 } finally {
8448 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008449 }
8450 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008451
8452 /**
8453 * Get Client request stats
8454 * @return List of Client Request Stats
8455 * @hide
8456 */
8457 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008458 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8459 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008461 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008462 return null;
8463 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008464 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 final long identity = Binder.clearCallingIdentity();
8467 try {
8468 if (phone != null) {
8469 return phone.getClientRequestStats();
8470 }
8471
8472 return null;
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008476 }
8477
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008478 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008479 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008480 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008481 }
Jack Yueb4124c2017-02-16 15:32:43 -08008482
8483 /**
Grace Chen70990072017-03-24 17:21:30 -07008484 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008485 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008486 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008487 * @param state State of SIM (power down, power up, pass through)
8488 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8489 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8490 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008491 *
8492 **/
8493 @Override
Grace Chen70990072017-03-24 17:21:30 -07008494 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008495 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008496 Phone phone = PhoneFactory.getPhone(slotIndex);
8497
vagdeviaf9a5b92018-08-15 16:01:53 -07008498 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008503 phone.setSimPowerState(state, null, workSource);
8504 }
8505 } finally {
8506 Binder.restoreCallingIdentity(identity);
8507 }
8508 }
8509
8510 /**
8511 * Set SIM card power state.
8512 *
8513 * @param slotIndex SIM slot id.
8514 * @param state State of SIM (power down, power up, pass through)
8515 * @param callback callback to trigger after success or failure
8516 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8517 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8518 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8519 *
8520 **/
8521 @Override
8522 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8523 IIntegerConsumer callback) {
8524 enforceModifyPermission();
8525 Phone phone = PhoneFactory.getPhone(slotIndex);
8526
8527 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8528
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 if (phone != null) {
8532 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8533 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008534 }
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008537 }
8538 }
Shuo Qiandd210312017-04-12 22:11:33 +00008539
Tyler Gunn65d45c22017-06-05 11:22:26 -07008540 private boolean isUssdApiAllowed(int subId) {
8541 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008542 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008543 if (configManager == null) {
8544 return false;
8545 }
8546 PersistableBundle pb = configManager.getConfigForSubId(subId);
8547 if (pb == null) {
8548 return false;
8549 }
8550 return pb.getBoolean(
8551 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8552 }
8553
Shuo Qiandd210312017-04-12 22:11:33 +00008554 /**
8555 * Check if phone is in emergency callback mode
8556 * @return true if phone is in emergency callback mode
8557 * @param subId sub id
8558 */
goneil9c5f4872017-12-05 14:07:56 -08008559 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008560 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008561 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008562 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563
8564 final long identity = Binder.clearCallingIdentity();
8565 try {
8566 if (phone != null) {
8567 return phone.isInEcm();
8568 } else {
8569 return false;
8570 }
8571 } finally {
8572 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008573 }
8574 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008575
8576 /**
8577 * Get the current signal strength information for the given subscription.
8578 * Because this information is not updated when the device is in a low power state
8579 * it should not be relied-upon to be current.
8580 * @param subId Subscription index
8581 * @return the most recent cached signal strength info from the modem
8582 */
8583 @Override
8584 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008585 final long identity = Binder.clearCallingIdentity();
8586 try {
8587 Phone p = getPhone(subId);
8588 if (p == null) {
8589 return null;
8590 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008592 return p.getSignalStrength();
8593 } finally {
8594 Binder.restoreCallingIdentity(identity);
8595 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008596 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008597
Pengquan Meng77b7f132018-08-22 14:49:57 -07008598 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008599 * Get the current modem radio state for the given slot.
8600 * @param slotIndex slot index.
8601 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008602 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008603 * @return the current radio power state from the modem
8604 */
8605 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008606 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008607 Phone phone = PhoneFactory.getPhone(slotIndex);
8608 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8610 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008611 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8612 }
8613
8614 final long identity = Binder.clearCallingIdentity();
8615 try {
8616 return phone.getRadioPowerState();
8617 } finally {
8618 Binder.restoreCallingIdentity(identity);
8619 }
8620 }
8621 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8622 }
8623
8624 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008625 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8626 *
8627 * <p>Requires one of the following permissions:
8628 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8629 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8630 * privileges.
8631 *
8632 * @param subId subscription id
8633 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8634 * {@code false}.
8635 */
8636 @Override
8637 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008638 try {
8639 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8640 null);
8641 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008642 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008643 mApp, subId, "isDataRoamingEnabled");
8644 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008645
Pengquan Menga1bb6272018-09-06 09:59:22 -07008646 boolean isEnabled = false;
8647 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008648 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008649 Phone phone = getPhone(subId);
8650 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008651 } finally {
8652 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008653 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008654 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008655 }
8656
8657
8658 /**
8659 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8660 *
8661 * <p> Requires permission:
8662 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8663 * privileges.
8664 *
8665 * @param subId subscription id
8666 * @param isEnabled {@code true} means enable, {@code false} means disable.
8667 */
8668 @Override
8669 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8671 mApp, subId, "setDataRoamingEnabled");
8672
Pengquan Menga1bb6272018-09-06 09:59:22 -07008673 final long identity = Binder.clearCallingIdentity();
8674 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008675 Phone phone = getPhone(subId);
8676 if (phone != null) {
8677 phone.setDataRoamingEnabled(isEnabled);
8678 }
8679 } finally {
8680 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008681 }
8682 }
8683
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008684 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008685 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008686 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008687 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008688 mApp, subId, "isManualNetworkSelectionAllowed");
8689
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008690 boolean isAllowed = true;
8691 final long identity = Binder.clearCallingIdentity();
8692 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008693 Phone phone = getPhone(subId);
8694 if (phone != null) {
8695 isAllowed = phone.isCspPlmnEnabled();
8696 }
8697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 return isAllowed;
8701 }
8702
8703 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008704 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008705 // Verify that tha callingPackage belongs to the calling UID
8706 mApp.getSystemService(AppOpsManager.class)
8707 .checkPackage(Binder.getCallingUid(), callingPackage);
8708
Jordan Liu1e142fc2019-04-22 15:10:43 -07008709 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008710 try {
8711 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008712 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008713 } catch (SecurityException e) {
8714 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8715 // has carrier privileges on an active UICC
8716 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8717 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008718 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008719 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008720 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008721
8722 final long identity = Binder.clearCallingIdentity();
8723 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008724 UiccController uiccController = UiccController.getInstance();
8725 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008726 if (hasReadPermission) {
8727 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008728 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008729
8730 // Remove private info if the caller doesn't have access
8731 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8732 for (UiccCardInfo cardInfo : cardInfos) {
8733 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8734 // is available
8735 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8736 if (card == null || card.getUiccProfile() == null) {
8737 // assume no access if the card or profile is unavailable
8738 filteredInfos.add(cardInfo.getUnprivileged());
8739 continue;
8740 }
8741 UiccProfile profile = card.getUiccProfile();
8742 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8743 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8744 filteredInfos.add(cardInfo);
8745 } else {
8746 filteredInfos.add(cardInfo.getUnprivileged());
8747 }
8748 }
8749 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008750 } finally {
8751 Binder.restoreCallingIdentity(identity);
8752 }
8753 }
8754
8755 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008756 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008757 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008759 final long identity = Binder.clearCallingIdentity();
8760 try {
8761 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8762 if (slots == null) {
8763 Rlog.i(LOG_TAG, "slots is null.");
8764 return null;
8765 }
8766
8767 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8768 for (int i = 0; i < slots.length; i++) {
8769 UiccSlot slot = slots[i];
8770 if (slot == null) {
8771 continue;
8772 }
8773
Jordan Liu7be7e652019-05-06 18:55:02 +00008774 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008775 UiccCard card = slot.getUiccCard();
8776 if (card != null) {
8777 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008778 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008779 cardId = slot.getEid();
8780 if (TextUtils.isEmpty(cardId)) {
8781 cardId = slot.getIccId();
8782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008783 }
8784
Jordan Liu857451f2019-05-09 16:35:35 -07008785 if (cardId != null) {
8786 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8787 // if cardId is an EID, it's all digits so this is fine
8788 cardId = IccUtils.stripTrailingFs(cardId);
8789 }
8790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008791 int cardState = 0;
8792 switch (slot.getCardState()) {
8793 case CARDSTATE_ABSENT:
8794 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8795 break;
8796 case CARDSTATE_PRESENT:
8797 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8798 break;
8799 case CARDSTATE_ERROR:
8800 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8801 break;
8802 case CARDSTATE_RESTRICTED:
8803 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8804 break;
8805 default:
8806 break;
8807
8808 }
8809
8810 infos[i] = new UiccSlotInfo(
8811 slot.isActive(),
8812 slot.isEuicc(),
8813 cardId,
8814 cardState,
8815 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008816 slot.isExtendedApduSupported(),
8817 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008818 }
8819 return infos;
8820 } finally {
8821 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008822 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008823 }
8824
8825 @Override
8826 public boolean switchSlots(int[] physicalSlots) {
8827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008828
8829 final long identity = Binder.clearCallingIdentity();
8830 try {
8831 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8832 } finally {
8833 Binder.restoreCallingIdentity(identity);
8834 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008835 }
Jack Yu4c988042018-02-27 15:30:01 -08008836
8837 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008838 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008839 final long identity = Binder.clearCallingIdentity();
8840 try {
8841 return UiccController.getInstance().getCardIdForDefaultEuicc();
8842 } finally {
8843 Binder.restoreCallingIdentity(identity);
8844 }
8845 }
8846
Pengquan Meng85728fb2018-03-12 16:31:21 -07008847 /**
goneil47ffb6e2018-04-06 15:40:58 -07008848 * A test API to reload the UICC profile.
8849 *
8850 * <p>Requires that the calling app has permission
8851 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8852 * @hide
8853 */
8854 @Override
8855 public void refreshUiccProfile(int subId) {
8856 enforceModifyPermission();
8857
8858 final long identity = Binder.clearCallingIdentity();
8859 try {
8860 Phone phone = getPhone(subId);
8861 if (phone == null) {
8862 return;
8863 }
8864 UiccCard uiccCard = phone.getUiccCard();
8865 if (uiccCard == null) {
8866 return;
8867 }
8868 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8869 if (uiccProfile == null) {
8870 return;
8871 }
8872 uiccProfile.refresh();
8873 } finally {
8874 Binder.restoreCallingIdentity(identity);
8875 }
8876 }
8877
8878 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008879 * Returns false if the mobile data is disabled by default, otherwise return true.
8880 */
8881 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008882 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008883 }
8884
8885 /**
8886 * Returns true if the data roaming is enabled by default, i.e the system property
8887 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8888 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8889 */
8890 private boolean getDefaultDataRoamingEnabled(int subId) {
8891 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008892 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008893 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008894 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8895 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8896 return isDataRoamingEnabled;
8897 }
8898
8899 /**
8900 * Returns the default network type for the given {@code subId}, if the default network type is
8901 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8902 */
8903 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008904 List<Integer> list = TelephonyProperties.default_network();
8905 int phoneId = mSubscriptionController.getPhoneId(subId);
8906 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8907 return list.get(phoneId);
8908 }
8909 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008910 }
fionaxua13278b2018-03-21 00:08:13 -07008911
8912 @Override
8913 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008914 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008915 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008916
8917 final long identity = Binder.clearCallingIdentity();
8918 try {
8919 final Phone phone = getPhone(subId);
8920 if (phone == null) {
8921 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8922 return;
8923 }
chen xueaba88a2019-03-15 13:15:10 -07008924 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8925 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008926 if (carrierPrivilegeRules == null) {
8927 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8928 } else {
8929 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008931 } finally {
8932 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008933 }
fionaxua13278b2018-03-21 00:08:13 -07008934 }
8935
8936 @Override
8937 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008938 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008939
8940 final long identity = Binder.clearCallingIdentity();
8941 try {
8942 final Phone phone = getPhone(subId);
8943 if (phone == null) {
8944 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8945 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8946 }
8947 return phone.getCarrierIdListVersion();
8948 } finally {
8949 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008950 }
fionaxua13278b2018-03-21 00:08:13 -07008951 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008952
8953 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008954 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8955 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008957 mApp, subId, callingPackage, callingFeatureId,
8958 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008959 return -1;
8960 }
8961
8962 final long identity = Binder.clearCallingIdentity();
8963 try {
8964 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8965 } finally {
8966 Binder.restoreCallingIdentity(identity);
8967 }
8968 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008969
8970 @Override
8971 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008972 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008973 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008974 mApp, subId, "getCdmaRoamingMode");
8975
8976 final long identity = Binder.clearCallingIdentity();
8977 try {
8978 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8979 } finally {
8980 Binder.restoreCallingIdentity(identity);
8981 }
8982 }
8983
8984 @Override
8985 public boolean setCdmaRoamingMode(int subId, int mode) {
8986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8987 mApp, subId, "setCdmaRoamingMode");
8988
8989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8992 } finally {
8993 Binder.restoreCallingIdentity(identity);
8994 }
8995 }
8996
8997 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008998 public int getCdmaSubscriptionMode(int subId) {
8999 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009000 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009001 mApp, subId, "getCdmaSubscriptionMode");
9002
9003 final long identity = Binder.clearCallingIdentity();
9004 try {
9005 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9006 } finally {
9007 Binder.restoreCallingIdentity(identity);
9008 }
9009 }
9010
9011 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009012 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9014 mApp, subId, "setCdmaSubscriptionMode");
9015
9016 final long identity = Binder.clearCallingIdentity();
9017 try {
9018 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9019 } finally {
9020 Binder.restoreCallingIdentity(identity);
9021 }
9022 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009023
sqianc5eccab2018-10-19 18:46:41 -07009024 @Override
sqian8c685422019-02-22 15:55:18 -08009025 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009026 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009027 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009028 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9029 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009030 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9031 }
9032 final long identity = Binder.clearCallingIdentity();
9033 try {
sqian854d44b2018-12-12 16:48:18 -08009034 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9035 for (Phone phone: PhoneFactory.getPhones()) {
9036 if (phone.getEmergencyNumberTracker() != null
9037 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9038 emergencyNumberListInternal.put(
9039 phone.getSubId(),
9040 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9041 }
sqian11b7a0e2018-12-05 18:48:28 -08009042 }
sqian854d44b2018-12-12 16:48:18 -08009043 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009044 } finally {
9045 Binder.restoreCallingIdentity(identity);
9046 }
sqianc5eccab2018-10-19 18:46:41 -07009047 }
9048
9049 @Override
sqian8c685422019-02-22 15:55:18 -08009050 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009051 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009052 if (!exactMatch) {
9053 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009054 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009055 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009056 }
9057 final long identity = Binder.clearCallingIdentity();
9058 try {
sqian854d44b2018-12-12 16:48:18 -08009059 for (Phone phone: PhoneFactory.getPhones()) {
9060 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009061 && phone.getEmergencyNumberTracker()
9062 .isEmergencyNumber(number, exactMatch)) {
9063 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009064 }
sqian11b7a0e2018-12-05 18:48:28 -08009065 }
9066 return false;
9067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
9071
sqianf4ca7ed2019-01-15 18:32:07 -08009072 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009073 * Start emergency callback mode for GsmCdmaPhone for testing.
9074 */
9075 @Override
9076 public void startEmergencyCallbackMode() {
9077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9078 "startEmergencyCallbackMode");
9079 enforceModifyPermission();
9080 final long identity = Binder.clearCallingIdentity();
9081 try {
9082 for (Phone phone : PhoneFactory.getPhones()) {
9083 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9084 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9085 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9086 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9087 gsmCdmaPhone.obtainMessage(
9088 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9089 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9090 }
9091 }
9092 } finally {
9093 Binder.restoreCallingIdentity(identity);
9094 }
9095 }
9096
9097 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009098 * Update emergency number list for test mode.
9099 */
9100 @Override
9101 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9102 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9103 "updateEmergencyNumberListTestMode");
9104
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
9107 for (Phone phone: PhoneFactory.getPhones()) {
9108 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9109 if (tracker != null) {
9110 tracker.executeEmergencyNumberTestModeCommand(action, num);
9111 }
9112 }
9113 } finally {
9114 Binder.restoreCallingIdentity(identity);
9115 }
9116 }
9117
9118 /**
9119 * Get the full emergency number list for test mode.
9120 */
9121 @Override
9122 public List<String> getEmergencyNumberListTestMode() {
9123 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9124 "getEmergencyNumberListTestMode");
9125
9126 final long identity = Binder.clearCallingIdentity();
9127 try {
9128 Set<String> emergencyNumbers = new HashSet<>();
9129 for (Phone phone: PhoneFactory.getPhones()) {
9130 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9131 if (tracker != null) {
9132 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9133 emergencyNumbers.add(num.getNumber());
9134 }
9135 }
9136 }
9137 return new ArrayList<>(emergencyNumbers);
9138 } finally {
9139 Binder.restoreCallingIdentity(identity);
9140 }
9141 }
9142
chen xud6b45bd2018-10-30 22:27:10 -07009143 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009144 public int getEmergencyNumberDbVersion(int subId) {
9145 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9146
9147 final long identity = Binder.clearCallingIdentity();
9148 try {
9149 final Phone phone = getPhone(subId);
9150 if (phone == null) {
9151 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9152 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9153 }
9154 return phone.getEmergencyNumberDbVersion();
9155 } finally {
9156 Binder.restoreCallingIdentity(identity);
9157 }
9158 }
9159
9160 @Override
9161 public void notifyOtaEmergencyNumberDbInstalled() {
9162 enforceModifyPermission();
9163
9164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 for (Phone phone: PhoneFactory.getPhones()) {
9167 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9168 if (tracker != null) {
9169 tracker.updateOtaEmergencyNumberDatabase();
9170 }
9171 }
9172 } finally {
9173 Binder.restoreCallingIdentity(identity);
9174 }
9175 }
9176
9177 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009178 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009179 enforceActiveEmergencySessionPermission();
9180
9181 final long identity = Binder.clearCallingIdentity();
9182 try {
9183 for (Phone phone: PhoneFactory.getPhones()) {
9184 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9185 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009186 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9187 }
9188 }
9189 } finally {
9190 Binder.restoreCallingIdentity(identity);
9191 }
9192 }
9193
9194 @Override
9195 public void resetOtaEmergencyNumberDbFilePath() {
9196 enforceActiveEmergencySessionPermission();
9197
9198 final long identity = Binder.clearCallingIdentity();
9199 try {
9200 for (Phone phone: PhoneFactory.getPhones()) {
9201 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9202 if (tracker != null) {
9203 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009204 }
9205 }
9206 } finally {
9207 Binder.restoreCallingIdentity(identity);
9208 }
9209 }
9210
9211 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009212 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9213 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9214 Phone phone = getPhone(subId);
9215 if (phone == null) {
9216 return null;
9217 }
9218 final long identity = Binder.clearCallingIdentity();
9219 try {
9220 UiccProfile profile = UiccController.getInstance()
9221 .getUiccProfileForPhone(phone.getPhoneId());
9222 if (profile != null) {
9223 return profile.getCertsFromCarrierPrivilegeAccessRules();
9224 }
9225 } finally {
9226 Binder.restoreCallingIdentity(identity);
9227 }
9228 return null;
9229 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009230
9231 /**
9232 * Enable or disable a modem stack.
9233 */
9234 @Override
9235 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9236 enforceModifyPermission();
9237
9238 final long identity = Binder.clearCallingIdentity();
9239 try {
9240 Phone phone = PhoneFactory.getPhone(slotIndex);
9241 if (phone == null) {
9242 return false;
9243 } else {
9244 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9245 }
9246 } finally {
9247 Binder.restoreCallingIdentity(identity);
9248 }
9249 }
Michelecea4cf22018-12-21 15:00:11 -08009250
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009251 /**
9252 * Whether a modem stack is enabled or not.
9253 */
9254 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009255 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9256 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009257 Phone phone = PhoneFactory.getPhone(slotIndex);
9258 if (phone == null) return false;
9259
9260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009261 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9262 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009263 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9264 }
9265
9266 final long identity = Binder.clearCallingIdentity();
9267 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009268 try {
9269 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9270 } catch (NoSuchElementException ex) {
9271 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9272 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009273 } finally {
9274 Binder.restoreCallingIdentity(identity);
9275 }
9276 }
9277
Michelecea4cf22018-12-21 15:00:11 -08009278 @Override
Michele0ea7d782019-03-19 14:58:42 -07009279 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009280 enforceModifyPermission();
9281
9282 final long identity = Binder.clearCallingIdentity();
9283 try {
9284 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009285 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009286 .commit();
9287 } finally {
9288 Binder.restoreCallingIdentity(identity);
9289 }
9290 }
9291
9292 @Override
Michele0ea7d782019-03-19 14:58:42 -07009293 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009294 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009296 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9297 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009298 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009299 }
Michelecea4cf22018-12-21 15:00:11 -08009300
9301 final long identity = Binder.clearCallingIdentity();
9302 try {
Michele0ea7d782019-03-19 14:58:42 -07009303 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009308
Michele0ea7d782019-03-19 14:58:42 -07009309 @TelephonyManager.IsMultiSimSupportedResult
9310 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009311 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9312 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9313 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009314 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9315 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009316 }
9317 // Check if the hardware supports multisim functionality. If usage of multisim is not
9318 // supported by the modem, indicate that it is restricted.
9319 PhoneCapability staticCapability =
9320 mPhoneConfigurationManager.getStaticPhoneCapability();
9321 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009322 loge("isMultiSimSupportedInternal: no static configuration available");
9323 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009324 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009325 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009326 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9327 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009328 }
9329 // Check if support of multiple SIMs is restricted by carrier
9330 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009331 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009332 }
9333
Michele0ea7d782019-03-19 14:58:42 -07009334 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009335 }
9336
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009337 /**
9338 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009339 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9340 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9341 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009342 * @param numOfSims number of active sims we want to switch to
9343 */
9344 @Override
9345 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009346 if (numOfSims == 1) {
9347 enforceModifyPermission();
9348 } else {
9349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9350 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9351 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009352 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009353
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009354 try {
Michele30b57b22019-03-01 12:01:14 -08009355 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009356 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009357 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9358 return;
9359 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009360 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9361 } finally {
9362 Binder.restoreCallingIdentity(identity);
9363 }
9364 }
9365
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009366 @Override
9367 public boolean isApplicationOnUicc(int subId, int appType) {
9368 enforceReadPrivilegedPermission("isApplicationOnUicc");
9369 Phone phone = getPhone(subId);
9370 if (phone == null) {
9371 return false;
9372 }
9373 final long identity = Binder.clearCallingIdentity();
9374 try {
9375 UiccCard uiccCard = phone.getUiccCard();
9376 if (uiccCard == null) {
9377 return false;
9378 }
9379 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9380 if (uiccProfile == null) {
9381 return false;
9382 }
9383 if (TelephonyManager.APPTYPE_SIM <= appType
9384 && appType <= TelephonyManager.APPTYPE_ISIM) {
9385 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9386 }
9387 return false;
9388 } finally {
9389 Binder.restoreCallingIdentity(identity);
9390 }
9391 }
9392
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009393 /**
chen xub4baa772019-04-03 10:23:41 -07009394 * Get whether making changes to modem configurations will trigger reboot.
9395 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009396 */
9397 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009398 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9399 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009401 mApp, subId, callingPackage, callingFeatureId,
9402 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009403 return false;
9404 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009405 final long identity = Binder.clearCallingIdentity();
9406 try {
9407 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9408 } finally {
9409 Binder.restoreCallingIdentity(identity);
9410 }
9411 }
9412
Nathan Harold29f5f052019-02-15 13:41:57 -08009413 private void updateModemStateMetrics() {
9414 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9415 // TODO: check the state for each modem if the api is ready.
9416 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9417 }
9418
Pengquan Meng3889a572019-01-23 11:16:29 -08009419 @Override
9420 public int[] getSlotsMapping() {
9421 enforceReadPrivilegedPermission("getSlotsMapping");
9422
9423 final long identity = Binder.clearCallingIdentity();
9424 try {
9425 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9426 // All logical slots should have a mapping to a physical slot.
9427 int[] logicalSlotsMapping = new int[phoneCount];
9428 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9429 for (int i = 0; i < slotInfos.length; i++) {
9430 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9431 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9432 }
9433 }
9434 return logicalSlotsMapping;
9435 } finally {
9436 Binder.restoreCallingIdentity(identity);
9437 }
9438 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009439
9440 /**
9441 * Get the IRadio HAL Version
9442 */
9443 @Override
9444 public int getRadioHalVersion() {
9445 Phone phone = getDefaultPhone();
9446 if (phone == null) return -1;
9447 HalVersion hv = phone.getHalVersion();
9448 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9449 return hv.major * 100 + hv.minor;
9450 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009451
9452 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009453 * Get the current calling package name.
9454 * @return the current calling package name
9455 */
9456 @Override
9457 public String getCurrentPackageName() {
9458 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9459 }
9460
9461 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009462 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9463 * corresponding network requests on a subId.
9464 *
9465 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009466 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009467 * 2) APN is un-metered for this subscription, or
9468 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009469 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009470 *
9471 * @return whether data is allowed for a apn type.
9472 *
9473 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009474 */
9475 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009476 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009477 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9478 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009479
9480 // Now that all security checks passes, perform the operation as ourselves.
9481 final long identity = Binder.clearCallingIdentity();
9482 try {
9483 Phone phone = getPhone(subId);
9484 if (phone == null) return false;
9485
Jack Yu41407ee2019-05-13 16:54:09 -07009486 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009487 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9488 } finally {
9489 Binder.restoreCallingIdentity(identity);
9490 }
9491 }
9492
9493 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009494 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009495 enforceReadPrivilegedPermission("isApnMetered");
9496
9497 // Now that all security checks passes, perform the operation as ourselves.
9498 final long identity = Binder.clearCallingIdentity();
9499 try {
9500 Phone phone = getPhone(subId);
9501 if (phone == null) return true; // By default return true.
9502
Jack Yu41407ee2019-05-13 16:54:09 -07009503 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009504 } finally {
9505 Binder.restoreCallingIdentity(identity);
9506 }
9507 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009508
9509 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009510 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9511 int subscriptionId, IBooleanConsumer resultCallback) {
9512 enforceModifyPermission();
9513 long token = Binder.clearCallingIdentity();
9514 try {
9515 Phone phone = getPhone(subscriptionId);
9516 if (phone == null) {
9517 try {
9518 if (resultCallback != null) {
9519 resultCallback.accept(false);
9520 }
9521 } catch (RemoteException e) {
9522 // ignore
9523 }
9524 return;
9525 }
9526 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9527 Pair.create(specifiers, (x) -> {
9528 try {
9529 if (resultCallback != null) {
9530 resultCallback.accept(x);
9531 }
9532 } catch (RemoteException e) {
9533 // ignore
9534 }
9535 });
9536 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9537 } finally {
9538 Binder.restoreCallingIdentity(token);
9539 }
9540 }
9541
9542 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009543 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9544 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009545 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009546 mApp, subId, "getSystemSelectionChannels");
9547 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9548 final long identity = Binder.clearCallingIdentity();
9549 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009550 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9551 if (result instanceof IllegalStateException) {
9552 throw (IllegalStateException) result;
9553 }
9554 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009555 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9556 return specifiers;
9557 } finally {
9558 Binder.restoreCallingIdentity(identity);
9559 }
9560 }
9561
9562 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009563 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009564 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009565 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9566 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9567 if (iccRecords == null) {
9568 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9569 return false;
9570 }
9571 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9572 }
9573
9574 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009575 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9576 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009577 if (callingPackage == null) {
9578 callingPackage = getCurrentPackageName();
9579 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009580 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9581 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009582 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9583 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009584 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9585 }
9586 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9587 Intent intent = new Intent();
9588 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9589 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9590 // Bring up choose default SMS subscription dialog right now
9591 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9592 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9593 mApp.startActivity(intent);
9594 }
chen xud5ca2d52019-05-28 15:20:57 -07009595
9596 @Override
9597 public String getMmsUAProfUrl(int subId) {
9598 //TODO investigate if this API should require proper permission check in R b/133791609
9599 final long identity = Binder.clearCallingIdentity();
9600 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009601 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9602 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9603 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9604 return carrierUAProfUrl;
9605 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009606 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9607 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009608 } finally {
9609 Binder.restoreCallingIdentity(identity);
9610 }
9611 }
9612
9613 @Override
9614 public String getMmsUserAgent(int subId) {
9615 //TODO investigate if this API should require proper permission check in R b/133791609
9616 final long identity = Binder.clearCallingIdentity();
9617 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009618 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9619 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9620 if (!TextUtils.isEmpty(carrierUserAgent)) {
9621 return carrierUserAgent;
9622 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009623 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9624 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009625 } finally {
9626 Binder.restoreCallingIdentity(identity);
9627 }
9628 }
Jack Yub07d4972019-05-28 16:12:25 -07009629
9630 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009631 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9632 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009633
Jack Yub07d4972019-05-28 16:12:25 -07009634 final long identity = Binder.clearCallingIdentity();
9635 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009636 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009637 if (phone == null) return false;
9638
Hall Liua62f5da2020-09-25 10:42:19 -07009639 switch (policy) {
9640 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9641 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9642 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9643 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9644 default:
9645 throw new IllegalArgumentException(policy + " is not a valid policy");
9646 }
Jack Yub07d4972019-05-28 16:12:25 -07009647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
9651
9652 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009653 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009654 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009655 enforceModifyPermission();
9656
changbettyd5c246e2019-12-24 15:40:37 +08009657 final long identity = Binder.clearCallingIdentity();
9658 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009659 Phone phone = getPhone(subscriptionId);
9660 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009661
Hall Liua62f5da2020-09-25 10:42:19 -07009662 switch (policy) {
9663 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9664 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9665 break;
9666 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9667 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9668 break;
9669 default:
9670 throw new IllegalArgumentException(policy + " is not a valid policy");
9671 }
changbettyd5c246e2019-12-24 15:40:37 +08009672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 }
9676
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009677 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009678 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009679 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9680 * otherwise.
9681 */
9682 @Override
9683 public void setCepEnabled(boolean isCepEnabled) {
9684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9685
9686 final long identity = Binder.clearCallingIdentity();
9687 try {
9688 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9689 for (Phone phone : PhoneFactory.getPhones()) {
9690 Phone defaultPhone = phone.getImsPhone();
9691 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9692 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9693 ImsPhoneCallTracker imsPhoneCallTracker =
9694 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9695 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9696 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9697 + imsPhone.getMsisdn());
9698 }
9699 }
9700 } finally {
9701 Binder.restoreCallingIdentity(identity);
9702 }
9703 }
allenwtsu46dcc572020-01-08 18:24:03 +08009704
9705 /**
9706 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9707 *
9708 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9709 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9710 * before being read.
9711 */
9712 @Override
9713 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9714 isCompressed) {
9715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9716 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009717 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9718 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9719 }
9720 if (!isImsAvailableOnDevice()) {
9721 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9722 "IMS not available on device.");
9723 }
9724
9725 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009726 try {
Hui Wang761a6682020-10-31 05:12:53 +00009727 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9728 } finally {
9729 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009730 }
9731 }
zoey chene02881a2019-12-30 16:11:23 +08009732
9733 @Override
9734 public boolean isIccLockEnabled(int subId) {
9735 enforceReadPrivilegedPermission("isIccLockEnabled");
9736
9737 // Now that all security checks passes, perform the operation as ourselves.
9738 final long identity = Binder.clearCallingIdentity();
9739 try {
9740 Phone phone = getPhone(subId);
9741 if (phone != null && phone.getIccCard() != null) {
9742 return phone.getIccCard().getIccLockEnabled();
9743 } else {
9744 return false;
9745 }
9746 } finally {
9747 Binder.restoreCallingIdentity(identity);
9748 }
9749 }
9750
9751 /**
9752 * Set the ICC pin lock enabled or disabled.
9753 *
9754 * @return an integer representing the status of IccLock enabled or disabled in the following
9755 * three cases:
9756 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9757 * successfully.
9758 * - Positive number and zero for remaining password attempts.
9759 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9760 *
9761 */
9762 @Override
9763 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9764 enforceModifyPermission();
9765
9766 Phone phone = getPhone(subId);
9767 if (phone == null) {
9768 return 0;
9769 }
9770 // Now that all security checks passes, perform the operation as ourselves.
9771 final long identity = Binder.clearCallingIdentity();
9772 try {
9773 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9774 new Pair<Boolean, String>(enabled, password), phone, null);
9775 return attemptsRemaining;
9776
9777 } catch (Exception e) {
9778 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 return 0;
9783 }
9784
9785 /**
9786 * Change the ICC password used in ICC pin lock.
9787 *
9788 * @return an integer representing the status of IccLock changed in the following three cases:
9789 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9790 * - Positive number and zero for remaining password attempts.
9791 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9792 *
9793 */
9794 @Override
9795 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9796 enforceModifyPermission();
9797
9798 Phone phone = getPhone(subId);
9799 if (phone == null) {
9800 return 0;
9801 }
9802 // Now that all security checks passes, perform the operation as ourselves.
9803 final long identity = Binder.clearCallingIdentity();
9804 try {
9805 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9806 new Pair<String, String>(oldPassword, newPassword), phone, null);
9807 return attemptsRemaining;
9808
9809 } catch (Exception e) {
9810 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9811 } finally {
9812 Binder.restoreCallingIdentity(identity);
9813 }
9814 return 0;
9815 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009816
9817 /**
9818 * Request for receiving user activity notification
9819 */
9820 @Override
9821 public void requestUserActivityNotification() {
9822 if (!mNotifyUserActivity.get()
9823 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9824 mNotifyUserActivity.set(true);
9825 }
9826 }
9827
9828 /**
9829 * Called when userActivity is signalled in the power manager.
9830 * This is safe to call from any thread, with any window manager locks held or not.
9831 */
9832 @Override
9833 public void userActivity() {
9834 // ***************************************
9835 // * Inherited from PhoneWindowManager *
9836 // ***************************************
9837 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9838 // WITH ITS LOCKS HELD.
9839 //
9840 // This code must be VERY careful about the locks
9841 // it acquires.
9842 // In fact, the current code acquires way too many,
9843 // and probably has lurking deadlocks.
9844
9845 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9846 throw new SecurityException("Only the OS may call notifyUserActivity()");
9847 }
9848
9849 if (mNotifyUserActivity.getAndSet(false)) {
9850 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9851 USER_ACTIVITY_NOTIFICATION_DELAY);
9852 }
9853 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009854
9855 @Override
9856 public boolean canConnectTo5GInDsdsMode() {
9857 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9858 }
Jack Yud10cdd42020-09-28 20:28:01 -07009859
9860 @Override
9861 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9862 String callingFeatureId) {
9863 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9864 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9865 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9866 }
9867
9868 Phone phone = getPhone(subId);
9869 if (phone == null) {
9870 throw new RuntimeException("phone is not available");
9871 }
9872 // Now that all security checks passes, perform the operation as ourselves.
9873 final long identity = Binder.clearCallingIdentity();
9874 try {
9875 return phone.getEquivalentHomePlmns();
9876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
Daniel Bright59e67312020-11-13 11:49:37 -08009880
9881 @Override
9882 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009883 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9884 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009885 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009886 if (radioInterfaceCapabilities == null) {
9887 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009888 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009889 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009890 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009891
Hui Wang641e81c2020-10-12 12:14:23 -07009892 @Override
9893 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9894 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009895 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9896 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9897 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9898 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9899 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009900 if (DBG) {
9901 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9902 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9903 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9904 }
9905
9906 if (!SubscriptionManager.isValidSubscriptionId(subId)
9907 || appType < TelephonyManager.APPTYPE_UNKNOWN
9908 || appType > TelephonyManager.APPTYPE_ISIM
9909 || nafUrl == null || securityProtocol == null || callback == null) {
9910 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9911 if (callback != null) {
9912 try {
9913 callback.onAuthenticationFailure(
9914 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9915 } catch (RemoteException exception) {
9916 log("Fail to notify onAuthenticationFailure due to " + exception);
9917 }
9918 return;
9919 }
9920 }
9921
9922 final long token = Binder.clearCallingIdentity();
9923 try {
9924 getGbaManager(subId).bootstrapAuthenticationRequest(
9925 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9926 forceBootStrapping, callback));
9927 } finally {
9928 Binder.restoreCallingIdentity(token);
9929 }
9930 }
9931
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009932 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009933 * Attempts to set the radio power state for all phones for thermal reason.
9934 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009935 * requested radio power state will actually be set. See {@link
9936 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9937 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009938 * @param enable {@code true} if trying to turn radio on.
9939 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9940 * false}.
9941 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009942 private boolean setRadioPowerForThermal(boolean enable) {
9943 boolean isPhoneAvailable = false;
9944 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9945 Phone phone = PhoneFactory.getPhone(i);
9946 if (phone != null) {
9947 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9948 isPhoneAvailable = true;
9949 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009950 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009951
9952 // return true if successfully informed the phone object about the thermal radio power
9953 // request.
9954 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009955 }
9956
9957 private int handleDataThrottlingRequest(int subId,
9958 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009959 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9960 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9961 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9962 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9963 throw new IllegalArgumentException("modem does not support data throttling");
9964 }
9965
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009966 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9967 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009968 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009969 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9970 }
9971
9972 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9973
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009974 if (isDataThrottlingSupported) {
9975 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009976 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009977 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9978 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9979 } else if (thermalMitigationResult
9980 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009981 log("Modem likely does not support data throttling on secondary carrier. Data " +
9982 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9983 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009984 }
9985 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009986 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009987
9988 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009989 }
9990
Jack Nudelman644b91a2021-03-12 14:09:48 -08009991 private static List<String> getThermalMitigationAllowlist(Context context) {
9992 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9993 for (String pckg : context.getResources()
9994 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9995 sThermalMitigationAllowlistedPackages.add(pckg);
9996 }
9997 }
9998
9999 return sThermalMitigationAllowlistedPackages;
10000 }
10001
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010002 private boolean isAnyPhoneInEmergencyState() {
10003 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10004 if (tm.isInEmergencyCall()) {
10005 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10006 return true;
10007 }
10008 for (Phone phone : PhoneFactory.getPhones()) {
10009 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10010 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10011 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10012 + phone.isInEcm());
10013 return true;
10014 }
10015 }
10016
10017 return false;
10018 }
10019
Jack Nudelman644b91a2021-03-12 14:09:48 -080010020 /**
10021 * Used by shell commands to add an authorized package name for thermal mitigation.
10022 * @param packageName name of package to be allowlisted
10023 * @param context
10024 */
10025 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10026 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10027 sThermalMitigationAllowlistedPackages.add(packageName);
10028 }
10029
10030 /**
10031 * Used by shell commands to remove an authorized package name for thermal mitigation.
10032 * @param packageName name of package to remove from allowlist
10033 * @param context
10034 */
10035 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10036 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10037 sThermalMitigationAllowlistedPackages.remove(packageName);
10038 }
10039
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010040 /**
10041 * Thermal mitigation request to control functionalities at modem.
10042 *
10043 * @param subId the id of the subscription.
10044 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010045 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010046 *
10047 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10048 */
10049 @Override
10050 @ThermalMitigationResult
10051 public int sendThermalMitigationRequest(
10052 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010053 ThermalMitigationRequest thermalMitigationRequest,
10054 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010055 enforceModifyPermission();
10056
Jack Nudelman644b91a2021-03-12 14:09:48 -080010057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10058 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10059 .contains(callingPackage)) {
10060 throw new SecurityException("Calling package must be configured in the device config. "
10061 + "calling package: " + callingPackage);
10062 }
10063
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10065 final long identity = Binder.clearCallingIdentity();
10066
10067 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10068 try {
10069 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10070 switch (thermalMitigationAction) {
10071 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10072 thermalMitigationResult =
10073 handleDataThrottlingRequest(subId,
10074 thermalMitigationRequest.getDataThrottlingRequest());
10075 break;
10076 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10077 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10078 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10079 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10080 }
10081
10082 // Ensure that radio is on. If not able to power on due to phone being
10083 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010084 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010085 thermalMitigationResult =
10086 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10087 break;
10088 }
10089
10090 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10091 false);
10092 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10093 break;
10094 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10095 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10096 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10097 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10098 }
10099
10100 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10101 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010102 Phone phone = getPhone(subId);
10103 if (phone == null) {
10104 thermalMitigationResult =
10105 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10106 break;
10107 }
10108
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010109 TelephonyConnectionService service =
10110 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010111 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010112 Log.e(LOG_TAG, "An emergency call is pending");
10113 thermalMitigationResult =
10114 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10115 break;
10116 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010117 thermalMitigationResult =
10118 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10119 break;
10120 }
10121 } else {
10122 thermalMitigationResult =
10123 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10124 break;
10125 }
10126
10127 // Turn radio off. If not able to power off due to phone being unavailable,
10128 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010129 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010130 thermalMitigationResult =
10131 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10132 break;
10133 }
10134 thermalMitigationResult =
10135 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10136 break;
10137 default:
10138 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10139 + "not exist. Requested action: " + thermalMitigationAction);
10140 }
10141 } catch (IllegalArgumentException e) {
10142 throw e;
10143 } catch (Exception e) {
10144 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10145 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10146 } finally {
10147 Binder.restoreCallingIdentity(identity);
10148 }
10149
10150 if (DBG) {
10151 log("thermalMitigationRequest returning with thermalMitigationResult: "
10152 + thermalMitigationResult);
10153 }
10154
10155 return thermalMitigationResult;
10156 }
Hui Wang641e81c2020-10-12 12:14:23 -070010157
10158 /**
10159 * Set the GbaService Package Name that Telephony will bind to.
10160 *
10161 * @param subId The sim that the GbaService is associated with.
10162 * @param packageName The name of the package to be replaced with.
10163 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10164 */
10165 @Override
10166 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10167 enforceModifyPermission();
10168
10169 final long identity = Binder.clearCallingIdentity();
10170 try {
10171 return getGbaManager(subId).overrideServicePackage(packageName);
10172 } finally {
10173 Binder.restoreCallingIdentity(identity);
10174 }
10175 }
10176
10177 /**
10178 * Return the package name of the currently bound GbaService.
10179 *
10180 * @param subId The sim that the GbaService is associated with.
10181 * @return the package name of the GbaService configuration, null if GBA is not supported.
10182 */
10183 @Override
10184 public String getBoundGbaService(int subId) {
10185 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10186
10187 final long identity = Binder.clearCallingIdentity();
10188 try {
10189 return getGbaManager(subId).getServicePackage();
10190 } finally {
10191 Binder.restoreCallingIdentity(identity);
10192 }
10193 }
10194
10195 /**
10196 * Set the release time for telephony to unbind GbaService.
10197 *
10198 * @param subId The sim that the GbaService is associated with.
10199 * @param interval The release time to unbind GbaService by millisecond.
10200 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10201 */
10202 @Override
10203 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10204 enforceModifyPermission();
10205
10206 final long identity = Binder.clearCallingIdentity();
10207 try {
10208 return getGbaManager(subId).overrideReleaseTime(interval);
10209 } finally {
10210 Binder.restoreCallingIdentity(identity);
10211 }
10212 }
10213
10214 /**
10215 * Return the release time for telephony to unbind GbaService.
10216 *
10217 * @param subId The sim that the GbaService is associated with.
10218 * @return The release time to unbind GbaService by millisecond.
10219 */
10220 @Override
10221 public int getGbaReleaseTime(int subId) {
10222 enforceReadPrivilegedPermission("getGbaReleaseTime");
10223
10224 final long identity = Binder.clearCallingIdentity();
10225 try {
10226 return getGbaManager(subId).getReleaseTime();
10227 } finally {
10228 Binder.restoreCallingIdentity(identity);
10229 }
10230 }
10231
10232 private GbaManager getGbaManager(int subId) {
10233 GbaManager instance = GbaManager.getInstance(subId);
10234 if (instance == null) {
10235 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10236 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10237 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10238 }
10239 return instance;
10240 }
Hui Wang761a6682020-10-31 05:12:53 +000010241
10242 /**
10243 * indicate whether the device and the carrier can support
10244 * RCS VoLTE single registration.
10245 */
10246 @Override
10247 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010248 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10249 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10250 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10251 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010252
10253 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10254 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10255 }
10256
10257 final long identity = Binder.clearCallingIdentity();
10258 try {
10259 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10260 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010261 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10262 if (isCapable != null) {
10263 return isCapable;
10264 }
Hui Wang761a6682020-10-31 05:12:53 +000010265 }
Hui Wang67af90e2021-06-04 16:57:15 -070010266 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10267 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010268 } finally {
10269 Binder.restoreCallingIdentity(identity);
10270 }
10271 }
10272
10273 /**
10274 * Register RCS provisioning callback.
10275 */
10276 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010277 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010278 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010279 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010280 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010281 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10282 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010283
10284 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10285 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10286 }
10287 if (!isImsAvailableOnDevice()) {
10288 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10289 "IMS not available on device.");
10290 }
10291
10292 final long identity = Binder.clearCallingIdentity();
10293 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010294 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010295 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010296 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10297 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010298 }
Hui Wang761a6682020-10-31 05:12:53 +000010299 } finally {
10300 Binder.restoreCallingIdentity(identity);
10301 }
10302 }
10303
10304 /**
10305 * Unregister RCS provisioning callback.
10306 */
10307 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010308 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010309 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010310 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010311 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010312 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10313 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010314
10315 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10316 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10317 }
10318 if (!isImsAvailableOnDevice()) {
10319 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10320 "IMS not available on device.");
10321 }
10322
10323 final long identity = Binder.clearCallingIdentity();
10324 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010325 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010326 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010327 } finally {
10328 Binder.restoreCallingIdentity(identity);
10329 }
10330 }
10331
10332 /**
10333 * trigger RCS reconfiguration.
10334 */
10335 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010336 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10337 "triggerRcsReconfiguration",
10338 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010339
10340 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10341 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10342 }
10343 if (!isImsAvailableOnDevice()) {
10344 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10345 "IMS not available on device.");
10346 }
10347
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
10350 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10351 } finally {
10352 Binder.restoreCallingIdentity(identity);
10353 }
10354 }
10355
10356 /**
10357 * Provide the client configuration parameters of the RCS application.
10358 */
10359 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010360 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10361 "setRcsClientConfiguration",
10362 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010363
10364 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10365 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10366 }
10367 if (!isImsAvailableOnDevice()) {
10368 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10369 "IMS not available on device.");
10370 }
10371
10372 final long identity = Binder.clearCallingIdentity();
10373
10374 try {
10375 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10376 if (configBinder == null) {
10377 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010378 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10379 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010380 } else {
10381 configBinder.setRcsClientConfiguration(rcc);
10382 }
10383 } catch (RemoteException e) {
10384 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010385 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10386 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010387 } finally {
10388 Binder.restoreCallingIdentity(identity);
10389 }
10390 }
10391
10392 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010393 * Enables or disables the test mode for RCS VoLTE single registration.
10394 */
10395 @Override
10396 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10398 "setRcsSingleRegistrationTestModeEnabled");
10399
10400 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10401 }
10402
10403 /**
10404 * Gets the test mode for RCS VoLTE single registration.
10405 */
10406 @Override
10407 public boolean getRcsSingleRegistrationTestModeEnabled() {
10408 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10409 "getRcsSingleRegistrationTestModeEnabled");
10410
10411 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10412 }
10413
10414 /**
Hui Wang761a6682020-10-31 05:12:53 +000010415 * Overrides the config of RCS VoLTE single registration enabled for the device.
10416 */
10417 @Override
10418 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10419 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10420 "setDeviceSingleRegistrationEnabledOverride");
10421 enforceModifyPermission();
10422
10423 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10424 : Boolean.parseBoolean(enabledStr);
10425 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010426 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010427 }
10428
10429 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010430 * Sends a device to device communication message. Only usable via shell.
10431 * @param message message to send.
10432 * @param value message value.
10433 */
10434 @Override
10435 public void sendDeviceToDeviceMessage(int message, int value) {
10436 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010437 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010438 enforceModifyPermission();
10439
10440 final long identity = Binder.clearCallingIdentity();
10441 try {
10442 TelephonyConnectionService service =
10443 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10444 if (service == null) {
10445 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10446 return;
10447 }
10448 service.sendTestDeviceToDeviceMessage(message, value);
10449 } finally {
10450 Binder.restoreCallingIdentity(identity);
10451 }
10452 }
10453
Tyler Gunnbabbda02021-02-10 11:05:02 -080010454 /**
10455 * Sets the specified device to device transport active.
10456 * @param transport The transport to set active.
10457 */
10458 @Override
10459 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10460 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10461 "setActiveDeviceToDeviceTransport");
10462 enforceModifyPermission();
10463
10464 final long identity = Binder.clearCallingIdentity();
10465 try {
10466 TelephonyConnectionService service =
10467 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10468 if (service == null) {
10469 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10470 return;
10471 }
10472 service.setActiveDeviceToDeviceTransport(transport);
10473 } finally {
10474 Binder.restoreCallingIdentity(identity);
10475 }
10476 }
Tyler Gunn92479152021-01-20 16:30:10 -080010477
Tyler Gunnd4339262021-05-03 14:46:49 -070010478 @Override
10479 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10480 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10481 "setDeviceToDeviceForceEnabled");
10482
10483 final long identity = Binder.clearCallingIdentity();
10484 try {
10485 Arrays.stream(PhoneFactory.getPhones()).forEach(
10486 p -> {
10487 Phone thePhone = p.getImsPhone();
10488 if (thePhone != null && thePhone instanceof ImsPhone) {
10489 ImsPhone imsPhone = (ImsPhone) thePhone;
10490 CallTracker tracker = imsPhone.getCallTracker();
10491 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10492 ImsPhoneCallTracker imsPhoneCallTracker =
10493 (ImsPhoneCallTracker) tracker;
10494 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10495 }
10496 }
10497 }
10498 );
10499 } finally {
10500 Binder.restoreCallingIdentity(identity);
10501 }
10502 }
10503
Tyler Gunn92479152021-01-20 16:30:10 -080010504 /**
Hui Wang761a6682020-10-31 05:12:53 +000010505 * Gets the config of RCS VoLTE single registration enabled for the device.
10506 */
10507 @Override
10508 public boolean getDeviceSingleRegistrationEnabled() {
10509 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10510 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10511 }
10512
10513 /**
10514 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10515 */
10516 @Override
10517 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10518 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10519 "setCarrierSingleRegistrationEnabledOverride");
10520 enforceModifyPermission();
10521
10522 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10523 : Boolean.parseBoolean(enabledStr);
10524 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10525 subId, enabled);
10526 }
10527
10528 /**
10529 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10530 */
10531 @Override
10532 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10533 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10534 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10535 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010536
10537 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010538 * Overrides the ims feature validation result
10539 */
10540 @Override
10541 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10542 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10543 "setImsFeatureValidationOverride");
10544
10545 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10546 : Boolean.parseBoolean(enabledStr);
10547 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10548 subId, enabled);
10549 }
10550
10551 /**
10552 * Gets the ims feature validation override value
10553 */
10554 @Override
10555 public boolean getImsFeatureValidationOverride(int subId) {
10556 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10557 "getImsFeatureValidationOverride");
10558 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10559 }
10560
10561 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010562 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10563 * their mobile plan.
10564 */
10565 @Override
10566 public String getMobileProvisioningUrl() {
10567 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10568 final long identity = Binder.clearCallingIdentity();
10569 try {
10570 return getDefaultPhone().getMobileProvisioningUrl();
10571 } finally {
10572 Binder.restoreCallingIdentity(identity);
10573 }
10574 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010575
James.cf Linbcdf8b32021-01-14 16:44:13 +080010576 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010577 * Get the EAB contact from the EAB database.
10578 */
10579 @Override
10580 public String getContactFromEab(String contact) {
10581 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10582 enforceModifyPermission();
10583 final long identity = Binder.clearCallingIdentity();
10584 try {
10585 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10586 } finally {
10587 Binder.restoreCallingIdentity(identity);
10588 }
10589 }
10590
10591 /**
Calvin Pana1434322021-07-01 19:27:01 +080010592 * Get the EAB capability from the EAB database.
10593 */
10594 @Override
10595 public String getCapabilityFromEab(String contact) {
10596 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10597 enforceModifyPermission();
10598 final long identity = Binder.clearCallingIdentity();
10599 try {
10600 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10601 } finally {
10602 Binder.restoreCallingIdentity(identity);
10603 }
10604 }
10605
10606 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010607 * Remove the EAB contacts from the EAB database.
10608 */
10609 @Override
10610 public int removeContactFromEab(int subId, String contacts) {
10611 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10612 enforceModifyPermission();
10613 final long identity = Binder.clearCallingIdentity();
10614 try {
10615 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10616 } finally {
10617 Binder.restoreCallingIdentity(identity);
10618 }
10619 }
10620
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010621 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010622 public boolean getDeviceUceEnabled() {
10623 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10624 final long identity = Binder.clearCallingIdentity();
10625 try {
10626 return mApp.getDeviceUceEnabled();
10627 } finally {
10628 Binder.restoreCallingIdentity(identity);
10629 }
10630 }
10631
10632 @Override
10633 public void setDeviceUceEnabled(boolean isEnabled) {
10634 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10635 final long identity = Binder.clearCallingIdentity();
10636 try {
10637 mApp.setDeviceUceEnabled(isEnabled);
10638 } finally {
10639 Binder.restoreCallingIdentity(identity);
10640 }
10641 }
10642
Brad Ebinger14d467f2021-02-12 06:18:28 +000010643 /**
10644 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10645 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10646 */
10647 // Used for SHELL command only right now.
10648 @Override
10649 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10650 List<String> featureTags) {
10651 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10652 "addUceRegistrationOverrideShell");
10653 final long identity = Binder.clearCallingIdentity();
10654 try {
10655 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10656 new ArraySet<>(featureTags));
10657 } catch (ImsException e) {
10658 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10659 } finally {
10660 Binder.restoreCallingIdentity(identity);
10661 }
10662 }
10663
10664 /**
10665 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10666 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10667 */
10668 // Used for SHELL command only right now.
10669 @Override
10670 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10671 List<String> featureTags) {
10672 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10673 "removeUceRegistrationOverrideShell");
10674 final long identity = Binder.clearCallingIdentity();
10675 try {
10676 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10677 new ArraySet<>(featureTags));
10678 } catch (ImsException e) {
10679 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10680 } finally {
10681 Binder.restoreCallingIdentity(identity);
10682 }
10683 }
10684
10685 /**
10686 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10687 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10688 */
10689 // Used for SHELL command only right now.
10690 @Override
10691 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10693 "clearUceRegistrationOverrideShell");
10694 final long identity = Binder.clearCallingIdentity();
10695 try {
10696 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10697 } catch (ImsException e) {
10698 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10699 } finally {
10700 Binder.restoreCallingIdentity(identity);
10701 }
10702 }
10703
10704 /**
10705 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10706 */
10707 // Used for SHELL command only right now.
10708 @Override
10709 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10710 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10711 "getLatestRcsContactUceCapabilityShell");
10712 final long identity = Binder.clearCallingIdentity();
10713 try {
10714 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10715 } catch (ImsException e) {
10716 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10717 } finally {
10718 Binder.restoreCallingIdentity(identity);
10719 }
10720 }
10721
10722 /**
10723 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10724 * device does not have an active PUBLISH.
10725 */
10726 // Used for SHELL command only right now.
10727 @Override
10728 public String getLastUcePidfXmlShell(int subId) {
10729 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10730 final long identity = Binder.clearCallingIdentity();
10731 try {
10732 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10733 } catch (ImsException e) {
10734 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10735 } finally {
10736 Binder.restoreCallingIdentity(identity);
10737 }
10738 }
10739
James.cf Line8713a42021-04-29 16:04:26 +080010740 /**
10741 * Remove UCE requests cannot be sent to the network status.
10742 */
10743 // Used for SHELL command only right now.
10744 @Override
10745 public boolean removeUceRequestDisallowedStatus(int subId) {
10746 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10747 final long identity = Binder.clearCallingIdentity();
10748 try {
10749 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10750 } catch (ImsException e) {
10751 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10752 } finally {
10753 Binder.restoreCallingIdentity(identity);
10754 }
10755 }
10756
James.cf Lin18bb9002021-05-25 01:37:38 +080010757 /**
10758 * Remove UCE requests cannot be sent to the network status.
10759 */
10760 // Used for SHELL command only.
10761 @Override
10762 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10763 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10764 final long identity = Binder.clearCallingIdentity();
10765 try {
10766 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10767 } catch (ImsException e) {
10768 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10769 } finally {
10770 Binder.restoreCallingIdentity(identity);
10771 }
10772 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010773
James.cf Lin4b784aa2021-01-31 03:25:15 +080010774 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010775 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10776 String callingPackage) {
10777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10778 mApp, subId, "setSignalStrengthUpdateRequest");
10779
10780 final int callingUid = Binder.getCallingUid();
10781 // Verify that tha callingPackage belongs to the calling UID
10782 mApp.getSystemService(AppOpsManager.class)
10783 .checkPackage(callingUid, callingPackage);
10784
10785 validateSignalStrengthUpdateRequest(request, callingUid);
10786
10787 final long identity = Binder.clearCallingIdentity();
10788 try {
10789 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10790 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10791
10792 if (result instanceof IllegalStateException) {
10793 throw (IllegalStateException) result;
10794 }
10795 } finally {
10796 Binder.restoreCallingIdentity(identity);
10797 }
10798 }
10799
10800 @Override
10801 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10802 String callingPackage) {
10803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10804 mApp, subId, "clearSignalStrengthUpdateRequest");
10805
10806 final int callingUid = Binder.getCallingUid();
10807 // Verify that tha callingPackage belongs to the calling UID
10808 mApp.getSystemService(AppOpsManager.class)
10809 .checkPackage(callingUid, callingPackage);
10810
10811 final long identity = Binder.clearCallingIdentity();
10812 try {
10813 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10814 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10815
10816 if (result instanceof IllegalStateException) {
10817 throw (IllegalStateException) result;
10818 }
10819 } finally {
10820 Binder.restoreCallingIdentity(identity);
10821 }
10822 }
10823
10824 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10825 int callingUid) {
10826 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10827 // phone/system process do not have further restriction on request
10828 return;
10829 }
10830
10831 // Applications has restrictions on how to use the request:
10832 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10833 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10834 // This is not system caller which has been checked above
10835 throw new IllegalArgumentException(
10836 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10837 }
10838
10839 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10840 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10841 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10842 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10843 || info.isEnabled()) {
10844 throw new IllegalArgumentException(
10845 "Only system can set hide fields in SignalThresholdInfo");
10846 }
10847
10848 // Thresholds length for each RAN need in range. This has been validated in
10849 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10850 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10851 final int[] thresholds = info.getThresholds();
10852 Objects.requireNonNull(thresholds);
10853 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10854 || thresholds.length
10855 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10856 throw new IllegalArgumentException(
10857 "thresholds length is out of range: " + thresholds.length);
10858 }
10859 }
10860 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010861
10862 /**
10863 * Gets the current phone capability.
10864 *
10865 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10866 * @return the PhoneCapability which describes the data connection capability of modem.
10867 * It's used to evaluate possible phone config change, for example from single
10868 * SIM device to multi-SIM device.
10869 */
10870 @Override
10871 public PhoneCapability getPhoneCapability() {
10872 enforceReadPrivilegedPermission("getPhoneCapability");
10873 final long identity = Binder.clearCallingIdentity();
10874 try {
10875 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10876 } finally {
10877 Binder.restoreCallingIdentity(identity);
10878 }
10879 }
Michele Berionne5e411512020-11-13 02:36:59 +000010880
10881 /**
10882 * Prepare TelephonyManager for an unattended reboot. The reboot is
10883 * required to be done shortly after the API is invoked.
10884 */
10885 @Override
10886 @TelephonyManager.PrepareUnattendedRebootResult
10887 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010888 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010889 enforceRebootPermission();
10890
10891 final long identity = Binder.clearCallingIdentity();
10892 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010893 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010894 } finally {
10895 Binder.restoreCallingIdentity(identity);
10896 }
10897 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010898
10899 /**
10900 * Request to get the current slicing configuration including URSP rules and
10901 * NSSAIs (configured, allowed and rejected).
10902 *
10903 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10904 */
10905 @Override
10906 public void getSlicingConfig(ResultReceiver callback) {
10907 enforceReadPrivilegedPermission("getSlicingConfig");
10908
10909 final long identity = Binder.clearCallingIdentity();
10910 try {
10911 Phone phone = getDefaultPhone();
10912 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10913 } finally {
10914 Binder.restoreCallingIdentity(identity);
10915 }
10916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010917}