blob: 7900a2adcc9c5370f48b08814b6f2469dfecdef4 [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;
Grace Jia59437e82021-09-21 15:47:32 -0700188import com.android.internal.telephony.uicc.PinStorage;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700190import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800191import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700192import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800193import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000194import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800195import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700196import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700197import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800198import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800199import com.android.phone.callcomposer.CallComposerPictureManager;
200import com.android.phone.callcomposer.CallComposerPictureTransfer;
201import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700202import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700203import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800204import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700205import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700206import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800207import com.android.services.telephony.TelecomAccountRegistry;
208import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800209import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800210
Hall Liu82694d52020-12-11 18:22:04 -0800211import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700212import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800213import java.io.IOException;
214import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700215import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800217import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800218import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800219import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800220import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100221import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800222import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700223import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800224import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800225import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800226import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800227import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800228import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700229
230/**
231 * Implementation of the ITelephony interface.
232 */
Santos Cordon117fee72014-05-16 17:56:12 -0700233public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234 private static final String LOG_TAG = "PhoneInterfaceManager";
235 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
236 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800237 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238
239 // Message codes used with mMainThreadHandler
240 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700241 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
242 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700243 private static final int CMD_OPEN_CHANNEL = 9;
244 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
245 private static final int CMD_CLOSE_CHANNEL = 11;
246 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800247 private static final int CMD_NV_READ_ITEM = 13;
248 private static final int EVENT_NV_READ_ITEM_DONE = 14;
249 private static final int CMD_NV_WRITE_ITEM = 15;
250 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
251 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
252 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700253 private static final int CMD_RESET_MODEM_CONFIG = 19;
254 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800255 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
256 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800257 private static final int CMD_SEND_ENVELOPE = 25;
258 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000259 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
260 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700261 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
262 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
263 private static final int CMD_EXCHANGE_SIM_IO = 31;
264 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800265 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
266 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700267 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
268 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700269 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
270 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700271 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
272 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
273 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
274 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700275 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
276 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
277 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
278 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700279 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800280 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
281 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000282 private static final int CMD_SWITCH_SLOTS = 50;
283 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700284 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
285 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
286 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
287 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
288 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
289 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
290 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
291 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700292 private static final int CMD_GET_ALL_CELL_INFO = 60;
293 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
294 private static final int CMD_GET_CELL_LOCATION = 62;
295 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700296 private static final int CMD_MODEM_REBOOT = 64;
297 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700298 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
299 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800300 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
301 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700302 private static final int CMD_GET_MODEM_STATUS = 70;
303 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700304 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
305 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700306 private static final int CMD_ERASE_MODEM_CONFIG = 74;
307 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800308 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
309 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
310 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
311 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800312 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
313 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800315 private static final int CMD_GET_CALL_FORWARDING = 83;
316 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
317 private static final int CMD_SET_CALL_FORWARDING = 85;
318 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
319 private static final int CMD_GET_CALL_WAITING = 87;
320 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
321 private static final int CMD_SET_CALL_WAITING = 89;
322 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700323 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
324 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
325 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
326 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700327 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
328 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800329 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
330 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800331 private static final int CMD_SET_DATA_THROTTLING = 99;
332 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800333 private static final int CMD_SET_SIM_POWER = 101;
334 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800335 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
336 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
337 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
338 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800339 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
340 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000341 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800342 private static final int CMD_GET_SLICING_CONFIG = 110;
343 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800344 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700345 private static final int CMD_ENABLE_VONR = 113;
346 private static final int EVENT_ENABLE_VONR_DONE = 114;
347 private static final int CMD_IS_VONR_ENABLED = 115;
348 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800350 // Parameters of select command.
351 private static final int SELECT_COMMAND = 0xA4;
352 private static final int SELECT_P1 = 0x04;
353 private static final int SELECT_P2 = 0;
354 private static final int SELECT_P3 = 0x10;
355
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 /** The singleton instance. */
357 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800358 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800362 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700363 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800364 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700365 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800366 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800367 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800368 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700369 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800370 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371
Peter Wangdafb9ac2020-01-15 14:13:38 -0800372 /** User Activity */
373 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800374 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
375
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700376 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
377
Derek Tan97ebb422014-09-05 16:55:38 -0700378 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
379 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800380 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800381 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700382
Michelecea4cf22018-12-21 15:00:11 -0800383 // String to store multi SIM allowed
384 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
385
Derek Tan740e1672017-06-27 14:56:27 -0700386 // The AID of ISD-R.
387 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
388
yinxub1bed742017-04-17 11:45:04 -0700389 private NetworkScanRequestTracker mNetworkScanRequestTracker;
390
David Kelly5e06a7f2018-03-12 14:10:59 +0000391 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
392 private static final int MANUFACTURER_CODE_LENGTH = 8;
393
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800394 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800395 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800396
Derek Tan89e89d42014-07-08 17:00:10 -0700397 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700398 * Experiment flag to enable erase modem config on reset network, default value is false
399 */
400 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
401 "reset_network_erase_modem_config_enabled";
402
Rambo Wang0f050d82021-02-12 11:43:36 -0800403 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
404
Naina Nallurid63128d2019-09-17 14:10:30 -0700405 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700406 * A request object to use for transmitting data to an ICC.
407 */
408 private static final class IccAPDUArgument {
409 public int channel, cla, command, p1, p2, p3;
410 public String data;
411
412 public IccAPDUArgument(int channel, int cla, int command,
413 int p1, int p2, int p3, String data) {
414 this.channel = channel;
415 this.cla = cla;
416 this.command = command;
417 this.p1 = p1;
418 this.p2 = p2;
419 this.p3 = p3;
420 this.data = data;
421 }
422 }
423
424 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700425 * A request object to use for transmitting data to an ICC.
426 */
427 private static final class ManualNetworkSelectionArgument {
428 public OperatorInfo operatorInfo;
429 public boolean persistSelection;
430
431 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
432 this.operatorInfo = operatorInfo;
433 this.persistSelection = persistSelection;
434 }
435 }
436
437 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
439 * request after sending. The main thread will notify the request when it is complete.
440 */
441 private static final class MainThreadRequest {
442 /** The argument to use for the request */
443 public Object argument;
444 /** The result of the request that is run on the main thread */
445 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800446 // The subscriber id that this request applies to. Defaults to
447 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
448 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449
Nathan Harold92bed182018-10-12 18:16:49 -0700450 // In cases where subId is unavailable, the caller needs to specify the phone.
451 public Phone phone;
452
vagdeviaf9a5b92018-08-15 16:01:53 -0700453 public WorkSource workSource;
454
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 public MainThreadRequest(Object argument) {
456 this.argument = argument;
457 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800458
Nathan Harold92bed182018-10-12 18:16:49 -0700459 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
460 this.argument = argument;
461 if (phone != null) {
462 this.phone = phone;
463 }
464 this.workSource = workSource;
465 }
466
vagdeviaf9a5b92018-08-15 16:01:53 -0700467 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800468 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800469 if (subId != null) {
470 this.subId = subId;
471 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700472 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474 }
475
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800476 private static final class IncomingThirdPartyCallArgs {
477 public final ComponentName component;
478 public final String callId;
479 public final String callerDisplayName;
480
481 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
482 String callerDisplayName) {
483 this.component = component;
484 this.callId = callId;
485 this.callerDisplayName = callerDisplayName;
486 }
487 }
488
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489 /**
490 * A handler that processes messages on the main thread in the phone process. Since many
491 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
492 * inbound binder threads to the main thread in the phone process. The Binder thread
493 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
494 * on, which will be notified when the operation completes and will contain the result of the
495 * request.
496 *
497 * <p>If a MainThreadRequest object is provided in the msg.obj field,
498 * note that request.result must be set to something non-null for the calling thread to
499 * unblock.
500 */
501 private final class MainThreadHandler extends Handler {
502 @Override
503 public void handleMessage(Message msg) {
504 MainThreadRequest request;
505 Message onCompleted;
506 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800507 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800509 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510
511 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 case CMD_HANDLE_USSD_REQUEST: {
513 request = (MainThreadRequest) msg.obj;
514 final Phone phone = getPhoneFromRequest(request);
515 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
516 String ussdRequest = ussdObject.first;
517 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700518
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 if (!isUssdApiAllowed(request.subId)) {
520 // Carrier does not support use of this API, return failure.
521 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
522 UssdResponse response = new UssdResponse(ussdRequest, null);
523 Bundle returnData = new Bundle();
524 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
525 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700526
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 request.result = true;
528 notifyRequester(request);
529 return;
530 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700531
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 try {
533 request.result = phone != null
534 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
535 } catch (CallStateException cse) {
536 request.result = false;
537 }
538 // Wake up the requesting thread
539 notifyRequester(request);
540 break;
pkanwar32d516d2016-10-14 19:37:38 -0700541 }
542
Yorke Lee716f67e2015-06-17 15:39:16 -0700543 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700545 final Phone phone = getPhoneFromRequest(request);
546 request.result = phone != null ?
547 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
548 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700549 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700551 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700553
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800557 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 if (uiccCard == null) {
559 loge("iccTransmitApduLogicalChannel: No UICC");
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
564 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 iccArgument.channel, iccArgument.cla, iccArgument.command,
567 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 break;
571
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
577 } else {
578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800581 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800583 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 } else {
585 loge("iccTransmitApduLogicalChannel: Unknown exception");
586 }
587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
593 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800594 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 if (uiccCard == null) {
596 loge("iccTransmitApduBasicChannel: No UICC");
597 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700598 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 } else {
600 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
601 request);
602 uiccCard.iccTransmitApduBasicChannel(
603 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
604 iccArgument.p3, iccArgument.data, onCompleted);
605 }
606 break;
607
608 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
611 if (ar.exception == null && ar.result != null) {
612 request.result = ar.result;
613 } else {
614 request.result = new IccIoResult(0x6F, 0, (byte[])null);
615 if (ar.result == null) {
616 loge("iccTransmitApduBasicChannel: Empty response");
617 } else if (ar.exception instanceof CommandException) {
618 loge("iccTransmitApduBasicChannel: CommandException: " +
619 ar.exception);
620 } else {
621 loge("iccTransmitApduBasicChannel: Unknown exception");
622 }
623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 break;
626
627 case CMD_EXCHANGE_SIM_IO:
628 request = (MainThreadRequest) msg.obj;
629 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800630 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700631 if (uiccCard == null) {
632 loge("iccExchangeSimIO: No UICC");
633 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 } else {
636 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
637 request);
638 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
639 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
640 iccArgument.data, onCompleted);
641 }
642 break;
643
644 case EVENT_EXCHANGE_SIM_IO_DONE:
645 ar = (AsyncResult) msg.obj;
646 request = (MainThreadRequest) ar.userObj;
647 if (ar.exception == null && ar.result != null) {
648 request.result = ar.result;
649 } else {
650 request.result = new IccIoResult(0x6f, 0, (byte[])null);
651 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700653 break;
654
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 case CMD_SEND_ENVELOPE:
656 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800657 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 if (uiccCard == null) {
659 loge("sendEnvelopeWithStatus: No UICC");
660 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 } else {
663 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
664 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
665 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800666 break;
667
668 case EVENT_SEND_ENVELOPE_DONE:
669 ar = (AsyncResult) msg.obj;
670 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700671 if (ar.exception == null && ar.result != null) {
672 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800673 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700674 request.result = new IccIoResult(0x6F, 0, (byte[])null);
675 if (ar.result == null) {
676 loge("sendEnvelopeWithStatus: Empty response");
677 } else if (ar.exception instanceof CommandException) {
678 loge("sendEnvelopeWithStatus: CommandException: " +
679 ar.exception);
680 } else {
681 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
682 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800683 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800685 break;
686
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 case CMD_OPEN_CHANNEL:
688 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800689 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800690 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 if (uiccCard == null) {
692 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800693 request.result = new IccOpenLogicalChannelResponse(-1,
694 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700696 } else {
697 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800698 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
699 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700700 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 break;
702
703 case EVENT_OPEN_CHANNEL_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700708 int[] result = (int[]) ar.result;
709 int channelId = result[0];
710 byte[] selectResponse = null;
711 if (result.length > 1) {
712 selectResponse = new byte[result.length - 1];
713 for (int i = 1; i < result.length; ++i) {
714 selectResponse[i - 1] = (byte) result[i];
715 }
716 }
717 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700718 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 if (ar.result == null) {
721 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700722 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700723 if (ar.exception != null) {
724 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
725 }
726
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700728 if (ar.exception instanceof CommandException) {
729 CommandException.Error error =
730 ((CommandException) (ar.exception)).getCommandError();
731 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700732 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700733 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700734 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700735 }
736 }
737 openChannelResp = new IccOpenLogicalChannelResponse(
738 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700739 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700740 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 break;
743
744 case CMD_CLOSE_CHANNEL:
745 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800746 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700747 if (uiccCard == null) {
748 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900749 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700750 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700751 } else {
752 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
753 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
754 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 break;
756
757 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800758 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
759 break;
760
761 case CMD_NV_READ_ITEM:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800764 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
765 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800766 break;
767
768 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 ar = (AsyncResult) msg.obj;
770 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800771 if (ar.exception == null && ar.result != null) {
772 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800774 request.result = "";
775 if (ar.result == null) {
776 loge("nvReadItem: Empty response");
777 } else if (ar.exception instanceof CommandException) {
778 loge("nvReadItem: CommandException: " +
779 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700780 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800781 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700782 }
783 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700784 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700785 break;
786
Jake Hambye994d462014-02-03 13:10:13 -0800787 case CMD_NV_WRITE_ITEM:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
790 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700792 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800793 break;
794
795 case EVENT_NV_WRITE_ITEM_DONE:
796 handleNullReturnEvent(msg, "nvWriteItem");
797 break;
798
799 case CMD_NV_WRITE_CDMA_PRL:
800 request = (MainThreadRequest) msg.obj;
801 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800802 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800803 break;
804
805 case EVENT_NV_WRITE_CDMA_PRL_DONE:
806 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
807 break;
808
chen xu6dac5ab2018-10-26 17:39:23 -0700809 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800810 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700811 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800812 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800813 break;
814
chen xu6dac5ab2018-10-26 17:39:23 -0700815 case EVENT_RESET_MODEM_CONFIG_DONE:
816 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800817 break;
818
Sooraj Sasindran37444802020-08-11 10:40:43 -0700819 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
822 request);
823 Phone phone = getPhoneFromRequest(request);
824 if (phone != null) {
825 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
826 } else {
827 loge("isNRDualConnectivityEnabled: No phone object");
828 request.result = false;
829 notifyRequester(request);
830 }
831 break;
832 }
833
834 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 if (ar.exception == null && ar.result != null) {
838 request.result = ar.result;
839 } else {
840 // request.result must be set to something non-null
841 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700842 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700843 request.result = ar.result;
844 } else {
845 request.result = false;
846 }
847 if (ar.result == null) {
848 loge("isNRDualConnectivityEnabled: Empty response");
849 } else if (ar.exception instanceof CommandException) {
850 loge("isNRDualConnectivityEnabled: CommandException: "
851 + ar.exception);
852 } else {
853 loge("isNRDualConnectivityEnabled: Unknown exception");
854 }
855 }
856 notifyRequester(request);
857 break;
858
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700859 case CMD_IS_VONR_ENABLED: {
860 request = (MainThreadRequest) msg.obj;
861 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
862 request);
863 Phone phone = getPhoneFromRequest(request);
864 if (phone != null) {
865 phone.isVoNrEnabled(onCompleted, request.workSource);
866 } else {
867 loge("isVoNrEnabled: No phone object");
868 request.result = false;
869 notifyRequester(request);
870 }
871 break;
872 }
873
874 case EVENT_IS_VONR_ENABLED_DONE:
875 ar = (AsyncResult) msg.obj;
876 request = (MainThreadRequest) ar.userObj;
877 if (ar.exception == null && ar.result != null) {
878 request.result = ar.result;
879 } else {
880 // request.result must be set to something non-null
881 // for the calling thread to unblock
882 if (ar.result != null) {
883 request.result = ar.result;
884 } else {
885 request.result = false;
886 }
887 if (ar.result == null) {
888 loge("isVoNrEnabled: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("isVoNrEnabled: CommandException: "
891 + ar.exception);
892 } else {
893 loge("isVoNrEnabled: Unknown exception");
894 }
895 }
896 notifyRequester(request);
897 break;
898
Sooraj Sasindran37444802020-08-11 10:40:43 -0700899 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
900 request = (MainThreadRequest) msg.obj;
901 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
902 Phone phone = getPhoneFromRequest(request);
903 if (phone != null) {
904 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
905 request.workSource);
906 } else {
907 loge("enableNrDualConnectivity: No phone object");
908 request.result =
909 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
910 notifyRequester(request);
911 }
912 break;
913 }
914
915 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null) {
919 request.result =
920 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
921 } else {
922 request.result =
923 TelephonyManager
924 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
925 if (ar.exception instanceof CommandException) {
926 CommandException.Error error =
927 ((CommandException) (ar.exception)).getCommandError();
928 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
929 request.result =
930 TelephonyManager
931 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000932 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
933 request.result =
934 TelephonyManager
935 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700936 }
937 loge("enableNrDualConnectivity" + ": CommandException: "
938 + ar.exception);
939 } else {
940 loge("enableNrDualConnectivity" + ": Unknown exception");
941 }
942 }
943 notifyRequester(request);
944 break;
945 }
946
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700947 case CMD_ENABLE_VONR: {
948 request = (MainThreadRequest) msg.obj;
949 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
950 Phone phone = getPhoneFromRequest(request);
951 if (phone != null) {
952 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
953 request.workSource);
954 } else {
955 loge("setVoNrEnabled: No phone object");
956 request.result =
957 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
958 notifyRequester(request);
959 }
960 break;
961 }
962
963 case EVENT_ENABLE_VONR_DONE: {
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 if (ar.exception == null) {
967 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
968 } else {
969 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
970 if (ar.exception instanceof CommandException) {
971 CommandException.Error error =
972 ((CommandException) (ar.exception)).getCommandError();
973 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
974 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
975 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
976 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
977 } else {
978 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
979 }
980 loge("setVoNrEnabled" + ": CommandException: "
981 + ar.exception);
982 } else {
983 loge("setVoNrEnabled" + ": Unknown exception");
984 }
985 }
986 notifyRequester(request);
987 break;
988 }
989
SongFerngWang3ef3e072020-12-21 16:41:52 +0800990 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800991 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800992 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
993 request);
994 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800995 break;
996
SongFerngWang3ef3e072020-12-21 16:41:52 +0800997 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception == null && ar.result != null) {
1001 request.result = ar.result; // Integer
1002 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301003 // request.result must be set to something non-null
1004 // for the calling thread to unblock
1005 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001006 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001007 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001008 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001009 loge("getAllowedNetworkTypesBitmask: CommandException: "
1010 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001011 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001012 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001013 }
1014 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001015 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001016 break;
1017
SongFerngWang3ef3e072020-12-21 16:41:52 +08001018 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001019 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001020 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1021 request);
1022 Pair<Integer, Long> reasonWithNetworkTypes =
1023 (Pair<Integer, Long>) request.argument;
1024 getPhoneFromRequest(request).setAllowedNetworkTypes(
1025 reasonWithNetworkTypes.first,
1026 reasonWithNetworkTypes.second,
1027 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001028 break;
1029
SongFerngWang3ef3e072020-12-21 16:41:52 +08001030 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1031 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001032 break;
1033
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001034 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1035 request = (MainThreadRequest)msg.obj;
1036 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001037 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001038 break;
1039
1040 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1041 ar = (AsyncResult)msg.obj;
1042 request = (MainThreadRequest)ar.userObj;
1043 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001044 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001045 break;
1046
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001047 case CMD_SET_VOICEMAIL_NUMBER:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1050 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001051 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1052 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001053 break;
1054
1055 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1056 handleNullReturnEvent(msg, "setVoicemailNumber");
1057 break;
1058
Stuart Scott54788802015-03-30 13:18:01 -07001059 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1060 request = (MainThreadRequest) msg.obj;
1061 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1062 request);
1063 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1064 break;
1065
1066 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1067 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1068 break;
1069
Shishir Agrawal302c8692015-06-19 13:49:39 -07001070 case CMD_PERFORM_NETWORK_SCAN:
1071 request = (MainThreadRequest) msg.obj;
1072 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1073 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1074 break;
1075
Hall Liu27d24262020-09-18 19:04:59 -07001076 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001077 request = (MainThreadRequest) msg.obj;
1078 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001079 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1080 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1081 request.argument;
1082 int callForwardingReason = args.first;
1083 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001084 break;
Hall Liu27d24262020-09-18 19:04:59 -07001085 }
1086 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001087 ar = (AsyncResult) msg.obj;
1088 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001089 TelephonyManager.CallForwardingInfoCallback callback =
1090 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1091 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001092 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001093 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001094 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1095 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1096 // Service Class is a bit mask per 3gpp 27.007. Search for
1097 // any service for voice call.
1098 if ((callForwardInfo.serviceClass
1099 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001100 callForwardingInfo = new CallForwardingInfo(true,
1101 callForwardInfo.reason,
1102 callForwardInfo.number,
1103 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001104 break;
1105 }
1106 }
1107 // Didn't find a call forward info for voice call.
1108 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001109 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1110 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001111 }
Hall Liu27d24262020-09-18 19:04:59 -07001112 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001113 } else {
1114 if (ar.result == null) {
1115 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1116 }
1117 if (ar.exception != null) {
1118 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1119 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001120 int errorCode = TelephonyManager
1121 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001122 if (ar.exception instanceof CommandException) {
1123 CommandException.Error error =
1124 ((CommandException) (ar.exception)).getCommandError();
1125 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001126 errorCode = TelephonyManager
1127 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001128 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001129 errorCode = TelephonyManager
1130 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001131 }
1132 }
Hall Liu27d24262020-09-18 19:04:59 -07001133 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 }
Shuo Qian4a594052020-01-23 11:59:30 -08001135 break;
Hall Liu27d24262020-09-18 19:04:59 -07001136 }
Shuo Qian4a594052020-01-23 11:59:30 -08001137
Hall Liu27d24262020-09-18 19:04:59 -07001138 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001141 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001142 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001143 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1144 request.argument).first;
1145 request.phone.setCallForwardingOption(
1146 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001147 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001148 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001149 callForwardingInfoToSet.getReason(),
1150 callForwardingInfoToSet.getNumber(),
1151 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1152 break;
Hall Liu27d24262020-09-18 19:04:59 -07001153 }
Shuo Qian4a594052020-01-23 11:59:30 -08001154
Hall Liu27d24262020-09-18 19:04:59 -07001155 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001156 ar = (AsyncResult) msg.obj;
1157 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001158 Consumer<Integer> callback =
1159 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1160 request.argument).second;
1161 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001162 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001163 int errorCode = TelephonyManager.CallForwardingInfoCallback
1164 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001165 if (ar.exception instanceof CommandException) {
1166 CommandException.Error error =
1167 ((CommandException) (ar.exception)).getCommandError();
1168 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001169 errorCode = TelephonyManager.CallForwardingInfoCallback
1170 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001171 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001172 errorCode = TelephonyManager.CallForwardingInfoCallback
1173 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001174 }
1175 }
1176 callback.accept(errorCode);
1177 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001178 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001179 }
Shuo Qian4a594052020-01-23 11:59:30 -08001180 break;
Hall Liu27d24262020-09-18 19:04:59 -07001181 }
Shuo Qian4a594052020-01-23 11:59:30 -08001182
Hall Liu27d24262020-09-18 19:04:59 -07001183 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1186 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1187 break;
Hall Liu27d24262020-09-18 19:04:59 -07001188 }
Shuo Qian4a594052020-01-23 11:59:30 -08001189
Hall Liu27d24262020-09-18 19:04:59 -07001190 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001191 ar = (AsyncResult) msg.obj;
1192 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001193 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001194 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1195 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001196 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001197 // Service Class is a bit mask per 3gpp 27.007.
1198 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001199 if (callForwardResults.length > 1
1200 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001201 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001202 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001203 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1204 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001205 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001206 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001207 }
1208 } else {
1209 if (ar.result == null) {
1210 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1211 }
1212 if (ar.exception != null) {
1213 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1214 }
1215 if (ar.exception instanceof CommandException) {
1216 CommandException.Error error =
1217 ((CommandException) (ar.exception)).getCommandError();
1218 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1219 callForwardingStatus =
1220 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1221 }
1222 }
1223 }
Hall Liu27d24262020-09-18 19:04:59 -07001224 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001225 break;
Hall Liu27d24262020-09-18 19:04:59 -07001226 }
Shuo Qian4a594052020-01-23 11:59:30 -08001227
Hall Liu27d24262020-09-18 19:04:59 -07001228 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001229 request = (MainThreadRequest) msg.obj;
1230 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001231 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1232 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001233 break;
Hall Liu27d24262020-09-18 19:04:59 -07001234 }
Shuo Qian4a594052020-01-23 11:59:30 -08001235
Hall Liu27d24262020-09-18 19:04:59 -07001236 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001237 ar = (AsyncResult) msg.obj;
1238 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001239 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1240 Consumer<Integer> callback =
1241 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1242 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001243 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001244 if (ar.exception instanceof CommandException) {
1245 CommandException.Error error =
1246 ((CommandException) (ar.exception)).getCommandError();
1247 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1248 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1249 } else {
1250 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1251 }
1252 } else {
1253 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1254 }
1255 } else {
1256 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1257 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001258 }
Shuo Qian4a594052020-01-23 11:59:30 -08001259 break;
Hall Liu27d24262020-09-18 19:04:59 -07001260 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001261 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1262 ar = (AsyncResult) msg.obj;
1263 request = (MainThreadRequest) ar.userObj;
1264 CellNetworkScanResult cellScanResult;
1265 if (ar.exception == null && ar.result != null) {
1266 cellScanResult = new CellNetworkScanResult(
1267 CellNetworkScanResult.STATUS_SUCCESS,
1268 (List<OperatorInfo>) ar.result);
1269 } else {
1270 if (ar.result == null) {
1271 loge("getCellNetworkScanResults: Empty response");
1272 }
1273 if (ar.exception != null) {
1274 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1275 }
1276 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1277 if (ar.exception instanceof CommandException) {
1278 CommandException.Error error =
1279 ((CommandException) (ar.exception)).getCommandError();
1280 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1281 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1282 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1283 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1284 }
1285 }
1286 cellScanResult = new CellNetworkScanResult(errorCode, null);
1287 }
1288 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001289 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001290 break;
1291
1292 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1293 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001294 ManualNetworkSelectionArgument selArg =
1295 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001296 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1297 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001298 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1299 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001300 break;
1301
1302 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null) {
1306 request.result = true;
1307 } else {
1308 request.result = false;
1309 loge("setNetworkSelectionModeManual " + ar.exception);
1310 }
1311 notifyRequester(request);
1312 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001313 break;
1314
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001315 case CMD_GET_MODEM_ACTIVITY_INFO:
1316 request = (MainThreadRequest) msg.obj;
1317 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001318 if (defaultPhone != null) {
1319 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001320 } else {
1321 ResultReceiver result = (ResultReceiver) request.argument;
1322 Bundle bundle = new Bundle();
1323 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001324 new ModemActivityInfo(0, 0, 0,
1325 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001326 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001327 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001328 break;
1329
Hall Liud0f208c2020-10-14 16:54:44 -07001330 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001331 ar = (AsyncResult) msg.obj;
1332 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001333 ResultReceiver result = (ResultReceiver) request.argument;
1334
Hall Liud0f208c2020-10-14 16:54:44 -07001335 ModemActivityInfo ret = null;
1336 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001337 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001338 // Update the last modem activity info and the result of the request.
1339 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1340 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001341 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001342 int[] txTimeMs = info.getTransmitTimeMillis();
1343 int[] lastModemTxTimeMs = mLastModemActivityInfo
1344 .getTransmitTimeMillis();
1345 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1346 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1347 }
Hall Liu49656c02020-10-09 19:00:11 -07001348 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001349 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1350 + mLastModemActivityInfo.getSleepTimeMillis());
1351 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1352 + mLastModemActivityInfo.getIdleTimeMillis());
1353 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1354 mLastModemActivityInfo.setReceiveTimeMillis(
1355 info.getReceiveTimeMillis()
1356 + mLastModemActivityInfo.getReceiveTimeMillis());
1357 }
Hall Liu49656c02020-10-09 19:00:11 -07001358 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001359 mLastModemActivityInfo.getSleepTimeMillis(),
1360 mLastModemActivityInfo.getIdleTimeMillis(),
1361 mLastModemActivityInfo.getTransmitTimeMillis(),
1362 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001363 } else {
1364 if (ar.result == null) {
1365 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001366 error = TelephonyManager.ModemActivityInfoException
1367 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001368 } else if (ar.exception instanceof CommandException) {
1369 loge("queryModemActivityInfo: CommandException: " +
1370 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001371 error = TelephonyManager.ModemActivityInfoException
1372 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001373 } else {
1374 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001375 error = TelephonyManager.ModemActivityInfoException
1376 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001377 }
1378 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001379 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001380 if (ret != null) {
1381 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1382 } else {
1383 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1384 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001385 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001386 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001387 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001388 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001389
Meng Wang1a7c35a2016-05-05 20:56:15 -07001390 case CMD_SET_ALLOWED_CARRIERS:
1391 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001392 CarrierRestrictionRules argument =
1393 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001394 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001395 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001396 break;
1397
1398 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception == null && ar.result != null) {
1402 request.result = ar.result;
1403 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001404 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1405 if (ar.exception instanceof CommandException) {
1406 loge("setAllowedCarriers: CommandException: " + ar.exception);
1407 CommandException.Error error =
1408 ((CommandException) (ar.exception)).getCommandError();
1409 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1410 request.result =
1411 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1412 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001413 } else {
1414 loge("setAllowedCarriers: Unknown exception");
1415 }
1416 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001417 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001418 break;
1419
1420 case CMD_GET_ALLOWED_CARRIERS:
1421 request = (MainThreadRequest) msg.obj;
1422 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001423 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001424 break;
1425
1426 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1427 ar = (AsyncResult) msg.obj;
1428 request = (MainThreadRequest) ar.userObj;
1429 if (ar.exception == null && ar.result != null) {
1430 request.result = ar.result;
1431 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001432 request.result = new IllegalStateException(
1433 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001434 if (ar.result == null) {
1435 loge("getAllowedCarriers: Empty response");
1436 } else if (ar.exception instanceof CommandException) {
1437 loge("getAllowedCarriers: CommandException: " +
1438 ar.exception);
1439 } else {
1440 loge("getAllowedCarriers: Unknown exception");
1441 }
1442 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001443 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001444 break;
1445
Nathan Haroldb3014052017-01-25 15:57:32 -08001446 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 if (ar.exception == null && ar.result != null) {
1450 request.result = ar.result;
1451 } else {
1452 request.result = new IllegalArgumentException(
1453 "Failed to retrieve Forbidden Plmns");
1454 if (ar.result == null) {
1455 loge("getForbiddenPlmns: Empty response");
1456 } else {
1457 loge("getForbiddenPlmns: Unknown exception");
1458 }
1459 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001460 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001461 break;
1462
1463 case CMD_GET_FORBIDDEN_PLMNS:
1464 request = (MainThreadRequest) msg.obj;
1465 uiccCard = getUiccCardFromRequest(request);
1466 if (uiccCard == null) {
1467 loge("getForbiddenPlmns() UiccCard is null");
1468 request.result = new IllegalArgumentException(
1469 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001470 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001471 break;
1472 }
1473 Integer appType = (Integer) request.argument;
1474 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1475 if (uiccApp == null) {
1476 loge("getForbiddenPlmns() no app with specified type -- "
1477 + appType);
1478 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001479 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001480 break;
1481 } else {
1482 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1483 + " specified type -- " + appType);
1484 }
1485 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1486 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1487 onCompleted);
1488 break;
1489
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001490 case CMD_SWITCH_SLOTS:
1491 request = (MainThreadRequest) msg.obj;
1492 int[] physicalSlots = (int[]) request.argument;
1493 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1494 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1495 break;
1496
1497 case EVENT_SWITCH_SLOTS_DONE:
1498 ar = (AsyncResult) msg.obj;
1499 request = (MainThreadRequest) ar.userObj;
1500 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 notifyRequester(request);
1502 break;
1503 case CMD_GET_NETWORK_SELECTION_MODE:
1504 request = (MainThreadRequest) msg.obj;
1505 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1506 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1507 break;
1508
1509 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1510 ar = (AsyncResult) msg.obj;
1511 request = (MainThreadRequest) ar.userObj;
1512 if (ar.exception != null) {
1513 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1514 } else {
1515 int mode = ((int[]) ar.result)[0];
1516 if (mode == 0) {
1517 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1518 } else {
1519 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1520 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
1523 break;
1524 case CMD_GET_CDMA_ROAMING_MODE:
1525 request = (MainThreadRequest) msg.obj;
1526 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1527 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1528 break;
1529 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 if (ar.exception != null) {
1533 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1534 } else {
1535 request.result = ((int[]) ar.result)[0];
1536 }
1537 notifyRequester(request);
1538 break;
1539 case CMD_SET_CDMA_ROAMING_MODE:
1540 request = (MainThreadRequest) msg.obj;
1541 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1542 int mode = (int) request.argument;
1543 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1544 break;
1545 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1546 ar = (AsyncResult) msg.obj;
1547 request = (MainThreadRequest) ar.userObj;
1548 request.result = ar.exception == null;
1549 notifyRequester(request);
1550 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001551 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1552 request = (MainThreadRequest) msg.obj;
1553 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1554 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1555 break;
1556 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1557 ar = (AsyncResult) msg.obj;
1558 request = (MainThreadRequest) ar.userObj;
1559 if (ar.exception != null) {
1560 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1561 } else {
1562 request.result = ((int[]) ar.result)[0];
1563 }
1564 notifyRequester(request);
1565 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001566 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1567 request = (MainThreadRequest) msg.obj;
1568 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1569 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001570 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1571 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001572 break;
1573 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1574 ar = (AsyncResult) msg.obj;
1575 request = (MainThreadRequest) ar.userObj;
1576 request.result = ar.exception == null;
1577 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001578 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001579 case CMD_GET_ALL_CELL_INFO:
1580 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001581 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001582 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001583 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001584 case EVENT_GET_ALL_CELL_INFO_DONE:
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001587 // If a timeout occurs, the response will be null
1588 request.result = (ar.exception == null && ar.result != null)
1589 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001590 synchronized (request) {
1591 request.notifyAll();
1592 }
1593 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001594 case CMD_REQUEST_CELL_INFO_UPDATE:
1595 request = (MainThreadRequest) msg.obj;
1596 request.phone.requestCellInfoUpdate(request.workSource,
1597 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1598 break;
1599 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1603 try {
1604 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001605 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001606 cb.onError(
1607 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1608 ar.exception.getClass().getName(),
1609 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001611 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001612 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001613 } else {
1614 // use the result as returned
1615 cb.onCellInfo((List<CellInfo>) ar.result);
1616 }
1617 } catch (RemoteException re) {
1618 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1619 }
1620 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001621 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001622 request = (MainThreadRequest) msg.obj;
1623 WorkSource ws = (WorkSource) request.argument;
1624 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001625 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001626 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001627 }
1628 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001629 ar = (AsyncResult) msg.obj;
1630 request = (MainThreadRequest) ar.userObj;
1631 if (ar.exception == null) {
1632 request.result = ar.result;
1633 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001634 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001635 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001636 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001637 }
1638
1639 synchronized (request) {
1640 request.notifyAll();
1641 }
1642 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001643 }
chen xu6dac5ab2018-10-26 17:39:23 -07001644 case CMD_MODEM_REBOOT:
1645 request = (MainThreadRequest) msg.obj;
1646 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001647 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001648 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001649 case EVENT_CMD_MODEM_REBOOT_DONE:
1650 handleNullReturnEvent(msg, "rebootModem");
1651 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001652 case CMD_REQUEST_ENABLE_MODEM:
1653 request = (MainThreadRequest) msg.obj;
1654 boolean enable = (boolean) request.argument;
1655 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001656 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001657 PhoneConfigurationManager.getInstance()
1658 .enablePhone(request.phone, enable, onCompleted);
1659 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001660 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001661 ar = (AsyncResult) msg.obj;
1662 request = (MainThreadRequest) ar.userObj;
1663 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001664 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001665 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001666 if ((boolean) request.result) {
1667 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1668 updateModemStateMetrics();
1669 } else {
1670 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1671 + ar.exception);
1672 }
1673 notifyRequester(request);
1674 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001675 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001676 case CMD_GET_MODEM_STATUS:
1677 request = (MainThreadRequest) msg.obj;
1678 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1679 PhoneConfigurationManager.getInstance()
1680 .getPhoneStatusFromModem(request.phone, onCompleted);
1681 break;
1682 case EVENT_GET_MODEM_STATUS_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 int id = request.phone.getPhoneId();
1686 if (ar.exception == null && ar.result != null) {
1687 request.result = ar.result;
1688 //update the cache as modem status has changed
1689 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1690 (boolean) request.result);
1691 } else {
1692 // Return true if modem status cannot be retrieved. For most cases,
1693 // modem status is on. And for older version modems, GET_MODEM_STATUS
1694 // and disable modem are not supported. Modem is always on.
1695 // TODO: this should be fixed in R to support a third
1696 // status UNKNOWN b/131631629
1697 request.result = true;
1698 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1699 + ar.exception);
1700 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001701 notifyRequester(request);
1702 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001703 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1706 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1707 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1708 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1709 break;
1710 }
1711 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1712 ar = (AsyncResult) msg.obj;
1713 request = (MainThreadRequest) ar.userObj;
1714 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1715 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1716 args.second.accept(ar.exception == null);
1717 notifyRequester(request);
1718 break;
1719 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001720 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1721 request = (MainThreadRequest) msg.obj;
1722 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1723 Phone phone = getPhoneFromRequest(request);
1724 if (phone != null) {
1725 phone.getSystemSelectionChannels(onCompleted);
1726 } else {
1727 loge("getSystemSelectionChannels: No phone object");
1728 request.result = new ArrayList<RadioAccessSpecifier>();
1729 notifyRequester(request);
1730 }
1731 break;
1732 }
1733 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736 if (ar.exception == null && ar.result != null) {
1737 request.result = ar.result;
1738 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001739 request.result = new IllegalStateException(
1740 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001741 if (ar.result == null) {
1742 loge("getSystemSelectionChannels: Empty response");
1743 } else {
1744 loge("getSystemSelectionChannels: Unknown exception");
1745 }
1746 }
1747 notifyRequester(request);
1748 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001749 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 if (ar.exception == null && ar.result != null) {
1753 request.result = ar.result;
1754 } else {
1755 request.result = -1;
1756 loge("Failed to set Forbidden Plmns");
1757 if (ar.result == null) {
1758 loge("setForbidenPlmns: Empty response");
1759 } else if (ar.exception != null) {
1760 loge("setForbiddenPlmns: Exception: " + ar.exception);
1761 request.result = -1;
1762 } else {
1763 loge("setForbiddenPlmns: Unknown exception");
1764 }
1765 }
1766 notifyRequester(request);
1767 break;
1768 case CMD_SET_FORBIDDEN_PLMNS:
1769 request = (MainThreadRequest) msg.obj;
1770 uiccCard = getUiccCardFromRequest(request);
1771 if (uiccCard == null) {
1772 loge("setForbiddenPlmns: UiccCard is null");
1773 request.result = -1;
1774 notifyRequester(request);
1775 break;
1776 }
1777 Pair<Integer, List<String>> setFplmnsArgs =
1778 (Pair<Integer, List<String>>) request.argument;
1779 appType = setFplmnsArgs.first;
1780 List<String> fplmns = setFplmnsArgs.second;
1781 uiccApp = uiccCard.getApplicationByType(appType);
1782 if (uiccApp == null) {
1783 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1784 request.result = -1;
1785 loge("Failed to get UICC App");
1786 notifyRequester(request);
1787 } else {
1788 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1789 ((SIMRecords) uiccApp.getIccRecords())
1790 .setForbiddenPlmns(onCompleted, fplmns);
1791 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001792 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001793 case CMD_ERASE_MODEM_CONFIG:
1794 request = (MainThreadRequest) msg.obj;
1795 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1796 defaultPhone.eraseModemConfig(onCompleted);
1797 break;
1798 case EVENT_ERASE_MODEM_CONFIG_DONE:
1799 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001800 break;
zoey chene02881a2019-12-30 16:11:23 +08001801
Kai Shif70f46f2021-03-03 13:59:46 -08001802 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1803 request = (MainThreadRequest) msg.obj;
1804 request.result = defaultPhone.eraseDataInSharedPreferences();
1805 notifyRequester(request);
1806 break;
1807
zoey chene02881a2019-12-30 16:11:23 +08001808 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1809 request = (MainThreadRequest) msg.obj;
1810 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1811 Pair<String, String> changed = (Pair<String, String>) request.argument;
1812 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1813 changed.first, changed.second, onCompleted);
1814 break;
1815 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1816 ar = (AsyncResult) msg.obj;
1817 request = (MainThreadRequest) ar.userObj;
1818 if (ar.exception == null) {
1819 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001820 // If the operation is successful, update the PIN storage
1821 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1822 int phoneId = getPhoneFromRequest(request).getPhoneId();
Grace Jia59437e82021-09-21 15:47:32 -07001823 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1824 pinStorage.storePin(passwords.second, phoneId,
1825 pinStorage.getIccid(phoneId));
zoey chene02881a2019-12-30 16:11:23 +08001826 } else {
1827 request.result = msg.arg1;
1828 }
1829 notifyRequester(request);
1830 break;
1831
Michele Berionne5e411512020-11-13 02:36:59 +00001832 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001833 request = (MainThreadRequest) msg.obj;
1834 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1835 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1836 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1837 enabled.first, enabled.second, onCompleted);
1838 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001839 }
zoey chene02881a2019-12-30 16:11:23 +08001840 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1841 ar = (AsyncResult) msg.obj;
1842 request = (MainThreadRequest) ar.userObj;
1843 if (ar.exception == null) {
1844 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001845 // If the operation is successful, update the PIN storage
1846 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1847 int phoneId = getPhoneFromRequest(request).getPhoneId();
1848 if (enabled.first) {
Grace Jia59437e82021-09-21 15:47:32 -07001849 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
1850 pinStorage.storePin(enabled.second, phoneId,
1851 pinStorage.getIccid(phoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00001852 } else {
1853 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1854 }
zoey chene02881a2019-12-30 16:11:23 +08001855 } else {
1856 request.result = msg.arg1;
1857 }
Michele Berionne5e411512020-11-13 02:36:59 +00001858
1859
zoey chene02881a2019-12-30 16:11:23 +08001860 notifyRequester(request);
1861 break;
1862
Peter Wangdafb9ac2020-01-15 14:13:38 -08001863 case MSG_NOTIFY_USER_ACTIVITY:
1864 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001865 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001866 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1867 getDefaultPhone().getContext().sendBroadcastAsUser(
1868 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1869 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001870
1871 case CMD_SET_DATA_THROTTLING: {
1872 request = (MainThreadRequest) msg.obj;
1873 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1874 DataThrottlingRequest dataThrottlingRequest =
1875 (DataThrottlingRequest) request.argument;
1876 Phone phone = getPhoneFromRequest(request);
1877 if (phone != null) {
1878 phone.setDataThrottling(onCompleted,
1879 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1880 dataThrottlingRequest.getCompletionDurationMillis());
1881 } else {
1882 loge("setDataThrottling: No phone object");
1883 request.result =
1884 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1885 notifyRequester(request);
1886 }
1887
1888 break;
1889 }
1890 case EVENT_SET_DATA_THROTTLING_DONE:
1891 ar = (AsyncResult) msg.obj;
1892 request = (MainThreadRequest) ar.userObj;
1893
1894 if (ar.exception == null) {
1895 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1896 } else if (ar.exception instanceof CommandException) {
1897 loge("setDataThrottling: CommandException: " + ar.exception);
1898 CommandException.Error error =
1899 ((CommandException) (ar.exception)).getCommandError();
1900
1901 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1902 request.result = TelephonyManager
1903 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1904 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1905 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001906 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1907 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001908 } else {
1909 request.result =
1910 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1911 }
1912 } else {
1913 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1914 }
1915 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1916 notifyRequester(request);
1917 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001918
1919 case CMD_SET_SIM_POWER: {
1920 request = (MainThreadRequest) msg.obj;
1921 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1922 request = (MainThreadRequest) msg.obj;
1923 int stateToSet =
1924 ((Pair<Integer, IIntegerConsumer>)
1925 request.argument).first;
1926 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1927 break;
1928 }
1929 case EVENT_SET_SIM_POWER_DONE: {
1930 ar = (AsyncResult) msg.obj;
1931 request = (MainThreadRequest) ar.userObj;
1932 IIntegerConsumer callback =
1933 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1934 if (ar.exception != null) {
1935 loge("setSimPower exception: " + ar.exception);
1936 int errorCode = TelephonyManager.CallForwardingInfoCallback
1937 .RESULT_ERROR_UNKNOWN;
1938 if (ar.exception instanceof CommandException) {
1939 CommandException.Error error =
1940 ((CommandException) (ar.exception)).getCommandError();
1941 if (error == CommandException.Error.SIM_ERR) {
1942 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1943 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1944 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1945 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1946 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1947 } else {
1948 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1949 }
1950 }
1951 try {
1952 callback.accept(errorCode);
1953 } catch (RemoteException e) {
1954 // Ignore if the remote process is no longer available to call back.
1955 Log.w(LOG_TAG, "setSimPower: callback not available.");
1956 }
1957 } else {
1958 try {
1959 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1960 } catch (RemoteException e) {
1961 // Ignore if the remote process is no longer available to call back.
1962 Log.w(LOG_TAG, "setSimPower: callback not available.");
1963 }
1964 }
1965 break;
1966 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001967 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1968 request = (MainThreadRequest) msg.obj;
1969
1970 final Phone phone = getPhoneFromRequest(request);
1971 if (phone == null || phone.getServiceStateTracker() == null) {
1972 request.result = new IllegalStateException("Phone or SST is null");
1973 notifyRequester(request);
1974 break;
1975 }
1976
1977 Pair<Integer, SignalStrengthUpdateRequest> pair =
1978 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1979 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1980 request);
1981 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1982 request.subId, pair.first /*callingUid*/,
1983 pair.second /*request*/, onCompleted);
1984 break;
1985 }
1986 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1987 ar = (AsyncResult) msg.obj;
1988 request = (MainThreadRequest) ar.userObj;
1989 // request.result will be the exception of ar if present, true otherwise.
1990 // Be cautious not to leave result null which will wait() forever
1991 request.result = ar.exception != null ? ar.exception : true;
1992 notifyRequester(request);
1993 break;
1994 }
1995 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1996 request = (MainThreadRequest) msg.obj;
1997
1998 Phone phone = getPhoneFromRequest(request);
1999 if (phone == null || phone.getServiceStateTracker() == null) {
2000 request.result = new IllegalStateException("Phone or SST is null");
2001 notifyRequester(request);
2002 break;
2003 }
2004
2005 Pair<Integer, SignalStrengthUpdateRequest> pair =
2006 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2007 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2008 request);
2009 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
2010 request.subId, pair.first /*callingUid*/,
2011 pair.second /*request*/, onCompleted);
2012 break;
2013 }
2014 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2015 ar = (AsyncResult) msg.obj;
2016 request = (MainThreadRequest) ar.userObj;
2017 request.result = ar.exception != null ? ar.exception : true;
2018 notifyRequester(request);
2019 break;
2020 }
Jordan Liu109698e2020-11-24 14:50:34 -08002021
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002022 case CMD_GET_SLICING_CONFIG: {
2023 request = (MainThreadRequest) msg.obj;
2024 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2025 request.phone.getSlicingConfig(onCompleted);
2026 break;
2027 }
2028 case EVENT_GET_SLICING_CONFIG_DONE: {
2029 ar = (AsyncResult) msg.obj;
2030 request = (MainThreadRequest) ar.userObj;
2031 ResultReceiver result = (ResultReceiver) request.argument;
2032
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002033 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002034 Bundle bundle = new Bundle();
2035 int resultCode = 0;
2036 if (ar.exception != null) {
2037 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2038 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002039 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 } else if (ar.result == null) {
2041 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002042 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002043 } else {
2044 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002045 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2046 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002047 }
2048
2049 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002050 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002051 }
2052 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2053 result.send(resultCode, bundle);
2054 notifyRequester(request);
2055 break;
2056 }
2057
Michele Berionne5e411512020-11-13 02:36:59 +00002058 case CMD_PREPARE_UNATTENDED_REBOOT:
2059 request = (MainThreadRequest) msg.obj;
2060 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002061 UiccController.getInstance().getPinStorage()
2062 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002063 notifyRequester(request);
2064 break;
2065
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 default:
2067 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2068 break;
2069 }
2070 }
Jake Hambye994d462014-02-03 13:10:13 -08002071
Pengquan Menga1bb6272018-09-06 09:59:22 -07002072 private void notifyRequester(MainThreadRequest request) {
2073 synchronized (request) {
2074 request.notifyAll();
2075 }
2076 }
2077
Jake Hambye994d462014-02-03 13:10:13 -08002078 private void handleNullReturnEvent(Message msg, String command) {
2079 AsyncResult ar = (AsyncResult) msg.obj;
2080 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2081 if (ar.exception == null) {
2082 request.result = true;
2083 } else {
2084 request.result = false;
2085 if (ar.exception instanceof CommandException) {
2086 loge(command + ": CommandException: " + ar.exception);
2087 } else {
2088 loge(command + ": Unknown exception");
2089 }
2090 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002091 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
2094
2095 /**
2096 * Posts the specified command to be executed on the main thread,
2097 * waits for the request to complete, and returns the result.
2098 * @see #sendRequestAsync
2099 */
2100 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002101 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2102 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002103 }
2104
2105 /**
2106 * Posts the specified command to be executed on the main thread,
2107 * waits for the request to complete, and returns the result.
2108 * @see #sendRequestAsync
2109 */
2110 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2111 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002112 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002113 }
2114
2115 /**
2116 * Posts the specified command to be executed on the main thread,
2117 * waits for the request to complete, and returns the result.
2118 * @see #sendRequestAsync
2119 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002120 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002121 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2122 }
2123
2124 /**
2125 * Posts the specified command to be executed on the main thread,
2126 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2127 * if not timeout or null otherwise.
2128 * @see #sendRequestAsync
2129 */
2130 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2131 long timeoutInMs) {
2132 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002133 }
2134
2135 /**
2136 * Posts the specified command to be executed on the main thread,
2137 * waits for the request to complete, and returns the result.
2138 * @see #sendRequestAsync
2139 */
Nathan Harold92bed182018-10-12 18:16:49 -07002140 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002141 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002142 }
2143
2144 /**
2145 * Posts the specified command to be executed on the main thread,
2146 * waits for the request to complete, and returns the result.
2147 * @see #sendRequestAsync
2148 */
2149 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002150 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2151 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002152 }
2153
2154 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002155 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2156 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2157 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002158 * @see #sendRequestAsync
2159 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002160 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2161 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2163 throw new RuntimeException("This method will deadlock if called from the main thread.");
2164 }
2165
Nathan Harold92bed182018-10-12 18:16:49 -07002166 MainThreadRequest request = null;
2167 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2168 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2169 } else if (phone != null) {
2170 request = new MainThreadRequest(argument, phone, workSource);
2171 } else {
2172 request = new MainThreadRequest(argument, subId, workSource);
2173 }
2174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 Message msg = mMainThreadHandler.obtainMessage(command, request);
2176 msg.sendToTarget();
2177
Rambo Wang0f050d82021-02-12 11:43:36 -08002178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002180 if (timeoutInMs >= 0) {
2181 // Wait for at least timeoutInMs before returning null request result
2182 long now = SystemClock.elapsedRealtime();
2183 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002184 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002185 try {
2186 request.wait(deadline - now);
2187 } catch (InterruptedException e) {
2188 // Do nothing, go back and check if request is completed or timeout
2189 } finally {
2190 now = SystemClock.elapsedRealtime();
2191 }
2192 }
2193 } else {
2194 // Wait for the request to complete
2195 while (request.result == null) {
2196 try {
2197 request.wait();
2198 } catch (InterruptedException e) {
2199 // Do nothing, go back and wait until the request is complete
2200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002201 }
2202 }
2203 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002204 if (request.result == null) {
2205 Log.wtf(LOG_TAG,
2206 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 return request.result;
2209 }
2210
2211 /**
2212 * Asynchronous ("fire and forget") version of sendRequest():
2213 * Posts the specified command to be executed on the main thread, and
2214 * returns immediately.
2215 * @see #sendRequest
2216 */
2217 private void sendRequestAsync(int command) {
2218 mMainThreadHandler.sendEmptyMessage(command);
2219 }
2220
2221 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002222 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002223 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002224 */
2225 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002226 sendRequestAsync(command, argument, null, null);
2227 }
2228
2229 /**
2230 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2231 * @see {@link #sendRequest(int,Object)}
2232 */
2233 private void sendRequestAsync(
2234 int command, Object argument, Phone phone, WorkSource workSource) {
2235 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002236 Message msg = mMainThreadHandler.obtainMessage(command, request);
2237 msg.sendToTarget();
2238 }
2239
2240 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 * Initialize the singleton PhoneInterfaceManager instance.
2242 * This is only done once, at startup, from PhoneApp.onCreate().
2243 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002244 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 synchronized (PhoneInterfaceManager.class) {
2246 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002247 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 } else {
2249 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2250 }
2251 return sInstance;
2252 }
2253 }
2254
2255 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002256 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002259 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002260 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002262 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002264 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002265 mTelephonySharedPreferences =
2266 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002267 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002268 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002269 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002270 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002271
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 publish();
2273 }
2274
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002275 private Phone getDefaultPhone() {
2276 Phone thePhone = getPhone(getDefaultSubscription());
2277 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2278 }
2279
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 private void publish() {
2281 if (DBG) log("publish: " + this);
2282
Peter Wangc035ce42020-01-08 21:00:22 -08002283 TelephonyFrameworkInitializer
2284 .getTelephonyServiceManager()
2285 .getTelephonyServiceRegisterer()
2286 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 }
2288
Stuart Scott584921c2015-01-15 17:10:34 -08002289 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002290 if (request.phone != null) {
2291 return request.phone;
2292 } else {
2293 return getPhoneFromSubId(request.subId);
2294 }
2295 }
2296
2297 private Phone getPhoneFromSubId(int subId) {
2298 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2299 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002300 }
2301
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002302 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2303 Phone phone = getPhoneFromRequest(request);
2304 return phone == null ? null :
2305 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2306 }
2307
Wink Saville36469e72014-06-11 15:17:00 -07002308 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002309 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002310 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312
Kai Shif70f46f2021-03-03 13:59:46 -08002313 private void sendEraseModemConfig(@NonNull Phone phone) {
2314 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2315 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2316 }
2317
2318 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2319 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2320 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002321 }
2322
Peter Wang44b186e2020-01-13 23:33:09 -08002323 private boolean isImsAvailableOnDevice() {
2324 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2325 if (pm == null) {
2326 // For some reason package manger is not available.. This will fail internally anyway,
2327 // so do not throw error and allow.
2328 return true;
2329 }
2330 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2331 }
2332
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002334 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
Wink Savilleb564aae2014-10-23 10:18:09 -07002337 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 if (DBG) log("dial: " + number);
2339 // No permission check needed here: This is just a wrapper around the
2340 // ACTION_DIAL intent, which is available to any app since it puts up
2341 // the UI before it does anything.
2342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 String url = createTelUrl(number);
2346 if (url == null) {
2347 return;
2348 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350 // PENDING: should we just silently fail if phone is offhook or ringing?
2351 PhoneConstants.State state = mCM.getState(subId);
2352 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2353 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2354 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2355 mApp.startActivity(intent);
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360 }
2361
2362 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002363 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002364 }
2365
Wink Savilleb564aae2014-10-23 10:18:09 -07002366 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 if (DBG) log("call: " + number);
2368
2369 // This is just a wrapper around the ACTION_CALL intent, but we still
2370 // need to do a permission check since we're calling startActivity()
2371 // from the context of the phone app.
2372 enforceCallPermission();
2373
Jordan Liu1617b712019-07-10 15:06:26 -07002374 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 != AppOpsManager.MODE_ALLOWED) {
2376 return;
2377 }
2378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 String url = createTelUrl(number);
2382 if (url == null) {
2383 return;
2384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386 boolean isValid = false;
2387 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2388 if (slist != null) {
2389 for (SubscriptionInfo subInfoRecord : slist) {
2390 if (subInfoRecord.getSubscriptionId() == subId) {
2391 isValid = true;
2392 break;
2393 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002394 }
Wink Saville08874612014-08-31 19:19:58 -07002395 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 if (!isValid) {
2397 return;
2398 }
Wink Saville08874612014-08-31 19:19:58 -07002399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002400 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2401 intent.putExtra(SUBSCRIPTION_KEY, subId);
2402 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2403 mApp.startActivity(intent);
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 }
2408
Wink Savilleb564aae2014-10-23 10:18:09 -07002409 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002410 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002411 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2412 }
2413
Wink Savilleb564aae2014-10-23 10:18:09 -07002414 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002415 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002416 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2417 }
2418
Wink Savilleb564aae2014-10-23 10:18:09 -07002419 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002421
2422 final long identity = Binder.clearCallingIdentity();
2423 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002424 Phone phone = getPhone(subId);
2425 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426 checkSimPin.start();
2427 return checkSimPin.unlockSim(null, pin);
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002434 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002435
2436 final long identity = Binder.clearCallingIdentity();
2437 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002438 Phone phone = getPhone(subId);
2439 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002440 checkSimPuk.start();
2441 return checkSimPuk.unlockSim(puk, pin);
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
2444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
2447 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002448 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 * a synchronous one.
2450 */
2451 private static class UnlockSim extends Thread {
2452
2453 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002454 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
2456 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002457 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2458 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002459
2460 // For replies from SimCard interface
2461 private Handler mHandler;
2462
2463 // For async handler to identify request type
2464 private static final int SUPPLY_PIN_COMPLETE = 100;
2465
Michele Berionne5e411512020-11-13 02:36:59 +00002466 UnlockSim(int phoneId, IccCard simCard) {
2467 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 mSimCard = simCard;
2469 }
2470
2471 @Override
2472 public void run() {
2473 Looper.prepare();
2474 synchronized (UnlockSim.this) {
2475 mHandler = new Handler() {
2476 @Override
2477 public void handleMessage(Message msg) {
2478 AsyncResult ar = (AsyncResult) msg.obj;
2479 switch (msg.what) {
2480 case SUPPLY_PIN_COMPLETE:
2481 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2482 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002483 mRetryCount = msg.arg1;
2484 if (ar.exception != null) {
2485 if (ar.exception instanceof CommandException &&
2486 ((CommandException)(ar.exception)).getCommandError()
2487 == CommandException.Error.PASSWORD_INCORRECT) {
2488 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002489 } //When UiccCardApp dispose,handle message and return exception
2490 else if (ar.exception instanceof CommandException &&
2491 ((CommandException) (ar.exception)).getCommandError()
2492 == CommandException.Error.ABORTED) {
2493 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002494 } else {
2495 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2496 }
2497 } else {
2498 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002500 mDone = true;
2501 UnlockSim.this.notifyAll();
2502 }
2503 break;
2504 }
2505 }
2506 };
2507 UnlockSim.this.notifyAll();
2508 }
2509 Looper.loop();
2510 }
2511
2512 /*
2513 * Use PIN or PUK to unlock SIM card
2514 *
2515 * If PUK is null, unlock SIM card with PIN
2516 *
2517 * If PUK is not null, unlock SIM card with PUK and set PIN code
2518 */
Wink Saville9de0f752013-10-22 19:04:03 -07002519 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520
2521 while (mHandler == null) {
2522 try {
2523 wait();
2524 } catch (InterruptedException e) {
2525 Thread.currentThread().interrupt();
2526 }
2527 }
2528 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2529
2530 if (puk == null) {
2531 mSimCard.supplyPin(pin, callback);
2532 } else {
2533 mSimCard.supplyPuk(puk, pin, callback);
2534 }
2535
2536 while (!mDone) {
2537 try {
2538 Log.d(LOG_TAG, "wait for done");
2539 wait();
2540 } catch (InterruptedException e) {
2541 // Restore the interrupted status
2542 Thread.currentThread().interrupt();
2543 }
2544 }
2545 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002546 int[] resultArray = new int[2];
2547 resultArray[0] = mResult;
2548 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002549
2550 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Grace Jia59437e82021-09-21 15:47:32 -07002551 PinStorage pinStorage = UiccController.getInstance().getPinStorage();
2552 pinStorage.storePin(pin, mPhoneId, pinStorage.getIccid(mPhoneId));
Michele Berionne5e411512020-11-13 02:36:59 +00002553 }
2554
Wink Saville9de0f752013-10-22 19:04:03 -07002555 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 }
2557 }
2558
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002559 /**
2560 * This method has been removed due to privacy and stability concerns.
2561 */
2562 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002564 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2565 return;
Wink Saville36469e72014-06-11 15:17:00 -07002566 }
2567
Nathan Harold1f889d82020-06-04 17:05:26 -07002568 @Override
2569 public void updateServiceLocationWithPackageName(String callingPackage) {
2570 mApp.getSystemService(AppOpsManager.class)
2571 .checkPackage(Binder.getCallingUid(), callingPackage);
2572
Nathan Haroldf096d982020-11-18 17:18:06 -08002573 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002574 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2575 // Callers targeting S have no business invoking this method.
2576 return;
2577 }
2578
2579 LocationAccessPolicy.LocationPermissionResult locationResult =
2580 LocationAccessPolicy.checkLocationPermission(mApp,
2581 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2582 .setCallingPackage(callingPackage)
2583 .setCallingFeatureId(null)
2584 .setCallingPid(Binder.getCallingPid())
2585 .setCallingUid(Binder.getCallingUid())
2586 .setMethod("updateServiceLocation")
2587 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2588 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2589 .build());
2590 // Apps that lack location permission have no business calling this method;
2591 // however, because no permission was declared in the public API, denials must
2592 // all be "soft".
2593 switch (locationResult) {
2594 case DENIED_HARD: /* fall through */
2595 case DENIED_SOFT:
2596 return;
2597 }
2598
2599 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 final long identity = Binder.clearCallingIdentity();
2601 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002602 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002604 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002611 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002612 @Override
2613 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002614 return isRadioOnWithFeature(callingPackage, null);
2615 }
2616
2617
2618 @Override
2619 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2620 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2621 callingFeatureId);
2622 }
2623
2624 @Deprecated
2625 @Override
2626 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2627 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002628 }
2629
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002631 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2632 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002634 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002635 return false;
2636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637
2638 final long identity = Binder.clearCallingIdentity();
2639 try {
2640 return isRadioOnForSubscriber(subId);
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002644 }
2645
2646 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 final Phone phone = getPhone(subId);
2650 if (phone != null) {
2651 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2652 } else {
2653 return false;
2654 }
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
2660 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002661 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 }
Wink Saville36469e72014-06-11 15:17:00 -07002663
Wink Savilleb564aae2014-10-23 10:18:09 -07002664 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 final Phone phone = getPhone(subId);
2670 if (phone != null) {
2671 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Wink Saville36469e72014-06-11 15:17:00 -07002676 }
2677
2678 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002679 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002680 }
2681
Wink Savilleb564aae2014-10-23 10:18:09 -07002682 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 final Phone phone = getPhone(subId);
2688 if (phone == null) {
2689 return false;
2690 }
2691 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2692 toggleRadioOnOffForSubscriber(subId);
2693 }
2694 return true;
2695 } finally {
2696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002698 }
Wink Saville36469e72014-06-11 15:17:00 -07002699
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002700 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002701 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002702 /*
2703 * If any of the Radios are available, it will need to be
2704 * shutdown. So return true if any Radio is available.
2705 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2709 Phone phone = PhoneFactory.getPhone(i);
2710 if (phone != null && phone.isRadioAvailable()) return true;
2711 }
2712 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2713 return false;
2714 } finally {
2715 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002717 }
2718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002720 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 enforceModifyPermission();
2722
2723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2726 logv("Shutting down Phone " + i);
2727 shutdownRadioUsingPhoneId(i);
2728 }
2729 } finally {
2730 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002731 }
2732 }
2733
2734 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002735 Phone phone = PhoneFactory.getPhone(phoneId);
2736 if (phone != null && phone.isRadioAvailable()) {
2737 phone.shutdownRadio();
2738 }
2739 }
2740
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002741 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002742 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2747 if (defaultPhone != null) {
2748 defaultPhone.setRadioPower(turnOn);
2749 return true;
2750 } else {
2751 loge("There's no default phone.");
2752 return false;
2753 }
2754 } finally {
2755 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002756 }
Wink Saville36469e72014-06-11 15:17:00 -07002757 }
2758
Wink Savilleb564aae2014-10-23 10:18:09 -07002759 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002761
2762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 final Phone phone = getPhone(subId);
2765 if (phone != null) {
2766 phone.setRadioPower(turnOn);
2767 return true;
2768 } else {
2769 return false;
2770 }
2771 } finally {
2772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 }
2775
Wink Saville36469e72014-06-11 15:17:00 -07002776 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 public boolean enableDataConnectivity() {
2779 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 int subId = mSubscriptionController.getDefaultDataSubId();
2784 final Phone phone = getPhone(subId);
2785 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002786 phone.getDataEnabledSettings().setDataEnabled(
2787 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002788 return true;
2789 } else {
2790 return false;
2791 }
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796
Wink Saville36469e72014-06-11 15:17:00 -07002797 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002798 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002799 public boolean disableDataConnectivity() {
2800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002801
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 int subId = mSubscriptionController.getDefaultDataSubId();
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002807 phone.getDataEnabledSettings().setDataEnabled(
2808 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809 return true;
2810 } else {
2811 return false;
2812 }
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 }
2817
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002819 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 final Phone phone = getPhone(subId);
2823 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002824 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 } else {
2826 return false;
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832
2833 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002834 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002835 }
2836
pkanwarae03a6b2016-11-06 20:37:09 -08002837 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 enforceCallPermission();
2839
2840 final long identity = Binder.clearCallingIdentity();
2841 try {
2842 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2843 return;
2844 }
2845 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2846 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
2849 }
pkanwar32d516d2016-10-14 19:37:38 -07002850 };
2851
Wink Savilleb564aae2014-10-23 10:18:09 -07002852 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2858 return false;
2859 }
2860 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 }
2865
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002866 /**
2867 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2868 * tag on getCallState Binder call.
2869 */
2870 @Deprecated
2871 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002873 if (CompatChanges.isChangeEnabled(
2874 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2875 Binder.getCallingUid())) {
2876 // Do not allow this API to be called on API version 31+, it should only be
2877 // called on old apps using this Binder call directly.
2878 throw new SecurityException("This method can only be used for applications "
2879 + "targeting API version 30 or less.");
2880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881 final long identity = Binder.clearCallingIdentity();
2882 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002883 Phone phone = getPhone(getDefaultSubscription());
2884 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2885 PhoneConstantConversions.convertCallState(phone.getState());
2886 } finally {
2887 Binder.restoreCallingIdentity(identity);
2888 }
2889 }
2890
2891 @Override
2892 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2893 if (CompatChanges.isChangeEnabled(
2894 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2895 Binder.getCallingUid())) {
2896 // Check READ_PHONE_STATE for API version 31+
2897 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2898 featureId, "getCallStateForSubscription")) {
2899 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2900 + "targeting API level 31+.");
2901 }
2902 }
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2907 PhoneConstantConversions.convertCallState(phone.getState());
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
2910 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002911 }
2912
Sanket Padawe356d7632015-06-22 14:03:32 -07002913 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002914 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002915 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2916 }
2917
2918 @Override
2919 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002920 final long identity = Binder.clearCallingIdentity();
2921 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002922 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 if (phone != null) {
2924 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2925 } else {
2926 return PhoneConstantConversions.convertDataState(
2927 PhoneConstants.DataState.DISCONNECTED);
2928 }
2929 } finally {
2930 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002932 }
2933
Sanket Padawe356d7632015-06-22 14:03:32 -07002934 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002935 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002936 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2937 }
2938
2939 @Override
2940 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 final long identity = Binder.clearCallingIdentity();
2942 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002943 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002944 if (phone != null) {
2945 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2946 } else {
2947 return TelephonyManager.DATA_ACTIVITY_NONE;
2948 }
2949 } finally {
2950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002952 }
2953
2954 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002955 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002956 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002957 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002958
2959 LocationAccessPolicy.LocationPermissionResult locationResult =
2960 LocationAccessPolicy.checkLocationPermission(mApp,
2961 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2962 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002963 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002964 .setCallingPid(Binder.getCallingPid())
2965 .setCallingUid(Binder.getCallingUid())
2966 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002967 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002968 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2969 .build());
2970 switch (locationResult) {
2971 case DENIED_HARD:
2972 throw new SecurityException("Not allowed to access cell location");
2973 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002974 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2975 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002976 }
2977
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002978 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002982 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002983 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
Svetoslav64fad262015-04-14 14:35:21 -07002987 }
2988
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002989 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002990 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002991 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2992 // registered cell info, so return a NULL country instead.
2993 final long identity = Binder.clearCallingIdentity();
2994 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002995 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2996 // Get default phone in this case.
2997 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2998 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002999 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07003001 if (phone == null) return "";
3002 ServiceStateTracker sst = phone.getServiceStateTracker();
3003 if (sst == null) return "";
3004 LocaleTracker lt = sst.getLocaleTracker();
3005 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003006 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003010 }
3011
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003012 /**
3013 * This method was removed due to potential issues caused by performing partial
3014 * updates of service state, and lack of a credible use case.
3015 *
3016 * This has the ability to break the telephony implementation by disabling notification of
3017 * changes in device connectivity. DO NOT USE THIS!
3018 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003019 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003020 public void enableLocationUpdates() {
3021 mApp.enforceCallingOrSelfPermission(
3022 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 }
3024
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003025 /**
3026 * This method was removed due to potential issues caused by performing partial
3027 * updates of service state, and lack of a credible use case.
3028 *
3029 * This has the ability to break the telephony implementation by disabling notification of
3030 * changes in device connectivity. DO NOT USE THIS!
3031 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003032 @Override
3033 public void disableLocationUpdates() {
3034 mApp.enforceCallingOrSelfPermission(
3035 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003036 }
3037
3038 @Override
3039 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003040 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3041 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003042 try {
3043 mApp.getSystemService(AppOpsManager.class)
3044 .checkPackage(Binder.getCallingUid(), callingPackage);
3045 } catch (SecurityException e) {
3046 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3047 throw e;
3048 }
3049
Nathan Haroldf096d982020-11-18 17:18:06 -08003050 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003051 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3052 throw new SecurityException(
3053 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3054 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003055
Jordan Liu1617b712019-07-10 15:06:26 -07003056 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3058 return null;
3059 }
Svetoslav64fad262015-04-14 14:35:21 -07003060
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003061 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003063 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003064 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003065
Nathan Haroldf180aac2018-06-01 18:43:55 -07003066 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3067 for (CellInfo ci : info) {
3068 if (ci instanceof CellInfoGsm) {
3069 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3070 } else if (ci instanceof CellInfoWcdma) {
3071 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3072 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003074 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003075 }
3076
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003077 private List<CellInfo> getCachedCellInfo() {
3078 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3079 for (Phone phone : PhoneFactory.getPhones()) {
3080 List<CellInfo> info = phone.getAllCellInfo();
3081 if (info != null) cellInfos.addAll(info);
3082 }
3083 return cellInfos;
3084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003085
3086 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003087 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003089 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003090
3091 LocationAccessPolicy.LocationPermissionResult locationResult =
3092 LocationAccessPolicy.checkLocationPermission(mApp,
3093 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3094 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003095 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003096 .setCallingPid(Binder.getCallingPid())
3097 .setCallingUid(Binder.getCallingUid())
3098 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003099 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003100 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3101 .build());
3102 switch (locationResult) {
3103 case DENIED_HARD:
3104 throw new SecurityException("Not allowed to access cell info");
3105 case DENIED_SOFT:
3106 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003107 }
3108
Nathan Haroldf096d982020-11-18 17:18:06 -08003109 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003110 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3111 return getCachedCellInfo();
3112 }
3113
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003114 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003115 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3119 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003120 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003121 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122 if (info != null) cellInfos.addAll(info);
3123 }
3124 return cellInfos;
3125 } finally {
3126 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 }
3128 }
3129
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003130 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003131 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3132 String callingFeatureId) {
3133 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3134 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003135 }
3136
3137 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003138 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3139 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003140 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003141 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003142 }
3143
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003144 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3145 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003146 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003147 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003148
3149 LocationAccessPolicy.LocationPermissionResult locationResult =
3150 LocationAccessPolicy.checkLocationPermission(mApp,
3151 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3152 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003153 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003154 .setCallingPid(Binder.getCallingPid())
3155 .setCallingUid(Binder.getCallingUid())
3156 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003157 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3158 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003159 .build());
3160 switch (locationResult) {
3161 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003162 if (TelephonyPermissions
3163 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003164 // Safetynet logging for b/154934934
3165 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3166 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003167 throw new SecurityException("Not allowed to access cell info");
3168 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003169 if (TelephonyPermissions
3170 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003171 // Safetynet logging for b/154934934
3172 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3173 }
Nathan Harold5320c422019-05-09 10:26:08 -07003174 try {
3175 cb.onCellInfo(new ArrayList<CellInfo>());
3176 } catch (RemoteException re) {
3177 // Drop without consequences
3178 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003179 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003180 }
3181
Nathan Harolda939a962019-05-09 10:13:47 -07003182
3183 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003184 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3185
3186 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3187 }
3188
3189 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003191 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003192 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003196 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 } finally {
3198 Binder.restoreCallingIdentity(identity);
3199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 }
3201
Shishir Agrawala9f32182016-04-12 12:00:16 -07003202 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003203 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003204 Phone phone = PhoneFactory.getPhone(slotIndex);
3205 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003206 return null;
3207 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003208 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003209 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003210 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003211 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003212 return null;
3213 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003214
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 return phone.getImei();
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
3220 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003221 }
3222
3223 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003224 public String getTypeAllocationCodeForSlot(int slotIndex) {
3225 Phone phone = PhoneFactory.getPhone(slotIndex);
3226 String tac = null;
3227 if (phone != null) {
3228 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003229 try {
3230 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3231 } catch (IndexOutOfBoundsException e) {
3232 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3233 return null;
3234 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003235 }
3236 return tac;
3237 }
3238
3239 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003240 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003241 try {
3242 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3243 } catch (SecurityException se) {
3244 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3245 throw new SecurityException("Package " + callingPackage + " does not belong to "
3246 + Binder.getCallingUid());
3247 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003248 Phone phone = PhoneFactory.getPhone(slotIndex);
3249 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003250 return null;
3251 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003252
Jeff Davidson913390f2018-02-23 17:11:49 -08003253 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003254 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003255 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003256 return null;
3257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003258
3259 final long identity = Binder.clearCallingIdentity();
3260 try {
3261 return phone.getMeid();
3262 } finally {
3263 Binder.restoreCallingIdentity(identity);
3264 }
Jack Yu2af8d712017-03-15 17:14:14 -07003265 }
3266
3267 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003268 public String getManufacturerCodeForSlot(int slotIndex) {
3269 Phone phone = PhoneFactory.getPhone(slotIndex);
3270 String manufacturerCode = null;
3271 if (phone != null) {
3272 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003273 try {
3274 manufacturerCode =
3275 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3276 } catch (IndexOutOfBoundsException e) {
3277 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3278 return null;
3279 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003280 }
3281 return manufacturerCode;
3282 }
3283
3284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003285 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3286 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 Phone phone = PhoneFactory.getPhone(slotIndex);
3288 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003289 return null;
3290 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003291 int subId = phone.getSubId();
3292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003293 mApp, subId, callingPackage, callingFeatureId,
3294 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003295 return null;
3296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003297
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 return phone.getDeviceSvn();
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003304 }
3305
fionaxu43304da2017-11-27 22:51:16 -08003306 @Override
3307 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 final Phone phone = getPhone(subId);
3311 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
fionaxu43304da2017-11-27 22:51:16 -08003315 }
3316
3317 @Override
3318 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 final Phone phone = getPhone(subId);
3322 return phone == null ? null : phone.getCarrierName();
3323 } finally {
3324 Binder.restoreCallingIdentity(identity);
3325 }
fionaxu43304da2017-11-27 22:51:16 -08003326 }
3327
calvinpanffe225e2018-11-01 19:43:06 +08003328 @Override
chen xu0026ca62019-03-06 15:28:50 -08003329 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 final Phone phone = getPhone(subId);
3333 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003334 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
3340 @Override
chen xu0026ca62019-03-06 15:28:50 -08003341 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003342 final long identity = Binder.clearCallingIdentity();
3343 try {
3344 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003345 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
3349 }
3350
chen xu651eec72018-11-11 19:03:44 -08003351 @Override
chen xu864e11c2018-12-06 22:10:03 -08003352 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3353 if (!isSubscriptionMccMnc) {
3354 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3355 }
chen xu651eec72018-11-11 19:03:44 -08003356 final Phone phone = PhoneFactory.getPhone(slotIndex);
3357 if (phone == null) {
3358 return TelephonyManager.UNKNOWN_CARRIER_ID;
3359 }
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3363 } finally {
3364 Binder.restoreCallingIdentity(identity);
3365 }
3366 }
3367
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003368 //
3369 // Internal helper methods.
3370 //
3371
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003372 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003373 * Make sure the caller is the calling package itself
3374 *
3375 * @throws SecurityException if the caller is not the calling package
3376 */
3377 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3378 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003379 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3380 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003381 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003382 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003383 } catch (PackageManager.NameNotFoundException e) {
3384 // packageUid is -1
3385 }
3386 if (packageUid != callingUid) {
3387 throw new SecurityException(message + ": Package " + callingPackage
3388 + " does not belong to " + callingUid);
3389 }
3390 }
3391
3392 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3394 *
3395 * @throws SecurityException if the caller does not have the required permission
3396 */
3397 private void enforceModifyPermission() {
3398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3399 }
3400
Shuo Qiancd19c462020-01-16 20:51:11 -08003401 /**
3402 * Make sure the caller is system.
3403 *
3404 * @throws SecurityException if the caller is not system.
3405 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003406 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003407 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3408 throw new SecurityException("Caller must be system");
3409 }
3410 }
3411
Shuo Qian3b6ee772019-11-13 17:43:31 -08003412 private void enforceActiveEmergencySessionPermission() {
3413 mApp.enforceCallingOrSelfPermission(
3414 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3415 }
3416
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003417 /**
3418 * Make sure the caller has the CALL_PHONE permission.
3419 *
3420 * @throws SecurityException if the caller does not have the required permission
3421 */
3422 private void enforceCallPermission() {
3423 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3424 }
3425
paulhu5a773602019-08-23 19:17:33 +08003426 private void enforceSettingsPermission() {
3427 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003428 }
3429
Michele Berionne5e411512020-11-13 02:36:59 +00003430 private void enforceRebootPermission() {
3431 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3432 }
3433
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003434 private String createTelUrl(String number) {
3435 if (TextUtils.isEmpty(number)) {
3436 return null;
3437 }
3438
Jake Hambye994d462014-02-03 13:10:13 -08003439 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 }
3441
Ihab Awadf9e92732013-12-05 18:02:52 -08003442 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003443 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3444 }
3445
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003446 private static void logv(String msg) {
3447 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3448 }
3449
Ihab Awadf9e92732013-12-05 18:02:52 -08003450 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3452 }
3453
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003454 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003455 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003456 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003457 }
3458
Sanket Padawe356d7632015-06-22 14:03:32 -07003459 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003460 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 final Phone phone = PhoneFactory.getPhone(slotIndex);
3464 if (phone == null) {
3465 return PhoneConstants.PHONE_TYPE_NONE;
3466 } else {
3467 return phone.getPhoneType();
3468 }
3469 } finally {
3470 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003471 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003472 }
3473
3474 /**
3475 * Returns the CDMA ERI icon index to display
3476 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003478 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3479 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3480 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003481 }
3482
Sanket Padawe356d7632015-06-22 14:03:32 -07003483 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003484 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3485 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003487 mApp, subId, callingPackage, callingFeatureId,
3488 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003489 return -1;
3490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 final Phone phone = getPhone(subId);
3495 if (phone != null) {
3496 return phone.getCdmaEriIconIndex();
3497 } else {
3498 return -1;
3499 }
3500 } finally {
3501 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003503 }
3504
3505 /**
3506 * Returns the CDMA ERI icon mode,
3507 * 0 - ON
3508 * 1 - FLASHING
3509 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003510 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003511 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3512 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3513 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003514 }
3515
Sanket Padawe356d7632015-06-22 14:03:32 -07003516 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003517 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3518 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003519 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003520 mApp, subId, callingPackage, callingFeatureId,
3521 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 return -1;
3523 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003524
3525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 final Phone phone = getPhone(subId);
3528 if (phone != null) {
3529 return phone.getCdmaEriIconMode();
3530 } else {
3531 return -1;
3532 }
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 }
3537
3538 /**
3539 * Returns the CDMA ERI text,
3540 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003541 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003542 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3543 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3544 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003545 }
3546
Sanket Padawe356d7632015-06-22 14:03:32 -07003547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3549 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003550 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003551 mApp, subId, callingPackage, callingFeatureId,
3552 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003553 return null;
3554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555
3556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 final Phone phone = getPhone(subId);
3559 if (phone != null) {
3560 return phone.getCdmaEriText();
3561 } else {
3562 return null;
3563 }
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003567 }
3568
3569 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003570 * Returns the CDMA MDN.
3571 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003572 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003573 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003574 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3575 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576
3577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 return phone.getLine1Number();
3582 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003583 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003584 return null;
3585 }
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003588 }
3589 }
3590
3591 /**
3592 * Returns the CDMA MIN.
3593 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003594 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003595 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3597 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003598
3599 final long identity = Binder.clearCallingIdentity();
3600 try {
3601 final Phone phone = getPhone(subId);
3602 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3603 return phone.getCdmaMin();
3604 } else {
3605 return null;
3606 }
3607 } finally {
3608 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003609 }
3610 }
3611
Hall Liud892bec2018-11-30 14:51:45 -08003612 @Override
3613 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3614 INumberVerificationCallback callback, String callingPackage) {
3615 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3616 != PERMISSION_GRANTED) {
3617 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3618 }
3619 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3620
3621 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3622 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003623 throw new SecurityException("Calling package must be configured in the device config: "
3624 + "calling package: " + callingPackage
3625 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003626 }
3627
3628 if (range == null) {
3629 throw new NullPointerException("Range must be non-null");
3630 }
3631
3632 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003633 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003634
3635 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3636 }
3637
Junda Liuca05d5d2014-08-14 22:36:34 -07003638 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003639 * Returns true if CDMA provisioning needs to run.
3640 */
3641 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642 final long identity = Binder.clearCallingIdentity();
3643 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003644 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 }
3649
3650 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003651 * Sets the voice mail number of a given subId.
3652 */
3653 @Override
3654 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003655 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3656 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
3660 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3661 new Pair<String, String>(alphaTag, number), new Integer(subId));
3662 return success;
3663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003666 }
3667
Ta-wei Yen87c49842016-05-13 21:19:52 -07003668 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003669 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3670 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003671 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3672 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003673 if (!TextUtils.equals(callingPackage, systemDialer)) {
3674 throw new SecurityException("caller must be system dialer");
3675 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003676
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3680 if (phoneAccountHandle == null) {
3681 return null;
3682 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003683 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003684 } finally {
3685 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003686 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003687 }
3688
3689 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003690 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3691 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003692 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003694 mApp, subId, callingPackage, callingFeatureId,
3695 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003696 return null;
3697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003699 final long identity = Binder.clearCallingIdentity();
3700 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003701 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003702 } finally {
3703 Binder.restoreCallingIdentity(identity);
3704 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003705 }
3706
3707 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003708 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3709 VisualVoicemailSmsFilterSettings settings) {
3710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711
3712 final long identity = Binder.clearCallingIdentity();
3713 try {
3714 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003715 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003716 } finally {
3717 Binder.restoreCallingIdentity(identity);
3718 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003719 }
3720
3721 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003722 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3723 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724
3725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003728 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003732 }
3733
3734 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003735 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3736 String callingPackage, int subId) {
3737 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738
3739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003746 }
3747
3748 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003749 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751
3752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003755 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003759 }
3760
3761 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003762 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3763 String callingAttributionTag, int subId, String number, int port, String text,
3764 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003765 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003766 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003767 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003768 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003769 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3770 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003771 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003772
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003773 /**
fionaxu0152e512016-11-14 13:36:14 -08003774 * Sets the voice activation state of a given subId.
3775 */
3776 @Override
3777 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3779 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003780
3781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 final Phone phone = getPhone(subId);
3784 if (phone != null) {
3785 phone.setVoiceActivationState(activationState);
3786 } else {
3787 loge("setVoiceActivationState fails with invalid subId: " + subId);
3788 }
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003791 }
3792 }
3793
3794 /**
3795 * Sets the data activation state of a given subId.
3796 */
3797 @Override
3798 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3800 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801
3802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 final Phone phone = getPhone(subId);
3805 if (phone != null) {
3806 phone.setDataActivationState(activationState);
3807 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003808 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 }
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003812 }
3813 }
3814
3815 /**
3816 * Returns the voice activation state of a given subId.
3817 */
3818 @Override
3819 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003820 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821
fionaxu0152e512016-11-14 13:36:14 -08003822 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003823 final long identity = Binder.clearCallingIdentity();
3824 try {
3825 if (phone != null) {
3826 return phone.getVoiceActivationState();
3827 } else {
3828 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3829 }
3830 } finally {
3831 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003832 }
3833 }
3834
3835 /**
3836 * Returns the data activation state of a given subId.
3837 */
3838 @Override
3839 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841
fionaxu0152e512016-11-14 13:36:14 -08003842 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003843 final long identity = Binder.clearCallingIdentity();
3844 try {
3845 if (phone != null) {
3846 return phone.getDataActivationState();
3847 } else {
3848 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3849 }
3850 } finally {
3851 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003852 }
3853 }
3854
3855 /**
Wink Saville36469e72014-06-11 15:17:00 -07003856 * Returns the unread count of voicemails for a subId
3857 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003859 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3860 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003862 mApp, subId, callingPackage, callingFeatureId,
3863 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003864 return 0;
3865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 final Phone phone = getPhone(subId);
3869 if (phone != null) {
3870 return phone.getVoiceMessageCount();
3871 } else {
3872 return 0;
3873 }
3874 } finally {
3875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003877 }
3878
3879 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003880 * returns true, if the device is in a state where both voice and data
3881 * are supported simultaneously. This can change based on location or network condition.
3882 */
3883 @Override
3884 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 final Phone phone = getPhone(subId);
3888 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3889 } finally {
3890 Binder.restoreCallingIdentity(identity);
3891 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003892 }
3893
3894 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003895 * Send the dialer code if called from the current default dialer or the caller has
3896 * carrier privilege.
3897 * @param inputCode The dialer code to send
3898 */
3899 @Override
3900 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003901 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003903 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3904 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003905 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003906 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003907 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003908 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909
3910 final long identity = Binder.clearCallingIdentity();
3911 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003912 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
fionaxu235cc5e2017-03-06 22:25:57 -08003916 }
3917
Pengquan Menga1bb6272018-09-06 09:59:22 -07003918 @Override
3919 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003920 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003921 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003922 mApp, subId, "getNetworkSelectionMode");
3923 final long identity = Binder.clearCallingIdentity();
3924 try {
3925 if (!isActiveSubscription(subId)) {
3926 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3927 }
3928 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3929 } finally {
3930 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003931 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003932 }
3933
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003935 public boolean isInEmergencySmsMode() {
3936 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3937 final long identity = Binder.clearCallingIdentity();
3938 try {
3939 for (Phone phone : PhoneFactory.getPhones()) {
3940 if (phone.isInEmergencySmsMode()) {
3941 return true;
3942 }
3943 }
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
3947 return false;
3948 }
3949
shilu366312e2019-12-17 09:28:10 -08003950 /**
3951 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3952 * @param subId The subscription to use to check the configuration.
3953 * @param c The callback that will be used to send the result.
3954 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003955 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003956 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3957 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003958 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003959 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003960
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003961 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3962 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3963 "IMS not available on device.");
3964 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 final long token = Binder.clearCallingIdentity();
3966 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003967 int slotId = getSlotIndexOrException(subId);
3968 verifyImsMmTelConfiguredOrThrow(slotId);
3969 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003970 } catch (ImsException e) {
3971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 } finally {
3973 Binder.restoreCallingIdentity(token);
3974 }
3975 }
3976
shilu366312e2019-12-17 09:28:10 -08003977 /**
3978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3979 * @param subId The subscription to use to check the configuration.
3980 * @param c The callback that will be used to send the result.
3981 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003983 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003984 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003985 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003986 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3987 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3988 }
Meng Wangafbc5852019-09-19 17:37:13 -07003989 final long token = Binder.clearCallingIdentity();
3990 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003991 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3992 .removeRegistrationCallbackForSubscription(c, subId);
3993 } catch (ImsException e) {
3994 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3995 + "is inactive, ignoring unregister.");
3996 // If the subscription is no longer active, just return, since the callback
3997 // will already have been removed internally.
3998 } finally {
3999 Binder.restoreCallingIdentity(token);
4000 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 }
4002
Brad Ebingera34a6c22019-10-22 17:36:18 -07004003 /**
4004 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4005 */
4006 @Override
4007 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4008 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4009 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4010 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4011 "IMS not available on device.");
4012 }
4013 final long token = Binder.clearCallingIdentity();
4014 try {
4015 Phone phone = getPhone(subId);
4016 if (phone == null) {
4017 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4018 + subId + "'");
4019 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4020 }
4021 phone.getImsRegistrationState(regState -> {
4022 try {
4023 consumer.accept((regState == null)
4024 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4025 } catch (RemoteException e) {
4026 // Ignore if the remote process is no longer available to call back.
4027 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4028 }
4029 });
4030 } finally {
4031 Binder.restoreCallingIdentity(token);
4032 }
4033 }
4034
4035 /**
4036 * Get the transport type for the IMS service registration state.
4037 */
4038 @Override
4039 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004040 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004041 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004042 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4043 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4044 "IMS not available on device.");
4045 }
4046 final long token = Binder.clearCallingIdentity();
4047 try {
4048 Phone phone = getPhone(subId);
4049 if (phone == null) {
4050 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4051 + subId + "'");
4052 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4053 }
4054 phone.getImsRegistrationTech(regTech -> {
4055 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4056 int regTechConverted = (regTech == null)
4057 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4058 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4059 regTechConverted);
4060 try {
4061 consumer.accept(regTechConverted);
4062 } catch (RemoteException e) {
4063 // Ignore if the remote process is no longer available to call back.
4064 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4065 }
4066 });
4067 } finally {
4068 Binder.restoreCallingIdentity(token);
4069 }
4070 }
4071
shilu366312e2019-12-17 09:28:10 -08004072 /**
4073 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4074 * @param subId The subscription to use to check the configuration.
4075 * @param c The callback that will be used to send the result.
4076 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004078 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4079 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004080 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004081 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004082 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4083 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4084 "IMS not available on device.");
4085 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 final long token = Binder.clearCallingIdentity();
4087 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004088 int slotId = getSlotIndexOrException(subId);
4089 verifyImsMmTelConfiguredOrThrow(slotId);
4090 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004091 } catch (ImsException e) {
4092 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004093 } finally {
4094 Binder.restoreCallingIdentity(token);
4095 }
4096 }
4097
shilu366312e2019-12-17 09:28:10 -08004098 /**
4099 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4100 * @param subId The subscription to use to check the configuration.
4101 * @param c The callback that will be used to send the result.
4102 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004104 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004105 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004106 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004107 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4108 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4109 }
Meng Wangafbc5852019-09-19 17:37:13 -07004110
4111 final long token = Binder.clearCallingIdentity();
4112 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004113 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004114 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004115 } catch (ImsException e) {
4116 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4117 + "is inactive, ignoring unregister.");
4118 // If the subscription is no longer active, just return, since the callback
4119 // will already have been removed internally.
4120 } finally {
4121 Binder.restoreCallingIdentity(token);
4122 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 }
4124
4125 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004126 public boolean isCapable(int subId, int capability, int regTech) {
4127 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 final long token = Binder.clearCallingIdentity();
4129 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004130 int slotId = getSlotIndexOrException(subId);
4131 verifyImsMmTelConfiguredOrThrow(slotId);
4132 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004133 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4135 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004136 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004137 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4138 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 } finally {
4140 Binder.restoreCallingIdentity(token);
4141 }
4142 }
4143
4144 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004145 public boolean isAvailable(int subId, int capability, int regTech) {
4146 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004147 final long token = Binder.clearCallingIdentity();
4148 try {
4149 Phone phone = getPhone(subId);
4150 if (phone == null) return false;
4151 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004152 } catch (com.android.ims.ImsException e) {
4153 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4154 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 } finally {
4156 Binder.restoreCallingIdentity(token);
4157 }
4158 }
4159
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004160 /**
4161 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4162 * subscription.
4163 * @param subId The subscription to use to check the configuration.
4164 * @param callback The callback that will be used to send the result.
4165 * @param capability The MmTelFeature capability that will be used to send the result.
4166 * @param transportType The transport type of the MmTelFeature capability.
4167 */
4168 @Override
4169 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4170 int transportType) {
4171 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4172 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4173 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4174 "IMS not available on device.");
4175 }
4176 final long token = Binder.clearCallingIdentity();
4177 try {
4178 int slotId = getSlotIndex(subId);
4179 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4180 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4181 + subId + "'");
4182 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4183 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004184 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004185 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4186 transportType, aBoolean -> {
4187 try {
4188 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4189 } catch (RemoteException e) {
4190 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4191 + "running. Ignore");
4192 }
4193 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004194 } catch (ImsException e) {
4195 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004196 } finally {
4197 Binder.restoreCallingIdentity(token);
4198 }
4199 }
4200
shilu366312e2019-12-17 09:28:10 -08004201 /**
4202 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4203 * @param subId The subscription to use to check the configuration.
4204 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 @Override
4206 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004207 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004208 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004209
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 final long token = Binder.clearCallingIdentity();
4211 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004212 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004213 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004214 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004215 } catch (ImsException e) {
4216 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 } finally {
4218 Binder.restoreCallingIdentity(token);
4219 }
4220 }
4221
4222 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004223 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004225 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004226 final long identity = Binder.clearCallingIdentity();
4227 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004228 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004229 // This setting doesn't require an active ImsService connection, so do not verify. The
4230 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004231 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004232 } catch (ImsException e) {
4233 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 } finally {
4235 Binder.restoreCallingIdentity(identity);
4236 }
4237 }
4238
shilu366312e2019-12-17 09:28:10 -08004239 /**
4240 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4241 * @param subId The subscription to use to check the configuration.
4242 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004244 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004245 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004246 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004247 final long identity = Binder.clearCallingIdentity();
4248 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004249 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004250 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004251 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004252 } catch (ImsException e) {
4253 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
4257 }
4258
4259 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004260 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004262 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004263 final long identity = Binder.clearCallingIdentity();
4264 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004265 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004266 // This setting doesn't require an active ImsService connection, so do not verify. The
4267 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004268 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004269 } catch (ImsException e) {
4270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
4274 }
4275
shilu366312e2019-12-17 09:28:10 -08004276 /**
4277 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4278 * @param subId The subscription to use to check the configuration.
4279 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 @Override
4281 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004282 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004283 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 final long identity = Binder.clearCallingIdentity();
4285 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004286 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004287 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004288 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004289 } catch (ImsException e) {
4290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
4293 }
4294 }
4295
4296 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004297 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004299 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004300 final long identity = Binder.clearCallingIdentity();
4301 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004302 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004303 // This setting doesn't require an active ImsService connection, so do not verify. The
4304 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004305 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004306 } catch (ImsException e) {
4307 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
4311 }
4312
shilu366312e2019-12-17 09:28:10 -08004313 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004314 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4315 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4316 * @param subId The subscription to use to check the configuration.
4317 */
4318 @Override
4319 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004320 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004321 mApp, subId, "isCrossSimCallingEnabledByUser");
4322 final long identity = Binder.clearCallingIdentity();
4323 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004324 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004325 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004326 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004327 } catch (ImsException e) {
4328 throw new ServiceSpecificException(e.getCode());
4329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
4332 }
4333
4334 /**
4335 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4336 * Requires MODIFY_PHONE_STATE permission.
4337 * @param subId The subscription to use to check the configuration.
4338 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4339 * false otherwise
4340 */
4341 @Override
4342 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4344 "setCrossSimCallingEnabled");
4345 final long identity = Binder.clearCallingIdentity();
4346 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004347 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004348 // This setting doesn't require an active ImsService connection, so do not verify. The
4349 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004350 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004351 } catch (ImsException e) {
4352 throw new ServiceSpecificException(e.getCode());
4353 } finally {
4354 Binder.restoreCallingIdentity(identity);
4355 }
4356 }
4357
4358 /**
shilu366312e2019-12-17 09:28:10 -08004359 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4360 * @param subId The subscription to use to check the configuration.
4361 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004363
Brad Ebinger35c841c2018-10-01 10:40:55 -07004364 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004365 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004366 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 final long identity = Binder.clearCallingIdentity();
4368 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004369 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004370 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004371 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004372 } catch (ImsException e) {
4373 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
4377 }
4378
4379 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004380 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004382 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004383 final long identity = Binder.clearCallingIdentity();
4384 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004385 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004386 // This setting doesn't require an active ImsService connection, so do not verify. The
4387 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004388 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004389 } catch (ImsException e) {
4390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004391 } finally {
4392 Binder.restoreCallingIdentity(identity);
4393 }
4394 }
4395
4396 @Override
4397 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4399 "setVoWiFiNonPersistent");
4400 final long identity = Binder.clearCallingIdentity();
4401 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004402 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004403 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004404 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004405 } catch (ImsException e) {
4406 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
4410 }
4411
shilu366312e2019-12-17 09:28:10 -08004412 /**
4413 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4414 * @param subId The subscription to use to check the configuration.
4415 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004416 @Override
4417 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004418 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004419 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004420 final long identity = Binder.clearCallingIdentity();
4421 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004422 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004423 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004424 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004425 } catch (ImsException e) {
4426 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
4430 }
4431
4432 @Override
4433 public void setVoWiFiModeSetting(int subId, int mode) {
4434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4435 "setVoWiFiModeSetting");
4436 final long identity = Binder.clearCallingIdentity();
4437 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004438 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004439 // This setting doesn't require an active ImsService connection, so do not verify. The
4440 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004441 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*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 int getVoWiFiRoamingModeSetting(int subId) {
4451 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4452 final long identity = Binder.clearCallingIdentity();
4453 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004454 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004455 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004456 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004457 } catch (ImsException e) {
4458 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
4462 }
4463
4464 @Override
4465 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4467 "setVoWiFiRoamingModeSetting");
4468 final long identity = Binder.clearCallingIdentity();
4469 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004470 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004471 // This setting doesn't require an active ImsService connection, so do not verify. The
4472 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004473 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004474 } catch (ImsException e) {
4475 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
4479 }
4480
4481 @Override
4482 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4483 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4484 "setRttCapabilityEnabled");
4485 final long identity = Binder.clearCallingIdentity();
4486 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004487 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004488 // This setting doesn't require an active ImsService connection, so do not verify. The
4489 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004490 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004491 } catch (ImsException e) {
4492 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
4496 }
4497
shilu366312e2019-12-17 09:28:10 -08004498 /**
4499 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4500 * @param subId The subscription to use to check the configuration.
4501 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 @Override
4503 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004504 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004505 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004506 final long identity = Binder.clearCallingIdentity();
4507 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004508 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004509 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004510 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004511 } catch (ImsException e) {
4512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004513 } finally {
4514 Binder.restoreCallingIdentity(identity);
4515 }
4516 }
4517
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004518 @Override
4519 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4520 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4521 final long identity = Binder.clearCallingIdentity();
4522 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004523 if (!isImsAvailableOnDevice()) {
4524 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4525 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004526 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004527 int slotId = getSlotIndexOrException(subId);
4528 verifyImsMmTelConfiguredOrThrow(slotId);
4529 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004530 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004531 } catch (ImsException e) {
4532 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
4536 }
4537
4538 @Override
4539 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4540 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4541 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004542 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4543 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4544 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004545 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004546 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004547 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004548 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004549 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4550 + "is inactive, ignoring unregister.");
4551 // If the subscription is no longer active, just return, since the callback will already
4552 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004553 } finally {
4554 Binder.restoreCallingIdentity(identity);
4555 }
4556 }
4557
allenwtsu99c623b2020-01-03 18:24:23 +08004558
4559 private void checkModifyPhoneStatePermission(int subId, String message) {
4560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4561 message);
4562 }
4563
4564 private boolean isImsProvisioningRequired(int subId, int capability,
4565 boolean isMmtelCapability) {
4566 Phone phone = getPhone(subId);
4567 if (phone == null) {
4568 loge("phone instance null for subid " + subId);
4569 return false;
4570 }
4571 if (isMmtelCapability) {
4572 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4573 return false;
4574 }
4575 } else {
4576 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4577 return false;
4578 }
4579 }
4580 return true;
4581 }
4582
4583 @Override
4584 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4585 boolean isProvisioned) {
4586 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4587
4588 final long identity = Binder.clearCallingIdentity();
4589 try {
4590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4591 if (!isImsProvisioningRequired(subId, capability, false)) {
4592 return;
4593 }
4594
4595 // this capability requires provisioning, route to the correct API.
4596 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4597 switch (capability) {
4598 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4599 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4600 ims.setEabProvisioned(isProvisioned);
4601 break;
4602 default: {
4603 throw new IllegalArgumentException("Tried to set provisioning for "
4604 + "rcs capability '" + capability + "', which does not require "
4605 + "provisioning.");
4606 }
4607 }
4608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
4611
4612 }
4613
4614
4615 @Override
4616 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4617 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4618 final long identity = Binder.clearCallingIdentity();
4619 try {
4620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4621 if (!isImsProvisioningRequired(subId, capability, false)) {
4622 return true;
4623 }
4624
4625 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4626 switch (capability) {
4627 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4628 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4629 return ims.isEabProvisionedOnDevice();
4630
4631 default: {
4632 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4633 + "capability '" + capability + "', which does not require "
4634 + "provisioning.");
4635 }
4636 }
4637
4638 } finally {
4639 Binder.restoreCallingIdentity(identity);
4640 }
4641 }
4642
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004643 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004644 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4645 boolean isProvisioned) {
4646 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004647 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4648 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4649 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004650 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4651 }
allenwtsu99c623b2020-01-03 18:24:23 +08004652 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004653 final long identity = Binder.clearCallingIdentity();
4654 try {
4655 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004656 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 return;
4658 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004659 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4660 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4661 loge("setImsProvisioningStatusForCapability: called for technology that does "
4662 + "not support provisioning - " + tech);
4663 return;
4664 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004665
4666 // this capability requires provisioning, route to the correct API.
4667 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4668 switch (capability) {
4669 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4670 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4671 ims.setVolteProvisioned(isProvisioned);
4672 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4673 ims.setWfcProvisioned(isProvisioned);
4674 }
4675 break;
4676 }
4677 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4678 // There is currently no difference in VT provisioning type.
4679 ims.setVtProvisioned(isProvisioned);
4680 break;
4681 }
4682 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4683 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4684 // change the capability of the feature instead if needed.
4685 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4686 == isProvisioned) {
4687 // No change in provisioning.
4688 return;
4689 }
4690 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4691 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004692 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004693 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004694 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4695 + ", Exception" + e.getMessage());
4696 }
4697 break;
4698 }
4699 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004700 throw new IllegalArgumentException("Tried to set provisioning for "
4701 + "MmTel capability '" + capability + "', which does not require "
4702 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004703 }
4704 }
4705
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
4708 }
4709 }
4710
4711 @Override
4712 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4713 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004714 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4715 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4716 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004717 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4718 }
4719 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4720 final long identity = Binder.clearCallingIdentity();
4721 try {
4722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004723 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 return true;
4725 }
4726
Brad Ebinger0d79c572021-04-17 15:20:49 -07004727 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4728 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4729 loge("getImsProvisioningStatusForCapability: called for technology that does "
4730 + "not support provisioning - " + tech);
4731 return true;
4732 }
4733
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4735 switch (capability) {
4736 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4737 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4738 return ims.isVolteProvisionedOnDevice();
4739 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4740 return ims.isWfcProvisionedOnDevice();
4741 }
4742 // This should never happen, since we are checking tech above to make sure it
4743 // is either LTE or IWLAN.
4744 throw new IllegalArgumentException("Invalid radio technology for voice "
4745 + "capability.");
4746 }
4747 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4748 // There is currently no difference in VT provisioning type.
4749 return ims.isVtProvisionedOnDevice();
4750 }
4751 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4752 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4753 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4754 }
4755 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004756 throw new IllegalArgumentException(
4757 "Tried to get provisioning for MmTel capability '" + capability
4758 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004759 }
4760 }
4761
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
4764 }
4765 }
4766
4767 @Override
4768 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4769 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4770 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4771 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4772 }
4773 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4774 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4775 return (provisionedBits & capability) > 0;
4776 }
4777
4778 @Override
4779 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4780 boolean isProvisioned) {
4781 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4782 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4783 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4784 }
4785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4786 "setProvisioningStatusForCapability");
4787 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4788 // If the current provisioning status for capability already matches isProvisioned,
4789 // do nothing.
4790 if (((provisionedBits & capability) > 0) == isProvisioned) {
4791 return;
4792 }
4793 if (isProvisioned) {
4794 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4795 } else {
4796 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4797 }
4798 }
4799
4800 /**
4801 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4802 * technology. The bitfield should mirror the bitfield defined by
4803 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4804 */
4805 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4806 String key = getMmTelProvisioningKey(subId, tech);
4807 // Default is no capabilities are provisioned.
4808 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4809 }
4810
4811 /**
4812 * Sets the MmTel capability provisioning bitfield (defined by
4813 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4814 * technology specified.
4815 *
4816 * Note: This is a synchronous command and should not be called on UI thread.
4817 */
4818 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4819 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4820 String key = getMmTelProvisioningKey(subId, tech);
4821 editor.putInt(key, newField);
4822 editor.commit();
4823 }
4824
4825 private static String getMmTelProvisioningKey(int subId, int tech) {
4826 // resulting key is provision_ims_mmtel_{subId}_{tech}
4827 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4828 }
4829
4830 /**
4831 * Query CarrierConfig to see if the specified capability requires provisioning for the
4832 * carrier associated with the subscription id.
4833 */
4834 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4835 int capability) {
4836 CarrierConfigManager configManager = new CarrierConfigManager(context);
4837 PersistableBundle c = configManager.getConfigForSubId(subId);
4838 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004839 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004840 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4841 false);
4842 boolean requireVoiceVtProvisioning = c.getBoolean(
4843 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4844
4845 // First check to make sure that the capability requires provisioning.
4846 switch (capability) {
4847 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4848 // intentional fallthrough
4849 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4850 if (requireVoiceVtProvisioning) {
4851 // Voice and Video requires provisioning
4852 return true;
4853 }
4854 break;
4855 }
4856 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4857 if (requireUtProvisioning) {
4858 // UT requires provisioning
4859 return true;
4860 }
4861 break;
4862 }
4863 }
4864 return false;
4865 }
4866
allenwtsu99c623b2020-01-03 18:24:23 +08004867 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4868 int capability) {
4869 CarrierConfigManager configManager = new CarrierConfigManager(context);
4870 PersistableBundle c = configManager.getConfigForSubId(subId);
4871
4872 boolean requireRcsProvisioning = c.getBoolean(
4873 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4874
4875 // First check to make sure that the capability requires provisioning.
4876 switch (capability) {
4877 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4878 // intentional fallthrough
4879 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4880 if (requireRcsProvisioning) {
4881 // OPTION or PRESENCE requires provisioning
4882 return true;
4883 }
4884 break;
4885 }
4886 }
4887 return false;
4888 }
4889
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004890 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004891 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004892 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4893 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4894 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004895 enforceReadPrivilegedPermission("getImsProvisioningInt");
4896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004899 int slotId = getSlotIndex(subId);
4900 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4901 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4902 + subId + "' for key:" + key);
4903 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4904 }
calvinpanb5a34062021-02-08 19:59:36 +08004905 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004906 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004907 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4908 + subId + "' for key:" + key);
4909 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004910 } finally {
4911 Binder.restoreCallingIdentity(identity);
4912 }
4913 }
4914
4915 @Override
4916 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004917 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4918 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4919 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004920 enforceReadPrivilegedPermission("getImsProvisioningString");
4921 final long identity = Binder.clearCallingIdentity();
4922 try {
4923 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004924 int slotId = getSlotIndex(subId);
4925 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4926 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4927 + subId + "' for key:" + key);
4928 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4929 }
calvinpanb5a34062021-02-08 19:59:36 +08004930 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004931 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004932 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4933 + subId + "' for key:" + key);
4934 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
4938 }
4939
4940 @Override
4941 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004942 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4943 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4944 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4946 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004947 final long identity = Binder.clearCallingIdentity();
4948 try {
4949 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004950 int slotId = getSlotIndex(subId);
4951 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4952 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4953 + subId + "' for key:" + key);
4954 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4955 }
calvinpanb5a34062021-02-08 19:59:36 +08004956 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4957 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004958 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004959 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004960 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004961 } finally {
4962 Binder.restoreCallingIdentity(identity);
4963 }
4964 }
4965
4966 @Override
4967 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004968 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4969 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4970 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4972 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004973 final long identity = Binder.clearCallingIdentity();
4974 try {
4975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004976 int slotId = getSlotIndex(subId);
4977 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4978 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4979 + subId + "' for key:" + key);
4980 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4981 }
calvinpanb5a34062021-02-08 19:59:36 +08004982 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4983 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004984 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004985 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004986 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004987 } finally {
4988 Binder.restoreCallingIdentity(identity);
4989 }
4990 }
4991
Brad Ebinger919631e2021-06-02 17:46:35 -07004992 /**
4993 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4994 * for the given slot ID or no ImsResolver instance has been created.
4995 * @param slotId The slot ID that the IMS service is created for.
4996 * @throws ImsException If there is no ImsService configured for this slot.
4997 */
4998 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4999 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
5000 ImsFeature.FEATURE_MMTEL)) {
5001 throw new ImsException("This subscription does not support MMTEL over IMS",
5002 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
5003 }
5004 }
5005
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005006 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005007 int slotId = SubscriptionManager.getSlotIndex(subId);
5008 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005009 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5010 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005011 }
5012 return slotId;
5013 }
5014
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005015 private int getSlotIndex(int subId) {
5016 int slotId = SubscriptionManager.getSlotIndex(subId);
5017 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5018 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5019 }
5020 return slotId;
5021 }
5022
Wink Saville36469e72014-06-11 15:17:00 -07005023 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005024 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005025 */
5026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005027 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5028 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005029 try {
5030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5031 } catch (SecurityException se) {
5032 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5033 throw new SecurityException("Package " + callingPackage + " does not belong to "
5034 + Binder.getCallingUid());
5035 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005036 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005037 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005038 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005039 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005040 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005041 mApp, subId, callingPackage, callingFeatureId,
5042 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005043 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5044 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 final Phone phone = getPhone(subId);
5049 if (phone != null) {
5050 return phone.getServiceState().getDataNetworkType();
5051 } else {
5052 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5053 }
5054 } finally {
5055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005057 }
5058
5059 /**
5060 * Returns the data network type
5061 */
5062 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005063 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005064 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5065 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005066 }
5067
5068 /**
5069 * Returns the data network type for a subId
5070 */
5071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005072 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5073 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005075 mApp, subId, callingPackage, callingFeatureId,
5076 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005077 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5078 }
5079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 final Phone phone = getPhone(subId);
5083 if (phone != null) {
5084 return phone.getServiceState().getDataNetworkType();
5085 } else {
5086 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5087 }
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005091 }
5092
5093 /**
Wink Saville36469e72014-06-11 15:17:00 -07005094 * Returns the Voice network type for a subId
5095 */
5096 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005097 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5098 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005100 mApp, subId, callingPackage, callingFeatureId,
5101 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005102 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5103 }
5104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 final long identity = Binder.clearCallingIdentity();
5106 try {
5107 final Phone phone = getPhone(subId);
5108 if (phone != null) {
5109 return phone.getServiceState().getVoiceNetworkType();
5110 } else {
5111 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5112 }
5113 } finally {
5114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005116 }
5117
5118 /**
5119 * @return true if a ICC card is present
5120 */
5121 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005122 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005123 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5124 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005125 }
5126
5127 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005128 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005129 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005130 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005131 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 final Phone phone = PhoneFactory.getPhone(slotIndex);
5135 if (phone != null) {
5136 return phone.getIccCard().hasIccCard();
5137 } else {
5138 return false;
5139 }
5140 } finally {
5141 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005143 }
5144
5145 /**
5146 * Return if the current radio is LTE on CDMA. This
5147 * is a tri-state return value as for a period of time
5148 * the mode may be unknown.
5149 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005150 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005151 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005152 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005153 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005154 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005155 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5156 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5157 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005158 }
5159
Sanket Padawe356d7632015-06-22 14:03:32 -07005160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005161 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5162 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005163 try {
5164 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5165 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005166 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5167 }
5168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 final Phone phone = getPhone(subId);
5172 if (phone == null) {
5173 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5174 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005175 return TelephonyProperties.lte_on_cdma_device()
5176 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005177 }
5178 } finally {
5179 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005180 }
Wink Saville36469e72014-06-11 15:17:00 -07005181 }
5182
Wink Saville36469e72014-06-11 15:17:00 -07005183 /**
5184 * {@hide}
5185 * Returns Default subId, 0 in the case of single standby.
5186 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005187 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005188 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005189 }
5190
Shishir Agrawala9f32182016-04-12 12:00:16 -07005191 private int getSlotForDefaultSubscription() {
5192 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5193 }
5194
Wink Savilleb564aae2014-10-23 10:18:09 -07005195 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005196 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005197 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005198
Pengquan Menge92a50d2018-09-21 15:54:48 -07005199 private boolean isActiveSubscription(int subId) {
5200 return mSubscriptionController.isActiveSubId(subId);
5201 }
5202
Ihab Awadf2177b72013-11-25 13:33:23 -08005203 /**
5204 * @see android.telephony.TelephonyManager.WifiCallingChoices
5205 */
5206 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 final long identity = Binder.clearCallingIdentity();
5208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005209 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5211 getWhenToMakeWifiCallsDefaultPreference());
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005215 }
5216
5217 /**
5218 * @see android.telephony.TelephonyManager.WifiCallingChoices
5219 */
5220 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005224 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5226 } finally {
5227 Binder.restoreCallingIdentity(identity);
5228 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005229 }
5230
Sailesh Nepald1e68152013-12-12 19:08:02 -08005231 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005232 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005233 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005234 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005235
Jordan Liu4c733742019-02-28 12:03:40 -08005236 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5237 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5238 if (phoneId == -1) {
5239 throw new IllegalArgumentException("Given slot index: " + slotIndex
5240 + " does not correspond to an active phone");
5241 }
5242 return PhoneFactory.getPhone(phoneId);
5243 }
5244
Shishir Agrawal566b7612013-10-28 14:41:00 -07005245 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005246 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5247 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5249 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005251 if (DBG) {
5252 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5253 }
5254 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5255 p2);
5256 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005257
Jordan Liu4c733742019-02-28 12:03:40 -08005258
5259 @Override
5260 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5261 int slotIndex, String callingPackage, String aid, int p2) {
5262 enforceModifyPermission();
5263 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5264 if (DBG) {
5265 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5266 }
5267 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5268 callingPackage, aid, p2);
5269 }
5270
5271 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5272 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 final long identity = Binder.clearCallingIdentity();
5274 try {
5275 if (TextUtils.equals(ISDR_AID, aid)) {
5276 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005277 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5278 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 if (bestComponent == null
5280 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5281 loge("The calling package is not allowed to access ISD-R.");
5282 throw new SecurityException(
5283 "The calling package is not allowed to access ISD-R.");
5284 }
Derek Tan740e1672017-06-27 14:56:27 -07005285 }
Derek Tan740e1672017-06-27 14:56:27 -07005286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005288 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5289 null /* workSource */);
5290 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005291 return response;
5292 } finally {
5293 Binder.restoreCallingIdentity(identity);
5294 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005295 }
5296
5297 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005298 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5300 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005301 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5302 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5303 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005304
Jordan Liu4c733742019-02-28 12:03:40 -08005305 @Override
5306 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5307 enforceModifyPermission();
5308 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5309 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5310 channel);
5311 }
5312
5313 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314 final long identity = Binder.clearCallingIdentity();
5315 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 if (channel < 0) {
5317 return false;
5318 }
Jordan Liu4c733742019-02-28 12:03:40 -08005319 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5320 null /* workSource */);
5321 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 return success;
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005325 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326 }
5327
5328 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005329 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005330 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5332 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005333 if (DBG) {
5334 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5335 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5336 + p3 + " data=" + data);
5337 }
5338 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5339 command, p1, p2, p3, data);
5340 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005341
Jordan Liu4c733742019-02-28 12:03:40 -08005342 @Override
5343 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5344 int command, int p1, int p2, int p3, String data) {
5345 enforceModifyPermission();
5346 if (DBG) {
5347 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5348 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5349 + p3 + " data=" + data);
5350 }
5351 return iccTransmitApduLogicalChannelWithPermission(
5352 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5353 data);
5354 }
5355
5356 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5357 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 final long identity = Binder.clearCallingIdentity();
5359 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005360 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 return "";
5362 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005365 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5366 null /* workSource */);
5367 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 // Append the returned status code to the end of the response payload.
5370 String s = Integer.toHexString(
5371 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5372 if (response.payload != null) {
5373 s = IccUtils.bytesToHexString(response.payload) + s;
5374 }
5375 return s;
5376 } finally {
5377 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005378 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005379 }
Jake Hambye994d462014-02-03 13:10:13 -08005380
Evan Charltonc66da362014-05-16 14:06:40 -07005381 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005382 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5383 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5385 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005387 if (DBG) {
5388 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5389 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5390 }
5391 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5392 cla, command, p1, p2, p3, data);
5393 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005394
Jordan Liu4c733742019-02-28 12:03:40 -08005395 @Override
5396 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5397 int command, int p1, int p2, int p3, String data) {
5398 enforceModifyPermission();
5399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5400 if (DBG) {
5401 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5402 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5403 + " data=" + data);
5404 }
5405
5406 return iccTransmitApduBasicChannelWithPermission(
5407 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5408 p2, p3, data);
5409 }
5410
5411 // open APDU basic channel assuming the caller has sufficient permissions
5412 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5413 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5417 && TextUtils.equals(ISDR_AID, data)) {
5418 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005419 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5420 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 if (bestComponent == null
5422 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5423 loge("The calling package is not allowed to select ISD-R.");
5424 throw new SecurityException(
5425 "The calling package is not allowed to select ISD-R.");
5426 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005427 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005430 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5431 null /* workSource */);
5432 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005434 // Append the returned status code to the end of the response payload.
5435 String s = Integer.toHexString(
5436 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5437 if (response.payload != null) {
5438 s = IccUtils.bytesToHexString(response.payload) + s;
5439 }
5440 return s;
5441 } finally {
5442 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005443 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444 }
5445
5446 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005447 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005448 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5450 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 final long identity = Binder.clearCallingIdentity();
5453 try {
5454 if (DBG) {
5455 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5456 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5457 }
5458
5459 IccIoResult response =
5460 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5461 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5462 subId);
5463
5464 if (DBG) {
5465 log("Exchange SIM_IO [R]" + response);
5466 }
5467
5468 byte[] result = null;
5469 int length = 2;
5470 if (response.payload != null) {
5471 length = 2 + response.payload.length;
5472 result = new byte[length];
5473 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5474 } else {
5475 result = new byte[length];
5476 }
5477
5478 result[length - 1] = (byte) response.sw2;
5479 result[length - 2] = (byte) response.sw1;
5480 return result;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005483 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005484 }
5485
Nathan Haroldb3014052017-01-25 15:57:32 -08005486 /**
5487 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5488 * on a particular subscription
5489 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005490 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5491 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005493 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005494 return null;
5495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496
5497 final long identity = Binder.clearCallingIdentity();
5498 try {
5499 if (appType != TelephonyManager.APPTYPE_USIM
5500 && appType != TelephonyManager.APPTYPE_SIM) {
5501 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5502 return null;
5503 }
5504 Object response = sendRequest(
5505 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5506 if (response instanceof String[]) {
5507 return (String[]) response;
5508 }
yincheng zhao2737e882019-09-06 17:06:54 -07005509 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005511 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 } finally {
5513 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005514 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005515 }
5516
yincheng zhao2737e882019-09-06 17:06:54 -07005517 /**
5518 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5519 * subscription.
5520 *
5521 * @param subId the id of the subscription.
5522 * @param appType the uicc app type, must be USIM or SIM.
5523 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5524 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005525 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005526 * @return number of fplmns that is successfully written to the SIM.
5527 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005528 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5529 String callingFeatureId) {
5530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5531 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005532 if (DBG) logv("no permissions for setForbiddenplmns");
5533 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5534 }
5535 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5536 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5537 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5538 }
5539 if (fplmns == null) {
5540 throw new IllegalArgumentException("Fplmn List provided is null");
5541 }
5542 for (String fplmn : fplmns) {
5543 if (!CellIdentity.isValidPlmn(fplmn)) {
5544 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5545 }
5546 }
5547 final long identity = Binder.clearCallingIdentity();
5548 try {
5549 Object response = sendRequest(
5550 CMD_SET_FORBIDDEN_PLMNS,
5551 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5552 subId);
5553 return (int) response;
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556 }
5557 }
5558
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005559 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005560 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5562 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 final long identity = Binder.clearCallingIdentity();
5565 try {
5566 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5567 if (response.payload == null) {
5568 return "";
5569 }
Evan Charltonc66da362014-05-16 14:06:40 -07005570
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005571 // Append the returned status code to the end of the response payload.
5572 String s = Integer.toHexString(
5573 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5574 s = IccUtils.bytesToHexString(response.payload) + s;
5575 return s;
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
Evan Charltonc66da362014-05-16 14:06:40 -07005579 }
5580
Jake Hambye994d462014-02-03 13:10:13 -08005581 /**
5582 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5583 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5584 *
5585 * @param itemID the ID of the item to read
5586 * @return the NV item as a String, or null on error.
5587 */
5588 @Override
5589 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005590 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5592 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593
5594 final long identity = Binder.clearCallingIdentity();
5595 try {
5596 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005597 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5599 return value;
5600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
Jake Hambye994d462014-02-03 13:10:13 -08005603 }
5604
5605 /**
5606 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5607 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5608 *
5609 * @param itemID the ID of the item to read
5610 * @param itemValue the value to write, as a String
5611 * @return true on success; false on any failure
5612 */
5613 @Override
5614 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005615 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5617 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618
5619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5622 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005623 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5625 return success;
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
Jake Hambye994d462014-02-03 13:10:13 -08005629 }
5630
5631 /**
5632 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5633 * Used for device configuration by some CDMA operators.
5634 *
5635 * @param preferredRoamingList byte array containing the new PRL
5636 * @return true on success; false on any failure
5637 */
5638 @Override
5639 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5641 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642
5643 final long identity = Binder.clearCallingIdentity();
5644 try {
5645 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5646 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5647 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5648 return success;
5649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
Jake Hambye994d462014-02-03 13:10:13 -08005652 }
5653
5654 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005655 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005656 * Used for device configuration by some CDMA operators.
5657 *
chen xu6dac5ab2018-10-26 17:39:23 -07005658 * @param slotIndex - device slot.
5659 *
Jake Hambye994d462014-02-03 13:10:13 -08005660 * @return true on success; false on any failure
5661 */
5662 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005663 public boolean resetModemConfig(int slotIndex) {
5664 Phone phone = PhoneFactory.getPhone(slotIndex);
5665 if (phone != null) {
5666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5667 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668
chen xu6dac5ab2018-10-26 17:39:23 -07005669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5672 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5673 return success;
5674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 }
chen xu6dac5ab2018-10-26 17:39:23 -07005678 return false;
5679 }
5680
5681 /**
5682 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5683 *
5684 * @param slotIndex - device slot.
5685 *
5686 * @return true on success; false on any failure
5687 */
5688 @Override
5689 public boolean rebootModem(int slotIndex) {
5690 Phone phone = PhoneFactory.getPhone(slotIndex);
5691 if (phone != null) {
5692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5693 mApp, phone.getSubId(), "rebootModem");
5694
5695 final long identity = Binder.clearCallingIdentity();
5696 try {
5697 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5698 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5699 return success;
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
5703 }
5704 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005705 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005706
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005707 public String[] getPcscfAddress(String apnType, String callingPackage,
5708 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005709 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005710 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5711 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005712 return new String[0];
5713 }
5714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 final long identity = Binder.clearCallingIdentity();
5716 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005717 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
Wink Saville36469e72014-06-11 15:17:00 -07005721 }
5722
Brad Ebinger51f743a2017-01-23 13:50:20 -08005723 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005724 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5725 * {@link #disableIms(int)}.
5726 * @param slotIndex device slot.
5727 */
5728 public void resetIms(int slotIndex) {
5729 enforceModifyPermission();
5730
5731 final long identity = Binder.clearCallingIdentity();
5732 try {
5733 if (mImsResolver == null) {
5734 // may happen if the does not support IMS.
5735 return;
5736 }
5737 mImsResolver.disableIms(slotIndex);
5738 mImsResolver.enableIms(slotIndex);
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
5742 }
5743
5744 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005745 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5746 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005747 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005748 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005749 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750
5751 final long identity = Binder.clearCallingIdentity();
5752 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005753 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005754 // may happen if the device does not support IMS.
5755 return;
5756 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005757 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758 } finally {
5759 Binder.restoreCallingIdentity(identity);
5760 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005761 }
5762
5763 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005764 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5765 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005766 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005767 public void disableIms(int slotId) {
5768 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769
5770 final long identity = Binder.clearCallingIdentity();
5771 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005772 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005773 // may happen if the device does not support IMS.
5774 return;
5775 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005776 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 } finally {
5778 Binder.restoreCallingIdentity(identity);
5779 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005780 }
5781
5782 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005783 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5784 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005785 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005786 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005787 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005788 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789
5790 final long identity = Binder.clearCallingIdentity();
5791 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005792 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005793 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5794 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005795 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005796 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005800 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005801 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005802 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5803 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005804 @Override
5805 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005806 enforceModifyPermission();
5807
5808 final long identity = Binder.clearCallingIdentity();
5809 try {
5810 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005811 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005812 } finally {
5813 Binder.restoreCallingIdentity(identity);
5814 }
5815 }
5816
5817 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005818 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005819 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005820 */
5821 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823
5824 final long identity = Binder.clearCallingIdentity();
5825 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005827 // may happen if the device does not support IMS.
5828 return null;
5829 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005830 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831 } finally {
5832 Binder.restoreCallingIdentity(identity);
5833 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005834 }
5835
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005836 /**
5837 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005838 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005839 */
5840 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5841 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005846 // may happen if the device does not support IMS.
5847 return null;
5848 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005849 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 } finally {
5851 Binder.restoreCallingIdentity(identity);
5852 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005853 }
5854
Brad Ebinger884c07b2018-02-15 16:17:40 -08005855 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005856 * Sets the ImsService Package Name that Telephony will bind to.
5857 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005858 * @param slotIndex the slot ID that the ImsService should bind for.
5859 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005860 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005861 * @param featureTypes An integer array of feature types associated with a packageName.
5862 * @param packageName The name of the package that the current configuration will be replaced
5863 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005864 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005865 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005866 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5867 int[] featureTypes, String packageName) {
5868 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5869 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5871 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005872 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 final long identity = Binder.clearCallingIdentity();
5875 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005877 // may happen if the device does not support IMS.
5878 return false;
5879 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005880 Map<Integer, String> featureConfig = new HashMap<>();
5881 for (int featureType : featureTypes) {
5882 featureConfig.put(featureType, packageName);
5883 }
5884 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5885 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 } finally {
5887 Binder.restoreCallingIdentity(identity);
5888 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005889 }
5890
5891 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005892 * Clears any carrier ImsService overrides for the slot index specified that were previously
5893 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5894 *
5895 * This should only be used for testing.
5896 *
5897 * @param slotIndex the slot ID that the ImsService should bind for.
5898 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5899 */
5900 @Override
5901 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5902 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5903 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5904 "clearCarrierImsServiceOverride");
5905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5906 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5907 "clearCarrierImsServiceOverride");
5908
5909 final long identity = Binder.clearCallingIdentity();
5910 try {
5911 if (mImsResolver == null) {
5912 // may happen if the device does not support IMS.
5913 return false;
5914 }
5915 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5916 } finally {
5917 Binder.restoreCallingIdentity(identity);
5918 }
5919 }
5920
5921 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005922 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005923 *
5924 * @param slotId The slot that the ImsService is associated with.
5925 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5926 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005927 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005928 * @return the package name of the ImsService configuration.
5929 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005930 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5931 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005932 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005933 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005934 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005935 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5936 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005938 final long identity = Binder.clearCallingIdentity();
5939 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005940 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005941 // may happen if the device does not support IMS.
5942 return "";
5943 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005944 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005945 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5946 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 } finally {
5948 Binder.restoreCallingIdentity(identity);
5949 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005950 }
5951
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005952 /**
5953 * Get the MmTelFeature state associated with the requested subscription id.
5954 * @param subId The subscription that the MmTelFeature is associated with.
5955 * @param callback A callback with an integer containing the
5956 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5957 */
5958 @Override
5959 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5960 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5961 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5962 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5963 "IMS not available on device.");
5964 }
5965 final long token = Binder.clearCallingIdentity();
5966 try {
5967 int slotId = getSlotIndex(subId);
5968 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5969 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5970 + subId + "'");
5971 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5972 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005973 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005974 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5975 try {
5976 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5977 } catch (RemoteException e) {
5978 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5979 + "Ignore");
5980 }
5981 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005982 } catch (ImsException e) {
5983 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005984 } finally {
5985 Binder.restoreCallingIdentity(token);
5986 }
5987 }
5988
Daniel Brightbb5840b2021-01-12 15:48:18 -08005989 /**
5990 * Sets the ims registration state on all valid {@link Phone}s.
5991 */
5992 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005993 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994
5995 final long identity = Binder.clearCallingIdentity();
5996 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005997 // NOTE: Before S, this method only set the default phone.
5998 for (final Phone phone : PhoneFactory.getPhones()) {
5999 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
6000 phone.setImsRegistrationState(registered);
6001 }
6002 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 } finally {
6004 Binder.restoreCallingIdentity(identity);
6005 }
Wink Saville36469e72014-06-11 15:17:00 -07006006 }
6007
6008 /**
Stuart Scott54788802015-03-30 13:18:01 -07006009 * Set the network selection mode to automatic.
6010 *
6011 */
6012 @Override
6013 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6015 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016
6017 final long identity = Binder.clearCallingIdentity();
6018 try {
shilufc958392020-01-20 11:36:01 -08006019 if (!isActiveSubscription(subId)) {
6020 return;
6021 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006023 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6024 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 } finally {
6026 Binder.restoreCallingIdentity(identity);
6027 }
Stuart Scott54788802015-03-30 13:18:01 -07006028 }
6029
Jack Yud10cdd42020-09-28 20:28:01 -07006030 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006031 * Ask the radio to connect to the input network and change selection mode to manual.
6032 *
6033 * @param subId the id of the subscription.
6034 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6035 * the operator to attach to.
6036 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6037 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6038 * normal network selection next time.
6039 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006040 */
6041 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006042 public boolean setNetworkSelectionModeManual(
6043 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6045 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006046
6047 if (!isActiveSubscription(subId)) {
6048 return false;
6049 }
6050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 final long identity = Binder.clearCallingIdentity();
6052 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006053 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006054 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006055 if (DBG) {
6056 log("setNetworkSelectionModeManual: subId: " + subId
6057 + " operator: " + operatorInfo);
6058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006059 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6060 } finally {
6061 Binder.restoreCallingIdentity(identity);
6062 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006063 }
shilu84f6e8b2019-12-19 13:58:01 -08006064 /**
6065 * Get the manual network selection
6066 *
6067 * @param subId the id of the subscription.
6068 *
6069 * @return the previously saved user selected PLMN
6070 */
6071 @Override
6072 public String getManualNetworkSelectionPlmn(int subId) {
6073 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006074 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006075 mApp, subId, "getManualNetworkSelectionPlmn");
6076
6077 final long identity = Binder.clearCallingIdentity();
6078 try {
6079 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006080 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006081 }
6082
6083 final Phone phone = getPhone(subId);
6084 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006085 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006086 }
6087 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6088 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6089 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
6093 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006094
6095 /**
6096 * Scans for available networks.
6097 */
6098 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006099 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6100 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6102 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006103 LocationAccessPolicy.LocationPermissionResult locationResult =
6104 LocationAccessPolicy.checkLocationPermission(mApp,
6105 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6106 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006107 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006108 .setCallingPid(Binder.getCallingPid())
6109 .setCallingUid(Binder.getCallingUid())
6110 .setMethod("getCellNetworkScanResults")
6111 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006112 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6113 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006114 .build());
6115 switch (locationResult) {
6116 case DENIED_HARD:
6117 throw new SecurityException("Not allowed to access scan results -- location");
6118 case DENIED_SOFT:
6119 return null;
6120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121
Pengquan Menga1bb6272018-09-06 09:59:22 -07006122 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 try {
6124 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006125 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 } finally {
6128 Binder.restoreCallingIdentity(identity);
6129 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006130 }
6131
6132 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006133 * Get the call forwarding info, given the call forwarding reason.
6134 */
6135 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006136 public void getCallForwarding(int subId, int callForwardingReason,
6137 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006138 enforceReadPrivilegedPermission("getCallForwarding");
6139 long identity = Binder.clearCallingIdentity();
6140 try {
6141 if (DBG) {
6142 log("getCallForwarding: subId " + subId
6143 + " callForwardingReason" + callForwardingReason);
6144 }
Hall Liu27d24262020-09-18 19:04:59 -07006145
6146 Phone phone = getPhone(subId);
6147 if (phone == null) {
6148 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006149 callback.onError(
6150 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006151 } catch (RemoteException e) {
6152 // ignore
6153 }
6154 return;
6155 }
6156
6157 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6158 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6159 @Override
6160 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6161 try {
6162 callback.onCallForwardingInfoAvailable(info);
6163 } catch (RemoteException e) {
6164 // ignore
6165 }
6166 }
6167
6168 @Override
6169 public void onError(int error) {
6170 try {
6171 callback.onError(error);
6172 } catch (RemoteException e) {
6173 // ignore
6174 }
6175 }
6176 });
6177 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180 }
6181 }
6182
6183 /**
6184 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6185 * reason, the number to forward, and the timeout before the forwarding is attempted.
6186 */
6187 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006188 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6189 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006190 enforceModifyPermission();
6191 long identity = Binder.clearCallingIdentity();
6192 try {
6193 if (DBG) {
6194 log("setCallForwarding: subId " + subId
6195 + " callForwardingInfo" + callForwardingInfo);
6196 }
Hall Liu27d24262020-09-18 19:04:59 -07006197
6198 Phone phone = getPhone(subId);
6199 if (phone == null) {
6200 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006201 callback.accept(
6202 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006203 } catch (RemoteException e) {
6204 // ignore
6205 }
6206 return;
6207 }
6208
6209 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6210 FunctionalUtils.ignoreRemoteException(callback::accept));
6211
6212 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006213 } finally {
6214 Binder.restoreCallingIdentity(identity);
6215 }
6216 }
6217
6218 /**
Hall Liu27d24262020-09-18 19:04:59 -07006219 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006220 */
6221 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006222 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006223 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006224 long identity = Binder.clearCallingIdentity();
6225 try {
Hall Liu27d24262020-09-18 19:04:59 -07006226 Phone phone = getPhone(subId);
6227 if (phone == null) {
6228 try {
6229 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6230 } catch (RemoteException e) {
6231 // ignore
6232 }
6233 return;
6234 }
SongFerngWang0e767992021-03-31 22:08:45 +08006235 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6236 PersistableBundle c = configManager.getConfigForSubId(subId);
6237 boolean requireUssd = c.getBoolean(
6238 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006239
Shuo Qian4a594052020-01-23 11:59:30 -08006240 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006241 if (requireUssd) {
6242 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6243 getSubscriptionCarrierId(subId));
6244 String newUssdCommand = "";
6245 try {
6246 newUssdCommand = carrierXmlParser.getFeature(
6247 CarrierXmlParser.FEATURE_CALL_WAITING)
6248 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6249 } catch (NullPointerException e) {
6250 loge("Failed to generate USSD number" + e);
6251 }
6252 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6253 mMainThreadHandler, callback, carrierXmlParser,
6254 CarrierXmlParser.SsEntry.SSAction.QUERY);
6255 final String ussdCommand = newUssdCommand;
6256 Executors.newSingleThreadExecutor().execute(() -> {
6257 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6258 });
6259 } else {
6260 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6261 callback::accept);
6262 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6263 }
Shuo Qian4a594052020-01-23 11:59:30 -08006264 } finally {
6265 Binder.restoreCallingIdentity(identity);
6266 }
6267 }
6268
6269 /**
Hall Liu27d24262020-09-18 19:04:59 -07006270 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006271 */
6272 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006273 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006274 enforceModifyPermission();
6275 long identity = Binder.clearCallingIdentity();
6276 try {
Hall Liu27d24262020-09-18 19:04:59 -07006277 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6278
6279 Phone phone = getPhone(subId);
6280 if (phone == null) {
6281 try {
6282 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6283 } catch (RemoteException e) {
6284 // ignore
6285 }
6286 return;
6287 }
6288
SongFerngWang0e767992021-03-31 22:08:45 +08006289 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6290 PersistableBundle c = configManager.getConfigForSubId(subId);
6291 boolean requireUssd = c.getBoolean(
6292 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006293
SongFerngWang0e767992021-03-31 22:08:45 +08006294 if (DBG) log("getCallWaitingStatus: subId " + subId);
6295 if (requireUssd) {
6296 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6297 getSubscriptionCarrierId(subId));
6298 CarrierXmlParser.SsEntry.SSAction ssAction =
6299 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6300 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6301 String newUssdCommand = "";
6302 try {
6303 newUssdCommand = carrierXmlParser.getFeature(
6304 CarrierXmlParser.FEATURE_CALL_WAITING)
6305 .makeCommand(ssAction, null);
6306 } catch (NullPointerException e) {
6307 loge("Failed to generate USSD number" + e);
6308 }
6309 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6310 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6311 final String ussdCommand = newUssdCommand;
6312 Executors.newSingleThreadExecutor().execute(() -> {
6313 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6314 });
6315 } else {
6316 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6317 FunctionalUtils.ignoreRemoteException(callback::accept));
6318
6319 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6320 }
Shuo Qian4a594052020-01-23 11:59:30 -08006321 } finally {
6322 Binder.restoreCallingIdentity(identity);
6323 }
6324 }
6325
6326 /**
yinxub1bed742017-04-17 11:45:04 -07006327 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006328 *
yinxub1bed742017-04-17 11:45:04 -07006329 * @param subId id of the subscription
6330 * @param request contains the radio access networks with bands/channels to scan
6331 * @param messenger callback messenger for scan results or errors
6332 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006333 * @return the id of the requested scan which can be used to stop the scan.
6334 */
6335 @Override
6336 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006337 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6339 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006340 LocationAccessPolicy.LocationPermissionResult locationResult =
6341 LocationAccessPolicy.checkLocationPermission(mApp,
6342 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6343 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006344 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006345 .setCallingPid(Binder.getCallingPid())
6346 .setCallingUid(Binder.getCallingUid())
6347 .setMethod("requestNetworkScan")
6348 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006349 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6350 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006351 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006352 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006353 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6354 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006355 if (e != null) {
6356 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6357 throw e;
6358 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006359 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006360 return TelephonyScanManager.INVALID_SCAN_ID;
6361 }
6362 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 }
Hall Liu912dfd32019-04-25 14:02:26 -07006364 int callingUid = Binder.getCallingUid();
6365 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006366 final long identity = Binder.clearCallingIdentity();
6367 try {
6368 return mNetworkScanRequestTracker.startNetworkScan(
6369 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006370 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
yinxu504e1392017-04-12 16:03:22 -07006374 }
6375
Hall Liub2ac8ef2019-02-28 15:56:23 -08006376 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006377 NetworkScanRequest request, int subId, String callingPackage) {
6378 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006379 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6380 boolean hasNetworkScanPermission =
6381 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6382 == PERMISSION_GRANTED;
6383
6384 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6385 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6386 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006387 }
6388
6389 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6390 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006391 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6392 return new SecurityException("Specific channels must not be"
6393 + " scanned without location access.");
6394 }
6395 }
6396 }
6397
Hall Liub2ac8ef2019-02-28 15:56:23 -08006398 return null;
6399 }
6400
yinxu504e1392017-04-12 16:03:22 -07006401 /**
6402 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006403 *
6404 * @param subId id of the subscription
6405 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006406 */
6407 @Override
6408 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6410 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411
Hall Liu912dfd32019-04-25 14:02:26 -07006412 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 final long identity = Binder.clearCallingIdentity();
6414 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006415 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
yinxu504e1392017-04-12 16:03:22 -07006419 }
6420
6421 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006422 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006423 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006424 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006425 */
6426 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006427 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006428 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006429 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006430 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006431
6432 final long identity = Binder.clearCallingIdentity();
6433 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006434 if (DBG) log("getAllowedNetworkTypesBitmask");
6435 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6436 int networkTypesBitmask = (result != null ? result[0] : -1);
6437 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6438 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 } finally {
6440 Binder.restoreCallingIdentity(identity);
6441 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006442 }
6443
6444 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006445 * Get the allowed network types for certain reason.
6446 *
6447 * @param subId the id of the subscription.
6448 * @param reason the reason the allowed network type change is taking place
6449 * @return the allowed network types.
6450 */
6451 @Override
6452 public long getAllowedNetworkTypesForReason(int subId,
6453 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006454 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006455 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006456 final long identity = Binder.clearCallingIdentity();
6457 try {
6458 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6459 } finally {
6460 Binder.restoreCallingIdentity(identity);
6461 }
6462 }
6463
6464 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006465 * Enable/Disable E-UTRA-NR Dual Connectivity
6466 * @param subId subscription id of the sim card
6467 * @param nrDualConnectivityState expected NR dual connectivity state
6468 * This can be passed following states
6469 * <ol>
6470 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6471 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6472 * <li>Disable NR dual connectivity and force secondary cell to be released
6473 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6474 * </ol>
6475 * @return operation result.
6476 */
6477 @Override
6478 public int setNrDualConnectivityState(int subId,
6479 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6481 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006482 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006483 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6484 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6485 }
6486
Sooraj Sasindran37444802020-08-11 10:40:43 -07006487 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6488 final long identity = Binder.clearCallingIdentity();
6489 try {
6490 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6491 nrDualConnectivityState, subId,
6492 workSource);
6493 if (DBG) log("enableNRDualConnectivity result: " + result);
6494 return result;
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
6498 }
6499
6500 /**
6501 * Is E-UTRA-NR Dual Connectivity enabled
6502 * @return true if dual connectivity is enabled else false
6503 */
6504 @Override
6505 public boolean isNrDualConnectivityEnabled(int subId) {
6506 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006507 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006508 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006509 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006510 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6511 return false;
6512 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006513 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6517 null, subId, workSource);
6518 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6519 return isEnabled;
6520 } finally {
6521 Binder.restoreCallingIdentity(identity);
6522 }
6523 }
6524
6525 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006526 * Set the allowed network types of the device and
6527 * provide the reason triggering the allowed network change.
6528 *
6529 * @param subId the id of the subscription.
6530 * @param reason the reason the allowed network type change is taking place
6531 * @param allowedNetworkTypes the allowed network types.
6532 * @return true on success; false on any failure.
6533 */
6534 @Override
6535 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006536 @TelephonyManager.AllowedNetworkTypesReason int reason,
6537 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006538 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6539 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006540 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006541 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6542 return false;
6543 }
6544 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6545 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006546 return false;
6547 }
6548
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006549 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6550 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6551
6552
6553 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6554 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6555 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006556 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006557
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006558 final long identity = Binder.clearCallingIdentity();
6559 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006560 Boolean success = (Boolean) sendRequest(
6561 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6562 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6563
6564 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6565 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006566 } finally {
6567 Binder.restoreCallingIdentity(identity);
6568 }
6569 }
6570
6571 /**
Miaoa84611c2019-03-15 09:21:10 +08006572 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006573 *
Miaoa84611c2019-03-15 09:21:10 +08006574 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006575 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006576 * @hide
6577 */
6578 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006579 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006580 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006581 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006582 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 try {
Miaoa84611c2019-03-15 09:21:10 +08006584 if (phone != null) {
6585 return phone.hasMatchedTetherApnSetting();
6586 } else {
6587 return false;
6588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 } finally {
6590 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006591 }
Junda Liu475951f2014-11-07 16:45:03 -08006592 }
6593
6594 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006595 * Enable or disable always reporting signal strength changes from radio.
6596 *
6597 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6598 */
6599 @Override
6600 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6601 enforceModifyPermission();
6602 enforceSystemCaller();
6603
6604 final long identity = Binder.clearCallingIdentity();
6605 final Phone phone = getPhone(subId);
6606 try {
6607 if (phone != null) {
6608 if (DBG) {
6609 log("setAlwaysReportSignalStrength: subId=" + subId
6610 + " isEnable=" + isEnable);
6611 }
6612 phone.setAlwaysReportSignalStrength(isEnable);
6613 } else {
6614 loge("setAlwaysReportSignalStrength: no phone found for subId="
6615 + subId);
6616 }
6617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
6620 }
6621
6622 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006623 * Get the user enabled state of Mobile Data.
6624 *
6625 * TODO: remove and use isUserDataEnabled.
6626 * This can't be removed now because some vendor codes
6627 * calls through ITelephony directly while they should
6628 * use TelephonyManager.
6629 *
6630 * @return true on enabled
6631 */
6632 @Override
6633 public boolean getDataEnabled(int subId) {
6634 return isUserDataEnabled(subId);
6635 }
6636
6637 /**
6638 * Get whether mobile data is enabled per user setting.
6639 *
6640 * There are other factors deciding whether mobile data is actually enabled, but they are
6641 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006642 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006643 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006644 *
6645 * @return {@code true} if data is enabled else {@code false}
6646 */
6647 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006648 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006649 try {
6650 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6651 null);
6652 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6654 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656
6657 final long identity = Binder.clearCallingIdentity();
6658 try {
6659 int phoneId = mSubscriptionController.getPhoneId(subId);
6660 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6661 Phone phone = PhoneFactory.getPhone(phoneId);
6662 if (phone != null) {
6663 boolean retVal = phone.isUserDataEnabled();
6664 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6665 return retVal;
6666 } else {
6667 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6668 return false;
6669 }
6670 } finally {
6671 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006672 }
6673 }
6674
6675 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006676 * Checks if the device is capable of mobile data by considering whether whether the
6677 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6678 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006679 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006680 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006681 */
6682 @Override
6683 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006684 try {
6685 try {
6686 mApp.enforceCallingOrSelfPermission(
6687 android.Manifest.permission.ACCESS_NETWORK_STATE,
6688 null);
6689 } catch (Exception e) {
6690 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6691 "isDataEnabled");
6692 }
6693 } catch (Exception e) {
6694 enforceReadPrivilegedPermission("isDataEnabled");
6695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696
6697 final long identity = Binder.clearCallingIdentity();
6698 try {
6699 int phoneId = mSubscriptionController.getPhoneId(subId);
6700 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6701 Phone phone = PhoneFactory.getPhone(phoneId);
6702 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006703 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6705 return retVal;
6706 } else {
6707 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6708 return false;
6709 }
6710 } finally {
6711 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006712 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006713 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006714
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006715 /**
6716 * Check if data is enabled for a specific reason
6717 * @param subId Subscription index
6718 * @param reason the reason the data enable change is taking place
6719 * @return {@code true} if the overall data is enabled; {@code false} if not.
6720 */
6721 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006722 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006723 @TelephonyManager.DataEnabledReason int reason) {
6724 try {
6725 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6726 null);
6727 } catch (Exception e) {
6728 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006729 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006730 }
6731
6732
6733 final long identity = Binder.clearCallingIdentity();
6734 try {
6735 int phoneId = mSubscriptionController.getPhoneId(subId);
6736 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006737 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006738 + " reason=" + reason);
6739 }
6740 Phone phone = PhoneFactory.getPhone(phoneId);
6741 if (phone != null) {
6742 boolean retVal;
6743 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6744 retVal = phone.isUserDataEnabled();
6745 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006746 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006747 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006748 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006749 return retVal;
6750 } else {
6751 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006752 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006753 + subId + " retVal=false");
6754 }
6755 return false;
6756 }
6757 } finally {
6758 Binder.restoreCallingIdentity(identity);
6759 }
6760 }
6761
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006762 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006763 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006764 if (uid == Process.PHONE_UID) {
6765 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6766 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006767 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6768 }
6769
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006770 //load access rules from carrier configs, and check those as well: b/139133814
6771 SubscriptionController subController = SubscriptionController.getInstance();
6772 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6773 || subController == null) return privilegeFromSim;
6774
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006775 PackageManager pkgMgr = phone.getContext().getPackageManager();
6776 String[] packages = pkgMgr.getPackagesForUid(uid);
6777
6778 final long identity = Binder.clearCallingIdentity();
6779 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006780 int subId = phone.getSubId();
6781 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6782 // A test override is in place for the privileges for this subId, so don't try to
6783 // read the subscription privileges.
6784 return privilegeFromSim;
6785 }
6786 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006787 SubscriptionManager subManager = (SubscriptionManager)
6788 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6789 for (String pkg : packages) {
6790 if (subManager.canManageSubscription(subInfo, pkg)) {
6791 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6792 }
6793 }
6794 return privilegeFromSim;
6795 } finally {
6796 Binder.restoreCallingIdentity(identity);
6797 }
6798 }
6799
6800 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6801 String pkgName) {
6802 //load access rules from carrier configs, and check those as well: b/139133814
6803 SubscriptionController subController = SubscriptionController.getInstance();
6804 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6805 || subController == null) return privilegeFromSim;
6806
6807 final long identity = Binder.clearCallingIdentity();
6808 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006809 int subId = phone.getSubId();
6810 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6811 // A test override is in place for the privileges for this subId, so don't try to
6812 // read the subscription privileges.
6813 return privilegeFromSim;
6814 }
6815 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006816 SubscriptionManager subManager = (SubscriptionManager)
6817 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6818 return subManager.canManageSubscription(subInfo, pkgName)
6819 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6820 } finally {
6821 Binder.restoreCallingIdentity(identity);
6822 }
6823 }
6824
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006825 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006826 public int getCarrierPrivilegeStatus(int subId) {
6827 final Phone phone = getPhone(subId);
6828 if (phone == null) {
6829 loge("getCarrierPrivilegeStatus: Invalid subId");
6830 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6831 }
6832 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006833 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006834 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006835 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6836 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006837
6838 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6839 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006840 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006841 }
Junda Liu29340342014-07-10 15:23:27 -07006842
6843 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006844 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006845 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006846 final Phone phone = getPhone(subId);
6847 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006848 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006849 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6850 }
6851 UiccProfile profile =
6852 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6853 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006854 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006855 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6856 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006857 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006858 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006859 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006860 }
6861
6862 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006863 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006864 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006865 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006866 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006867 }
6868
6869 int phoneId = SubscriptionManager.getPhoneId(subId);
6870 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006871 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006872 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006873 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6874 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006875 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6876 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6877 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006878 }
6879
6880 @Override
6881 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006882 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006883 if (TextUtils.isEmpty(pkgName))
6884 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006885 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6886 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6887 UiccCard card = UiccController.getInstance().getUiccCard(i);
6888 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006889 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006890 continue;
6891 }
6892
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006893 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6894 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6895 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006896 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6897 break;
6898 }
6899 }
6900
6901 return result;
Junda Liu29340342014-07-10 15:23:27 -07006902 }
Derek Tan89e89d42014-07-08 17:00:10 -07006903
6904 @Override
Junda Liue64de782015-04-16 17:19:16 -07006905 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006906 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006907 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6908 loge("phoneId " + phoneId + " is not valid.");
6909 return null;
6910 }
6911 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006912 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006913 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006914 return null ;
6915 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006916 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006917 }
6918
Amith Yamasani6e118872016-02-19 12:53:51 -08006919 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006920 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006921 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006922 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006923 List<String> privilegedPackages = new ArrayList<>();
6924 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006925 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6926 // has UICC in that slot.
6927 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006928 if (card.hasCarrierPrivilegeRules()) {
6929 if (packages == null) {
6930 // Only check packages in user 0 for now
6931 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006932 PackageManager.MATCH_DISABLED_COMPONENTS
6933 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006934 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006935 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006936 }
6937 for (int p = packages.size() - 1; p >= 0; p--) {
6938 PackageInfo pkgInfo = packages.get(p);
6939 if (pkgInfo != null && pkgInfo.packageName != null
6940 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006941 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006942 privilegedPackages.add(pkgInfo.packageName);
6943 }
6944 }
6945 }
6946 }
6947 return privilegedPackages;
6948 }
6949
chen xuf7e9fe82019-05-09 19:31:02 -07006950 @Override
6951 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006952 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6953
6954 final long identity = Binder.clearCallingIdentity();
6955
chen xuf7e9fe82019-05-09 19:31:02 -07006956 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006957 try {
6958 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6959 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6960 }
6961 } finally {
6962 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006963 }
6964 return privilegedPackages;
6965 }
6966
Wink Savilleb564aae2014-10-23 10:18:09 -07006967 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006968 final Phone phone = getPhone(subId);
6969 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006970 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006971 return null;
6972 }
6973 String iccId = card.getIccId();
6974 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006975 return null;
6976 }
6977 return iccId;
6978 }
6979
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006980 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006981 public void setCallComposerStatus(int subId, int status) {
6982 enforceModifyPermission();
6983
6984 final long identity = Binder.clearCallingIdentity();
6985 try {
6986 Phone phone = getPhone(subId);
6987 if (phone != null) {
6988 Phone defaultPhone = phone.getImsPhone();
6989 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6990 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6991 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006992 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6993 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006994 }
6995 }
Shuo Qian284ae752020-12-22 19:10:14 -08006996 } catch (ImsException e) {
6997 throw new ServiceSpecificException(e.getCode());
6998 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006999 Binder.restoreCallingIdentity(identity);
7000 }
7001 }
7002
7003 @Override
7004 public int getCallComposerStatus(int subId) {
7005 enforceReadPrivilegedPermission("getCallComposerStatus");
7006
7007 final long identity = Binder.clearCallingIdentity();
7008 try {
7009 Phone phone = getPhone(subId);
7010 if (phone != null) {
7011 Phone defaultPhone = phone.getImsPhone();
7012 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7013 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7014 return imsPhone.getCallComposerStatus();
7015 }
7016 }
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
7019 }
7020 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7021 }
7022
7023 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007024 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7025 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007027 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 final long identity = Binder.clearCallingIdentity();
7030 try {
7031 final String iccId = getIccId(subId);
7032 final Phone phone = getPhone(subId);
7033 if (phone == null) {
7034 return false;
7035 }
7036 final String subscriberId = phone.getSubscriberId();
7037
7038 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007039 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 + subscriberId + " to " + number);
7041 }
7042
7043 if (TextUtils.isEmpty(iccId)) {
7044 return false;
7045 }
7046
7047 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7048
7049 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7050 if (alphaTag == null) {
7051 editor.remove(alphaTagPrefKey);
7052 } else {
7053 editor.putString(alphaTagPrefKey, alphaTag);
7054 }
7055
7056 // Record both the line number and IMSI for this ICCID, since we need to
7057 // track all merged IMSIs based on line number
7058 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7059 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7060 if (number == null) {
7061 editor.remove(numberPrefKey);
7062 editor.remove(subscriberPrefKey);
7063 } else {
7064 editor.putString(numberPrefKey, number);
7065 editor.putString(subscriberPrefKey, subscriberId);
7066 }
7067
7068 editor.commit();
7069 return true;
7070 } finally {
7071 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007072 }
Derek Tan7226c842014-07-02 17:42:23 -07007073 }
7074
7075 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007076 public String getLine1NumberForDisplay(int subId, String callingPackage,
7077 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007078 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007080 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007081 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007082 return null;
7083 }
Derek Tan97ebb422014-09-05 16:55:38 -07007084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 final long identity = Binder.clearCallingIdentity();
7086 try {
7087 String iccId = getIccId(subId);
7088 if (iccId != null) {
7089 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7090 if (DBG_MERGE) {
7091 log("getLine1NumberForDisplay returning "
7092 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7093 }
7094 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7097 return null;
7098 } finally {
7099 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007100 }
Derek Tan7226c842014-07-02 17:42:23 -07007101 }
7102
7103 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007104 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7105 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007106 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007107 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007108 return null;
7109 }
Derek Tan97ebb422014-09-05 16:55:38 -07007110
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 String iccId = getIccId(subId);
7114 if (iccId != null) {
7115 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7116 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7117 }
7118 return null;
7119 } finally {
7120 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007121 }
Derek Tan7226c842014-07-02 17:42:23 -07007122 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007123
7124 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007125 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7126 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007127 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7128 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007130 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007131 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007132 return null;
7133 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007134
Jordan Liub49b04b2019-05-06 14:45:15 -07007135 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7136 // the process, where TelephonyManager was instantiated.
7137 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007138 final long identity = Binder.clearCallingIdentity();
7139 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007140 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 final TelephonyManager tele = TelephonyManager.from(context);
7142 final SubscriptionManager sub = SubscriptionManager.from(context);
7143
7144 // Figure out what subscribers are currently active
7145 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146
Jordan Liub49b04b2019-05-06 14:45:15 -07007147 // Only consider subs which match the current subId
7148 // This logic can be simplified. See b/131189269 for progress.
7149 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007150 activeSubscriberIds.add(tele.getSubscriberId(subId));
7151 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007152
7153 // First pass, find a number override for an active subscriber
7154 String mergeNumber = null;
7155 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7156 for (String key : prefs.keySet()) {
7157 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7158 final String subscriberId = (String) prefs.get(key);
7159 if (activeSubscriberIds.contains(subscriberId)) {
7160 final String iccId = key.substring(
7161 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7162 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7163 mergeNumber = (String) prefs.get(numberKey);
7164 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007165 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 + " for active subscriber " + subscriberId);
7167 }
7168 if (!TextUtils.isEmpty(mergeNumber)) {
7169 break;
7170 }
7171 }
7172 }
7173 }
7174
7175 // Shortcut when no active merged subscribers
7176 if (TextUtils.isEmpty(mergeNumber)) {
7177 return null;
7178 }
7179
7180 // Second pass, find all subscribers under that line override
7181 final ArraySet<String> result = new ArraySet<>();
7182 for (String key : prefs.keySet()) {
7183 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7184 final String number = (String) prefs.get(key);
7185 if (mergeNumber.equals(number)) {
7186 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7187 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7188 final String subscriberId = (String) prefs.get(subscriberKey);
7189 if (!TextUtils.isEmpty(subscriberId)) {
7190 result.add(subscriberId);
7191 }
7192 }
7193 }
7194 }
7195
7196 final String[] resultArray = result.toArray(new String[result.size()]);
7197 Arrays.sort(resultArray);
7198 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007199 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007200 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7201 }
7202 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007203 } finally {
7204 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007205 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007206 }
7207
7208 @Override
zoey chen38003472019-12-13 17:16:31 +08007209 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7210 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007211
7212 final long identity = Binder.clearCallingIdentity();
7213 try {
7214 final TelephonyManager telephonyManager = mApp.getSystemService(
7215 TelephonyManager.class);
7216 String subscriberId = telephonyManager.getSubscriberId(subId);
7217 if (subscriberId == null) {
7218 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007219 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007220 + subId);
7221 }
7222 return null;
7223 }
7224
7225 final SubscriptionInfo info = SubscriptionController.getInstance()
7226 .getSubscriptionInfo(subId);
7227 final ParcelUuid groupUuid = info.getGroupUuid();
7228 // If it doesn't belong to any group, return just subscriberId of itself.
7229 if (groupUuid == null) {
7230 return new String[]{subscriberId};
7231 }
7232
7233 // Get all subscriberIds from the group.
7234 final List<String> mergedSubscriberIds = new ArrayList<>();
7235 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007236 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007237 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007238 for (SubscriptionInfo subInfo : groupInfos) {
7239 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7240 if (subscriberId != null) {
7241 mergedSubscriberIds.add(subscriberId);
7242 }
7243 }
7244
7245 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248
7249 }
7250 }
7251
7252 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007253 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007254 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007255 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007256
7257 final long identity = Binder.clearCallingIdentity();
7258 try {
7259 final Phone phone = getPhone(subId);
7260 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7261 } finally {
7262 Binder.restoreCallingIdentity(identity);
7263 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007264 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007265
7266 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007267 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007268 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7269 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007270 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7271 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272
7273 final long identity = Binder.clearCallingIdentity();
7274 try {
7275 final Phone phone = getPhone(subId);
7276 if (phone == null) {
7277 return false;
7278 }
7279 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7280 cdmaNonRoamingList);
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007283 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007284 }
7285
7286 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007287 @Deprecated
7288 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7289 enforceModifyPermission();
7290
7291 int returnValue = 0;
7292 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007293 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007294 if(result.exception == null) {
7295 if (result.result != null) {
7296 byte[] responseData = (byte[])(result.result);
7297 if(responseData.length > oemResp.length) {
7298 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7299 responseData.length + "bytes. Buffer Size is " +
7300 oemResp.length + "bytes.");
7301 }
7302 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7303 returnValue = responseData.length;
7304 }
7305 } else {
7306 CommandException ex = (CommandException) result.exception;
7307 returnValue = ex.getCommandError().ordinal();
7308 if(returnValue > 0) returnValue *= -1;
7309 }
7310 } catch (RuntimeException e) {
7311 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7312 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7313 if(returnValue > 0) returnValue *= -1;
7314 }
7315
7316 return returnValue;
7317 }
7318
7319 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007320 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007321 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007322 try {
7323 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007324 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007325 mApp, phone.getSubId(), "getRadioAccessFamily");
7326 } catch (SecurityException e) {
7327 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7328 throw e;
7329 }
chen xub97461a2018-10-26 14:17:57 -07007330 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007331 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007332 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007333 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007334 final long identity = Binder.clearCallingIdentity();
7335 try {
chen xub97461a2018-10-26 14:17:57 -07007336 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007337 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007338 mApp, phone.getSubId(), "getRadioAccessFamily");
7339 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 } finally {
7341 Binder.restoreCallingIdentity(identity);
7342 }
chen xub97461a2018-10-26 14:17:57 -07007343 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007344 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007345
7346 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007347 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007348 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007349 try {
7350 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7351 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007352 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007353 }
7354 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007355 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007356 }
7357 RoleManager rm = mApp.getSystemService(RoleManager.class);
7358 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7359 if (!dialerRoleHolders.contains(callingPackage)) {
7360 throw new SecurityException("App must be the dialer role holder to"
7361 + " upload a call composer pic");
7362 }
7363
7364 Executors.newSingleThreadExecutor().execute(() -> {
7365 ByteArrayOutputStream output = new ByteArrayOutputStream(
7366 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7367 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7368 boolean readUntilEnd = false;
7369 int totalBytesRead = 0;
7370 byte[] buffer = new byte[16 * 1024];
7371 while (true) {
7372 int numRead;
7373 try {
7374 numRead = input.read(buffer);
7375 } catch (IOException e) {
7376 try {
7377 fd.checkError();
7378 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7379 null);
7380 } catch (IOException e1) {
7381 // This means that the other side closed explicitly with an error. If this
7382 // happens, log and ignore.
7383 loge("Remote end of call composer picture pipe closed: " + e1);
7384 }
7385 break;
7386 }
7387 if (numRead == -1) {
7388 readUntilEnd = true;
7389 break;
7390 }
7391 totalBytesRead += numRead;
7392 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7393 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7394 try {
7395 input.close();
7396 } catch (IOException e) {
7397 // ignore
7398 }
7399 break;
7400 }
7401 output.write(buffer, 0, numRead);
7402 }
7403 // Generally, the remote end will close the file descriptors. The only case where we
7404 // close is above, where the picture size is too big.
7405
7406 try {
7407 fd.checkError();
7408 } catch (IOException e) {
7409 loge("Remote end for call composer closed with an error: " + e);
7410 return;
7411 }
7412
Hall Liuaa4211e2021-01-20 15:43:39 -08007413 if (!readUntilEnd) {
7414 loge("Did not finish reading entire image; aborting");
7415 return;
7416 }
Hall Liu82694d52020-12-11 18:22:04 -08007417
Hall Liuaa4211e2021-01-20 15:43:39 -08007418 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7419 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7420 new CallComposerPictureTransfer.Factory() {},
7421 imageData,
7422 (result) -> {
7423 if (result.first != null) {
7424 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7425 Bundle outputResult = new Bundle();
7426 outputResult.putParcelable(
7427 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7428 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7429 outputResult);
7430 } else {
7431 callback.send(result.second, null);
7432 }
7433 }
7434 );
Hall Liu82694d52020-12-11 18:22:04 -08007435 });
7436 }
7437
7438 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007439 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007440 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007441 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442
7443 final long identity = Binder.clearCallingIdentity();
7444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007445 ImsManager.getInstance(defaultPhone.getContext(),
7446 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007450 }
7451
7452 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007453 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007454 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007455 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7456 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007457 return false;
7458 }
Svet Ganovb320e182015-04-16 12:30:10 -07007459
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 // Check the user preference and the system-level IMS setting. Even if the user has
7463 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7464 // In the long run, we may instead need to check if there exists a connection service
7465 // which can support video calling.
7466 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007467 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 return imsManager.isVtEnabledByPlatform()
7469 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7470 && imsManager.isVtEnabledByUser();
7471 } finally {
7472 Binder.restoreCallingIdentity(identity);
7473 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007474 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007475
Andrew Leea1239f22015-03-02 17:44:07 -08007476 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007477 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7478 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007480 mApp, subId, callingPackage, callingFeatureId,
7481 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 return false;
7483 }
7484
7485 final long identity = Binder.clearCallingIdentity();
7486 try {
7487 CarrierConfigManager configManager =
7488 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007489 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
Andrew Leea1239f22015-03-02 17:44:07 -08007494 }
7495
7496 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007497 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007498 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007499 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 return false;
7501 }
7502
7503 final long identity = Binder.clearCallingIdentity();
7504 try {
7505 CarrierConfigManager configManager =
7506 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007507 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Andrew Leea1239f22015-03-02 17:44:07 -08007512 }
7513
Andrew Lee9431b832015-03-09 18:46:45 -07007514 @Override
7515 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007516 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007517 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007518 }
7519
7520 @Override
7521 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 final long identity = Binder.clearCallingIdentity();
7523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007524 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
Andrew Lee9431b832015-03-09 18:46:45 -07007528 }
7529
Hall Liuf6668912018-10-31 17:05:23 -07007530 /**
7531 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7532 * support for the feature and device firmware support.
7533 *
7534 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7535 */
7536 @Override
7537 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007539 final Phone phone = getPhone(subscriptionId);
7540 if (phone == null) {
7541 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7542 return false;
7543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007545 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7547 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007548 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 return isCarrierSupported && isDeviceSupported;
7550 } finally {
7551 Binder.restoreCallingIdentity(identity);
7552 }
Hall Liu98187582018-01-22 19:15:32 -08007553 }
7554
Hall Liuf6668912018-10-31 17:05:23 -07007555 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007556 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7557 * RTT setting, will return true if the device and carrier both support RTT.
7558 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007559 */
7560 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 final long identity = Binder.clearCallingIdentity();
7562 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007563 boolean isRttSupported = isRttSupported(subscriptionId);
7564 boolean isUserRttSettingOn = Settings.Secure.getInt(
7565 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7566 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7567 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7568 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007572 }
7573
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007574 @Deprecated
7575 @Override
7576 public String getDeviceId(String callingPackage) {
7577 return getDeviceIdWithFeature(callingPackage, null);
7578 }
7579
Sanket Padawe7310cc72015-01-14 09:53:20 -08007580 /**
7581 * Returns the unique device ID of phone, for example, the IMEI for
7582 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7583 *
7584 * <p>Requires Permission:
7585 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7586 */
7587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007588 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007589 try {
7590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7591 } catch (SecurityException se) {
7592 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7593 throw new SecurityException("Package " + callingPackage + " does not belong to "
7594 + Binder.getCallingUid());
7595 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007596 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007597 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007598 return null;
7599 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007600 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007601 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007602 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007603 return null;
7604 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605
7606 final long identity = Binder.clearCallingIdentity();
7607 try {
7608 return phone.getDeviceId();
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
7611 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007612 }
7613
Ping Sunc67b7c22016-03-02 19:16:45 +08007614 /**
7615 * {@hide}
7616 * Returns the IMS Registration Status on a particular subid
7617 *
7618 * @param subId
7619 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007620 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007621 Phone phone = getPhone(subId);
7622 if (phone != null) {
7623 return phone.isImsRegistered();
7624 } else {
7625 return false;
7626 }
7627 }
7628
Santos Cordon7a1885b2015-02-03 11:15:19 -08007629 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007630 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007631 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007633 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007634 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7635 }
7636 final long identity = Binder.clearCallingIdentity();
7637 try {
7638 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7639 } finally {
7640 Binder.restoreCallingIdentity(identity);
7641 }
7642 }
7643
7644 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007645 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007646 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007647 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007648 mApp,
7649 subscriptionId,
7650 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 Phone phone = getPhone(subscriptionId);
7654 if (phone == null) {
7655 return null;
7656 }
7657 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
7661 }
7662
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007663 /**
7664 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007665 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007666 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 final long identity = Binder.clearCallingIdentity();
7668 try {
7669 Phone phone = getPhone(subId);
7670 if (phone != null) {
7671 return phone.isWifiCallingEnabled();
7672 } else {
7673 return false;
7674 }
7675 } finally {
7676 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007677 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007678 }
7679
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007680 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007681 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007682 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007683 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007684 final long identity = Binder.clearCallingIdentity();
7685 try {
7686 Phone phone = getPhone(subId);
7687 if (phone != null) {
7688 return phone.isVideoEnabled();
7689 } else {
7690 return false;
7691 }
7692 } finally {
7693 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007694 }
7695 }
7696
7697 /**
7698 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7699 * defined in {@link ImsRegistrationImplBase}.
7700 */
7701 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702 final long identity = Binder.clearCallingIdentity();
7703 try {
7704 Phone phone = getPhone(subId);
7705 if (phone != null) {
7706 return phone.getImsRegistrationTech();
7707 } else {
7708 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7709 }
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007712 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007713 }
7714
Stuart Scott8eef64f2015-04-08 15:13:54 -07007715 @Override
7716 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007717 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007718 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7719 return;
7720 }
Kai Shif70f46f2021-03-03 13:59:46 -08007721 Phone defaultPhone = getDefaultPhone();
7722 if (defaultPhone != null) {
7723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7724 mApp, getDefaultPhone().getSubId(), "factoryReset");
7725 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007726 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007727
Svet Ganovcc087f82015-05-12 20:35:54 -07007728 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007729 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7730 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007731 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007732 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007733 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007734 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007735 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007736 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007737 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007738 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007739 // There has been issues when Sms raw table somehow stores orphan
7740 // fragments. They lead to garbled message when new fragments come
7741 // in and combined with those stale ones. In case this happens again,
7742 // user can reset all network settings which will clean up this table.
7743 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007744 // Clean up IMS settings as well here.
7745 int slotId = getSlotIndex(subId);
7746 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7747 ImsManager.getInstance(mApp, slotId).factoryReset();
7748 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007749
Kai Shif70f46f2021-03-03 13:59:46 -08007750 if (defaultPhone == null) {
7751 return;
7752 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007753 // Erase modem config if erase modem on network setting is enabled.
7754 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7755 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7756 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007757 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007758 }
Kai Shif70f46f2021-03-03 13:59:46 -08007759
7760 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007763 }
7764 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007765
SongFerngWangfd89b102021-05-27 22:44:54 +08007766 @VisibleForTesting
7767 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7768 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7769 return;
7770 }
7771 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7772 RILConstants.PREFERRED_NETWORK_MODE);
7773 SubscriptionManager.setSubscriptionProperty(subId,
7774 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7775 "user=" + defaultNetworkType);
7776 phone.loadAllowedNetworksFromSubscriptionDatabase();
7777 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7778 defaultNetworkType, null);
7779 }
7780
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007781 private void cleanUpSmsRawTable(Context context) {
7782 ContentResolver resolver = context.getContentResolver();
7783 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7784 resolver.delete(uri, null, null);
7785 }
7786
Narayan Kamath1c496c22015-04-16 14:40:19 +01007787 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007788 public String getSimLocaleForSubscriber(int subId) {
7789 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7790 final Phone phone = getPhone(subId);
7791 if (phone == null) {
7792 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007793 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 final long identity = Binder.clearCallingIdentity();
7796 try {
chen xu5d3637b2019-01-21 23:31:38 -08007797 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007798 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007799 if (info == null) {
7800 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7801 return null;
7802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007803 // Try and fetch the locale from the carrier properties or from the SIM language
7804 // preferences (EF-PL and EF-LI)...
7805 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007807 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7808 if (localeFromDefaultSim != null) {
7809 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7810 if (DBG) log("Using locale from subId: " + subId + " locale: "
7811 + localeFromDefaultSim);
7812 return localeFromDefaultSim.toLanguageTag();
7813 } else {
7814 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007815 }
7816 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 // The SIM language preferences only store a language (e.g. fr = French), not an
7819 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7820 // the SIM and carrier preferences does not include a country we add the country
7821 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007822 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007824 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007825 return mccLocale.toLanguageTag();
7826 }
7827
7828 if (DBG) log("No locale found - returning null");
7829 return null;
7830 } finally {
7831 Binder.restoreCallingIdentity(identity);
7832 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007833 }
7834
7835 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007836 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007837 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007838 }
7839
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007840 /**
7841 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7842 */
7843 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007844 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007845 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007846 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007847
Chenjie Yu1ba97252018-01-11 18:16:20 -08007848 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007849 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007850
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007851 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007852 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7853 * representing the state of the modem.
7854 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007855 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7856 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007857 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007858 */
7859 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007860 public void requestModemActivityInfo(ResultReceiver result) {
7861 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007862 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007863
7864 final long identity = Binder.clearCallingIdentity();
7865 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007866 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867 } finally {
7868 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007869 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007870 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007871
Siddharth Rayb8114062018-06-17 15:02:38 -07007872 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7873 // less than total activity duration.
7874 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7875 if (info == null) {
7876 return false;
7877 }
7878 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007879 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7880 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7881
Siddharth Rayb8114062018-06-17 15:02:38 -07007882 return (info.isValid()
7883 && (info.getSleepTimeMillis() <= activityDurationMs)
7884 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007885 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007886 && (totalTxTimeMs <= activityDurationMs));
7887 }
7888
Jack Yu85bd38a2015-11-09 11:34:32 -08007889 /**
7890 * {@hide}
7891 * Returns the service state information on specified subscription.
7892 */
7893 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007894 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7895 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007897 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007898 return null;
7899 }
7900
Hall Liuf19c44f2018-11-27 14:38:17 -08007901 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7902 LocationAccessPolicy.checkLocationPermission(mApp,
7903 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7904 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007905 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007906 .setCallingPid(Binder.getCallingPid())
7907 .setCallingUid(Binder.getCallingUid())
7908 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007909 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007910 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007911 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7912 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007913 .build());
7914
7915 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7916 LocationAccessPolicy.checkLocationPermission(mApp,
7917 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7918 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007919 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007920 .setCallingPid(Binder.getCallingPid())
7921 .setCallingUid(Binder.getCallingUid())
7922 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007923 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007924 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007925 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7926 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007927 .build());
7928 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7929 boolean hasFinePermission =
7930 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7931 boolean hasCoarsePermission =
7932 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7933
Jack Yu479f40e2020-10-27 21:29:25 -07007934 final Phone phone = getPhone(subId);
7935 if (phone == null) {
7936 return null;
7937 }
7938
Jordan Liu0f2bc442020-11-18 16:47:37 -08007939 final long identity = Binder.clearCallingIdentity();
7940
Jack Yu479f40e2020-10-27 21:29:25 -07007941 boolean isCallingPackageDataService = phone.getDataServicePackages()
7942 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007943 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007944 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7945 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7946 Rlog.d(LOG_TAG,
7947 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7948 return null;
7949 }
7950
Hall Liuf19c44f2018-11-27 14:38:17 -08007951 ServiceState ss = phone.getServiceState();
7952
7953 // Scrub out the location info in ServiceState depending on what level of access
7954 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007955 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007956 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7957 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 } finally {
7959 Binder.restoreCallingIdentity(identity);
7960 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007961 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007962
7963 /**
7964 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7965 *
7966 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7967 * voicemail ringtone.
7968 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7969 * PhoneAccount.
7970 */
7971 @Override
7972 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7976 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007977 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007984 }
7985
7986 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007987 * Sets the per-account voicemail ringtone.
7988 *
7989 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7990 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7991 *
7992 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7993 * voicemail ringtone.
7994 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7995 * PhoneAccount.
7996 */
7997 @Override
7998 public void setVoicemailRingtoneUri(String callingPackage,
7999 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008000 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008002 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8003 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8005 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8006 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008
8009 final long identity = Binder.clearCallingIdentity();
8010 try {
8011 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8012 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008013 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014 }
8015 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008018 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008019 }
8020
8021 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008022 * Returns whether vibration is set for voicemail notification in Phone settings.
8023 *
8024 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8025 * voicemail vibration setting.
8026 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8027 */
8028 @Override
8029 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8033 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008034 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008037 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008041 }
8042
Youhan Wange64578a2016-05-02 15:32:42 -07008043 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008044 * Sets the per-account voicemail vibration.
8045 *
8046 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8047 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8048 *
8049 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8050 * voicemail vibration setting.
8051 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8052 * specific PhoneAccount.
8053 */
8054 @Override
8055 public void setVoicemailVibrationEnabled(String callingPackage,
8056 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008057 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008059 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8060 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8062 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8063 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008064 }
8065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8069 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008070 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071 }
8072 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8073 } finally {
8074 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008075 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008076 }
8077
8078 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008079 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8080 *
8081 * @throws SecurityException if the caller does not have the required permission
8082 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008083 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008084 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008085 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008086 }
8087
8088 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008089 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8090 * permission.
8091 *
8092 * @throws SecurityException if the caller does not have the required permission
8093 */
8094 private void enforceSendSmsPermission() {
8095 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8096 }
8097
8098 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008099 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008100 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008101 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008102 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008103 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 final long identity = Binder.clearCallingIdentity();
8105 try {
8106 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008107 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 if (componentName == null) {
8109 throw new SecurityException(
8110 "Caller not current active visual voicemail package[null]");
8111 }
8112 String vvmPackage = componentName.getPackageName();
8113 if (!callingPackage.equals(vvmPackage)) {
8114 throw new SecurityException("Caller not current active visual voicemail package["
8115 + vvmPackage + "]");
8116 }
8117 } finally {
8118 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008119 }
8120 }
8121
8122 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008123 * Return the application ID for the app type.
8124 *
8125 * @param subId the subscription ID that this request applies to.
8126 * @param appType the uicc app type.
8127 * @return Application ID for specificied app type, or null if no uicc.
8128 */
8129 @Override
8130 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008131 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008132 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008133
8134 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008135 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008136 if (phone == null) {
8137 return null;
8138 }
8139 String aid = null;
8140 try {
8141 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8142 .getApplicationByType(appType).getAid();
8143 } catch (Exception e) {
8144 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8145 }
8146 return aid;
8147 } finally {
8148 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008149 }
Youhan Wange64578a2016-05-02 15:32:42 -07008150 }
8151
Youhan Wang4001d252016-05-11 10:29:41 -07008152 /**
8153 * Return the Electronic Serial Number.
8154 *
8155 * @param subId the subscription ID that this request applies to.
8156 * @return ESN or null if error.
8157 */
8158 @Override
8159 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008160 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008161 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162
8163 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008164 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008165 if (phone == null) {
8166 return null;
8167 }
8168 String esn = null;
8169 try {
8170 esn = phone.getEsn();
8171 } catch (Exception e) {
8172 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8173 }
8174 return esn;
8175 } finally {
8176 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008177 }
Youhan Wang4001d252016-05-11 10:29:41 -07008178 }
8179
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008180 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008181 * Return the Preferred Roaming List Version.
8182 *
8183 * @param subId the subscription ID that this request applies to.
8184 * @return PRLVersion or null if error.
8185 */
8186 @Override
8187 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008188 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008189 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008190
8191 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008192 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008193 if (phone == null) {
8194 return null;
8195 }
8196 String cdmaPrlVersion = null;
8197 try {
8198 cdmaPrlVersion = phone.getCdmaPrlVersion();
8199 } catch (Exception e) {
8200 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8201 }
8202 return cdmaPrlVersion;
8203 } finally {
8204 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008205 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008206 }
8207
8208 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008209 * Get snapshot of Telephony histograms
8210 * @return List of Telephony histograms
8211 * @hide
8212 */
8213 @Override
8214 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8216 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008217
8218 final long identity = Binder.clearCallingIdentity();
8219 try {
8220 return RIL.getTelephonyRILTimingHistograms();
8221 } finally {
8222 Binder.restoreCallingIdentity(identity);
8223 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008224 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008225
8226 /**
8227 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008228 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8229 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008230 * Require system privileges. In the future we may add this to carrier APIs.
8231 *
Michele Berionne482f8202018-11-27 18:57:59 -08008232 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008233 */
8234 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008235 @TelephonyManager.SetCarrierRestrictionResult
8236 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008237 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008238 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008239
Michele Berionne482f8202018-11-27 18:57:59 -08008240 if (carrierRestrictionRules == null) {
8241 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008242 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 final long identity = Binder.clearCallingIdentity();
8245 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008246 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008247 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008251 }
8252
8253 /**
8254 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008255 * Get the allowed carrier list and the excluded carrier list, including the priority between
8256 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008257 * Require system privileges. In the future we may add this to carrier APIs.
8258 *
Michele Berionne482f8202018-11-27 18:57:59 -08008259 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008260 */
8261 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008262 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008263 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265
8266 final long identity = Binder.clearCallingIdentity();
8267 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008268 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8269 if (response instanceof CarrierRestrictionRules) {
8270 return (CarrierRestrictionRules) response;
8271 }
8272 // Response is an Exception of some kind,
8273 // which is signalled to the user as a NULL retval
8274 return null;
8275 } catch (Exception e) {
8276 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8277 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008281 }
8282
fionaxu59545b42016-05-25 15:53:37 -07008283 /**
fionaxu59545b42016-05-25 15:53:37 -07008284 * Action set from carrier signalling broadcast receivers to enable/disable radio
8285 * @param subId the subscription ID that this action applies to.
8286 * @param enabled control enable or disable radio.
8287 * {@hide}
8288 */
8289 @Override
8290 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8291 enforceModifyPermission();
8292 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008293
8294 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008295 if (phone == null) {
8296 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8297 return;
8298 }
8299 try {
8300 phone.carrierActionSetRadioEnabled(enabled);
8301 } catch (Exception e) {
8302 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 } finally {
8304 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008305 }
8306 }
8307
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008308 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008309 * Enable or disable Voice over NR (VoNR)
8310 * @param subId the subscription ID that this action applies to.
8311 * @param enabled enable or disable VoNR.
8312 * @return operation result.
8313 */
8314 @Override
8315 public int setVoNrEnabled(int subId, boolean enabled) {
8316 enforceModifyPermission();
8317 final Phone phone = getPhone(subId);
8318
8319 final long identity = Binder.clearCallingIdentity();
8320 if (phone == null) {
8321 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8322 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8323 }
8324
8325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8326 try {
8327 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8328 workSource);
8329 if (DBG) log("setVoNrEnabled result: " + result);
8330 return result;
8331 } finally {
8332 Binder.restoreCallingIdentity(identity);
8333 }
8334 }
8335
8336 /**
8337 * Is voice over NR enabled
8338 * @return true if VoNR is enabled else false
8339 */
8340 @Override
8341 public boolean isVoNrEnabled(int subId) {
8342 enforceReadPrivilegedPermission("isVoNrEnabled");
8343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8344 final long identity = Binder.clearCallingIdentity();
8345 try {
8346 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8347 null, subId, workSource);
8348 if (DBG) log("isVoNrEnabled: " + isEnabled);
8349 return isEnabled;
8350 } finally {
8351 Binder.restoreCallingIdentity(identity);
8352 }
8353 }
8354
8355 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008356 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8357 * network status based on which carrier apps could apply actions accordingly,
8358 * enable/disable default url handler for example.
8359 *
8360 * @param subId the subscription ID that this action applies to.
8361 * @param report control start/stop reporting the default network status.
8362 * {@hide}
8363 */
8364 @Override
8365 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8366 enforceModifyPermission();
8367 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008368
8369 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008370 if (phone == null) {
8371 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8372 return;
8373 }
8374 try {
8375 phone.carrierActionReportDefaultNetworkStatus(report);
8376 } catch (Exception e) {
8377 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008378 } finally {
8379 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008380 }
8381 }
8382
8383 /**
fionaxud9622282017-07-17 17:51:30 -07008384 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8385 * @param subId the subscription ID that this action applies to.
8386 * {@hide}
8387 */
8388 @Override
8389 public void carrierActionResetAll(int subId) {
8390 enforceModifyPermission();
8391 final Phone phone = getPhone(subId);
8392 if (phone == null) {
8393 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8394 return;
8395 }
8396 try {
8397 phone.carrierActionResetAll();
8398 } catch (Exception e) {
8399 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8400 }
8401 }
8402
8403 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008404 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8405 * bug report is being generated.
8406 */
8407 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008408 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008409 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8410 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008411 writer.println("Permission Denial: can't dump Phone from pid="
8412 + Binder.getCallingPid()
8413 + ", uid=" + Binder.getCallingUid()
8414 + "without permission "
8415 + android.Manifest.permission.DUMP);
8416 return;
8417 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008418 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008419 }
Jack Yueb89b242016-06-22 13:27:47 -07008420
Brad Ebingerdac2f002018-04-03 15:17:52 -07008421 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008422 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8423 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8424 @NonNull String[] args) {
8425 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8426 this, in.getFileDescriptor(), out.getFileDescriptor(),
8427 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008428 }
8429
Jack Yueb89b242016-06-22 13:27:47 -07008430 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008431 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008432 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008433 * @param reason the reason the data enable change is taking place
8434 * @param enabled True if enabling the data, otherwise disabling.
8435 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008436 */
8437 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008438 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008439 boolean enabled) {
8440 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8441 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8442 try {
8443 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008444 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008445 } catch (SecurityException se) {
8446 enforceModifyPermission();
8447 }
8448 } else {
8449 enforceModifyPermission();
8450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451
8452 final long identity = Binder.clearCallingIdentity();
8453 try {
8454 Phone phone = getPhone(subId);
8455 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008456 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8457 phone.carrierActionSetMeteredApnsEnabled(enabled);
8458 } else {
8459 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8460 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008461 }
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008464 }
8465 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008466
8467 /**
8468 * Get Client request stats
8469 * @return List of Client Request Stats
8470 * @hide
8471 */
8472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008473 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8474 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008476 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008477 return null;
8478 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008479 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008481 final long identity = Binder.clearCallingIdentity();
8482 try {
8483 if (phone != null) {
8484 return phone.getClientRequestStats();
8485 }
8486
8487 return null;
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008491 }
8492
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008493 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008494 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008495 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008496 }
Jack Yueb4124c2017-02-16 15:32:43 -08008497
8498 /**
Grace Chen70990072017-03-24 17:21:30 -07008499 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008500 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008501 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008502 * @param state State of SIM (power down, power up, pass through)
8503 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8504 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8505 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008506 *
8507 **/
8508 @Override
Grace Chen70990072017-03-24 17:21:30 -07008509 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008510 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008511 Phone phone = PhoneFactory.getPhone(slotIndex);
8512
vagdeviaf9a5b92018-08-15 16:01:53 -07008513 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8514
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008518 phone.setSimPowerState(state, null, workSource);
8519 }
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
8523 }
8524
8525 /**
8526 * Set SIM card power state.
8527 *
8528 * @param slotIndex SIM slot id.
8529 * @param state State of SIM (power down, power up, pass through)
8530 * @param callback callback to trigger after success or failure
8531 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8532 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8533 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8534 *
8535 **/
8536 @Override
8537 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8538 IIntegerConsumer callback) {
8539 enforceModifyPermission();
8540 Phone phone = PhoneFactory.getPhone(slotIndex);
8541
8542 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8543
8544 final long identity = Binder.clearCallingIdentity();
8545 try {
8546 if (phone != null) {
8547 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8548 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008549 }
8550 } finally {
8551 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008552 }
8553 }
Shuo Qiandd210312017-04-12 22:11:33 +00008554
Tyler Gunn65d45c22017-06-05 11:22:26 -07008555 private boolean isUssdApiAllowed(int subId) {
8556 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008557 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008558 if (configManager == null) {
8559 return false;
8560 }
8561 PersistableBundle pb = configManager.getConfigForSubId(subId);
8562 if (pb == null) {
8563 return false;
8564 }
8565 return pb.getBoolean(
8566 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8567 }
8568
Shuo Qiandd210312017-04-12 22:11:33 +00008569 /**
8570 * Check if phone is in emergency callback mode
8571 * @return true if phone is in emergency callback mode
8572 * @param subId sub id
8573 */
goneil9c5f4872017-12-05 14:07:56 -08008574 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008575 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008576 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008577 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578
8579 final long identity = Binder.clearCallingIdentity();
8580 try {
8581 if (phone != null) {
8582 return phone.isInEcm();
8583 } else {
8584 return false;
8585 }
8586 } finally {
8587 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008588 }
8589 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008590
8591 /**
8592 * Get the current signal strength information for the given subscription.
8593 * Because this information is not updated when the device is in a low power state
8594 * it should not be relied-upon to be current.
8595 * @param subId Subscription index
8596 * @return the most recent cached signal strength info from the modem
8597 */
8598 @Override
8599 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600 final long identity = Binder.clearCallingIdentity();
8601 try {
8602 Phone p = getPhone(subId);
8603 if (p == null) {
8604 return null;
8605 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008607 return p.getSignalStrength();
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008611 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008612
Pengquan Meng77b7f132018-08-22 14:49:57 -07008613 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008614 * Get the current modem radio state for the given slot.
8615 * @param slotIndex slot index.
8616 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008617 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008618 * @return the current radio power state from the modem
8619 */
8620 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008621 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008622 Phone phone = PhoneFactory.getPhone(slotIndex);
8623 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008624 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8625 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008626 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8627 }
8628
8629 final long identity = Binder.clearCallingIdentity();
8630 try {
8631 return phone.getRadioPowerState();
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
8636 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8637 }
8638
8639 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008640 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8641 *
8642 * <p>Requires one of the following permissions:
8643 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8644 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8645 * privileges.
8646 *
8647 * @param subId subscription id
8648 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8649 * {@code false}.
8650 */
8651 @Override
8652 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008653 try {
8654 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8655 null);
8656 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008657 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008658 mApp, subId, "isDataRoamingEnabled");
8659 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008660
Pengquan Menga1bb6272018-09-06 09:59:22 -07008661 boolean isEnabled = false;
8662 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008663 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008664 Phone phone = getPhone(subId);
8665 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008666 } finally {
8667 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008668 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008669 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008670 }
8671
8672
8673 /**
8674 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8675 *
8676 * <p> Requires permission:
8677 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8678 * privileges.
8679 *
8680 * @param subId subscription id
8681 * @param isEnabled {@code true} means enable, {@code false} means disable.
8682 */
8683 @Override
8684 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8686 mApp, subId, "setDataRoamingEnabled");
8687
Pengquan Menga1bb6272018-09-06 09:59:22 -07008688 final long identity = Binder.clearCallingIdentity();
8689 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008690 Phone phone = getPhone(subId);
8691 if (phone != null) {
8692 phone.setDataRoamingEnabled(isEnabled);
8693 }
8694 } finally {
8695 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008696 }
8697 }
8698
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008699 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008700 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008701 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008702 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008703 mApp, subId, "isManualNetworkSelectionAllowed");
8704
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008705 boolean isAllowed = true;
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008708 Phone phone = getPhone(subId);
8709 if (phone != null) {
8710 isAllowed = phone.isCspPlmnEnabled();
8711 }
8712 } finally {
8713 Binder.restoreCallingIdentity(identity);
8714 }
8715 return isAllowed;
8716 }
8717
8718 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008719 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008720 // Verify that tha callingPackage belongs to the calling UID
8721 mApp.getSystemService(AppOpsManager.class)
8722 .checkPackage(Binder.getCallingUid(), callingPackage);
8723
Jordan Liu1e142fc2019-04-22 15:10:43 -07008724 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008725 try {
8726 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008727 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008728 } catch (SecurityException e) {
8729 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8730 // has carrier privileges on an active UICC
8731 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8732 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008733 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008734 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008735 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008736
8737 final long identity = Binder.clearCallingIdentity();
8738 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008739 UiccController uiccController = UiccController.getInstance();
8740 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008741 if (hasReadPermission) {
8742 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008743 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008744
8745 // Remove private info if the caller doesn't have access
8746 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8747 for (UiccCardInfo cardInfo : cardInfos) {
8748 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8749 // is available
8750 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8751 if (card == null || card.getUiccProfile() == null) {
8752 // assume no access if the card or profile is unavailable
8753 filteredInfos.add(cardInfo.getUnprivileged());
8754 continue;
8755 }
8756 UiccProfile profile = card.getUiccProfile();
8757 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8758 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8759 filteredInfos.add(cardInfo);
8760 } else {
8761 filteredInfos.add(cardInfo.getUnprivileged());
8762 }
8763 }
8764 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008765 } finally {
8766 Binder.restoreCallingIdentity(identity);
8767 }
8768 }
8769
8770 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008771 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008772 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008774 final long identity = Binder.clearCallingIdentity();
8775 try {
8776 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8777 if (slots == null) {
8778 Rlog.i(LOG_TAG, "slots is null.");
8779 return null;
8780 }
8781
8782 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8783 for (int i = 0; i < slots.length; i++) {
8784 UiccSlot slot = slots[i];
8785 if (slot == null) {
8786 continue;
8787 }
8788
Jordan Liu7be7e652019-05-06 18:55:02 +00008789 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008790 UiccCard card = slot.getUiccCard();
8791 if (card != null) {
8792 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008793 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008794 cardId = slot.getEid();
8795 if (TextUtils.isEmpty(cardId)) {
8796 cardId = slot.getIccId();
8797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008798 }
8799
Jordan Liu857451f2019-05-09 16:35:35 -07008800 if (cardId != null) {
8801 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8802 // if cardId is an EID, it's all digits so this is fine
8803 cardId = IccUtils.stripTrailingFs(cardId);
8804 }
8805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008806 int cardState = 0;
8807 switch (slot.getCardState()) {
8808 case CARDSTATE_ABSENT:
8809 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8810 break;
8811 case CARDSTATE_PRESENT:
8812 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8813 break;
8814 case CARDSTATE_ERROR:
8815 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8816 break;
8817 case CARDSTATE_RESTRICTED:
8818 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8819 break;
8820 default:
8821 break;
8822
8823 }
8824
8825 infos[i] = new UiccSlotInfo(
8826 slot.isActive(),
8827 slot.isEuicc(),
8828 cardId,
8829 cardState,
8830 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008831 slot.isExtendedApduSupported(),
8832 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008833 }
8834 return infos;
8835 } finally {
8836 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008837 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008838 }
8839
8840 @Override
8841 public boolean switchSlots(int[] physicalSlots) {
8842 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008843
8844 final long identity = Binder.clearCallingIdentity();
8845 try {
8846 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8847 } finally {
8848 Binder.restoreCallingIdentity(identity);
8849 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008850 }
Jack Yu4c988042018-02-27 15:30:01 -08008851
8852 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008853 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 return UiccController.getInstance().getCardIdForDefaultEuicc();
8857 } finally {
8858 Binder.restoreCallingIdentity(identity);
8859 }
8860 }
8861
Pengquan Meng85728fb2018-03-12 16:31:21 -07008862 /**
goneil47ffb6e2018-04-06 15:40:58 -07008863 * A test API to reload the UICC profile.
8864 *
8865 * <p>Requires that the calling app has permission
8866 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8867 * @hide
8868 */
8869 @Override
8870 public void refreshUiccProfile(int subId) {
8871 enforceModifyPermission();
8872
8873 final long identity = Binder.clearCallingIdentity();
8874 try {
8875 Phone phone = getPhone(subId);
8876 if (phone == null) {
8877 return;
8878 }
8879 UiccCard uiccCard = phone.getUiccCard();
8880 if (uiccCard == null) {
8881 return;
8882 }
8883 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8884 if (uiccProfile == null) {
8885 return;
8886 }
8887 uiccProfile.refresh();
8888 } finally {
8889 Binder.restoreCallingIdentity(identity);
8890 }
8891 }
8892
8893 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008894 * Returns false if the mobile data is disabled by default, otherwise return true.
8895 */
8896 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008897 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008898 }
8899
8900 /**
8901 * Returns true if the data roaming is enabled by default, i.e the system property
8902 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8903 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8904 */
8905 private boolean getDefaultDataRoamingEnabled(int subId) {
8906 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008907 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008908 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008909 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8910 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8911 return isDataRoamingEnabled;
8912 }
8913
8914 /**
8915 * Returns the default network type for the given {@code subId}, if the default network type is
8916 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8917 */
8918 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008919 List<Integer> list = TelephonyProperties.default_network();
8920 int phoneId = mSubscriptionController.getPhoneId(subId);
8921 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8922 return list.get(phoneId);
8923 }
8924 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008925 }
fionaxua13278b2018-03-21 00:08:13 -07008926
8927 @Override
8928 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008929 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008930 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008931
8932 final long identity = Binder.clearCallingIdentity();
8933 try {
8934 final Phone phone = getPhone(subId);
8935 if (phone == null) {
8936 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8937 return;
8938 }
chen xueaba88a2019-03-15 13:15:10 -07008939 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8940 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008941 if (carrierPrivilegeRules == null) {
8942 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8943 } else {
8944 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008946 } finally {
8947 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008948 }
fionaxua13278b2018-03-21 00:08:13 -07008949 }
8950
8951 @Override
8952 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008953 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008954
8955 final long identity = Binder.clearCallingIdentity();
8956 try {
8957 final Phone phone = getPhone(subId);
8958 if (phone == null) {
8959 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8960 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8961 }
8962 return phone.getCarrierIdListVersion();
8963 } finally {
8964 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008965 }
fionaxua13278b2018-03-21 00:08:13 -07008966 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008967
8968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008969 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8970 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008972 mApp, subId, callingPackage, callingFeatureId,
8973 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008974 return -1;
8975 }
8976
8977 final long identity = Binder.clearCallingIdentity();
8978 try {
8979 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008984
8985 @Override
8986 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008987 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008988 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008989 mApp, subId, "getCdmaRoamingMode");
8990
8991 final long identity = Binder.clearCallingIdentity();
8992 try {
8993 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
8998
8999 @Override
9000 public boolean setCdmaRoamingMode(int subId, int mode) {
9001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9002 mApp, subId, "setCdmaRoamingMode");
9003
9004 final long identity = Binder.clearCallingIdentity();
9005 try {
9006 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9007 } finally {
9008 Binder.restoreCallingIdentity(identity);
9009 }
9010 }
9011
9012 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009013 public int getCdmaSubscriptionMode(int subId) {
9014 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009015 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009016 mApp, subId, "getCdmaSubscriptionMode");
9017
9018 final long identity = Binder.clearCallingIdentity();
9019 try {
9020 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9021 } finally {
9022 Binder.restoreCallingIdentity(identity);
9023 }
9024 }
9025
9026 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009027 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9029 mApp, subId, "setCdmaSubscriptionMode");
9030
9031 final long identity = Binder.clearCallingIdentity();
9032 try {
9033 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9034 } finally {
9035 Binder.restoreCallingIdentity(identity);
9036 }
9037 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009038
sqianc5eccab2018-10-19 18:46:41 -07009039 @Override
sqian8c685422019-02-22 15:55:18 -08009040 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009041 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009043 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9044 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009045 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9046 }
9047 final long identity = Binder.clearCallingIdentity();
9048 try {
sqian854d44b2018-12-12 16:48:18 -08009049 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9050 for (Phone phone: PhoneFactory.getPhones()) {
9051 if (phone.getEmergencyNumberTracker() != null
9052 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9053 emergencyNumberListInternal.put(
9054 phone.getSubId(),
9055 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9056 }
sqian11b7a0e2018-12-05 18:48:28 -08009057 }
sqian854d44b2018-12-12 16:48:18 -08009058 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009059 } finally {
9060 Binder.restoreCallingIdentity(identity);
9061 }
sqianc5eccab2018-10-19 18:46:41 -07009062 }
9063
9064 @Override
sqian8c685422019-02-22 15:55:18 -08009065 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009066 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009067 if (!exactMatch) {
9068 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009069 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009070 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009071 }
9072 final long identity = Binder.clearCallingIdentity();
9073 try {
sqian854d44b2018-12-12 16:48:18 -08009074 for (Phone phone: PhoneFactory.getPhones()) {
9075 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009076 && phone.getEmergencyNumberTracker()
9077 .isEmergencyNumber(number, exactMatch)) {
9078 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009079 }
sqian11b7a0e2018-12-05 18:48:28 -08009080 }
9081 return false;
9082 } finally {
9083 Binder.restoreCallingIdentity(identity);
9084 }
9085 }
9086
sqianf4ca7ed2019-01-15 18:32:07 -08009087 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009088 * Start emergency callback mode for GsmCdmaPhone for testing.
9089 */
9090 @Override
9091 public void startEmergencyCallbackMode() {
9092 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9093 "startEmergencyCallbackMode");
9094 enforceModifyPermission();
9095 final long identity = Binder.clearCallingIdentity();
9096 try {
9097 for (Phone phone : PhoneFactory.getPhones()) {
9098 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9099 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9100 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9101 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9102 gsmCdmaPhone.obtainMessage(
9103 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9104 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9105 }
9106 }
9107 } finally {
9108 Binder.restoreCallingIdentity(identity);
9109 }
9110 }
9111
9112 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009113 * Update emergency number list for test mode.
9114 */
9115 @Override
9116 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9118 "updateEmergencyNumberListTestMode");
9119
9120 final long identity = Binder.clearCallingIdentity();
9121 try {
9122 for (Phone phone: PhoneFactory.getPhones()) {
9123 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9124 if (tracker != null) {
9125 tracker.executeEmergencyNumberTestModeCommand(action, num);
9126 }
9127 }
9128 } finally {
9129 Binder.restoreCallingIdentity(identity);
9130 }
9131 }
9132
9133 /**
9134 * Get the full emergency number list for test mode.
9135 */
9136 @Override
9137 public List<String> getEmergencyNumberListTestMode() {
9138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9139 "getEmergencyNumberListTestMode");
9140
9141 final long identity = Binder.clearCallingIdentity();
9142 try {
9143 Set<String> emergencyNumbers = new HashSet<>();
9144 for (Phone phone: PhoneFactory.getPhones()) {
9145 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9146 if (tracker != null) {
9147 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9148 emergencyNumbers.add(num.getNumber());
9149 }
9150 }
9151 }
9152 return new ArrayList<>(emergencyNumbers);
9153 } finally {
9154 Binder.restoreCallingIdentity(identity);
9155 }
9156 }
9157
chen xud6b45bd2018-10-30 22:27:10 -07009158 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009159 public int getEmergencyNumberDbVersion(int subId) {
9160 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9161
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
9164 final Phone phone = getPhone(subId);
9165 if (phone == null) {
9166 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9167 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9168 }
9169 return phone.getEmergencyNumberDbVersion();
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
9175 @Override
9176 public void notifyOtaEmergencyNumberDbInstalled() {
9177 enforceModifyPermission();
9178
9179 final long identity = Binder.clearCallingIdentity();
9180 try {
9181 for (Phone phone: PhoneFactory.getPhones()) {
9182 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9183 if (tracker != null) {
9184 tracker.updateOtaEmergencyNumberDatabase();
9185 }
9186 }
9187 } finally {
9188 Binder.restoreCallingIdentity(identity);
9189 }
9190 }
9191
9192 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009193 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009194 enforceActiveEmergencySessionPermission();
9195
9196 final long identity = Binder.clearCallingIdentity();
9197 try {
9198 for (Phone phone: PhoneFactory.getPhones()) {
9199 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9200 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009201 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9202 }
9203 }
9204 } finally {
9205 Binder.restoreCallingIdentity(identity);
9206 }
9207 }
9208
9209 @Override
9210 public void resetOtaEmergencyNumberDbFilePath() {
9211 enforceActiveEmergencySessionPermission();
9212
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
9215 for (Phone phone: PhoneFactory.getPhones()) {
9216 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9217 if (tracker != null) {
9218 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009219 }
9220 }
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 }
9225
9226 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009227 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9228 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9229 Phone phone = getPhone(subId);
9230 if (phone == null) {
9231 return null;
9232 }
9233 final long identity = Binder.clearCallingIdentity();
9234 try {
9235 UiccProfile profile = UiccController.getInstance()
9236 .getUiccProfileForPhone(phone.getPhoneId());
9237 if (profile != null) {
9238 return profile.getCertsFromCarrierPrivilegeAccessRules();
9239 }
9240 } finally {
9241 Binder.restoreCallingIdentity(identity);
9242 }
9243 return null;
9244 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009245
9246 /**
9247 * Enable or disable a modem stack.
9248 */
9249 @Override
9250 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9251 enforceModifyPermission();
9252
9253 final long identity = Binder.clearCallingIdentity();
9254 try {
9255 Phone phone = PhoneFactory.getPhone(slotIndex);
9256 if (phone == null) {
9257 return false;
9258 } else {
9259 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9260 }
9261 } finally {
9262 Binder.restoreCallingIdentity(identity);
9263 }
9264 }
Michelecea4cf22018-12-21 15:00:11 -08009265
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009266 /**
9267 * Whether a modem stack is enabled or not.
9268 */
9269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009270 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9271 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009272 Phone phone = PhoneFactory.getPhone(slotIndex);
9273 if (phone == null) return false;
9274
9275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009276 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9277 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009278 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9279 }
9280
9281 final long identity = Binder.clearCallingIdentity();
9282 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009283 try {
9284 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9285 } catch (NoSuchElementException ex) {
9286 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9287 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009288 } finally {
9289 Binder.restoreCallingIdentity(identity);
9290 }
9291 }
9292
Michelecea4cf22018-12-21 15:00:11 -08009293 @Override
Michele0ea7d782019-03-19 14:58:42 -07009294 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009295 enforceModifyPermission();
9296
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
9299 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009300 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009301 .commit();
9302 } finally {
9303 Binder.restoreCallingIdentity(identity);
9304 }
9305 }
9306
9307 @Override
Michele0ea7d782019-03-19 14:58:42 -07009308 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009309 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009311 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9312 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009313 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009314 }
Michelecea4cf22018-12-21 15:00:11 -08009315
9316 final long identity = Binder.clearCallingIdentity();
9317 try {
Michele0ea7d782019-03-19 14:58:42 -07009318 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009319 } finally {
9320 Binder.restoreCallingIdentity(identity);
9321 }
9322 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009323
Michele0ea7d782019-03-19 14:58:42 -07009324 @TelephonyManager.IsMultiSimSupportedResult
9325 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009326 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9327 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9328 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009329 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9330 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009331 }
9332 // Check if the hardware supports multisim functionality. If usage of multisim is not
9333 // supported by the modem, indicate that it is restricted.
9334 PhoneCapability staticCapability =
9335 mPhoneConfigurationManager.getStaticPhoneCapability();
9336 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009337 loge("isMultiSimSupportedInternal: no static configuration available");
9338 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009339 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009340 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009341 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9342 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009343 }
9344 // Check if support of multiple SIMs is restricted by carrier
9345 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009346 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009347 }
9348
Michele0ea7d782019-03-19 14:58:42 -07009349 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009350 }
9351
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009352 /**
9353 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009354 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9355 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9356 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009357 * @param numOfSims number of active sims we want to switch to
9358 */
9359 @Override
9360 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009361 if (numOfSims == 1) {
9362 enforceModifyPermission();
9363 } else {
9364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9365 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9366 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009367 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009368
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009369 try {
Michele30b57b22019-03-01 12:01:14 -08009370 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009371 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009372 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9373 return;
9374 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009375 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9376 } finally {
9377 Binder.restoreCallingIdentity(identity);
9378 }
9379 }
9380
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009381 @Override
9382 public boolean isApplicationOnUicc(int subId, int appType) {
9383 enforceReadPrivilegedPermission("isApplicationOnUicc");
9384 Phone phone = getPhone(subId);
9385 if (phone == null) {
9386 return false;
9387 }
9388 final long identity = Binder.clearCallingIdentity();
9389 try {
9390 UiccCard uiccCard = phone.getUiccCard();
9391 if (uiccCard == null) {
9392 return false;
9393 }
9394 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9395 if (uiccProfile == null) {
9396 return false;
9397 }
9398 if (TelephonyManager.APPTYPE_SIM <= appType
9399 && appType <= TelephonyManager.APPTYPE_ISIM) {
9400 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9401 }
9402 return false;
9403 } finally {
9404 Binder.restoreCallingIdentity(identity);
9405 }
9406 }
9407
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009408 /**
chen xub4baa772019-04-03 10:23:41 -07009409 * Get whether making changes to modem configurations will trigger reboot.
9410 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009411 */
9412 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009413 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9414 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009415 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009416 mApp, subId, callingPackage, callingFeatureId,
9417 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009418 return false;
9419 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009420 final long identity = Binder.clearCallingIdentity();
9421 try {
9422 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9423 } finally {
9424 Binder.restoreCallingIdentity(identity);
9425 }
9426 }
9427
Nathan Harold29f5f052019-02-15 13:41:57 -08009428 private void updateModemStateMetrics() {
9429 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9430 // TODO: check the state for each modem if the api is ready.
9431 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9432 }
9433
Pengquan Meng3889a572019-01-23 11:16:29 -08009434 @Override
9435 public int[] getSlotsMapping() {
9436 enforceReadPrivilegedPermission("getSlotsMapping");
9437
9438 final long identity = Binder.clearCallingIdentity();
9439 try {
9440 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9441 // All logical slots should have a mapping to a physical slot.
9442 int[] logicalSlotsMapping = new int[phoneCount];
9443 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9444 for (int i = 0; i < slotInfos.length; i++) {
9445 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9446 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9447 }
9448 }
9449 return logicalSlotsMapping;
9450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
9453 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009454
9455 /**
9456 * Get the IRadio HAL Version
9457 */
9458 @Override
9459 public int getRadioHalVersion() {
9460 Phone phone = getDefaultPhone();
9461 if (phone == null) return -1;
9462 HalVersion hv = phone.getHalVersion();
9463 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9464 return hv.major * 100 + hv.minor;
9465 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009466
9467 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009468 * Get the current calling package name.
9469 * @return the current calling package name
9470 */
9471 @Override
9472 public String getCurrentPackageName() {
9473 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9474 }
9475
9476 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009477 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9478 * corresponding network requests on a subId.
9479 *
9480 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009481 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009482 * 2) APN is un-metered for this subscription, or
9483 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009484 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009485 *
9486 * @return whether data is allowed for a apn type.
9487 *
9488 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009489 */
9490 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009491 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009492 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9493 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009494
9495 // Now that all security checks passes, perform the operation as ourselves.
9496 final long identity = Binder.clearCallingIdentity();
9497 try {
9498 Phone phone = getPhone(subId);
9499 if (phone == null) return false;
9500
Jack Yu41407ee2019-05-13 16:54:09 -07009501 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009502 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9503 } finally {
9504 Binder.restoreCallingIdentity(identity);
9505 }
9506 }
9507
9508 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009509 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009510 enforceReadPrivilegedPermission("isApnMetered");
9511
9512 // Now that all security checks passes, perform the operation as ourselves.
9513 final long identity = Binder.clearCallingIdentity();
9514 try {
9515 Phone phone = getPhone(subId);
9516 if (phone == null) return true; // By default return true.
9517
Jack Yu41407ee2019-05-13 16:54:09 -07009518 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009519 } finally {
9520 Binder.restoreCallingIdentity(identity);
9521 }
9522 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009523
9524 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009525 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9526 int subscriptionId, IBooleanConsumer resultCallback) {
9527 enforceModifyPermission();
9528 long token = Binder.clearCallingIdentity();
9529 try {
9530 Phone phone = getPhone(subscriptionId);
9531 if (phone == null) {
9532 try {
9533 if (resultCallback != null) {
9534 resultCallback.accept(false);
9535 }
9536 } catch (RemoteException e) {
9537 // ignore
9538 }
9539 return;
9540 }
9541 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9542 Pair.create(specifiers, (x) -> {
9543 try {
9544 if (resultCallback != null) {
9545 resultCallback.accept(x);
9546 }
9547 } catch (RemoteException e) {
9548 // ignore
9549 }
9550 });
9551 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9552 } finally {
9553 Binder.restoreCallingIdentity(token);
9554 }
9555 }
9556
9557 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009558 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9559 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009560 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009561 mApp, subId, "getSystemSelectionChannels");
9562 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9563 final long identity = Binder.clearCallingIdentity();
9564 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009565 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9566 if (result instanceof IllegalStateException) {
9567 throw (IllegalStateException) result;
9568 }
9569 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009570 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9571 return specifiers;
9572 } finally {
9573 Binder.restoreCallingIdentity(identity);
9574 }
9575 }
9576
9577 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009578 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009579 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009580 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9581 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9582 if (iccRecords == null) {
9583 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9584 return false;
9585 }
9586 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9587 }
9588
9589 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009590 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9591 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009592 if (callingPackage == null) {
9593 callingPackage = getCurrentPackageName();
9594 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009595 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9596 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009597 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9598 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009599 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9600 }
9601 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9602 Intent intent = new Intent();
9603 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9604 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9605 // Bring up choose default SMS subscription dialog right now
9606 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9607 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9608 mApp.startActivity(intent);
9609 }
chen xud5ca2d52019-05-28 15:20:57 -07009610
9611 @Override
9612 public String getMmsUAProfUrl(int subId) {
9613 //TODO investigate if this API should require proper permission check in R b/133791609
9614 final long identity = Binder.clearCallingIdentity();
9615 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009616 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9617 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9618 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9619 return carrierUAProfUrl;
9620 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009621 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9622 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009623 } finally {
9624 Binder.restoreCallingIdentity(identity);
9625 }
9626 }
9627
9628 @Override
9629 public String getMmsUserAgent(int subId) {
9630 //TODO investigate if this API should require proper permission check in R b/133791609
9631 final long identity = Binder.clearCallingIdentity();
9632 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009633 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9634 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9635 if (!TextUtils.isEmpty(carrierUserAgent)) {
9636 return carrierUserAgent;
9637 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009638 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9639 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009640 } finally {
9641 Binder.restoreCallingIdentity(identity);
9642 }
9643 }
Jack Yub07d4972019-05-28 16:12:25 -07009644
9645 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009646 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9647 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009648
Jack Yub07d4972019-05-28 16:12:25 -07009649 final long identity = Binder.clearCallingIdentity();
9650 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009651 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009652 if (phone == null) return false;
9653
Hall Liua62f5da2020-09-25 10:42:19 -07009654 switch (policy) {
9655 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9656 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9657 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9658 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9659 default:
9660 throw new IllegalArgumentException(policy + " is not a valid policy");
9661 }
Jack Yub07d4972019-05-28 16:12:25 -07009662 } finally {
9663 Binder.restoreCallingIdentity(identity);
9664 }
9665 }
9666
9667 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009668 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009669 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009670 enforceModifyPermission();
9671
changbettyd5c246e2019-12-24 15:40:37 +08009672 final long identity = Binder.clearCallingIdentity();
9673 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009674 Phone phone = getPhone(subscriptionId);
9675 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009676
Hall Liua62f5da2020-09-25 10:42:19 -07009677 switch (policy) {
9678 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9679 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9680 break;
9681 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9682 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9683 break;
9684 default:
9685 throw new IllegalArgumentException(policy + " is not a valid policy");
9686 }
changbettyd5c246e2019-12-24 15:40:37 +08009687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690 }
9691
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009692 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009693 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009694 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9695 * otherwise.
9696 */
9697 @Override
9698 public void setCepEnabled(boolean isCepEnabled) {
9699 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9700
9701 final long identity = Binder.clearCallingIdentity();
9702 try {
9703 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9704 for (Phone phone : PhoneFactory.getPhones()) {
9705 Phone defaultPhone = phone.getImsPhone();
9706 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9707 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9708 ImsPhoneCallTracker imsPhoneCallTracker =
9709 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9710 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9711 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9712 + imsPhone.getMsisdn());
9713 }
9714 }
9715 } finally {
9716 Binder.restoreCallingIdentity(identity);
9717 }
9718 }
allenwtsu46dcc572020-01-08 18:24:03 +08009719
9720 /**
9721 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9722 *
9723 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9724 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9725 * before being read.
9726 */
9727 @Override
9728 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9729 isCompressed) {
9730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9731 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009732 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9733 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9734 }
9735 if (!isImsAvailableOnDevice()) {
9736 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9737 "IMS not available on device.");
9738 }
9739
9740 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009741 try {
Hui Wang761a6682020-10-31 05:12:53 +00009742 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9743 } finally {
9744 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009745 }
9746 }
zoey chene02881a2019-12-30 16:11:23 +08009747
9748 @Override
9749 public boolean isIccLockEnabled(int subId) {
9750 enforceReadPrivilegedPermission("isIccLockEnabled");
9751
9752 // Now that all security checks passes, perform the operation as ourselves.
9753 final long identity = Binder.clearCallingIdentity();
9754 try {
9755 Phone phone = getPhone(subId);
9756 if (phone != null && phone.getIccCard() != null) {
9757 return phone.getIccCard().getIccLockEnabled();
9758 } else {
9759 return false;
9760 }
9761 } finally {
9762 Binder.restoreCallingIdentity(identity);
9763 }
9764 }
9765
9766 /**
9767 * Set the ICC pin lock enabled or disabled.
9768 *
9769 * @return an integer representing the status of IccLock enabled or disabled in the following
9770 * three cases:
9771 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9772 * successfully.
9773 * - Positive number and zero for remaining password attempts.
9774 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9775 *
9776 */
9777 @Override
9778 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9779 enforceModifyPermission();
9780
9781 Phone phone = getPhone(subId);
9782 if (phone == null) {
9783 return 0;
9784 }
9785 // Now that all security checks passes, perform the operation as ourselves.
9786 final long identity = Binder.clearCallingIdentity();
9787 try {
9788 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9789 new Pair<Boolean, String>(enabled, password), phone, null);
9790 return attemptsRemaining;
9791
9792 } catch (Exception e) {
9793 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9794 } finally {
9795 Binder.restoreCallingIdentity(identity);
9796 }
9797 return 0;
9798 }
9799
9800 /**
9801 * Change the ICC password used in ICC pin lock.
9802 *
9803 * @return an integer representing the status of IccLock changed in the following three cases:
9804 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9805 * - Positive number and zero for remaining password attempts.
9806 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9807 *
9808 */
9809 @Override
9810 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9811 enforceModifyPermission();
9812
9813 Phone phone = getPhone(subId);
9814 if (phone == null) {
9815 return 0;
9816 }
9817 // Now that all security checks passes, perform the operation as ourselves.
9818 final long identity = Binder.clearCallingIdentity();
9819 try {
9820 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9821 new Pair<String, String>(oldPassword, newPassword), phone, null);
9822 return attemptsRemaining;
9823
9824 } catch (Exception e) {
9825 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9826 } finally {
9827 Binder.restoreCallingIdentity(identity);
9828 }
9829 return 0;
9830 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009831
9832 /**
9833 * Request for receiving user activity notification
9834 */
9835 @Override
9836 public void requestUserActivityNotification() {
9837 if (!mNotifyUserActivity.get()
9838 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9839 mNotifyUserActivity.set(true);
9840 }
9841 }
9842
9843 /**
9844 * Called when userActivity is signalled in the power manager.
9845 * This is safe to call from any thread, with any window manager locks held or not.
9846 */
9847 @Override
9848 public void userActivity() {
9849 // ***************************************
9850 // * Inherited from PhoneWindowManager *
9851 // ***************************************
9852 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9853 // WITH ITS LOCKS HELD.
9854 //
9855 // This code must be VERY careful about the locks
9856 // it acquires.
9857 // In fact, the current code acquires way too many,
9858 // and probably has lurking deadlocks.
9859
9860 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9861 throw new SecurityException("Only the OS may call notifyUserActivity()");
9862 }
9863
9864 if (mNotifyUserActivity.getAndSet(false)) {
9865 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9866 USER_ACTIVITY_NOTIFICATION_DELAY);
9867 }
9868 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009869
9870 @Override
9871 public boolean canConnectTo5GInDsdsMode() {
9872 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9873 }
Jack Yud10cdd42020-09-28 20:28:01 -07009874
9875 @Override
9876 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9877 String callingFeatureId) {
9878 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9879 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9880 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9881 }
9882
9883 Phone phone = getPhone(subId);
9884 if (phone == null) {
9885 throw new RuntimeException("phone is not available");
9886 }
9887 // Now that all security checks passes, perform the operation as ourselves.
9888 final long identity = Binder.clearCallingIdentity();
9889 try {
9890 return phone.getEquivalentHomePlmns();
9891 } finally {
9892 Binder.restoreCallingIdentity(identity);
9893 }
9894 }
Daniel Bright59e67312020-11-13 11:49:37 -08009895
9896 @Override
9897 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009898 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9899 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009900 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009901 if (radioInterfaceCapabilities == null) {
9902 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009903 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009904 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009905 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009906
Hui Wang641e81c2020-10-12 12:14:23 -07009907 @Override
9908 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9909 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009910 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9911 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9912 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9913 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9914 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009915 if (DBG) {
9916 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9917 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9918 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9919 }
9920
9921 if (!SubscriptionManager.isValidSubscriptionId(subId)
9922 || appType < TelephonyManager.APPTYPE_UNKNOWN
9923 || appType > TelephonyManager.APPTYPE_ISIM
9924 || nafUrl == null || securityProtocol == null || callback == null) {
9925 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9926 if (callback != null) {
9927 try {
9928 callback.onAuthenticationFailure(
9929 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9930 } catch (RemoteException exception) {
9931 log("Fail to notify onAuthenticationFailure due to " + exception);
9932 }
9933 return;
9934 }
9935 }
9936
9937 final long token = Binder.clearCallingIdentity();
9938 try {
9939 getGbaManager(subId).bootstrapAuthenticationRequest(
9940 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9941 forceBootStrapping, callback));
9942 } finally {
9943 Binder.restoreCallingIdentity(token);
9944 }
9945 }
9946
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009947 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009948 * Attempts to set the radio power state for all phones for thermal reason.
9949 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009950 * requested radio power state will actually be set. See {@link
9951 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9952 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009953 * @param enable {@code true} if trying to turn radio on.
9954 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9955 * false}.
9956 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009957 private boolean setRadioPowerForThermal(boolean enable) {
9958 boolean isPhoneAvailable = false;
9959 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9960 Phone phone = PhoneFactory.getPhone(i);
9961 if (phone != null) {
9962 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9963 isPhoneAvailable = true;
9964 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009965 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009966
9967 // return true if successfully informed the phone object about the thermal radio power
9968 // request.
9969 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009970 }
9971
9972 private int handleDataThrottlingRequest(int subId,
9973 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009974 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9975 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9976 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9977 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9978 throw new IllegalArgumentException("modem does not support data throttling");
9979 }
9980
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009981 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9982 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009983 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009984 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9985 }
9986
9987 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9988
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009989 if (isDataThrottlingSupported) {
9990 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009991 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009992 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9993 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9994 } else if (thermalMitigationResult
9995 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009996 log("Modem likely does not support data throttling on secondary carrier. Data " +
9997 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9998 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009999 }
10000 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010001 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010002
10003 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010004 }
10005
Jack Nudelman644b91a2021-03-12 14:09:48 -080010006 private static List<String> getThermalMitigationAllowlist(Context context) {
10007 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10008 for (String pckg : context.getResources()
10009 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10010 sThermalMitigationAllowlistedPackages.add(pckg);
10011 }
10012 }
10013
10014 return sThermalMitigationAllowlistedPackages;
10015 }
10016
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010017 private boolean isAnyPhoneInEmergencyState() {
10018 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10019 if (tm.isInEmergencyCall()) {
10020 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10021 return true;
10022 }
10023 for (Phone phone : PhoneFactory.getPhones()) {
10024 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10025 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10026 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10027 + phone.isInEcm());
10028 return true;
10029 }
10030 }
10031
10032 return false;
10033 }
10034
Jack Nudelman644b91a2021-03-12 14:09:48 -080010035 /**
10036 * Used by shell commands to add an authorized package name for thermal mitigation.
10037 * @param packageName name of package to be allowlisted
10038 * @param context
10039 */
10040 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10041 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10042 sThermalMitigationAllowlistedPackages.add(packageName);
10043 }
10044
10045 /**
10046 * Used by shell commands to remove an authorized package name for thermal mitigation.
10047 * @param packageName name of package to remove from allowlist
10048 * @param context
10049 */
10050 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10051 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10052 sThermalMitigationAllowlistedPackages.remove(packageName);
10053 }
10054
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010055 /**
10056 * Thermal mitigation request to control functionalities at modem.
10057 *
10058 * @param subId the id of the subscription.
10059 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010060 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010061 *
10062 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10063 */
10064 @Override
10065 @ThermalMitigationResult
10066 public int sendThermalMitigationRequest(
10067 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010068 ThermalMitigationRequest thermalMitigationRequest,
10069 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010070 enforceModifyPermission();
10071
Jack Nudelman644b91a2021-03-12 14:09:48 -080010072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10073 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10074 .contains(callingPackage)) {
10075 throw new SecurityException("Calling package must be configured in the device config. "
10076 + "calling package: " + callingPackage);
10077 }
10078
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010079 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10080 final long identity = Binder.clearCallingIdentity();
10081
10082 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10083 try {
10084 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10085 switch (thermalMitigationAction) {
10086 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10087 thermalMitigationResult =
10088 handleDataThrottlingRequest(subId,
10089 thermalMitigationRequest.getDataThrottlingRequest());
10090 break;
10091 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10092 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10093 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10094 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10095 }
10096
10097 // Ensure that radio is on. If not able to power on due to phone being
10098 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010099 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010100 thermalMitigationResult =
10101 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10102 break;
10103 }
10104
10105 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10106 false);
10107 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10108 break;
10109 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10110 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10111 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10112 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10113 }
10114
10115 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10116 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010117 Phone phone = getPhone(subId);
10118 if (phone == null) {
10119 thermalMitigationResult =
10120 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10121 break;
10122 }
10123
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010124 TelephonyConnectionService service =
10125 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010126 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010127 Log.e(LOG_TAG, "An emergency call is pending");
10128 thermalMitigationResult =
10129 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10130 break;
10131 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010132 thermalMitigationResult =
10133 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10134 break;
10135 }
10136 } else {
10137 thermalMitigationResult =
10138 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10139 break;
10140 }
10141
10142 // Turn radio off. If not able to power off due to phone being unavailable,
10143 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010144 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010145 thermalMitigationResult =
10146 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10147 break;
10148 }
10149 thermalMitigationResult =
10150 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10151 break;
10152 default:
10153 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10154 + "not exist. Requested action: " + thermalMitigationAction);
10155 }
10156 } catch (IllegalArgumentException e) {
10157 throw e;
10158 } catch (Exception e) {
10159 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10160 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10161 } finally {
10162 Binder.restoreCallingIdentity(identity);
10163 }
10164
10165 if (DBG) {
10166 log("thermalMitigationRequest returning with thermalMitigationResult: "
10167 + thermalMitigationResult);
10168 }
10169
10170 return thermalMitigationResult;
10171 }
Hui Wang641e81c2020-10-12 12:14:23 -070010172
10173 /**
10174 * Set the GbaService Package Name that Telephony will bind to.
10175 *
10176 * @param subId The sim that the GbaService is associated with.
10177 * @param packageName The name of the package to be replaced with.
10178 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10179 */
10180 @Override
10181 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10182 enforceModifyPermission();
10183
10184 final long identity = Binder.clearCallingIdentity();
10185 try {
10186 return getGbaManager(subId).overrideServicePackage(packageName);
10187 } finally {
10188 Binder.restoreCallingIdentity(identity);
10189 }
10190 }
10191
10192 /**
10193 * Return the package name of the currently bound GbaService.
10194 *
10195 * @param subId The sim that the GbaService is associated with.
10196 * @return the package name of the GbaService configuration, null if GBA is not supported.
10197 */
10198 @Override
10199 public String getBoundGbaService(int subId) {
10200 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10201
10202 final long identity = Binder.clearCallingIdentity();
10203 try {
10204 return getGbaManager(subId).getServicePackage();
10205 } finally {
10206 Binder.restoreCallingIdentity(identity);
10207 }
10208 }
10209
10210 /**
10211 * Set the release time for telephony to unbind GbaService.
10212 *
10213 * @param subId The sim that the GbaService is associated with.
10214 * @param interval The release time to unbind GbaService by millisecond.
10215 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10216 */
10217 @Override
10218 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10219 enforceModifyPermission();
10220
10221 final long identity = Binder.clearCallingIdentity();
10222 try {
10223 return getGbaManager(subId).overrideReleaseTime(interval);
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
10228
10229 /**
10230 * Return the release time for telephony to unbind GbaService.
10231 *
10232 * @param subId The sim that the GbaService is associated with.
10233 * @return The release time to unbind GbaService by millisecond.
10234 */
10235 @Override
10236 public int getGbaReleaseTime(int subId) {
10237 enforceReadPrivilegedPermission("getGbaReleaseTime");
10238
10239 final long identity = Binder.clearCallingIdentity();
10240 try {
10241 return getGbaManager(subId).getReleaseTime();
10242 } finally {
10243 Binder.restoreCallingIdentity(identity);
10244 }
10245 }
10246
10247 private GbaManager getGbaManager(int subId) {
10248 GbaManager instance = GbaManager.getInstance(subId);
10249 if (instance == null) {
10250 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10251 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10252 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10253 }
10254 return instance;
10255 }
Hui Wang761a6682020-10-31 05:12:53 +000010256
10257 /**
10258 * indicate whether the device and the carrier can support
10259 * RCS VoLTE single registration.
10260 */
10261 @Override
10262 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010263 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10264 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10265 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10266 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010267
10268 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10269 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10270 }
10271
10272 final long identity = Binder.clearCallingIdentity();
10273 try {
10274 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10275 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010276 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10277 if (isCapable != null) {
10278 return isCapable;
10279 }
Hui Wang761a6682020-10-31 05:12:53 +000010280 }
Hui Wang67af90e2021-06-04 16:57:15 -070010281 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10282 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010283 } finally {
10284 Binder.restoreCallingIdentity(identity);
10285 }
10286 }
10287
10288 /**
10289 * Register RCS provisioning callback.
10290 */
10291 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010292 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010293 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010294 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010295 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010296 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10297 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010298
10299 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10300 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10301 }
10302 if (!isImsAvailableOnDevice()) {
10303 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10304 "IMS not available on device.");
10305 }
10306
10307 final long identity = Binder.clearCallingIdentity();
10308 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010309 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010310 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010311 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10312 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010313 }
Hui Wang761a6682020-10-31 05:12:53 +000010314 } finally {
10315 Binder.restoreCallingIdentity(identity);
10316 }
10317 }
10318
10319 /**
10320 * Unregister RCS provisioning callback.
10321 */
10322 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010323 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010324 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010325 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010326 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010327 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10328 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010329
10330 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10331 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10332 }
10333 if (!isImsAvailableOnDevice()) {
10334 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10335 "IMS not available on device.");
10336 }
10337
10338 final long identity = Binder.clearCallingIdentity();
10339 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010340 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010341 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010342 } finally {
10343 Binder.restoreCallingIdentity(identity);
10344 }
10345 }
10346
10347 /**
10348 * trigger RCS reconfiguration.
10349 */
10350 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010351 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10352 "triggerRcsReconfiguration",
10353 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010354
10355 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10356 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10357 }
10358 if (!isImsAvailableOnDevice()) {
10359 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10360 "IMS not available on device.");
10361 }
10362
10363 final long identity = Binder.clearCallingIdentity();
10364 try {
10365 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10366 } finally {
10367 Binder.restoreCallingIdentity(identity);
10368 }
10369 }
10370
10371 /**
10372 * Provide the client configuration parameters of the RCS application.
10373 */
10374 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010375 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10376 "setRcsClientConfiguration",
10377 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010378
10379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10380 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10381 }
10382 if (!isImsAvailableOnDevice()) {
10383 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10384 "IMS not available on device.");
10385 }
10386
10387 final long identity = Binder.clearCallingIdentity();
10388
10389 try {
10390 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10391 if (configBinder == null) {
10392 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010393 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10394 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010395 } else {
10396 configBinder.setRcsClientConfiguration(rcc);
10397 }
10398 } catch (RemoteException e) {
10399 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010400 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10401 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010402 } finally {
10403 Binder.restoreCallingIdentity(identity);
10404 }
10405 }
10406
10407 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010408 * Enables or disables the test mode for RCS VoLTE single registration.
10409 */
10410 @Override
10411 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10412 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10413 "setRcsSingleRegistrationTestModeEnabled");
10414
10415 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10416 }
10417
10418 /**
10419 * Gets the test mode for RCS VoLTE single registration.
10420 */
10421 @Override
10422 public boolean getRcsSingleRegistrationTestModeEnabled() {
10423 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10424 "getRcsSingleRegistrationTestModeEnabled");
10425
10426 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10427 }
10428
10429 /**
Hui Wang761a6682020-10-31 05:12:53 +000010430 * Overrides the config of RCS VoLTE single registration enabled for the device.
10431 */
10432 @Override
10433 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10435 "setDeviceSingleRegistrationEnabledOverride");
10436 enforceModifyPermission();
10437
10438 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10439 : Boolean.parseBoolean(enabledStr);
10440 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010441 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010442 }
10443
10444 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010445 * Sends a device to device communication message. Only usable via shell.
10446 * @param message message to send.
10447 * @param value message value.
10448 */
10449 @Override
10450 public void sendDeviceToDeviceMessage(int message, int value) {
10451 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010452 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010453 enforceModifyPermission();
10454
10455 final long identity = Binder.clearCallingIdentity();
10456 try {
10457 TelephonyConnectionService service =
10458 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10459 if (service == null) {
10460 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10461 return;
10462 }
10463 service.sendTestDeviceToDeviceMessage(message, value);
10464 } finally {
10465 Binder.restoreCallingIdentity(identity);
10466 }
10467 }
10468
Tyler Gunnbabbda02021-02-10 11:05:02 -080010469 /**
10470 * Sets the specified device to device transport active.
10471 * @param transport The transport to set active.
10472 */
10473 @Override
10474 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10475 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10476 "setActiveDeviceToDeviceTransport");
10477 enforceModifyPermission();
10478
10479 final long identity = Binder.clearCallingIdentity();
10480 try {
10481 TelephonyConnectionService service =
10482 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10483 if (service == null) {
10484 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10485 return;
10486 }
10487 service.setActiveDeviceToDeviceTransport(transport);
10488 } finally {
10489 Binder.restoreCallingIdentity(identity);
10490 }
10491 }
Tyler Gunn92479152021-01-20 16:30:10 -080010492
Tyler Gunnd4339262021-05-03 14:46:49 -070010493 @Override
10494 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10495 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10496 "setDeviceToDeviceForceEnabled");
10497
10498 final long identity = Binder.clearCallingIdentity();
10499 try {
10500 Arrays.stream(PhoneFactory.getPhones()).forEach(
10501 p -> {
10502 Phone thePhone = p.getImsPhone();
10503 if (thePhone != null && thePhone instanceof ImsPhone) {
10504 ImsPhone imsPhone = (ImsPhone) thePhone;
10505 CallTracker tracker = imsPhone.getCallTracker();
10506 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10507 ImsPhoneCallTracker imsPhoneCallTracker =
10508 (ImsPhoneCallTracker) tracker;
10509 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10510 }
10511 }
10512 }
10513 );
10514 } finally {
10515 Binder.restoreCallingIdentity(identity);
10516 }
10517 }
10518
Tyler Gunn92479152021-01-20 16:30:10 -080010519 /**
Hui Wang761a6682020-10-31 05:12:53 +000010520 * Gets the config of RCS VoLTE single registration enabled for the device.
10521 */
10522 @Override
10523 public boolean getDeviceSingleRegistrationEnabled() {
10524 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10525 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10526 }
10527
10528 /**
10529 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10530 */
10531 @Override
10532 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10533 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10534 "setCarrierSingleRegistrationEnabledOverride");
10535 enforceModifyPermission();
10536
10537 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10538 : Boolean.parseBoolean(enabledStr);
10539 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10540 subId, enabled);
10541 }
10542
10543 /**
10544 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10545 */
10546 @Override
10547 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10548 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10549 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10550 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010551
10552 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010553 * Overrides the ims feature validation result
10554 */
10555 @Override
10556 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10557 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10558 "setImsFeatureValidationOverride");
10559
10560 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10561 : Boolean.parseBoolean(enabledStr);
10562 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10563 subId, enabled);
10564 }
10565
10566 /**
10567 * Gets the ims feature validation override value
10568 */
10569 @Override
10570 public boolean getImsFeatureValidationOverride(int subId) {
10571 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10572 "getImsFeatureValidationOverride");
10573 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10574 }
10575
10576 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010577 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10578 * their mobile plan.
10579 */
10580 @Override
10581 public String getMobileProvisioningUrl() {
10582 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10583 final long identity = Binder.clearCallingIdentity();
10584 try {
10585 return getDefaultPhone().getMobileProvisioningUrl();
10586 } finally {
10587 Binder.restoreCallingIdentity(identity);
10588 }
10589 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010590
James.cf Linbcdf8b32021-01-14 16:44:13 +080010591 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010592 * Get the EAB contact from the EAB database.
10593 */
10594 @Override
10595 public String getContactFromEab(String contact) {
10596 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10597 enforceModifyPermission();
10598 final long identity = Binder.clearCallingIdentity();
10599 try {
10600 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10601 } finally {
10602 Binder.restoreCallingIdentity(identity);
10603 }
10604 }
10605
10606 /**
Calvin Pana1434322021-07-01 19:27:01 +080010607 * Get the EAB capability from the EAB database.
10608 */
10609 @Override
10610 public String getCapabilityFromEab(String contact) {
10611 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10612 enforceModifyPermission();
10613 final long identity = Binder.clearCallingIdentity();
10614 try {
10615 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10616 } finally {
10617 Binder.restoreCallingIdentity(identity);
10618 }
10619 }
10620
10621 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010622 * Remove the EAB contacts from the EAB database.
10623 */
10624 @Override
10625 public int removeContactFromEab(int subId, String contacts) {
10626 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10627 enforceModifyPermission();
10628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10631 } finally {
10632 Binder.restoreCallingIdentity(identity);
10633 }
10634 }
10635
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010636 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010637 public boolean getDeviceUceEnabled() {
10638 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10639 final long identity = Binder.clearCallingIdentity();
10640 try {
10641 return mApp.getDeviceUceEnabled();
10642 } finally {
10643 Binder.restoreCallingIdentity(identity);
10644 }
10645 }
10646
10647 @Override
10648 public void setDeviceUceEnabled(boolean isEnabled) {
10649 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10650 final long identity = Binder.clearCallingIdentity();
10651 try {
10652 mApp.setDeviceUceEnabled(isEnabled);
10653 } finally {
10654 Binder.restoreCallingIdentity(identity);
10655 }
10656 }
10657
Brad Ebinger14d467f2021-02-12 06:18:28 +000010658 /**
10659 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10660 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10661 */
10662 // Used for SHELL command only right now.
10663 @Override
10664 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10665 List<String> featureTags) {
10666 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10667 "addUceRegistrationOverrideShell");
10668 final long identity = Binder.clearCallingIdentity();
10669 try {
10670 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10671 new ArraySet<>(featureTags));
10672 } catch (ImsException e) {
10673 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10674 } finally {
10675 Binder.restoreCallingIdentity(identity);
10676 }
10677 }
10678
10679 /**
10680 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10681 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10682 */
10683 // Used for SHELL command only right now.
10684 @Override
10685 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10686 List<String> featureTags) {
10687 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10688 "removeUceRegistrationOverrideShell");
10689 final long identity = Binder.clearCallingIdentity();
10690 try {
10691 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10692 new ArraySet<>(featureTags));
10693 } catch (ImsException e) {
10694 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10695 } finally {
10696 Binder.restoreCallingIdentity(identity);
10697 }
10698 }
10699
10700 /**
10701 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10702 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10703 */
10704 // Used for SHELL command only right now.
10705 @Override
10706 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10708 "clearUceRegistrationOverrideShell");
10709 final long identity = Binder.clearCallingIdentity();
10710 try {
10711 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10712 } catch (ImsException e) {
10713 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10714 } finally {
10715 Binder.restoreCallingIdentity(identity);
10716 }
10717 }
10718
10719 /**
10720 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10721 */
10722 // Used for SHELL command only right now.
10723 @Override
10724 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10725 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10726 "getLatestRcsContactUceCapabilityShell");
10727 final long identity = Binder.clearCallingIdentity();
10728 try {
10729 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10730 } catch (ImsException e) {
10731 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10732 } finally {
10733 Binder.restoreCallingIdentity(identity);
10734 }
10735 }
10736
10737 /**
10738 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10739 * device does not have an active PUBLISH.
10740 */
10741 // Used for SHELL command only right now.
10742 @Override
10743 public String getLastUcePidfXmlShell(int subId) {
10744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10745 final long identity = Binder.clearCallingIdentity();
10746 try {
10747 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10748 } catch (ImsException e) {
10749 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10750 } finally {
10751 Binder.restoreCallingIdentity(identity);
10752 }
10753 }
10754
James.cf Line8713a42021-04-29 16:04:26 +080010755 /**
10756 * Remove UCE requests cannot be sent to the network status.
10757 */
10758 // Used for SHELL command only right now.
10759 @Override
10760 public boolean removeUceRequestDisallowedStatus(int subId) {
10761 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10762 final long identity = Binder.clearCallingIdentity();
10763 try {
10764 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10765 } catch (ImsException e) {
10766 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10767 } finally {
10768 Binder.restoreCallingIdentity(identity);
10769 }
10770 }
10771
James.cf Lin18bb9002021-05-25 01:37:38 +080010772 /**
10773 * Remove UCE requests cannot be sent to the network status.
10774 */
10775 // Used for SHELL command only.
10776 @Override
10777 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10779 final long identity = Binder.clearCallingIdentity();
10780 try {
10781 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10782 } catch (ImsException e) {
10783 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10784 } finally {
10785 Binder.restoreCallingIdentity(identity);
10786 }
10787 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010788
James.cf Lin4b784aa2021-01-31 03:25:15 +080010789 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010790 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10791 String callingPackage) {
10792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10793 mApp, subId, "setSignalStrengthUpdateRequest");
10794
10795 final int callingUid = Binder.getCallingUid();
10796 // Verify that tha callingPackage belongs to the calling UID
10797 mApp.getSystemService(AppOpsManager.class)
10798 .checkPackage(callingUid, callingPackage);
10799
10800 validateSignalStrengthUpdateRequest(request, callingUid);
10801
10802 final long identity = Binder.clearCallingIdentity();
10803 try {
10804 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10805 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10806
10807 if (result instanceof IllegalStateException) {
10808 throw (IllegalStateException) result;
10809 }
10810 } finally {
10811 Binder.restoreCallingIdentity(identity);
10812 }
10813 }
10814
10815 @Override
10816 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10817 String callingPackage) {
10818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10819 mApp, subId, "clearSignalStrengthUpdateRequest");
10820
10821 final int callingUid = Binder.getCallingUid();
10822 // Verify that tha callingPackage belongs to the calling UID
10823 mApp.getSystemService(AppOpsManager.class)
10824 .checkPackage(callingUid, callingPackage);
10825
10826 final long identity = Binder.clearCallingIdentity();
10827 try {
10828 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10829 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10830
10831 if (result instanceof IllegalStateException) {
10832 throw (IllegalStateException) result;
10833 }
10834 } finally {
10835 Binder.restoreCallingIdentity(identity);
10836 }
10837 }
10838
10839 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10840 int callingUid) {
10841 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10842 // phone/system process do not have further restriction on request
10843 return;
10844 }
10845
10846 // Applications has restrictions on how to use the request:
10847 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10848 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10849 // This is not system caller which has been checked above
10850 throw new IllegalArgumentException(
10851 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10852 }
10853
10854 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10855 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10856 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10857 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10858 || info.isEnabled()) {
10859 throw new IllegalArgumentException(
10860 "Only system can set hide fields in SignalThresholdInfo");
10861 }
10862
10863 // Thresholds length for each RAN need in range. This has been validated in
10864 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10865 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10866 final int[] thresholds = info.getThresholds();
10867 Objects.requireNonNull(thresholds);
10868 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10869 || thresholds.length
10870 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10871 throw new IllegalArgumentException(
10872 "thresholds length is out of range: " + thresholds.length);
10873 }
10874 }
10875 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010876
10877 /**
10878 * Gets the current phone capability.
10879 *
10880 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10881 * @return the PhoneCapability which describes the data connection capability of modem.
10882 * It's used to evaluate possible phone config change, for example from single
10883 * SIM device to multi-SIM device.
10884 */
10885 @Override
10886 public PhoneCapability getPhoneCapability() {
10887 enforceReadPrivilegedPermission("getPhoneCapability");
10888 final long identity = Binder.clearCallingIdentity();
10889 try {
10890 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10891 } finally {
10892 Binder.restoreCallingIdentity(identity);
10893 }
10894 }
Michele Berionne5e411512020-11-13 02:36:59 +000010895
10896 /**
10897 * Prepare TelephonyManager for an unattended reboot. The reboot is
10898 * required to be done shortly after the API is invoked.
10899 */
10900 @Override
10901 @TelephonyManager.PrepareUnattendedRebootResult
10902 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010903 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010904 enforceRebootPermission();
10905
10906 final long identity = Binder.clearCallingIdentity();
10907 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010908 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010909 } finally {
10910 Binder.restoreCallingIdentity(identity);
10911 }
10912 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010913
10914 /**
10915 * Request to get the current slicing configuration including URSP rules and
10916 * NSSAIs (configured, allowed and rejected).
10917 *
10918 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10919 */
10920 @Override
10921 public void getSlicingConfig(ResultReceiver callback) {
10922 enforceReadPrivilegedPermission("getSlicingConfig");
10923
10924 final long identity = Binder.clearCallingIdentity();
10925 try {
10926 Phone phone = getDefaultPhone();
10927 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10928 } finally {
10929 Binder.restoreCallingIdentity(identity);
10930 }
10931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010932}