blob: b3916c1f41918b7a621933ee5337e4f33a74adef [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();
3229 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3230 }
3231 return tac;
3232 }
3233
3234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003235 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003236 try {
3237 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3238 } catch (SecurityException se) {
3239 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3240 throw new SecurityException("Package " + callingPackage + " does not belong to "
3241 + Binder.getCallingUid());
3242 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003243 Phone phone = PhoneFactory.getPhone(slotIndex);
3244 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003245 return null;
3246 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003247
Jeff Davidson913390f2018-02-23 17:11:49 -08003248 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003249 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003250 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003251 return null;
3252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003253
3254 final long identity = Binder.clearCallingIdentity();
3255 try {
3256 return phone.getMeid();
3257 } finally {
3258 Binder.restoreCallingIdentity(identity);
3259 }
Jack Yu2af8d712017-03-15 17:14:14 -07003260 }
3261
3262 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003263 public String getManufacturerCodeForSlot(int slotIndex) {
3264 Phone phone = PhoneFactory.getPhone(slotIndex);
3265 String manufacturerCode = null;
3266 if (phone != null) {
3267 String meid = phone.getMeid();
3268 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3269 }
3270 return manufacturerCode;
3271 }
3272
3273 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003274 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3275 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003276 Phone phone = PhoneFactory.getPhone(slotIndex);
3277 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003278 return null;
3279 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003280 int subId = phone.getSubId();
3281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003282 mApp, subId, callingPackage, callingFeatureId,
3283 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003284 return null;
3285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286
3287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 return phone.getDeviceSvn();
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003293 }
3294
fionaxu43304da2017-11-27 22:51:16 -08003295 @Override
3296 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 final Phone phone = getPhone(subId);
3300 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
fionaxu43304da2017-11-27 22:51:16 -08003304 }
3305
3306 @Override
3307 public String getSubscriptionCarrierName(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 ? null : phone.getCarrierName();
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
3314 }
fionaxu43304da2017-11-27 22:51:16 -08003315 }
3316
calvinpanffe225e2018-11-01 19:43:06 +08003317 @Override
chen xu0026ca62019-03-06 15:28:50 -08003318 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 final Phone phone = getPhone(subId);
3322 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003323 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003324 } finally {
3325 Binder.restoreCallingIdentity(identity);
3326 }
3327 }
3328
3329 @Override
chen xu0026ca62019-03-06 15:28:50 -08003330 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003334 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
chen xu651eec72018-11-11 19:03:44 -08003340 @Override
chen xu864e11c2018-12-06 22:10:03 -08003341 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3342 if (!isSubscriptionMccMnc) {
3343 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3344 }
chen xu651eec72018-11-11 19:03:44 -08003345 final Phone phone = PhoneFactory.getPhone(slotIndex);
3346 if (phone == null) {
3347 return TelephonyManager.UNKNOWN_CARRIER_ID;
3348 }
3349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
3355 }
3356
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003357 //
3358 // Internal helper methods.
3359 //
3360
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003361 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003362 * Make sure the caller is the calling package itself
3363 *
3364 * @throws SecurityException if the caller is not the calling package
3365 */
3366 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3367 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003368 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3369 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003370 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003371 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003372 } catch (PackageManager.NameNotFoundException e) {
3373 // packageUid is -1
3374 }
3375 if (packageUid != callingUid) {
3376 throw new SecurityException(message + ": Package " + callingPackage
3377 + " does not belong to " + callingUid);
3378 }
3379 }
3380
3381 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003382 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3383 *
3384 * @throws SecurityException if the caller does not have the required permission
3385 */
3386 private void enforceModifyPermission() {
3387 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3388 }
3389
Shuo Qiancd19c462020-01-16 20:51:11 -08003390 /**
3391 * Make sure the caller is system.
3392 *
3393 * @throws SecurityException if the caller is not system.
3394 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003395 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003396 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3397 throw new SecurityException("Caller must be system");
3398 }
3399 }
3400
Shuo Qian3b6ee772019-11-13 17:43:31 -08003401 private void enforceActiveEmergencySessionPermission() {
3402 mApp.enforceCallingOrSelfPermission(
3403 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3404 }
3405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003406 /**
3407 * Make sure the caller has the CALL_PHONE permission.
3408 *
3409 * @throws SecurityException if the caller does not have the required permission
3410 */
3411 private void enforceCallPermission() {
3412 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3413 }
3414
paulhu5a773602019-08-23 19:17:33 +08003415 private void enforceSettingsPermission() {
3416 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003417 }
3418
Michele Berionne5e411512020-11-13 02:36:59 +00003419 private void enforceRebootPermission() {
3420 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3421 }
3422
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003423 private String createTelUrl(String number) {
3424 if (TextUtils.isEmpty(number)) {
3425 return null;
3426 }
3427
Jake Hambye994d462014-02-03 13:10:13 -08003428 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003429 }
3430
Ihab Awadf9e92732013-12-05 18:02:52 -08003431 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003432 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3433 }
3434
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003435 private static void logv(String msg) {
3436 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3437 }
3438
Ihab Awadf9e92732013-12-05 18:02:52 -08003439 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003440 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3441 }
3442
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003443 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003444 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003445 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003446 }
3447
Sanket Padawe356d7632015-06-22 14:03:32 -07003448 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003449 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003450 final long identity = Binder.clearCallingIdentity();
3451 try {
3452 final Phone phone = PhoneFactory.getPhone(slotIndex);
3453 if (phone == null) {
3454 return PhoneConstants.PHONE_TYPE_NONE;
3455 } else {
3456 return phone.getPhoneType();
3457 }
3458 } finally {
3459 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 }
3462
3463 /**
3464 * Returns the CDMA ERI icon index to display
3465 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003466 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003467 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3468 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3469 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003470 }
3471
Sanket Padawe356d7632015-06-22 14:03:32 -07003472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003473 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3474 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003476 mApp, subId, callingPackage, callingFeatureId,
3477 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003478 return -1;
3479 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 final Phone phone = getPhone(subId);
3484 if (phone != null) {
3485 return phone.getCdmaEriIconIndex();
3486 } else {
3487 return -1;
3488 }
3489 } finally {
3490 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003491 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003492 }
3493
3494 /**
3495 * Returns the CDMA ERI icon mode,
3496 * 0 - ON
3497 * 1 - FLASHING
3498 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003499 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003500 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3501 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3502 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003503 }
3504
Sanket Padawe356d7632015-06-22 14:03:32 -07003505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003506 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3507 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003509 mApp, subId, callingPackage, callingFeatureId,
3510 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003511 return -1;
3512 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003513
3514 final long identity = Binder.clearCallingIdentity();
3515 try {
3516 final Phone phone = getPhone(subId);
3517 if (phone != null) {
3518 return phone.getCdmaEriIconMode();
3519 } else {
3520 return -1;
3521 }
3522 } finally {
3523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003525 }
3526
3527 /**
3528 * Returns the CDMA ERI text,
3529 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003530 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003531 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3532 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3533 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003534 }
3535
Sanket Padawe356d7632015-06-22 14:03:32 -07003536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003537 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3538 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003540 mApp, subId, callingPackage, callingFeatureId,
3541 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003542 return null;
3543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003544
3545 final long identity = Binder.clearCallingIdentity();
3546 try {
3547 final Phone phone = getPhone(subId);
3548 if (phone != null) {
3549 return phone.getCdmaEriText();
3550 } else {
3551 return null;
3552 }
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003556 }
3557
3558 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003559 * Returns the CDMA MDN.
3560 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003561 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003562 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3564 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565
3566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003569 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003570 return phone.getLine1Number();
3571 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003572 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 return null;
3574 }
3575 } finally {
3576 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003577 }
3578 }
3579
3580 /**
3581 * Returns the CDMA MIN.
3582 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003584 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3586 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587
3588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 final Phone phone = getPhone(subId);
3591 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3592 return phone.getCdmaMin();
3593 } else {
3594 return null;
3595 }
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003598 }
3599 }
3600
Hall Liud892bec2018-11-30 14:51:45 -08003601 @Override
3602 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3603 INumberVerificationCallback callback, String callingPackage) {
3604 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3605 != PERMISSION_GRANTED) {
3606 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3607 }
3608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3609
3610 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3611 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003612 throw new SecurityException("Calling package must be configured in the device config: "
3613 + "calling package: " + callingPackage
3614 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003615 }
3616
3617 if (range == null) {
3618 throw new NullPointerException("Range must be non-null");
3619 }
3620
3621 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003622 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003623
3624 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3625 }
3626
Junda Liuca05d5d2014-08-14 22:36:34 -07003627 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003628 * Returns true if CDMA provisioning needs to run.
3629 */
3630 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631 final long identity = Binder.clearCallingIdentity();
3632 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003633 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003637 }
3638
3639 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003640 * Sets the voice mail number of a given subId.
3641 */
3642 @Override
3643 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003644 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3645 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646
3647 final long identity = Binder.clearCallingIdentity();
3648 try {
3649 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3650 new Pair<String, String>(alphaTag, number), new Integer(subId));
3651 return success;
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
3654 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003655 }
3656
Ta-wei Yen87c49842016-05-13 21:19:52 -07003657 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003658 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003660 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3661 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003662 if (!TextUtils.equals(callingPackage, systemDialer)) {
3663 throw new SecurityException("caller must be system dialer");
3664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3669 if (phoneAccountHandle == null) {
3670 return null;
3671 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003672 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003673 } finally {
3674 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003675 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003676 }
3677
3678 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003679 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3680 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003683 mApp, subId, callingPackage, callingFeatureId,
3684 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003685 return null;
3686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003688 final long identity = Binder.clearCallingIdentity();
3689 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003690 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003694 }
3695
3696 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003697 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3698 VisualVoicemailSmsFilterSettings settings) {
3699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003700
3701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003704 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003705 } finally {
3706 Binder.restoreCallingIdentity(identity);
3707 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003708 }
3709
3710 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003711 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003713
3714 final long identity = Binder.clearCallingIdentity();
3715 try {
3716 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003721 }
3722
3723 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003724 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3725 String callingPackage, int subId) {
3726 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003727
3728 final long identity = Binder.clearCallingIdentity();
3729 try {
3730 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003731 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003735 }
3736
3737 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003738 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003739 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003740
3741 final long identity = Binder.clearCallingIdentity();
3742 try {
3743 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003744 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745 } finally {
3746 Binder.restoreCallingIdentity(identity);
3747 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003748 }
3749
3750 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003751 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3752 String callingAttributionTag, int subId, String number, int port, String text,
3753 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003755 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003756 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003757 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003758 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3759 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003760 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003761
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003762 /**
fionaxu0152e512016-11-14 13:36:14 -08003763 * Sets the voice activation state of a given subId.
3764 */
3765 @Override
3766 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3768 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769
3770 final long identity = Binder.clearCallingIdentity();
3771 try {
3772 final Phone phone = getPhone(subId);
3773 if (phone != null) {
3774 phone.setVoiceActivationState(activationState);
3775 } else {
3776 loge("setVoiceActivationState fails with invalid subId: " + subId);
3777 }
3778 } finally {
3779 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003780 }
3781 }
3782
3783 /**
3784 * Sets the data activation state of a given subId.
3785 */
3786 @Override
3787 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3789 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003790
3791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 final Phone phone = getPhone(subId);
3794 if (phone != null) {
3795 phone.setDataActivationState(activationState);
3796 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003797 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003798 }
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003801 }
3802 }
3803
3804 /**
3805 * Returns the voice activation state of a given subId.
3806 */
3807 @Override
3808 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003809 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810
fionaxu0152e512016-11-14 13:36:14 -08003811 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003812 final long identity = Binder.clearCallingIdentity();
3813 try {
3814 if (phone != null) {
3815 return phone.getVoiceActivationState();
3816 } else {
3817 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3818 }
3819 } finally {
3820 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003821 }
3822 }
3823
3824 /**
3825 * Returns the data activation state of a given subId.
3826 */
3827 @Override
3828 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003830
fionaxu0152e512016-11-14 13:36:14 -08003831 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832 final long identity = Binder.clearCallingIdentity();
3833 try {
3834 if (phone != null) {
3835 return phone.getDataActivationState();
3836 } else {
3837 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3838 }
3839 } finally {
3840 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003841 }
3842 }
3843
3844 /**
Wink Saville36469e72014-06-11 15:17:00 -07003845 * Returns the unread count of voicemails for a subId
3846 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003848 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3849 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003851 mApp, subId, callingPackage, callingFeatureId,
3852 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003853 return 0;
3854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003855 final long identity = Binder.clearCallingIdentity();
3856 try {
3857 final Phone phone = getPhone(subId);
3858 if (phone != null) {
3859 return phone.getVoiceMessageCount();
3860 } else {
3861 return 0;
3862 }
3863 } finally {
3864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003866 }
3867
3868 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003869 * returns true, if the device is in a state where both voice and data
3870 * are supported simultaneously. This can change based on location or network condition.
3871 */
3872 @Override
3873 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003874 final long identity = Binder.clearCallingIdentity();
3875 try {
3876 final Phone phone = getPhone(subId);
3877 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
3880 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003881 }
3882
3883 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003884 * Send the dialer code if called from the current default dialer or the caller has
3885 * carrier privilege.
3886 * @param inputCode The dialer code to send
3887 */
3888 @Override
3889 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003890 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003891 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003892 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3893 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003894 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003895 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003896 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003897 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898
3899 final long identity = Binder.clearCallingIdentity();
3900 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003901 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902 } finally {
3903 Binder.restoreCallingIdentity(identity);
3904 }
fionaxu235cc5e2017-03-06 22:25:57 -08003905 }
3906
Pengquan Menga1bb6272018-09-06 09:59:22 -07003907 @Override
3908 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003909 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003910 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003911 mApp, subId, "getNetworkSelectionMode");
3912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 if (!isActiveSubscription(subId)) {
3915 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3916 }
3917 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003920 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003921 }
3922
Brad Ebinger35c841c2018-10-01 10:40:55 -07003923 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003924 public boolean isInEmergencySmsMode() {
3925 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3926 final long identity = Binder.clearCallingIdentity();
3927 try {
3928 for (Phone phone : PhoneFactory.getPhones()) {
3929 if (phone.isInEmergencySmsMode()) {
3930 return true;
3931 }
3932 }
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
3935 }
3936 return false;
3937 }
3938
shilu366312e2019-12-17 09:28:10 -08003939 /**
3940 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3941 * @param subId The subscription to use to check the configuration.
3942 * @param c The callback that will be used to send the result.
3943 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003944 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003945 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3946 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003947 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003948 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003949
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003950 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3951 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3952 "IMS not available on device.");
3953 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 final long token = Binder.clearCallingIdentity();
3955 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003956 int slotId = getSlotIndexOrException(subId);
3957 verifyImsMmTelConfiguredOrThrow(slotId);
3958 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003959 } catch (ImsException e) {
3960 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 } finally {
3962 Binder.restoreCallingIdentity(token);
3963 }
3964 }
3965
shilu366312e2019-12-17 09:28:10 -08003966 /**
3967 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3968 * @param subId The subscription to use to check the configuration.
3969 * @param c The callback that will be used to send the result.
3970 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003972 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003973 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003974 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003975 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3976 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3977 }
Meng Wangafbc5852019-09-19 17:37:13 -07003978 final long token = Binder.clearCallingIdentity();
3979 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003980 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3981 .removeRegistrationCallbackForSubscription(c, subId);
3982 } catch (ImsException e) {
3983 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3984 + "is inactive, ignoring unregister.");
3985 // If the subscription is no longer active, just return, since the callback
3986 // will already have been removed internally.
3987 } finally {
3988 Binder.restoreCallingIdentity(token);
3989 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 }
3991
Brad Ebingera34a6c22019-10-22 17:36:18 -07003992 /**
3993 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3994 */
3995 @Override
3996 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3997 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3998 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3999 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4000 "IMS not available on device.");
4001 }
4002 final long token = Binder.clearCallingIdentity();
4003 try {
4004 Phone phone = getPhone(subId);
4005 if (phone == null) {
4006 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4007 + subId + "'");
4008 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4009 }
4010 phone.getImsRegistrationState(regState -> {
4011 try {
4012 consumer.accept((regState == null)
4013 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4014 } catch (RemoteException e) {
4015 // Ignore if the remote process is no longer available to call back.
4016 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4017 }
4018 });
4019 } finally {
4020 Binder.restoreCallingIdentity(token);
4021 }
4022 }
4023
4024 /**
4025 * Get the transport type for the IMS service registration state.
4026 */
4027 @Override
4028 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004029 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004030 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004031 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4033 "IMS not available on device.");
4034 }
4035 final long token = Binder.clearCallingIdentity();
4036 try {
4037 Phone phone = getPhone(subId);
4038 if (phone == null) {
4039 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4040 + subId + "'");
4041 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4042 }
4043 phone.getImsRegistrationTech(regTech -> {
4044 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4045 int regTechConverted = (regTech == null)
4046 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4047 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4048 regTechConverted);
4049 try {
4050 consumer.accept(regTechConverted);
4051 } catch (RemoteException e) {
4052 // Ignore if the remote process is no longer available to call back.
4053 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4054 }
4055 });
4056 } finally {
4057 Binder.restoreCallingIdentity(token);
4058 }
4059 }
4060
shilu366312e2019-12-17 09:28:10 -08004061 /**
4062 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4063 * @param subId The subscription to use to check the configuration.
4064 * @param c The callback that will be used to send the result.
4065 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004067 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4068 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004069 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004070 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004071 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4072 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4073 "IMS not available on device.");
4074 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 final long token = Binder.clearCallingIdentity();
4076 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004077 int slotId = getSlotIndexOrException(subId);
4078 verifyImsMmTelConfiguredOrThrow(slotId);
4079 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004080 } catch (ImsException e) {
4081 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 } finally {
4083 Binder.restoreCallingIdentity(token);
4084 }
4085 }
4086
shilu366312e2019-12-17 09:28:10 -08004087 /**
4088 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4089 * @param subId The subscription to use to check the configuration.
4090 * @param c The callback that will be used to send the result.
4091 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004092 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004093 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004094 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004095 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004096 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4097 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4098 }
Meng Wangafbc5852019-09-19 17:37:13 -07004099
4100 final long token = Binder.clearCallingIdentity();
4101 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004102 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004103 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004104 } catch (ImsException e) {
4105 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4106 + "is inactive, ignoring unregister.");
4107 // If the subscription is no longer active, just return, since the callback
4108 // will already have been removed internally.
4109 } finally {
4110 Binder.restoreCallingIdentity(token);
4111 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 }
4113
4114 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004115 public boolean isCapable(int subId, int capability, int regTech) {
4116 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 final long token = Binder.clearCallingIdentity();
4118 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004119 int slotId = getSlotIndexOrException(subId);
4120 verifyImsMmTelConfiguredOrThrow(slotId);
4121 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004122 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4124 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004125 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004126 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4127 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004128 } finally {
4129 Binder.restoreCallingIdentity(token);
4130 }
4131 }
4132
4133 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004134 public boolean isAvailable(int subId, int capability, int regTech) {
4135 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 final long token = Binder.clearCallingIdentity();
4137 try {
4138 Phone phone = getPhone(subId);
4139 if (phone == null) return false;
4140 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004141 } catch (com.android.ims.ImsException e) {
4142 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4143 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 } finally {
4145 Binder.restoreCallingIdentity(token);
4146 }
4147 }
4148
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004149 /**
4150 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4151 * subscription.
4152 * @param subId The subscription to use to check the configuration.
4153 * @param callback The callback that will be used to send the result.
4154 * @param capability The MmTelFeature capability that will be used to send the result.
4155 * @param transportType The transport type of the MmTelFeature capability.
4156 */
4157 @Override
4158 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4159 int transportType) {
4160 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4161 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4162 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4163 "IMS not available on device.");
4164 }
4165 final long token = Binder.clearCallingIdentity();
4166 try {
4167 int slotId = getSlotIndex(subId);
4168 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4169 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4170 + subId + "'");
4171 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4172 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004173 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004174 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4175 transportType, aBoolean -> {
4176 try {
4177 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4178 } catch (RemoteException e) {
4179 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4180 + "running. Ignore");
4181 }
4182 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004183 } catch (ImsException e) {
4184 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004185 } finally {
4186 Binder.restoreCallingIdentity(token);
4187 }
4188 }
4189
shilu366312e2019-12-17 09:28:10 -08004190 /**
4191 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4192 * @param subId The subscription to use to check the configuration.
4193 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 @Override
4195 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004196 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004197 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004198
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 final long token = Binder.clearCallingIdentity();
4200 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004201 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004202 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004203 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004204 } catch (ImsException e) {
4205 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 } finally {
4207 Binder.restoreCallingIdentity(token);
4208 }
4209 }
4210
4211 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004212 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004214 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 final long identity = Binder.clearCallingIdentity();
4216 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004217 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004218 // This setting doesn't require an active ImsService connection, so do not verify. The
4219 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004220 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004221 } catch (ImsException e) {
4222 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
4226 }
4227
shilu366312e2019-12-17 09:28:10 -08004228 /**
4229 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4230 * @param subId The subscription to use to check the configuration.
4231 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004233 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004234 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004235 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 final long identity = Binder.clearCallingIdentity();
4237 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004238 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004239 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004240 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004241 } catch (ImsException e) {
4242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 } finally {
4244 Binder.restoreCallingIdentity(identity);
4245 }
4246 }
4247
4248 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004249 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004251 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 final long identity = Binder.clearCallingIdentity();
4253 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004254 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004255 // This setting doesn't require an active ImsService connection, so do not verify. The
4256 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004257 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004258 } catch (ImsException e) {
4259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
4263 }
4264
shilu366312e2019-12-17 09:28:10 -08004265 /**
4266 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4267 * @param subId The subscription to use to check the configuration.
4268 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 @Override
4270 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004271 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004272 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004275 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004276 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004277 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004278 } catch (ImsException e) {
4279 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 } finally {
4281 Binder.restoreCallingIdentity(identity);
4282 }
4283 }
4284
4285 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004286 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004288 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 final long identity = Binder.clearCallingIdentity();
4290 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004291 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004292 // This setting doesn't require an active ImsService connection, so do not verify. The
4293 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004294 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004295 } catch (ImsException e) {
4296 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
4300 }
4301
shilu366312e2019-12-17 09:28:10 -08004302 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004303 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4304 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4305 * @param subId The subscription to use to check the configuration.
4306 */
4307 @Override
4308 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004309 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004310 mApp, subId, "isCrossSimCallingEnabledByUser");
4311 final long identity = Binder.clearCallingIdentity();
4312 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004313 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004314 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004315 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004316 } catch (ImsException e) {
4317 throw new ServiceSpecificException(e.getCode());
4318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
4321 }
4322
4323 /**
4324 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4325 * Requires MODIFY_PHONE_STATE permission.
4326 * @param subId The subscription to use to check the configuration.
4327 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4328 * false otherwise
4329 */
4330 @Override
4331 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4333 "setCrossSimCallingEnabled");
4334 final long identity = Binder.clearCallingIdentity();
4335 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004336 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004337 // This setting doesn't require an active ImsService connection, so do not verify. The
4338 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004339 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004340 } catch (ImsException e) {
4341 throw new ServiceSpecificException(e.getCode());
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
4345 }
4346
4347 /**
shilu366312e2019-12-17 09:28:10 -08004348 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4349 * @param subId The subscription to use to check the configuration.
4350 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004352
Brad Ebinger35c841c2018-10-01 10:40:55 -07004353 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004354 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004355 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004356 final long identity = Binder.clearCallingIdentity();
4357 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004358 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004359 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004360 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004361 } catch (ImsException e) {
4362 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
4366 }
4367
4368 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004369 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004371 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004372 final long identity = Binder.clearCallingIdentity();
4373 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004374 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004375 // This setting doesn't require an active ImsService connection, so do not verify. The
4376 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004377 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004378 } catch (ImsException e) {
4379 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
4383 }
4384
4385 @Override
4386 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4388 "setVoWiFiNonPersistent");
4389 final long identity = Binder.clearCallingIdentity();
4390 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004391 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004392 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004393 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004394 } catch (ImsException e) {
4395 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004396 } finally {
4397 Binder.restoreCallingIdentity(identity);
4398 }
4399 }
4400
shilu366312e2019-12-17 09:28:10 -08004401 /**
4402 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4403 * @param subId The subscription to use to check the configuration.
4404 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004405 @Override
4406 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004407 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004408 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004409 final long identity = Binder.clearCallingIdentity();
4410 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004411 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004412 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004413 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004414 } catch (ImsException e) {
4415 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004416 } finally {
4417 Binder.restoreCallingIdentity(identity);
4418 }
4419 }
4420
4421 @Override
4422 public void setVoWiFiModeSetting(int subId, int mode) {
4423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4424 "setVoWiFiModeSetting");
4425 final long identity = Binder.clearCallingIdentity();
4426 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004427 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004428 // This setting doesn't require an active ImsService connection, so do not verify. The
4429 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004430 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004431 } catch (ImsException e) {
4432 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004433 } finally {
4434 Binder.restoreCallingIdentity(identity);
4435 }
4436 }
4437
4438 @Override
4439 public int getVoWiFiRoamingModeSetting(int subId) {
4440 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4441 final long identity = Binder.clearCallingIdentity();
4442 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004443 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004444 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004445 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004446 } catch (ImsException e) {
4447 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
4451 }
4452
4453 @Override
4454 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4456 "setVoWiFiRoamingModeSetting");
4457 final long identity = Binder.clearCallingIdentity();
4458 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004459 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004460 // This setting doesn't require an active ImsService connection, so do not verify. The
4461 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004462 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004463 } catch (ImsException e) {
4464 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004465 } finally {
4466 Binder.restoreCallingIdentity(identity);
4467 }
4468 }
4469
4470 @Override
4471 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4473 "setRttCapabilityEnabled");
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004476 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004477 // This setting doesn't require an active ImsService connection, so do not verify. The
4478 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004479 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004480 } catch (ImsException e) {
4481 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004482 } finally {
4483 Binder.restoreCallingIdentity(identity);
4484 }
4485 }
4486
shilu366312e2019-12-17 09:28:10 -08004487 /**
4488 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4489 * @param subId The subscription to use to check the configuration.
4490 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004491 @Override
4492 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004493 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004494 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004497 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004498 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004499 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004500 } catch (ImsException e) {
4501 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 } finally {
4503 Binder.restoreCallingIdentity(identity);
4504 }
4505 }
4506
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004507 @Override
4508 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4509 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004512 if (!isImsAvailableOnDevice()) {
4513 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4514 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004515 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004516 int slotId = getSlotIndexOrException(subId);
4517 verifyImsMmTelConfiguredOrThrow(slotId);
4518 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004519 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004520 } catch (ImsException e) {
4521 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004522 } finally {
4523 Binder.restoreCallingIdentity(identity);
4524 }
4525 }
4526
4527 @Override
4528 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4529 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4530 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004531 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4532 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4533 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004535 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004536 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004537 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004538 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4539 + "is inactive, ignoring unregister.");
4540 // If the subscription is no longer active, just return, since the callback will already
4541 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004542 } finally {
4543 Binder.restoreCallingIdentity(identity);
4544 }
4545 }
4546
allenwtsu99c623b2020-01-03 18:24:23 +08004547
4548 private void checkModifyPhoneStatePermission(int subId, String message) {
4549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4550 message);
4551 }
4552
4553 private boolean isImsProvisioningRequired(int subId, int capability,
4554 boolean isMmtelCapability) {
4555 Phone phone = getPhone(subId);
4556 if (phone == null) {
4557 loge("phone instance null for subid " + subId);
4558 return false;
4559 }
4560 if (isMmtelCapability) {
4561 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4562 return false;
4563 }
4564 } else {
4565 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4566 return false;
4567 }
4568 }
4569 return true;
4570 }
4571
4572 @Override
4573 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4574 boolean isProvisioned) {
4575 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4576
4577 final long identity = Binder.clearCallingIdentity();
4578 try {
4579 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4580 if (!isImsProvisioningRequired(subId, capability, false)) {
4581 return;
4582 }
4583
4584 // this capability requires provisioning, route to the correct API.
4585 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4586 switch (capability) {
4587 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4588 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4589 ims.setEabProvisioned(isProvisioned);
4590 break;
4591 default: {
4592 throw new IllegalArgumentException("Tried to set provisioning for "
4593 + "rcs capability '" + capability + "', which does not require "
4594 + "provisioning.");
4595 }
4596 }
4597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
4600
4601 }
4602
4603
4604 @Override
4605 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4606 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4607 final long identity = Binder.clearCallingIdentity();
4608 try {
4609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4610 if (!isImsProvisioningRequired(subId, capability, false)) {
4611 return true;
4612 }
4613
4614 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4615 switch (capability) {
4616 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4617 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4618 return ims.isEabProvisionedOnDevice();
4619
4620 default: {
4621 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4622 + "capability '" + capability + "', which does not require "
4623 + "provisioning.");
4624 }
4625 }
4626
4627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
4630 }
4631
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004632 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004633 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4634 boolean isProvisioned) {
4635 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004636 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4637 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4638 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004639 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4640 }
allenwtsu99c623b2020-01-03 18:24:23 +08004641 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004642 final long identity = Binder.clearCallingIdentity();
4643 try {
4644 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004645 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004646 return;
4647 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004648 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4649 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4650 loge("setImsProvisioningStatusForCapability: called for technology that does "
4651 + "not support provisioning - " + tech);
4652 return;
4653 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004654
4655 // this capability requires provisioning, route to the correct API.
4656 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4657 switch (capability) {
4658 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4659 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4660 ims.setVolteProvisioned(isProvisioned);
4661 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4662 ims.setWfcProvisioned(isProvisioned);
4663 }
4664 break;
4665 }
4666 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4667 // There is currently no difference in VT provisioning type.
4668 ims.setVtProvisioned(isProvisioned);
4669 break;
4670 }
4671 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4672 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4673 // change the capability of the feature instead if needed.
4674 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4675 == isProvisioned) {
4676 // No change in provisioning.
4677 return;
4678 }
4679 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4680 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004681 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004682 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004683 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4684 + ", Exception" + e.getMessage());
4685 }
4686 break;
4687 }
4688 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004689 throw new IllegalArgumentException("Tried to set provisioning for "
4690 + "MmTel capability '" + capability + "', which does not require "
4691 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004692 }
4693 }
4694
4695 } finally {
4696 Binder.restoreCallingIdentity(identity);
4697 }
4698 }
4699
4700 @Override
4701 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4702 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004703 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4704 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4705 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004706 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4707 }
4708 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4709 final long identity = Binder.clearCallingIdentity();
4710 try {
4711 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004712 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713 return true;
4714 }
4715
Brad Ebinger0d79c572021-04-17 15:20:49 -07004716 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4717 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4718 loge("getImsProvisioningStatusForCapability: called for technology that does "
4719 + "not support provisioning - " + tech);
4720 return true;
4721 }
4722
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004723 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4724 switch (capability) {
4725 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4726 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4727 return ims.isVolteProvisionedOnDevice();
4728 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4729 return ims.isWfcProvisionedOnDevice();
4730 }
4731 // This should never happen, since we are checking tech above to make sure it
4732 // is either LTE or IWLAN.
4733 throw new IllegalArgumentException("Invalid radio technology for voice "
4734 + "capability.");
4735 }
4736 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4737 // There is currently no difference in VT provisioning type.
4738 return ims.isVtProvisionedOnDevice();
4739 }
4740 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4741 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4742 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4743 }
4744 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004745 throw new IllegalArgumentException(
4746 "Tried to get provisioning for MmTel capability '" + capability
4747 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004748 }
4749 }
4750
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
4753 }
4754 }
4755
4756 @Override
4757 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4758 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4759 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4760 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4761 }
4762 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4763 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4764 return (provisionedBits & capability) > 0;
4765 }
4766
4767 @Override
4768 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4769 boolean isProvisioned) {
4770 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4771 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4772 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4773 }
4774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4775 "setProvisioningStatusForCapability");
4776 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4777 // If the current provisioning status for capability already matches isProvisioned,
4778 // do nothing.
4779 if (((provisionedBits & capability) > 0) == isProvisioned) {
4780 return;
4781 }
4782 if (isProvisioned) {
4783 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4784 } else {
4785 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4786 }
4787 }
4788
4789 /**
4790 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4791 * technology. The bitfield should mirror the bitfield defined by
4792 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4793 */
4794 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4795 String key = getMmTelProvisioningKey(subId, tech);
4796 // Default is no capabilities are provisioned.
4797 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4798 }
4799
4800 /**
4801 * Sets the MmTel capability provisioning bitfield (defined by
4802 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4803 * technology specified.
4804 *
4805 * Note: This is a synchronous command and should not be called on UI thread.
4806 */
4807 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4808 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4809 String key = getMmTelProvisioningKey(subId, tech);
4810 editor.putInt(key, newField);
4811 editor.commit();
4812 }
4813
4814 private static String getMmTelProvisioningKey(int subId, int tech) {
4815 // resulting key is provision_ims_mmtel_{subId}_{tech}
4816 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4817 }
4818
4819 /**
4820 * Query CarrierConfig to see if the specified capability requires provisioning for the
4821 * carrier associated with the subscription id.
4822 */
4823 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4824 int capability) {
4825 CarrierConfigManager configManager = new CarrierConfigManager(context);
4826 PersistableBundle c = configManager.getConfigForSubId(subId);
4827 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004828 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004829 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4830 false);
4831 boolean requireVoiceVtProvisioning = c.getBoolean(
4832 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4833
4834 // First check to make sure that the capability requires provisioning.
4835 switch (capability) {
4836 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4837 // intentional fallthrough
4838 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4839 if (requireVoiceVtProvisioning) {
4840 // Voice and Video requires provisioning
4841 return true;
4842 }
4843 break;
4844 }
4845 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4846 if (requireUtProvisioning) {
4847 // UT requires provisioning
4848 return true;
4849 }
4850 break;
4851 }
4852 }
4853 return false;
4854 }
4855
allenwtsu99c623b2020-01-03 18:24:23 +08004856 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4857 int capability) {
4858 CarrierConfigManager configManager = new CarrierConfigManager(context);
4859 PersistableBundle c = configManager.getConfigForSubId(subId);
4860
4861 boolean requireRcsProvisioning = c.getBoolean(
4862 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4863
4864 // First check to make sure that the capability requires provisioning.
4865 switch (capability) {
4866 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4867 // intentional fallthrough
4868 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4869 if (requireRcsProvisioning) {
4870 // OPTION or PRESENCE requires provisioning
4871 return true;
4872 }
4873 break;
4874 }
4875 }
4876 return false;
4877 }
4878
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004879 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004880 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004881 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4882 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4883 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004884 enforceReadPrivilegedPermission("getImsProvisioningInt");
4885 final long identity = Binder.clearCallingIdentity();
4886 try {
4887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 int slotId = getSlotIndex(subId);
4889 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4890 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4891 + subId + "' for key:" + key);
4892 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4893 }
calvinpanb5a34062021-02-08 19:59:36 +08004894 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004895 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004896 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4897 + subId + "' for key:" + key);
4898 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
4902 }
4903
4904 @Override
4905 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004906 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4907 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4908 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004909 enforceReadPrivilegedPermission("getImsProvisioningString");
4910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004913 int slotId = getSlotIndex(subId);
4914 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4915 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4916 + subId + "' for key:" + key);
4917 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4918 }
calvinpanb5a34062021-02-08 19:59:36 +08004919 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004920 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004921 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4922 + subId + "' for key:" + key);
4923 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004924 } finally {
4925 Binder.restoreCallingIdentity(identity);
4926 }
4927 }
4928
4929 @Override
4930 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4932 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4933 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4935 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004939 int slotId = getSlotIndex(subId);
4940 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4941 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4942 + subId + "' for key:" + key);
4943 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4944 }
calvinpanb5a34062021-02-08 19:59:36 +08004945 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4946 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004947 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004948 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004949 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
4953 }
4954
4955 @Override
4956 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004957 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4958 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4959 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4961 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004965 int slotId = getSlotIndex(subId);
4966 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4967 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4968 + subId + "' for key:" + key);
4969 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4970 }
calvinpanb5a34062021-02-08 19:59:36 +08004971 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4972 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004973 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004974 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004975 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
4979 }
4980
Brad Ebinger919631e2021-06-02 17:46:35 -07004981 /**
4982 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4983 * for the given slot ID or no ImsResolver instance has been created.
4984 * @param slotId The slot ID that the IMS service is created for.
4985 * @throws ImsException If there is no ImsService configured for this slot.
4986 */
4987 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4988 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4989 ImsFeature.FEATURE_MMTEL)) {
4990 throw new ImsException("This subscription does not support MMTEL over IMS",
4991 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4992 }
4993 }
4994
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004995 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004996 int slotId = SubscriptionManager.getSlotIndex(subId);
4997 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004998 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4999 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005000 }
5001 return slotId;
5002 }
5003
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005004 private int getSlotIndex(int subId) {
5005 int slotId = SubscriptionManager.getSlotIndex(subId);
5006 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5007 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5008 }
5009 return slotId;
5010 }
5011
Wink Saville36469e72014-06-11 15:17:00 -07005012 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005013 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005014 */
5015 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005016 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5017 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005018 try {
5019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5020 } catch (SecurityException se) {
5021 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5022 throw new SecurityException("Package " + callingPackage + " does not belong to "
5023 + Binder.getCallingUid());
5024 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005025 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005026 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005027 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005028 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005029 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005030 mApp, subId, callingPackage, callingFeatureId,
5031 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005032 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5033 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005034
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 final Phone phone = getPhone(subId);
5038 if (phone != null) {
5039 return phone.getServiceState().getDataNetworkType();
5040 } else {
5041 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5042 }
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005045 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005046 }
5047
5048 /**
5049 * Returns the data network type
5050 */
5051 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005052 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005053 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5054 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005055 }
5056
5057 /**
5058 * Returns the data network type for a subId
5059 */
5060 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005061 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5062 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005064 mApp, subId, callingPackage, callingFeatureId,
5065 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005066 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5067 }
5068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 final Phone phone = getPhone(subId);
5072 if (phone != null) {
5073 return phone.getServiceState().getDataNetworkType();
5074 } else {
5075 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5076 }
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005080 }
5081
5082 /**
Wink Saville36469e72014-06-11 15:17:00 -07005083 * Returns the Voice network type for a subId
5084 */
5085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005086 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5087 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005089 mApp, subId, callingPackage, callingFeatureId,
5090 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005091 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5092 }
5093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
5096 final Phone phone = getPhone(subId);
5097 if (phone != null) {
5098 return phone.getServiceState().getVoiceNetworkType();
5099 } else {
5100 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5101 }
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005105 }
5106
5107 /**
5108 * @return true if a ICC card is present
5109 */
5110 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005111 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005112 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5113 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005114 }
5115
5116 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005117 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005118 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005119 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005120 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
5123 final Phone phone = PhoneFactory.getPhone(slotIndex);
5124 if (phone != null) {
5125 return phone.getIccCard().hasIccCard();
5126 } else {
5127 return false;
5128 }
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005132 }
5133
5134 /**
5135 * Return if the current radio is LTE on CDMA. This
5136 * is a tri-state return value as for a period of time
5137 * the mode may be unknown.
5138 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005139 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005140 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005141 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005142 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005143 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005144 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5145 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5146 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005147 }
5148
Sanket Padawe356d7632015-06-22 14:03:32 -07005149 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005150 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5151 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005152 try {
5153 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5154 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005155 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5156 }
5157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 final long identity = Binder.clearCallingIdentity();
5159 try {
5160 final Phone phone = getPhone(subId);
5161 if (phone == null) {
5162 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5163 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005164 return TelephonyProperties.lte_on_cdma_device()
5165 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005169 }
Wink Saville36469e72014-06-11 15:17:00 -07005170 }
5171
Wink Saville36469e72014-06-11 15:17:00 -07005172 /**
5173 * {@hide}
5174 * Returns Default subId, 0 in the case of single standby.
5175 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005176 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005177 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005178 }
5179
Shishir Agrawala9f32182016-04-12 12:00:16 -07005180 private int getSlotForDefaultSubscription() {
5181 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5182 }
5183
Wink Savilleb564aae2014-10-23 10:18:09 -07005184 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005185 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005186 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005187
Pengquan Menge92a50d2018-09-21 15:54:48 -07005188 private boolean isActiveSubscription(int subId) {
5189 return mSubscriptionController.isActiveSubId(subId);
5190 }
5191
Ihab Awadf2177b72013-11-25 13:33:23 -08005192 /**
5193 * @see android.telephony.TelephonyManager.WifiCallingChoices
5194 */
5195 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 final long identity = Binder.clearCallingIdentity();
5197 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005198 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5200 getWhenToMakeWifiCallsDefaultPreference());
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005204 }
5205
5206 /**
5207 * @see android.telephony.TelephonyManager.WifiCallingChoices
5208 */
5209 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 final long identity = Binder.clearCallingIdentity();
5211 try {
5212 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005213 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5215 } finally {
5216 Binder.restoreCallingIdentity(identity);
5217 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005218 }
5219
Sailesh Nepald1e68152013-12-12 19:08:02 -08005220 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005221 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005222 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005223 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005224
Jordan Liu4c733742019-02-28 12:03:40 -08005225 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5226 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5227 if (phoneId == -1) {
5228 throw new IllegalArgumentException("Given slot index: " + slotIndex
5229 + " does not correspond to an active phone");
5230 }
5231 return PhoneFactory.getPhone(phoneId);
5232 }
5233
Shishir Agrawal566b7612013-10-28 14:41:00 -07005234 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005235 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5236 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5238 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005240 if (DBG) {
5241 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5242 }
5243 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5244 p2);
5245 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005246
Jordan Liu4c733742019-02-28 12:03:40 -08005247
5248 @Override
5249 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5250 int slotIndex, String callingPackage, String aid, int p2) {
5251 enforceModifyPermission();
5252 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5253 if (DBG) {
5254 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5255 }
5256 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5257 callingPackage, aid, p2);
5258 }
5259
5260 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5261 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 final long identity = Binder.clearCallingIdentity();
5263 try {
5264 if (TextUtils.equals(ISDR_AID, aid)) {
5265 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005266 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5267 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 if (bestComponent == null
5269 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5270 loge("The calling package is not allowed to access ISD-R.");
5271 throw new SecurityException(
5272 "The calling package is not allowed to access ISD-R.");
5273 }
Derek Tan740e1672017-06-27 14:56:27 -07005274 }
Derek Tan740e1672017-06-27 14:56:27 -07005275
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005277 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5278 null /* workSource */);
5279 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 return response;
5281 } finally {
5282 Binder.restoreCallingIdentity(identity);
5283 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005284 }
5285
5286 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005287 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5289 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005290 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5291 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5292 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005293
Jordan Liu4c733742019-02-28 12:03:40 -08005294 @Override
5295 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5296 enforceModifyPermission();
5297 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5298 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5299 channel);
5300 }
5301
5302 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303 final long identity = Binder.clearCallingIdentity();
5304 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 if (channel < 0) {
5306 return false;
5307 }
Jordan Liu4c733742019-02-28 12:03:40 -08005308 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5309 null /* workSource */);
5310 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 return success;
5312 } finally {
5313 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005314 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005315 }
5316
5317 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005318 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005319 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5321 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005322 if (DBG) {
5323 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5324 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5325 + p3 + " data=" + data);
5326 }
5327 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5328 command, p1, p2, p3, data);
5329 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005330
Jordan Liu4c733742019-02-28 12:03:40 -08005331 @Override
5332 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5333 int command, int p1, int p2, int p3, String data) {
5334 enforceModifyPermission();
5335 if (DBG) {
5336 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5337 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5338 + p3 + " data=" + data);
5339 }
5340 return iccTransmitApduLogicalChannelWithPermission(
5341 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5342 data);
5343 }
5344
5345 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5346 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005347 final long identity = Binder.clearCallingIdentity();
5348 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005349 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005350 return "";
5351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005354 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5355 null /* workSource */);
5356 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005357
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358 // Append the returned status code to the end of the response payload.
5359 String s = Integer.toHexString(
5360 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5361 if (response.payload != null) {
5362 s = IccUtils.bytesToHexString(response.payload) + s;
5363 }
5364 return s;
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005367 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005368 }
Jake Hambye994d462014-02-03 13:10:13 -08005369
Evan Charltonc66da362014-05-16 14:06:40 -07005370 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005371 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5372 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5374 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005376 if (DBG) {
5377 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5378 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5379 }
5380 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5381 cla, command, p1, p2, p3, data);
5382 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005383
Jordan Liu4c733742019-02-28 12:03:40 -08005384 @Override
5385 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5386 int command, int p1, int p2, int p3, String data) {
5387 enforceModifyPermission();
5388 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5389 if (DBG) {
5390 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5391 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5392 + " data=" + data);
5393 }
5394
5395 return iccTransmitApduBasicChannelWithPermission(
5396 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5397 p2, p3, data);
5398 }
5399
5400 // open APDU basic channel assuming the caller has sufficient permissions
5401 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5402 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403 final long identity = Binder.clearCallingIdentity();
5404 try {
5405 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5406 && TextUtils.equals(ISDR_AID, data)) {
5407 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005408 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5409 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 if (bestComponent == null
5411 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5412 loge("The calling package is not allowed to select ISD-R.");
5413 throw new SecurityException(
5414 "The calling package is not allowed to select ISD-R.");
5415 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005416 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005419 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5420 null /* workSource */);
5421 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 // Append the returned status code to the end of the response payload.
5424 String s = Integer.toHexString(
5425 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5426 if (response.payload != null) {
5427 s = IccUtils.bytesToHexString(response.payload) + s;
5428 }
5429 return s;
5430 } finally {
5431 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005432 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005433 }
5434
5435 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005436 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005437 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5439 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 if (DBG) {
5444 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5445 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5446 }
5447
5448 IccIoResult response =
5449 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5450 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5451 subId);
5452
5453 if (DBG) {
5454 log("Exchange SIM_IO [R]" + response);
5455 }
5456
5457 byte[] result = null;
5458 int length = 2;
5459 if (response.payload != null) {
5460 length = 2 + response.payload.length;
5461 result = new byte[length];
5462 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5463 } else {
5464 result = new byte[length];
5465 }
5466
5467 result[length - 1] = (byte) response.sw2;
5468 result[length - 2] = (byte) response.sw1;
5469 return result;
5470 } finally {
5471 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005472 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005473 }
5474
Nathan Haroldb3014052017-01-25 15:57:32 -08005475 /**
5476 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5477 * on a particular subscription
5478 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005479 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5480 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005482 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005483 return null;
5484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485
5486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 if (appType != TelephonyManager.APPTYPE_USIM
5489 && appType != TelephonyManager.APPTYPE_SIM) {
5490 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5491 return null;
5492 }
5493 Object response = sendRequest(
5494 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5495 if (response instanceof String[]) {
5496 return (String[]) response;
5497 }
yincheng zhao2737e882019-09-06 17:06:54 -07005498 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005500 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005501 } finally {
5502 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005503 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005504 }
5505
yincheng zhao2737e882019-09-06 17:06:54 -07005506 /**
5507 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5508 * subscription.
5509 *
5510 * @param subId the id of the subscription.
5511 * @param appType the uicc app type, must be USIM or SIM.
5512 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5513 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005514 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005515 * @return number of fplmns that is successfully written to the SIM.
5516 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005517 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5518 String callingFeatureId) {
5519 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5520 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005521 if (DBG) logv("no permissions for setForbiddenplmns");
5522 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5523 }
5524 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5525 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5526 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5527 }
5528 if (fplmns == null) {
5529 throw new IllegalArgumentException("Fplmn List provided is null");
5530 }
5531 for (String fplmn : fplmns) {
5532 if (!CellIdentity.isValidPlmn(fplmn)) {
5533 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5534 }
5535 }
5536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 Object response = sendRequest(
5539 CMD_SET_FORBIDDEN_PLMNS,
5540 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5541 subId);
5542 return (int) response;
5543 } finally {
5544 Binder.restoreCallingIdentity(identity);
5545 }
5546 }
5547
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005548 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005549 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5551 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 final long identity = Binder.clearCallingIdentity();
5554 try {
5555 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5556 if (response.payload == null) {
5557 return "";
5558 }
Evan Charltonc66da362014-05-16 14:06:40 -07005559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 // Append the returned status code to the end of the response payload.
5561 String s = Integer.toHexString(
5562 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5563 s = IccUtils.bytesToHexString(response.payload) + s;
5564 return s;
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
Evan Charltonc66da362014-05-16 14:06:40 -07005568 }
5569
Jake Hambye994d462014-02-03 13:10:13 -08005570 /**
5571 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5572 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5573 *
5574 * @param itemID the ID of the item to read
5575 * @return the NV item as a String, or null on error.
5576 */
5577 @Override
5578 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005579 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5581 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582
5583 final long identity = Binder.clearCallingIdentity();
5584 try {
5585 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005586 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5588 return value;
5589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
Jake Hambye994d462014-02-03 13:10:13 -08005592 }
5593
5594 /**
5595 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5596 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5597 *
5598 * @param itemID the ID of the item to read
5599 * @param itemValue the value to write, as a String
5600 * @return true on success; false on any failure
5601 */
5602 @Override
5603 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005604 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5606 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607
5608 final long identity = Binder.clearCallingIdentity();
5609 try {
5610 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5611 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005612 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5614 return success;
5615 } finally {
5616 Binder.restoreCallingIdentity(identity);
5617 }
Jake Hambye994d462014-02-03 13:10:13 -08005618 }
5619
5620 /**
5621 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5622 * Used for device configuration by some CDMA operators.
5623 *
5624 * @param preferredRoamingList byte array containing the new PRL
5625 * @return true on success; false on any failure
5626 */
5627 @Override
5628 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5630 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005631
5632 final long identity = Binder.clearCallingIdentity();
5633 try {
5634 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5635 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5636 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5637 return success;
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
Jake Hambye994d462014-02-03 13:10:13 -08005641 }
5642
5643 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005644 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005645 * Used for device configuration by some CDMA operators.
5646 *
chen xu6dac5ab2018-10-26 17:39:23 -07005647 * @param slotIndex - device slot.
5648 *
Jake Hambye994d462014-02-03 13:10:13 -08005649 * @return true on success; false on any failure
5650 */
5651 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005652 public boolean resetModemConfig(int slotIndex) {
5653 Phone phone = PhoneFactory.getPhone(slotIndex);
5654 if (phone != null) {
5655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5656 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657
chen xu6dac5ab2018-10-26 17:39:23 -07005658 final long identity = Binder.clearCallingIdentity();
5659 try {
5660 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5661 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5662 return success;
5663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 }
chen xu6dac5ab2018-10-26 17:39:23 -07005667 return false;
5668 }
5669
5670 /**
5671 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5672 *
5673 * @param slotIndex - device slot.
5674 *
5675 * @return true on success; false on any failure
5676 */
5677 @Override
5678 public boolean rebootModem(int slotIndex) {
5679 Phone phone = PhoneFactory.getPhone(slotIndex);
5680 if (phone != null) {
5681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5682 mApp, phone.getSubId(), "rebootModem");
5683
5684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5687 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5688 return success;
5689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691 }
5692 }
5693 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005694 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005695
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005696 public String[] getPcscfAddress(String apnType, String callingPackage,
5697 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005698 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5700 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005701 return new String[0];
5702 }
5703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 final long identity = Binder.clearCallingIdentity();
5705 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005706 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
Wink Saville36469e72014-06-11 15:17:00 -07005710 }
5711
Brad Ebinger51f743a2017-01-23 13:50:20 -08005712 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005713 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5714 * {@link #disableIms(int)}.
5715 * @param slotIndex device slot.
5716 */
5717 public void resetIms(int slotIndex) {
5718 enforceModifyPermission();
5719
5720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 if (mImsResolver == null) {
5723 // may happen if the does not support IMS.
5724 return;
5725 }
5726 mImsResolver.disableIms(slotIndex);
5727 mImsResolver.enableIms(slotIndex);
5728 } finally {
5729 Binder.restoreCallingIdentity(identity);
5730 }
5731 }
5732
5733 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005734 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5735 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005736 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005737 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005738 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739
5740 final long identity = Binder.clearCallingIdentity();
5741 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005743 // may happen if the device does not support IMS.
5744 return;
5745 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005746 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005750 }
5751
5752 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005753 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5754 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005755 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005756 public void disableIms(int slotId) {
5757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005761 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005762 // may happen if the device does not support IMS.
5763 return;
5764 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005765 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005769 }
5770
5771 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005772 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5773 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005774 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005775 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005776 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005777 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778
5779 final long identity = Binder.clearCallingIdentity();
5780 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005781 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005782 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5783 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005784 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005785 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005789 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005790 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005791 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5792 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005793 @Override
5794 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005795 enforceModifyPermission();
5796
5797 final long identity = Binder.clearCallingIdentity();
5798 try {
5799 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005800 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
5804 }
5805
5806 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005807 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005808 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005809 */
5810 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5811 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005812
5813 final long identity = Binder.clearCallingIdentity();
5814 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005815 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005816 // may happen if the device does not support IMS.
5817 return null;
5818 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005819 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820 } finally {
5821 Binder.restoreCallingIdentity(identity);
5822 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005823 }
5824
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005825 /**
5826 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005827 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005828 */
5829 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5830 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831
5832 final long identity = Binder.clearCallingIdentity();
5833 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005834 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005835 // may happen if the device does not support IMS.
5836 return null;
5837 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005838 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839 } finally {
5840 Binder.restoreCallingIdentity(identity);
5841 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005842 }
5843
Brad Ebinger884c07b2018-02-15 16:17:40 -08005844 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005845 * Sets the ImsService Package Name that Telephony will bind to.
5846 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005847 * @param slotIndex the slot ID that the ImsService should bind for.
5848 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005849 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005850 * @param featureTypes An integer array of feature types associated with a packageName.
5851 * @param packageName The name of the package that the current configuration will be replaced
5852 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005853 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005854 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005855 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5856 int[] featureTypes, String packageName) {
5857 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5858 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5860 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005861 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 final long identity = Binder.clearCallingIdentity();
5864 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005865 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005866 // may happen if the device does not support IMS.
5867 return false;
5868 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 Map<Integer, String> featureConfig = new HashMap<>();
5870 for (int featureType : featureTypes) {
5871 featureConfig.put(featureType, packageName);
5872 }
5873 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5874 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 } finally {
5876 Binder.restoreCallingIdentity(identity);
5877 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005878 }
5879
5880 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005881 * Clears any carrier ImsService overrides for the slot index specified that were previously
5882 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5883 *
5884 * This should only be used for testing.
5885 *
5886 * @param slotIndex the slot ID that the ImsService should bind for.
5887 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5888 */
5889 @Override
5890 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5891 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5892 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5893 "clearCarrierImsServiceOverride");
5894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5895 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5896 "clearCarrierImsServiceOverride");
5897
5898 final long identity = Binder.clearCallingIdentity();
5899 try {
5900 if (mImsResolver == null) {
5901 // may happen if the device does not support IMS.
5902 return false;
5903 }
5904 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5905 } finally {
5906 Binder.restoreCallingIdentity(identity);
5907 }
5908 }
5909
5910 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005911 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005912 *
5913 * @param slotId The slot that the ImsService is associated with.
5914 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5915 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005916 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005917 * @return the package name of the ImsService configuration.
5918 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005919 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5920 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005921 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005922 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005923 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005924 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5925 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 final long identity = Binder.clearCallingIdentity();
5928 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005929 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005930 // may happen if the device does not support IMS.
5931 return "";
5932 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005933 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005934 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5935 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005939 }
5940
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005941 /**
5942 * Get the MmTelFeature state associated with the requested subscription id.
5943 * @param subId The subscription that the MmTelFeature is associated with.
5944 * @param callback A callback with an integer containing the
5945 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5946 */
5947 @Override
5948 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5949 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5950 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5951 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5952 "IMS not available on device.");
5953 }
5954 final long token = Binder.clearCallingIdentity();
5955 try {
5956 int slotId = getSlotIndex(subId);
5957 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5958 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5959 + subId + "'");
5960 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5961 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005962 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005963 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5964 try {
5965 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5966 } catch (RemoteException e) {
5967 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5968 + "Ignore");
5969 }
5970 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005971 } catch (ImsException e) {
5972 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005973 } finally {
5974 Binder.restoreCallingIdentity(token);
5975 }
5976 }
5977
Daniel Brightbb5840b2021-01-12 15:48:18 -08005978 /**
5979 * Sets the ims registration state on all valid {@link Phone}s.
5980 */
5981 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005982 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983
5984 final long identity = Binder.clearCallingIdentity();
5985 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005986 // NOTE: Before S, this method only set the default phone.
5987 for (final Phone phone : PhoneFactory.getPhones()) {
5988 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5989 phone.setImsRegistrationState(registered);
5990 }
5991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 } finally {
5993 Binder.restoreCallingIdentity(identity);
5994 }
Wink Saville36469e72014-06-11 15:17:00 -07005995 }
5996
5997 /**
Stuart Scott54788802015-03-30 13:18:01 -07005998 * Set the network selection mode to automatic.
5999 *
6000 */
6001 @Override
6002 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6004 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005
6006 final long identity = Binder.clearCallingIdentity();
6007 try {
shilufc958392020-01-20 11:36:01 -08006008 if (!isActiveSubscription(subId)) {
6009 return;
6010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006012 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6013 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 } finally {
6015 Binder.restoreCallingIdentity(identity);
6016 }
Stuart Scott54788802015-03-30 13:18:01 -07006017 }
6018
Jack Yud10cdd42020-09-28 20:28:01 -07006019 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006020 * Ask the radio to connect to the input network and change selection mode to manual.
6021 *
6022 * @param subId the id of the subscription.
6023 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6024 * the operator to attach to.
6025 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6026 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6027 * normal network selection next time.
6028 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006029 */
6030 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006031 public boolean setNetworkSelectionModeManual(
6032 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6034 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006035
6036 if (!isActiveSubscription(subId)) {
6037 return false;
6038 }
6039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 final long identity = Binder.clearCallingIdentity();
6041 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006042 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006044 if (DBG) {
6045 log("setNetworkSelectionModeManual: subId: " + subId
6046 + " operator: " + operatorInfo);
6047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006048 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006052 }
shilu84f6e8b2019-12-19 13:58:01 -08006053 /**
6054 * Get the manual network selection
6055 *
6056 * @param subId the id of the subscription.
6057 *
6058 * @return the previously saved user selected PLMN
6059 */
6060 @Override
6061 public String getManualNetworkSelectionPlmn(int subId) {
6062 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006063 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006064 mApp, subId, "getManualNetworkSelectionPlmn");
6065
6066 final long identity = Binder.clearCallingIdentity();
6067 try {
6068 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006069 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006070 }
6071
6072 final Phone phone = getPhone(subId);
6073 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006074 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006075 }
6076 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6077 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6078 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6079 } finally {
6080 Binder.restoreCallingIdentity(identity);
6081 }
6082 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006083
6084 /**
6085 * Scans for available networks.
6086 */
6087 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006088 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6089 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6091 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006092 LocationAccessPolicy.LocationPermissionResult locationResult =
6093 LocationAccessPolicy.checkLocationPermission(mApp,
6094 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6095 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006096 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006097 .setCallingPid(Binder.getCallingPid())
6098 .setCallingUid(Binder.getCallingUid())
6099 .setMethod("getCellNetworkScanResults")
6100 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006101 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6102 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006103 .build());
6104 switch (locationResult) {
6105 case DENIED_HARD:
6106 throw new SecurityException("Not allowed to access scan results -- location");
6107 case DENIED_SOFT:
6108 return null;
6109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006110
Pengquan Menga1bb6272018-09-06 09:59:22 -07006111 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 try {
6113 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006114 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 } finally {
6117 Binder.restoreCallingIdentity(identity);
6118 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006119 }
6120
6121 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006122 * Get the call forwarding info, given the call forwarding reason.
6123 */
6124 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006125 public void getCallForwarding(int subId, int callForwardingReason,
6126 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006127 enforceReadPrivilegedPermission("getCallForwarding");
6128 long identity = Binder.clearCallingIdentity();
6129 try {
6130 if (DBG) {
6131 log("getCallForwarding: subId " + subId
6132 + " callForwardingReason" + callForwardingReason);
6133 }
Hall Liu27d24262020-09-18 19:04:59 -07006134
6135 Phone phone = getPhone(subId);
6136 if (phone == null) {
6137 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006138 callback.onError(
6139 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006140 } catch (RemoteException e) {
6141 // ignore
6142 }
6143 return;
6144 }
6145
6146 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6147 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6148 @Override
6149 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6150 try {
6151 callback.onCallForwardingInfoAvailable(info);
6152 } catch (RemoteException e) {
6153 // ignore
6154 }
6155 }
6156
6157 @Override
6158 public void onError(int error) {
6159 try {
6160 callback.onError(error);
6161 } catch (RemoteException e) {
6162 // ignore
6163 }
6164 }
6165 });
6166 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
6170 }
6171
6172 /**
6173 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6174 * reason, the number to forward, and the timeout before the forwarding is attempted.
6175 */
6176 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006177 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6178 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006179 enforceModifyPermission();
6180 long identity = Binder.clearCallingIdentity();
6181 try {
6182 if (DBG) {
6183 log("setCallForwarding: subId " + subId
6184 + " callForwardingInfo" + callForwardingInfo);
6185 }
Hall Liu27d24262020-09-18 19:04:59 -07006186
6187 Phone phone = getPhone(subId);
6188 if (phone == null) {
6189 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006190 callback.accept(
6191 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006192 } catch (RemoteException e) {
6193 // ignore
6194 }
6195 return;
6196 }
6197
6198 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6199 FunctionalUtils.ignoreRemoteException(callback::accept));
6200
6201 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006202 } finally {
6203 Binder.restoreCallingIdentity(identity);
6204 }
6205 }
6206
6207 /**
Hall Liu27d24262020-09-18 19:04:59 -07006208 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006209 */
6210 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006211 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006212 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006213 long identity = Binder.clearCallingIdentity();
6214 try {
Hall Liu27d24262020-09-18 19:04:59 -07006215 Phone phone = getPhone(subId);
6216 if (phone == null) {
6217 try {
6218 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6219 } catch (RemoteException e) {
6220 // ignore
6221 }
6222 return;
6223 }
SongFerngWang0e767992021-03-31 22:08:45 +08006224 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6225 PersistableBundle c = configManager.getConfigForSubId(subId);
6226 boolean requireUssd = c.getBoolean(
6227 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006228
Shuo Qian4a594052020-01-23 11:59:30 -08006229 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006230 if (requireUssd) {
6231 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6232 getSubscriptionCarrierId(subId));
6233 String newUssdCommand = "";
6234 try {
6235 newUssdCommand = carrierXmlParser.getFeature(
6236 CarrierXmlParser.FEATURE_CALL_WAITING)
6237 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6238 } catch (NullPointerException e) {
6239 loge("Failed to generate USSD number" + e);
6240 }
6241 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6242 mMainThreadHandler, callback, carrierXmlParser,
6243 CarrierXmlParser.SsEntry.SSAction.QUERY);
6244 final String ussdCommand = newUssdCommand;
6245 Executors.newSingleThreadExecutor().execute(() -> {
6246 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6247 });
6248 } else {
6249 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6250 callback::accept);
6251 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6252 }
Shuo Qian4a594052020-01-23 11:59:30 -08006253 } finally {
6254 Binder.restoreCallingIdentity(identity);
6255 }
6256 }
6257
6258 /**
Hall Liu27d24262020-09-18 19:04:59 -07006259 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006260 */
6261 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006262 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006263 enforceModifyPermission();
6264 long identity = Binder.clearCallingIdentity();
6265 try {
Hall Liu27d24262020-09-18 19:04:59 -07006266 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6267
6268 Phone phone = getPhone(subId);
6269 if (phone == null) {
6270 try {
6271 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6272 } catch (RemoteException e) {
6273 // ignore
6274 }
6275 return;
6276 }
6277
SongFerngWang0e767992021-03-31 22:08:45 +08006278 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6279 PersistableBundle c = configManager.getConfigForSubId(subId);
6280 boolean requireUssd = c.getBoolean(
6281 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006282
SongFerngWang0e767992021-03-31 22:08:45 +08006283 if (DBG) log("getCallWaitingStatus: subId " + subId);
6284 if (requireUssd) {
6285 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6286 getSubscriptionCarrierId(subId));
6287 CarrierXmlParser.SsEntry.SSAction ssAction =
6288 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6289 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6290 String newUssdCommand = "";
6291 try {
6292 newUssdCommand = carrierXmlParser.getFeature(
6293 CarrierXmlParser.FEATURE_CALL_WAITING)
6294 .makeCommand(ssAction, null);
6295 } catch (NullPointerException e) {
6296 loge("Failed to generate USSD number" + e);
6297 }
6298 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6299 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6300 final String ussdCommand = newUssdCommand;
6301 Executors.newSingleThreadExecutor().execute(() -> {
6302 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6303 });
6304 } else {
6305 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6306 FunctionalUtils.ignoreRemoteException(callback::accept));
6307
6308 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6309 }
Shuo Qian4a594052020-01-23 11:59:30 -08006310 } finally {
6311 Binder.restoreCallingIdentity(identity);
6312 }
6313 }
6314
6315 /**
yinxub1bed742017-04-17 11:45:04 -07006316 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006317 *
yinxub1bed742017-04-17 11:45:04 -07006318 * @param subId id of the subscription
6319 * @param request contains the radio access networks with bands/channels to scan
6320 * @param messenger callback messenger for scan results or errors
6321 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006322 * @return the id of the requested scan which can be used to stop the scan.
6323 */
6324 @Override
6325 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006326 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6328 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006329 LocationAccessPolicy.LocationPermissionResult locationResult =
6330 LocationAccessPolicy.checkLocationPermission(mApp,
6331 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6332 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006333 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006334 .setCallingPid(Binder.getCallingPid())
6335 .setCallingUid(Binder.getCallingUid())
6336 .setMethod("requestNetworkScan")
6337 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006338 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6339 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006340 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006341 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006342 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6343 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006344 if (e != null) {
6345 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6346 throw e;
6347 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006348 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006349 return TelephonyScanManager.INVALID_SCAN_ID;
6350 }
6351 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352 }
Hall Liu912dfd32019-04-25 14:02:26 -07006353 int callingUid = Binder.getCallingUid();
6354 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 return mNetworkScanRequestTracker.startNetworkScan(
6358 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006359 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006360 } finally {
6361 Binder.restoreCallingIdentity(identity);
6362 }
yinxu504e1392017-04-12 16:03:22 -07006363 }
6364
Hall Liub2ac8ef2019-02-28 15:56:23 -08006365 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006366 NetworkScanRequest request, int subId, String callingPackage) {
6367 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006368 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6369 boolean hasNetworkScanPermission =
6370 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6371 == PERMISSION_GRANTED;
6372
6373 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6374 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6375 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006376 }
6377
6378 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6379 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006380 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6381 return new SecurityException("Specific channels must not be"
6382 + " scanned without location access.");
6383 }
6384 }
6385 }
6386
Hall Liub2ac8ef2019-02-28 15:56:23 -08006387 return null;
6388 }
6389
yinxu504e1392017-04-12 16:03:22 -07006390 /**
6391 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006392 *
6393 * @param subId id of the subscription
6394 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006395 */
6396 @Override
6397 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6399 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400
Hall Liu912dfd32019-04-25 14:02:26 -07006401 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 final long identity = Binder.clearCallingIdentity();
6403 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006404 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 } finally {
6406 Binder.restoreCallingIdentity(identity);
6407 }
yinxu504e1392017-04-12 16:03:22 -07006408 }
6409
6410 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006411 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006412 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006413 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006414 */
6415 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006416 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006417 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006418 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006419 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420
6421 final long identity = Binder.clearCallingIdentity();
6422 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006423 if (DBG) log("getAllowedNetworkTypesBitmask");
6424 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6425 int networkTypesBitmask = (result != null ? result[0] : -1);
6426 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6427 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006431 }
6432
6433 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006434 * Get the allowed network types for certain reason.
6435 *
6436 * @param subId the id of the subscription.
6437 * @param reason the reason the allowed network type change is taking place
6438 * @return the allowed network types.
6439 */
6440 @Override
6441 public long getAllowedNetworkTypesForReason(int subId,
6442 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006443 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006444 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006445 final long identity = Binder.clearCallingIdentity();
6446 try {
6447 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
6451 }
6452
6453 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006454 * Enable/Disable E-UTRA-NR Dual Connectivity
6455 * @param subId subscription id of the sim card
6456 * @param nrDualConnectivityState expected NR dual connectivity state
6457 * This can be passed following states
6458 * <ol>
6459 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6460 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6461 * <li>Disable NR dual connectivity and force secondary cell to be released
6462 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6463 * </ol>
6464 * @return operation result.
6465 */
6466 @Override
6467 public int setNrDualConnectivityState(int subId,
6468 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6470 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006471 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006472 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6473 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6474 }
6475
Sooraj Sasindran37444802020-08-11 10:40:43 -07006476 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6477 final long identity = Binder.clearCallingIdentity();
6478 try {
6479 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6480 nrDualConnectivityState, subId,
6481 workSource);
6482 if (DBG) log("enableNRDualConnectivity result: " + result);
6483 return result;
6484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
6487 }
6488
6489 /**
6490 * Is E-UTRA-NR Dual Connectivity enabled
6491 * @return true if dual connectivity is enabled else false
6492 */
6493 @Override
6494 public boolean isNrDualConnectivityEnabled(int subId) {
6495 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006496 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006497 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006498 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006499 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6500 return false;
6501 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6503 final long identity = Binder.clearCallingIdentity();
6504 try {
6505 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6506 null, subId, workSource);
6507 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6508 return isEnabled;
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
6512 }
6513
6514 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006515 * Set the allowed network types of the device and
6516 * provide the reason triggering the allowed network change.
6517 *
6518 * @param subId the id of the subscription.
6519 * @param reason the reason the allowed network type change is taking place
6520 * @param allowedNetworkTypes the allowed network types.
6521 * @return true on success; false on any failure.
6522 */
6523 @Override
6524 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006525 @TelephonyManager.AllowedNetworkTypesReason int reason,
6526 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6528 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006529 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006530 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6531 return false;
6532 }
6533 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6534 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006535 return false;
6536 }
6537
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006538 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6539 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6540
6541
6542 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6543 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6544 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006545 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006546
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006547 final long identity = Binder.clearCallingIdentity();
6548 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006549 Boolean success = (Boolean) sendRequest(
6550 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6551 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6552
6553 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6554 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006555 } finally {
6556 Binder.restoreCallingIdentity(identity);
6557 }
6558 }
6559
6560 /**
Miaoa84611c2019-03-15 09:21:10 +08006561 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006562 *
Miaoa84611c2019-03-15 09:21:10 +08006563 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006564 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006565 * @hide
6566 */
6567 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006568 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006571 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 try {
Miaoa84611c2019-03-15 09:21:10 +08006573 if (phone != null) {
6574 return phone.hasMatchedTetherApnSetting();
6575 } else {
6576 return false;
6577 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 } finally {
6579 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006580 }
Junda Liu475951f2014-11-07 16:45:03 -08006581 }
6582
6583 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006584 * Enable or disable always reporting signal strength changes from radio.
6585 *
6586 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6587 */
6588 @Override
6589 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6590 enforceModifyPermission();
6591 enforceSystemCaller();
6592
6593 final long identity = Binder.clearCallingIdentity();
6594 final Phone phone = getPhone(subId);
6595 try {
6596 if (phone != null) {
6597 if (DBG) {
6598 log("setAlwaysReportSignalStrength: subId=" + subId
6599 + " isEnable=" + isEnable);
6600 }
6601 phone.setAlwaysReportSignalStrength(isEnable);
6602 } else {
6603 loge("setAlwaysReportSignalStrength: no phone found for subId="
6604 + subId);
6605 }
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
6608 }
6609 }
6610
6611 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006612 * Get the user enabled state of Mobile Data.
6613 *
6614 * TODO: remove and use isUserDataEnabled.
6615 * This can't be removed now because some vendor codes
6616 * calls through ITelephony directly while they should
6617 * use TelephonyManager.
6618 *
6619 * @return true on enabled
6620 */
6621 @Override
6622 public boolean getDataEnabled(int subId) {
6623 return isUserDataEnabled(subId);
6624 }
6625
6626 /**
6627 * Get whether mobile data is enabled per user setting.
6628 *
6629 * There are other factors deciding whether mobile data is actually enabled, but they are
6630 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006631 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006632 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006633 *
6634 * @return {@code true} if data is enabled else {@code false}
6635 */
6636 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006637 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006638 try {
6639 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6640 null);
6641 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6643 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645
6646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 int phoneId = mSubscriptionController.getPhoneId(subId);
6649 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6650 Phone phone = PhoneFactory.getPhone(phoneId);
6651 if (phone != null) {
6652 boolean retVal = phone.isUserDataEnabled();
6653 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6654 return retVal;
6655 } else {
6656 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6657 return false;
6658 }
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006661 }
6662 }
6663
6664 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006665 * Checks if the device is capable of mobile data by considering whether whether the
6666 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6667 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006668 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006669 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006670 */
6671 @Override
6672 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006673 try {
6674 try {
6675 mApp.enforceCallingOrSelfPermission(
6676 android.Manifest.permission.ACCESS_NETWORK_STATE,
6677 null);
6678 } catch (Exception e) {
6679 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6680 "isDataEnabled");
6681 }
6682 } catch (Exception e) {
6683 enforceReadPrivilegedPermission("isDataEnabled");
6684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685
6686 final long identity = Binder.clearCallingIdentity();
6687 try {
6688 int phoneId = mSubscriptionController.getPhoneId(subId);
6689 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6690 Phone phone = PhoneFactory.getPhone(phoneId);
6691 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006692 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006693 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6694 return retVal;
6695 } else {
6696 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6697 return false;
6698 }
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006701 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006702 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006703
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006704 /**
6705 * Check if data is enabled for a specific reason
6706 * @param subId Subscription index
6707 * @param reason the reason the data enable change is taking place
6708 * @return {@code true} if the overall data is enabled; {@code false} if not.
6709 */
6710 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006711 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006712 @TelephonyManager.DataEnabledReason int reason) {
6713 try {
6714 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6715 null);
6716 } catch (Exception e) {
6717 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006718 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 }
6720
6721
6722 final long identity = Binder.clearCallingIdentity();
6723 try {
6724 int phoneId = mSubscriptionController.getPhoneId(subId);
6725 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006726 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006727 + " reason=" + reason);
6728 }
6729 Phone phone = PhoneFactory.getPhone(phoneId);
6730 if (phone != null) {
6731 boolean retVal;
6732 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6733 retVal = phone.isUserDataEnabled();
6734 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006735 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006736 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006737 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006738 return retVal;
6739 } else {
6740 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006741 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006742 + subId + " retVal=false");
6743 }
6744 return false;
6745 }
6746 } finally {
6747 Binder.restoreCallingIdentity(identity);
6748 }
6749 }
6750
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006751 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006752 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006753 if (uid == Process.PHONE_UID) {
6754 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6755 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006756 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6757 }
6758
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006759 //load access rules from carrier configs, and check those as well: b/139133814
6760 SubscriptionController subController = SubscriptionController.getInstance();
6761 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6762 || subController == null) return privilegeFromSim;
6763
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006764 PackageManager pkgMgr = phone.getContext().getPackageManager();
6765 String[] packages = pkgMgr.getPackagesForUid(uid);
6766
6767 final long identity = Binder.clearCallingIdentity();
6768 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006769 int subId = phone.getSubId();
6770 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6771 // A test override is in place for the privileges for this subId, so don't try to
6772 // read the subscription privileges.
6773 return privilegeFromSim;
6774 }
6775 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006776 SubscriptionManager subManager = (SubscriptionManager)
6777 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6778 for (String pkg : packages) {
6779 if (subManager.canManageSubscription(subInfo, pkg)) {
6780 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6781 }
6782 }
6783 return privilegeFromSim;
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
6787 }
6788
6789 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6790 String pkgName) {
6791 //load access rules from carrier configs, and check those as well: b/139133814
6792 SubscriptionController subController = SubscriptionController.getInstance();
6793 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6794 || subController == null) return privilegeFromSim;
6795
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006798 int subId = phone.getSubId();
6799 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6800 // A test override is in place for the privileges for this subId, so don't try to
6801 // read the subscription privileges.
6802 return privilegeFromSim;
6803 }
6804 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006805 SubscriptionManager subManager = (SubscriptionManager)
6806 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6807 return subManager.canManageSubscription(subInfo, pkgName)
6808 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6809 } finally {
6810 Binder.restoreCallingIdentity(identity);
6811 }
6812 }
6813
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006814 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006815 public int getCarrierPrivilegeStatus(int subId) {
6816 final Phone phone = getPhone(subId);
6817 if (phone == null) {
6818 loge("getCarrierPrivilegeStatus: Invalid subId");
6819 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6820 }
6821 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006822 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006823 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006824 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6825 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006826
6827 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6828 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006829 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006830 }
Junda Liu29340342014-07-10 15:23:27 -07006831
6832 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006833 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006834 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006835 final Phone phone = getPhone(subId);
6836 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006837 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006838 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6839 }
6840 UiccProfile profile =
6841 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6842 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006843 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006844 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6845 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006846 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006847 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006848 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006849 }
6850
6851 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006852 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006853 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006854 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006855 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006856 }
6857
6858 int phoneId = SubscriptionManager.getPhoneId(subId);
6859 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006860 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006861 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006862 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6863 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006864 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6865 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6866 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006867 }
6868
6869 @Override
6870 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006871 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006872 if (TextUtils.isEmpty(pkgName))
6873 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006874 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6875 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6876 UiccCard card = UiccController.getInstance().getUiccCard(i);
6877 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006878 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006879 continue;
6880 }
6881
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006882 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6883 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6884 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006885 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6886 break;
6887 }
6888 }
6889
6890 return result;
Junda Liu29340342014-07-10 15:23:27 -07006891 }
Derek Tan89e89d42014-07-08 17:00:10 -07006892
6893 @Override
Junda Liue64de782015-04-16 17:19:16 -07006894 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006895 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006896 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6897 loge("phoneId " + phoneId + " is not valid.");
6898 return null;
6899 }
6900 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006901 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006902 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006903 return null ;
6904 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006905 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006906 }
6907
Amith Yamasani6e118872016-02-19 12:53:51 -08006908 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006909 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006910 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006911 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006912 List<String> privilegedPackages = new ArrayList<>();
6913 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006914 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6915 // has UICC in that slot.
6916 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006917 if (card.hasCarrierPrivilegeRules()) {
6918 if (packages == null) {
6919 // Only check packages in user 0 for now
6920 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006921 PackageManager.MATCH_DISABLED_COMPONENTS
6922 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006923 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006924 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006925 }
6926 for (int p = packages.size() - 1; p >= 0; p--) {
6927 PackageInfo pkgInfo = packages.get(p);
6928 if (pkgInfo != null && pkgInfo.packageName != null
6929 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006930 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006931 privilegedPackages.add(pkgInfo.packageName);
6932 }
6933 }
6934 }
6935 }
6936 return privilegedPackages;
6937 }
6938
chen xuf7e9fe82019-05-09 19:31:02 -07006939 @Override
6940 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006941 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6942
6943 final long identity = Binder.clearCallingIdentity();
6944
chen xuf7e9fe82019-05-09 19:31:02 -07006945 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006946 try {
6947 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6948 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6949 }
6950 } finally {
6951 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006952 }
6953 return privilegedPackages;
6954 }
6955
Wink Savilleb564aae2014-10-23 10:18:09 -07006956 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006957 final Phone phone = getPhone(subId);
6958 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006959 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006960 return null;
6961 }
6962 String iccId = card.getIccId();
6963 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006964 return null;
6965 }
6966 return iccId;
6967 }
6968
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006969 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006970 public void setCallComposerStatus(int subId, int status) {
6971 enforceModifyPermission();
6972
6973 final long identity = Binder.clearCallingIdentity();
6974 try {
6975 Phone phone = getPhone(subId);
6976 if (phone != null) {
6977 Phone defaultPhone = phone.getImsPhone();
6978 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6979 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6980 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006981 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6982 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006983 }
6984 }
Shuo Qian284ae752020-12-22 19:10:14 -08006985 } catch (ImsException e) {
6986 throw new ServiceSpecificException(e.getCode());
6987 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006988 Binder.restoreCallingIdentity(identity);
6989 }
6990 }
6991
6992 @Override
6993 public int getCallComposerStatus(int subId) {
6994 enforceReadPrivilegedPermission("getCallComposerStatus");
6995
6996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 Phone phone = getPhone(subId);
6999 if (phone != null) {
7000 Phone defaultPhone = phone.getImsPhone();
7001 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7002 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7003 return imsPhone.getCallComposerStatus();
7004 }
7005 }
7006 } finally {
7007 Binder.restoreCallingIdentity(identity);
7008 }
7009 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7010 }
7011
7012 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007013 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7014 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007015 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007016 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 final long identity = Binder.clearCallingIdentity();
7019 try {
7020 final String iccId = getIccId(subId);
7021 final Phone phone = getPhone(subId);
7022 if (phone == null) {
7023 return false;
7024 }
7025 final String subscriberId = phone.getSubscriberId();
7026
7027 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007028 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 + subscriberId + " to " + number);
7030 }
7031
7032 if (TextUtils.isEmpty(iccId)) {
7033 return false;
7034 }
7035
7036 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7037
7038 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7039 if (alphaTag == null) {
7040 editor.remove(alphaTagPrefKey);
7041 } else {
7042 editor.putString(alphaTagPrefKey, alphaTag);
7043 }
7044
7045 // Record both the line number and IMSI for this ICCID, since we need to
7046 // track all merged IMSIs based on line number
7047 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7048 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7049 if (number == null) {
7050 editor.remove(numberPrefKey);
7051 editor.remove(subscriberPrefKey);
7052 } else {
7053 editor.putString(numberPrefKey, number);
7054 editor.putString(subscriberPrefKey, subscriberId);
7055 }
7056
7057 editor.commit();
7058 return true;
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007061 }
Derek Tan7226c842014-07-02 17:42:23 -07007062 }
7063
7064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007065 public String getLine1NumberForDisplay(int subId, String callingPackage,
7066 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007067 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007069 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007070 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007071 return null;
7072 }
Derek Tan97ebb422014-09-05 16:55:38 -07007073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 String iccId = getIccId(subId);
7077 if (iccId != null) {
7078 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7079 if (DBG_MERGE) {
7080 log("getLine1NumberForDisplay returning "
7081 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7082 }
7083 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007085 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7086 return null;
7087 } finally {
7088 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007089 }
Derek Tan7226c842014-07-02 17:42:23 -07007090 }
7091
7092 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007093 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7094 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007095 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007096 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007097 return null;
7098 }
Derek Tan97ebb422014-09-05 16:55:38 -07007099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100 final long identity = Binder.clearCallingIdentity();
7101 try {
7102 String iccId = getIccId(subId);
7103 if (iccId != null) {
7104 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7105 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7106 }
7107 return null;
7108 } finally {
7109 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007110 }
Derek Tan7226c842014-07-02 17:42:23 -07007111 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007112
7113 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007114 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7115 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007116 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7117 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007119 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007120 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007121 return null;
7122 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007123
Jordan Liub49b04b2019-05-06 14:45:15 -07007124 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7125 // the process, where TelephonyManager was instantiated.
7126 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007127 final long identity = Binder.clearCallingIdentity();
7128 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007129 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130 final TelephonyManager tele = TelephonyManager.from(context);
7131 final SubscriptionManager sub = SubscriptionManager.from(context);
7132
7133 // Figure out what subscribers are currently active
7134 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007135
Jordan Liub49b04b2019-05-06 14:45:15 -07007136 // Only consider subs which match the current subId
7137 // This logic can be simplified. See b/131189269 for progress.
7138 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007139 activeSubscriberIds.add(tele.getSubscriberId(subId));
7140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141
7142 // First pass, find a number override for an active subscriber
7143 String mergeNumber = null;
7144 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7145 for (String key : prefs.keySet()) {
7146 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7147 final String subscriberId = (String) prefs.get(key);
7148 if (activeSubscriberIds.contains(subscriberId)) {
7149 final String iccId = key.substring(
7150 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7151 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7152 mergeNumber = (String) prefs.get(numberKey);
7153 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007154 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 + " for active subscriber " + subscriberId);
7156 }
7157 if (!TextUtils.isEmpty(mergeNumber)) {
7158 break;
7159 }
7160 }
7161 }
7162 }
7163
7164 // Shortcut when no active merged subscribers
7165 if (TextUtils.isEmpty(mergeNumber)) {
7166 return null;
7167 }
7168
7169 // Second pass, find all subscribers under that line override
7170 final ArraySet<String> result = new ArraySet<>();
7171 for (String key : prefs.keySet()) {
7172 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7173 final String number = (String) prefs.get(key);
7174 if (mergeNumber.equals(number)) {
7175 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7176 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7177 final String subscriberId = (String) prefs.get(subscriberKey);
7178 if (!TextUtils.isEmpty(subscriberId)) {
7179 result.add(subscriberId);
7180 }
7181 }
7182 }
7183 }
7184
7185 final String[] resultArray = result.toArray(new String[result.size()]);
7186 Arrays.sort(resultArray);
7187 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007188 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7190 }
7191 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007192 } finally {
7193 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007194 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007195 }
7196
7197 @Override
zoey chen38003472019-12-13 17:16:31 +08007198 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7199 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007200
7201 final long identity = Binder.clearCallingIdentity();
7202 try {
7203 final TelephonyManager telephonyManager = mApp.getSystemService(
7204 TelephonyManager.class);
7205 String subscriberId = telephonyManager.getSubscriberId(subId);
7206 if (subscriberId == null) {
7207 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007208 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007209 + subId);
7210 }
7211 return null;
7212 }
7213
7214 final SubscriptionInfo info = SubscriptionController.getInstance()
7215 .getSubscriptionInfo(subId);
7216 final ParcelUuid groupUuid = info.getGroupUuid();
7217 // If it doesn't belong to any group, return just subscriberId of itself.
7218 if (groupUuid == null) {
7219 return new String[]{subscriberId};
7220 }
7221
7222 // Get all subscriberIds from the group.
7223 final List<String> mergedSubscriberIds = new ArrayList<>();
7224 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007225 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007226 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007227 for (SubscriptionInfo subInfo : groupInfos) {
7228 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7229 if (subscriberId != null) {
7230 mergedSubscriberIds.add(subscriberId);
7231 }
7232 }
7233
7234 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237
7238 }
7239 }
7240
7241 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007242 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007243 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007244 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245
7246 final long identity = Binder.clearCallingIdentity();
7247 try {
7248 final Phone phone = getPhone(subId);
7249 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7250 } finally {
7251 Binder.restoreCallingIdentity(identity);
7252 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007253 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007254
7255 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007256 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007257 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7258 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007259 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7260 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007261
7262 final long identity = Binder.clearCallingIdentity();
7263 try {
7264 final Phone phone = getPhone(subId);
7265 if (phone == null) {
7266 return false;
7267 }
7268 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7269 cdmaNonRoamingList);
7270 } finally {
7271 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007272 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007273 }
7274
7275 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007276 @Deprecated
7277 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7278 enforceModifyPermission();
7279
7280 int returnValue = 0;
7281 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007282 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007283 if(result.exception == null) {
7284 if (result.result != null) {
7285 byte[] responseData = (byte[])(result.result);
7286 if(responseData.length > oemResp.length) {
7287 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7288 responseData.length + "bytes. Buffer Size is " +
7289 oemResp.length + "bytes.");
7290 }
7291 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7292 returnValue = responseData.length;
7293 }
7294 } else {
7295 CommandException ex = (CommandException) result.exception;
7296 returnValue = ex.getCommandError().ordinal();
7297 if(returnValue > 0) returnValue *= -1;
7298 }
7299 } catch (RuntimeException e) {
7300 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7301 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7302 if(returnValue > 0) returnValue *= -1;
7303 }
7304
7305 return returnValue;
7306 }
7307
7308 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007309 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007310 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007311 try {
7312 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007313 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007314 mApp, phone.getSubId(), "getRadioAccessFamily");
7315 } catch (SecurityException e) {
7316 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7317 throw e;
7318 }
chen xub97461a2018-10-26 14:17:57 -07007319 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007320 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007321 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007322 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007323 final long identity = Binder.clearCallingIdentity();
7324 try {
chen xub97461a2018-10-26 14:17:57 -07007325 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007326 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007327 mApp, phone.getSubId(), "getRadioAccessFamily");
7328 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 } finally {
7330 Binder.restoreCallingIdentity(identity);
7331 }
chen xub97461a2018-10-26 14:17:57 -07007332 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007333 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007334
7335 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007336 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007337 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007338 try {
7339 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7340 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007341 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007342 }
7343 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007344 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007345 }
7346 RoleManager rm = mApp.getSystemService(RoleManager.class);
7347 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7348 if (!dialerRoleHolders.contains(callingPackage)) {
7349 throw new SecurityException("App must be the dialer role holder to"
7350 + " upload a call composer pic");
7351 }
7352
7353 Executors.newSingleThreadExecutor().execute(() -> {
7354 ByteArrayOutputStream output = new ByteArrayOutputStream(
7355 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7356 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7357 boolean readUntilEnd = false;
7358 int totalBytesRead = 0;
7359 byte[] buffer = new byte[16 * 1024];
7360 while (true) {
7361 int numRead;
7362 try {
7363 numRead = input.read(buffer);
7364 } catch (IOException e) {
7365 try {
7366 fd.checkError();
7367 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7368 null);
7369 } catch (IOException e1) {
7370 // This means that the other side closed explicitly with an error. If this
7371 // happens, log and ignore.
7372 loge("Remote end of call composer picture pipe closed: " + e1);
7373 }
7374 break;
7375 }
7376 if (numRead == -1) {
7377 readUntilEnd = true;
7378 break;
7379 }
7380 totalBytesRead += numRead;
7381 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7382 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7383 try {
7384 input.close();
7385 } catch (IOException e) {
7386 // ignore
7387 }
7388 break;
7389 }
7390 output.write(buffer, 0, numRead);
7391 }
7392 // Generally, the remote end will close the file descriptors. The only case where we
7393 // close is above, where the picture size is too big.
7394
7395 try {
7396 fd.checkError();
7397 } catch (IOException e) {
7398 loge("Remote end for call composer closed with an error: " + e);
7399 return;
7400 }
7401
Hall Liuaa4211e2021-01-20 15:43:39 -08007402 if (!readUntilEnd) {
7403 loge("Did not finish reading entire image; aborting");
7404 return;
7405 }
Hall Liu82694d52020-12-11 18:22:04 -08007406
Hall Liuaa4211e2021-01-20 15:43:39 -08007407 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7408 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7409 new CallComposerPictureTransfer.Factory() {},
7410 imageData,
7411 (result) -> {
7412 if (result.first != null) {
7413 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7414 Bundle outputResult = new Bundle();
7415 outputResult.putParcelable(
7416 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7417 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7418 outputResult);
7419 } else {
7420 callback.send(result.second, null);
7421 }
7422 }
7423 );
Hall Liu82694d52020-12-11 18:22:04 -08007424 });
7425 }
7426
7427 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007428 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007429 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007431
7432 final long identity = Binder.clearCallingIdentity();
7433 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007434 ImsManager.getInstance(defaultPhone.getContext(),
7435 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007439 }
7440
7441 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007442 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007443 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007444 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7445 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007446 return false;
7447 }
Svet Ganovb320e182015-04-16 12:30:10 -07007448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 final long identity = Binder.clearCallingIdentity();
7450 try {
7451 // Check the user preference and the system-level IMS setting. Even if the user has
7452 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7453 // In the long run, we may instead need to check if there exists a connection service
7454 // which can support video calling.
7455 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007456 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007457 return imsManager.isVtEnabledByPlatform()
7458 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7459 && imsManager.isVtEnabledByUser();
7460 } finally {
7461 Binder.restoreCallingIdentity(identity);
7462 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007463 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007464
Andrew Leea1239f22015-03-02 17:44:07 -08007465 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007466 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7467 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007469 mApp, subId, callingPackage, callingFeatureId,
7470 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 return false;
7472 }
7473
7474 final long identity = Binder.clearCallingIdentity();
7475 try {
7476 CarrierConfigManager configManager =
7477 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007478 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482 }
Andrew Leea1239f22015-03-02 17:44:07 -08007483 }
7484
7485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007486 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007488 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 return false;
7490 }
7491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
7494 CarrierConfigManager configManager =
7495 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007496 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7498 } finally {
7499 Binder.restoreCallingIdentity(identity);
7500 }
Andrew Leea1239f22015-03-02 17:44:07 -08007501 }
7502
Andrew Lee9431b832015-03-09 18:46:45 -07007503 @Override
7504 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007505 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007506 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007507 }
7508
7509 @Override
7510 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 final long identity = Binder.clearCallingIdentity();
7512 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007513 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 } finally {
7515 Binder.restoreCallingIdentity(identity);
7516 }
Andrew Lee9431b832015-03-09 18:46:45 -07007517 }
7518
Hall Liuf6668912018-10-31 17:05:23 -07007519 /**
7520 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7521 * support for the feature and device firmware support.
7522 *
7523 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7524 */
7525 @Override
7526 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007528 final Phone phone = getPhone(subscriptionId);
7529 if (phone == null) {
7530 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7531 return false;
7532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007534 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007535 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7536 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007537 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 return isCarrierSupported && isDeviceSupported;
7539 } finally {
7540 Binder.restoreCallingIdentity(identity);
7541 }
Hall Liu98187582018-01-22 19:15:32 -08007542 }
7543
Hall Liuf6668912018-10-31 17:05:23 -07007544 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007545 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7546 * RTT setting, will return true if the device and carrier both support RTT.
7547 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007548 */
7549 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550 final long identity = Binder.clearCallingIdentity();
7551 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007552 boolean isRttSupported = isRttSupported(subscriptionId);
7553 boolean isUserRttSettingOn = Settings.Secure.getInt(
7554 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7555 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7556 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7557 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 } finally {
7559 Binder.restoreCallingIdentity(identity);
7560 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007561 }
7562
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007563 @Deprecated
7564 @Override
7565 public String getDeviceId(String callingPackage) {
7566 return getDeviceIdWithFeature(callingPackage, null);
7567 }
7568
Sanket Padawe7310cc72015-01-14 09:53:20 -08007569 /**
7570 * Returns the unique device ID of phone, for example, the IMEI for
7571 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7572 *
7573 * <p>Requires Permission:
7574 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7575 */
7576 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007577 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007578 try {
7579 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7580 } catch (SecurityException se) {
7581 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7582 throw new SecurityException("Package " + callingPackage + " does not belong to "
7583 + Binder.getCallingUid());
7584 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007585 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007586 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007587 return null;
7588 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007589 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007590 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007591 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007592 return null;
7593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007594
7595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 return phone.getDeviceId();
7598 } finally {
7599 Binder.restoreCallingIdentity(identity);
7600 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007601 }
7602
Ping Sunc67b7c22016-03-02 19:16:45 +08007603 /**
7604 * {@hide}
7605 * Returns the IMS Registration Status on a particular subid
7606 *
7607 * @param subId
7608 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007609 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007610 Phone phone = getPhone(subId);
7611 if (phone != null) {
7612 return phone.isImsRegistered();
7613 } else {
7614 return false;
7615 }
7616 }
7617
Santos Cordon7a1885b2015-02-03 11:15:19 -08007618 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007619 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007620 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007622 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007623 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7624 }
7625 final long identity = Binder.clearCallingIdentity();
7626 try {
7627 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7628 } finally {
7629 Binder.restoreCallingIdentity(identity);
7630 }
7631 }
7632
7633 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007634 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007635 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007636 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007637 mApp,
7638 subscriptionId,
7639 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007640 final long identity = Binder.clearCallingIdentity();
7641 try {
7642 Phone phone = getPhone(subscriptionId);
7643 if (phone == null) {
7644 return null;
7645 }
7646 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7647 } finally {
7648 Binder.restoreCallingIdentity(identity);
7649 }
7650 }
7651
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007652 /**
7653 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007654 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007655 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 final long identity = Binder.clearCallingIdentity();
7657 try {
7658 Phone phone = getPhone(subId);
7659 if (phone != null) {
7660 return phone.isWifiCallingEnabled();
7661 } else {
7662 return false;
7663 }
7664 } finally {
7665 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007666 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007667 }
7668
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007669 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007670 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007671 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007672 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673 final long identity = Binder.clearCallingIdentity();
7674 try {
7675 Phone phone = getPhone(subId);
7676 if (phone != null) {
7677 return phone.isVideoEnabled();
7678 } else {
7679 return false;
7680 }
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007683 }
7684 }
7685
7686 /**
7687 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7688 * defined in {@link ImsRegistrationImplBase}.
7689 */
7690 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 Phone phone = getPhone(subId);
7694 if (phone != null) {
7695 return phone.getImsRegistrationTech();
7696 } else {
7697 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7698 }
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007701 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007702 }
7703
Stuart Scott8eef64f2015-04-08 15:13:54 -07007704 @Override
7705 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007706 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007707 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7708 return;
7709 }
Kai Shif70f46f2021-03-03 13:59:46 -08007710 Phone defaultPhone = getDefaultPhone();
7711 if (defaultPhone != null) {
7712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7713 mApp, getDefaultPhone().getSubId(), "factoryReset");
7714 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007715 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007716
Svet Ganovcc087f82015-05-12 20:35:54 -07007717 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007718 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7719 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007720 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007721 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007722 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007723 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007724 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007725 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007726 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007727 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007728 // There has been issues when Sms raw table somehow stores orphan
7729 // fragments. They lead to garbled message when new fragments come
7730 // in and combined with those stale ones. In case this happens again,
7731 // user can reset all network settings which will clean up this table.
7732 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007733 // Clean up IMS settings as well here.
7734 int slotId = getSlotIndex(subId);
7735 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7736 ImsManager.getInstance(mApp, slotId).factoryReset();
7737 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007738
Kai Shif70f46f2021-03-03 13:59:46 -08007739 if (defaultPhone == null) {
7740 return;
7741 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007742 // Erase modem config if erase modem on network setting is enabled.
7743 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7744 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7745 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007746 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007747 }
Kai Shif70f46f2021-03-03 13:59:46 -08007748
7749 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007750 } finally {
7751 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007752 }
7753 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007754
SongFerngWangfd89b102021-05-27 22:44:54 +08007755 @VisibleForTesting
7756 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7757 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7758 return;
7759 }
7760 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7761 RILConstants.PREFERRED_NETWORK_MODE);
7762 SubscriptionManager.setSubscriptionProperty(subId,
7763 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7764 "user=" + defaultNetworkType);
7765 phone.loadAllowedNetworksFromSubscriptionDatabase();
7766 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7767 defaultNetworkType, null);
7768 }
7769
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007770 private void cleanUpSmsRawTable(Context context) {
7771 ContentResolver resolver = context.getContentResolver();
7772 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7773 resolver.delete(uri, null, null);
7774 }
7775
Narayan Kamath1c496c22015-04-16 14:40:19 +01007776 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007777 public String getSimLocaleForSubscriber(int subId) {
7778 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7779 final Phone phone = getPhone(subId);
7780 if (phone == null) {
7781 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007782 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 final long identity = Binder.clearCallingIdentity();
7785 try {
chen xu5d3637b2019-01-21 23:31:38 -08007786 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007787 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007788 if (info == null) {
7789 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7790 return null;
7791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 // Try and fetch the locale from the carrier properties or from the SIM language
7793 // preferences (EF-PL and EF-LI)...
7794 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007796 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7797 if (localeFromDefaultSim != null) {
7798 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7799 if (DBG) log("Using locale from subId: " + subId + " locale: "
7800 + localeFromDefaultSim);
7801 return localeFromDefaultSim.toLanguageTag();
7802 } else {
7803 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804 }
7805 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007806
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007807 // The SIM language preferences only store a language (e.g. fr = French), not an
7808 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7809 // the SIM and carrier preferences does not include a country we add the country
7810 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007811 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007813 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 return mccLocale.toLanguageTag();
7815 }
7816
7817 if (DBG) log("No locale found - returning null");
7818 return null;
7819 } finally {
7820 Binder.restoreCallingIdentity(identity);
7821 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007822 }
7823
7824 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007825 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007826 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007827 }
7828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 /**
7830 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7831 */
7832 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007833 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007834 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007835 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007836
Chenjie Yu1ba97252018-01-11 18:16:20 -08007837 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007838 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007839
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007840 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007841 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7842 * representing the state of the modem.
7843 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007844 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7845 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007846 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007847 */
7848 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007849 public void requestModemActivityInfo(ResultReceiver result) {
7850 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007851 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007852
7853 final long identity = Binder.clearCallingIdentity();
7854 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007855 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856 } finally {
7857 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007858 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007859 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007860
Siddharth Rayb8114062018-06-17 15:02:38 -07007861 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7862 // less than total activity duration.
7863 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7864 if (info == null) {
7865 return false;
7866 }
7867 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007868 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7869 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7870
Siddharth Rayb8114062018-06-17 15:02:38 -07007871 return (info.isValid()
7872 && (info.getSleepTimeMillis() <= activityDurationMs)
7873 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007874 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007875 && (totalTxTimeMs <= activityDurationMs));
7876 }
7877
Jack Yu85bd38a2015-11-09 11:34:32 -08007878 /**
7879 * {@hide}
7880 * Returns the service state information on specified subscription.
7881 */
7882 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007883 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7884 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007886 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007887 return null;
7888 }
7889
Hall Liuf19c44f2018-11-27 14:38:17 -08007890 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7891 LocationAccessPolicy.checkLocationPermission(mApp,
7892 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7893 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007894 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007895 .setCallingPid(Binder.getCallingPid())
7896 .setCallingUid(Binder.getCallingUid())
7897 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007898 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007899 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007900 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7901 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007902 .build());
7903
7904 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7905 LocationAccessPolicy.checkLocationPermission(mApp,
7906 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7907 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007908 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007909 .setCallingPid(Binder.getCallingPid())
7910 .setCallingUid(Binder.getCallingUid())
7911 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007912 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007913 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007914 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7915 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007916 .build());
7917 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7918 boolean hasFinePermission =
7919 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7920 boolean hasCoarsePermission =
7921 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7922
Jack Yu479f40e2020-10-27 21:29:25 -07007923 final Phone phone = getPhone(subId);
7924 if (phone == null) {
7925 return null;
7926 }
7927
Jordan Liu0f2bc442020-11-18 16:47:37 -08007928 final long identity = Binder.clearCallingIdentity();
7929
Jack Yu479f40e2020-10-27 21:29:25 -07007930 boolean isCallingPackageDataService = phone.getDataServicePackages()
7931 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007933 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7934 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7935 Rlog.d(LOG_TAG,
7936 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7937 return null;
7938 }
7939
Hall Liuf19c44f2018-11-27 14:38:17 -08007940 ServiceState ss = phone.getServiceState();
7941
7942 // Scrub out the location info in ServiceState depending on what level of access
7943 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007944 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007945 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7946 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007947 } finally {
7948 Binder.restoreCallingIdentity(identity);
7949 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007950 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007951
7952 /**
7953 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7954 *
7955 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7956 * voicemail ringtone.
7957 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7958 * PhoneAccount.
7959 */
7960 @Override
7961 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007962 final long identity = Binder.clearCallingIdentity();
7963 try {
7964 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7965 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007966 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007967 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7970 } finally {
7971 Binder.restoreCallingIdentity(identity);
7972 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007973 }
7974
7975 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007976 * Sets the per-account voicemail ringtone.
7977 *
7978 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7979 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7980 *
7981 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7982 * voicemail ringtone.
7983 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7984 * PhoneAccount.
7985 */
7986 @Override
7987 public void setVoicemailRingtoneUri(String callingPackage,
7988 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007989 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007990 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007991 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7992 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7994 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7995 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997
7998 final long identity = Binder.clearCallingIdentity();
7999 try {
8000 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8001 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008002 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 }
8004 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8005 } finally {
8006 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008007 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008008 }
8009
8010 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008011 * Returns whether vibration is set for voicemail notification in Phone settings.
8012 *
8013 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8014 * voicemail vibration setting.
8015 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8016 */
8017 @Override
8018 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 final long identity = Binder.clearCallingIdentity();
8020 try {
8021 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8022 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008023 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8027 } finally {
8028 Binder.restoreCallingIdentity(identity);
8029 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008030 }
8031
Youhan Wange64578a2016-05-02 15:32:42 -07008032 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008033 * Sets the per-account voicemail vibration.
8034 *
8035 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8036 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8037 *
8038 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8039 * voicemail vibration setting.
8040 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8041 * specific PhoneAccount.
8042 */
8043 @Override
8044 public void setVoicemailVibrationEnabled(String callingPackage,
8045 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008046 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008047 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008048 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8049 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8051 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8052 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008053 }
8054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008055 final long identity = Binder.clearCallingIdentity();
8056 try {
8057 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8058 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008059 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060 }
8061 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8062 } finally {
8063 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008064 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008065 }
8066
8067 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008068 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8069 *
8070 * @throws SecurityException if the caller does not have the required permission
8071 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008072 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008073 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008074 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008075 }
8076
8077 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008078 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8079 * permission.
8080 *
8081 * @throws SecurityException if the caller does not have the required permission
8082 */
8083 private void enforceSendSmsPermission() {
8084 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8085 }
8086
8087 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008088 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008089 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008090 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008091 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008092 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008093 final long identity = Binder.clearCallingIdentity();
8094 try {
8095 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008096 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 if (componentName == null) {
8098 throw new SecurityException(
8099 "Caller not current active visual voicemail package[null]");
8100 }
8101 String vvmPackage = componentName.getPackageName();
8102 if (!callingPackage.equals(vvmPackage)) {
8103 throw new SecurityException("Caller not current active visual voicemail package["
8104 + vvmPackage + "]");
8105 }
8106 } finally {
8107 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008108 }
8109 }
8110
8111 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008112 * Return the application ID for the app type.
8113 *
8114 * @param subId the subscription ID that this request applies to.
8115 * @param appType the uicc app type.
8116 * @return Application ID for specificied app type, or null if no uicc.
8117 */
8118 @Override
8119 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008120 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008121 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008122
8123 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008124 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008125 if (phone == null) {
8126 return null;
8127 }
8128 String aid = null;
8129 try {
8130 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8131 .getApplicationByType(appType).getAid();
8132 } catch (Exception e) {
8133 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8134 }
8135 return aid;
8136 } finally {
8137 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008138 }
Youhan Wange64578a2016-05-02 15:32:42 -07008139 }
8140
Youhan Wang4001d252016-05-11 10:29:41 -07008141 /**
8142 * Return the Electronic Serial Number.
8143 *
8144 * @param subId the subscription ID that this request applies to.
8145 * @return ESN or null if error.
8146 */
8147 @Override
8148 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008149 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008150 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151
8152 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008153 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008154 if (phone == null) {
8155 return null;
8156 }
8157 String esn = null;
8158 try {
8159 esn = phone.getEsn();
8160 } catch (Exception e) {
8161 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8162 }
8163 return esn;
8164 } finally {
8165 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008166 }
Youhan Wang4001d252016-05-11 10:29:41 -07008167 }
8168
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008169 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008170 * Return the Preferred Roaming List Version.
8171 *
8172 * @param subId the subscription ID that this request applies to.
8173 * @return PRLVersion or null if error.
8174 */
8175 @Override
8176 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008177 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008178 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179
8180 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008181 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008182 if (phone == null) {
8183 return null;
8184 }
8185 String cdmaPrlVersion = null;
8186 try {
8187 cdmaPrlVersion = phone.getCdmaPrlVersion();
8188 } catch (Exception e) {
8189 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8190 }
8191 return cdmaPrlVersion;
8192 } finally {
8193 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008194 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008195 }
8196
8197 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008198 * Get snapshot of Telephony histograms
8199 * @return List of Telephony histograms
8200 * @hide
8201 */
8202 @Override
8203 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8205 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206
8207 final long identity = Binder.clearCallingIdentity();
8208 try {
8209 return RIL.getTelephonyRILTimingHistograms();
8210 } finally {
8211 Binder.restoreCallingIdentity(identity);
8212 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008213 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008214
8215 /**
8216 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008217 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8218 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008219 * Require system privileges. In the future we may add this to carrier APIs.
8220 *
Michele Berionne482f8202018-11-27 18:57:59 -08008221 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008222 */
8223 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008224 @TelephonyManager.SetCarrierRestrictionResult
8225 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008226 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008227 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008228
Michele Berionne482f8202018-11-27 18:57:59 -08008229 if (carrierRestrictionRules == null) {
8230 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008231 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008233 final long identity = Binder.clearCallingIdentity();
8234 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008235 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008236 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008237 } finally {
8238 Binder.restoreCallingIdentity(identity);
8239 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008240 }
8241
8242 /**
8243 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008244 * Get the allowed carrier list and the excluded carrier list, including the priority between
8245 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008246 * Require system privileges. In the future we may add this to carrier APIs.
8247 *
Michele Berionne482f8202018-11-27 18:57:59 -08008248 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008249 */
8250 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008251 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008252 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008253 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254
8255 final long identity = Binder.clearCallingIdentity();
8256 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008257 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8258 if (response instanceof CarrierRestrictionRules) {
8259 return (CarrierRestrictionRules) response;
8260 }
8261 // Response is an Exception of some kind,
8262 // which is signalled to the user as a NULL retval
8263 return null;
8264 } catch (Exception e) {
8265 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8266 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 } finally {
8268 Binder.restoreCallingIdentity(identity);
8269 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008270 }
8271
fionaxu59545b42016-05-25 15:53:37 -07008272 /**
fionaxu59545b42016-05-25 15:53:37 -07008273 * Action set from carrier signalling broadcast receivers to enable/disable radio
8274 * @param subId the subscription ID that this action applies to.
8275 * @param enabled control enable or disable radio.
8276 * {@hide}
8277 */
8278 @Override
8279 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8280 enforceModifyPermission();
8281 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008282
8283 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008284 if (phone == null) {
8285 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8286 return;
8287 }
8288 try {
8289 phone.carrierActionSetRadioEnabled(enabled);
8290 } catch (Exception e) {
8291 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 } finally {
8293 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008294 }
8295 }
8296
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008297 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008298 * Enable or disable Voice over NR (VoNR)
8299 * @param subId the subscription ID that this action applies to.
8300 * @param enabled enable or disable VoNR.
8301 * @return operation result.
8302 */
8303 @Override
8304 public int setVoNrEnabled(int subId, boolean enabled) {
8305 enforceModifyPermission();
8306 final Phone phone = getPhone(subId);
8307
8308 final long identity = Binder.clearCallingIdentity();
8309 if (phone == null) {
8310 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8311 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8312 }
8313
8314 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8315 try {
8316 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8317 workSource);
8318 if (DBG) log("setVoNrEnabled result: " + result);
8319 return result;
8320 } finally {
8321 Binder.restoreCallingIdentity(identity);
8322 }
8323 }
8324
8325 /**
8326 * Is voice over NR enabled
8327 * @return true if VoNR is enabled else false
8328 */
8329 @Override
8330 public boolean isVoNrEnabled(int subId) {
8331 enforceReadPrivilegedPermission("isVoNrEnabled");
8332 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8336 null, subId, workSource);
8337 if (DBG) log("isVoNrEnabled: " + isEnabled);
8338 return isEnabled;
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
8342 }
8343
8344 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008345 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8346 * network status based on which carrier apps could apply actions accordingly,
8347 * enable/disable default url handler for example.
8348 *
8349 * @param subId the subscription ID that this action applies to.
8350 * @param report control start/stop reporting the default network status.
8351 * {@hide}
8352 */
8353 @Override
8354 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8355 enforceModifyPermission();
8356 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008357
8358 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008359 if (phone == null) {
8360 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8361 return;
8362 }
8363 try {
8364 phone.carrierActionReportDefaultNetworkStatus(report);
8365 } catch (Exception e) {
8366 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367 } finally {
8368 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008369 }
8370 }
8371
8372 /**
fionaxud9622282017-07-17 17:51:30 -07008373 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8374 * @param subId the subscription ID that this action applies to.
8375 * {@hide}
8376 */
8377 @Override
8378 public void carrierActionResetAll(int subId) {
8379 enforceModifyPermission();
8380 final Phone phone = getPhone(subId);
8381 if (phone == null) {
8382 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8383 return;
8384 }
8385 try {
8386 phone.carrierActionResetAll();
8387 } catch (Exception e) {
8388 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8389 }
8390 }
8391
8392 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008393 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8394 * bug report is being generated.
8395 */
8396 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008397 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008398 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8399 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008400 writer.println("Permission Denial: can't dump Phone from pid="
8401 + Binder.getCallingPid()
8402 + ", uid=" + Binder.getCallingUid()
8403 + "without permission "
8404 + android.Manifest.permission.DUMP);
8405 return;
8406 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008407 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008408 }
Jack Yueb89b242016-06-22 13:27:47 -07008409
Brad Ebingerdac2f002018-04-03 15:17:52 -07008410 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008411 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8412 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8413 @NonNull String[] args) {
8414 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8415 this, in.getFileDescriptor(), out.getFileDescriptor(),
8416 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008417 }
8418
Jack Yueb89b242016-06-22 13:27:47 -07008419 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008420 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008421 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008422 * @param reason the reason the data enable change is taking place
8423 * @param enabled True if enabling the data, otherwise disabling.
8424 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008425 */
8426 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008427 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008428 boolean enabled) {
8429 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8430 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8431 try {
8432 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008433 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008434 } catch (SecurityException se) {
8435 enforceModifyPermission();
8436 }
8437 } else {
8438 enforceModifyPermission();
8439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008440
8441 final long identity = Binder.clearCallingIdentity();
8442 try {
8443 Phone phone = getPhone(subId);
8444 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008445 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8446 phone.carrierActionSetMeteredApnsEnabled(enabled);
8447 } else {
8448 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008450 }
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008453 }
8454 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008455
8456 /**
8457 * Get Client request stats
8458 * @return List of Client Request Stats
8459 * @hide
8460 */
8461 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008462 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8463 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008465 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008466 return null;
8467 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008468 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008470 final long identity = Binder.clearCallingIdentity();
8471 try {
8472 if (phone != null) {
8473 return phone.getClientRequestStats();
8474 }
8475
8476 return null;
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
8479 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008480 }
8481
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008482 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008483 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008484 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008485 }
Jack Yueb4124c2017-02-16 15:32:43 -08008486
8487 /**
Grace Chen70990072017-03-24 17:21:30 -07008488 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008489 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008490 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008491 * @param state State of SIM (power down, power up, pass through)
8492 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8493 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8494 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008495 *
8496 **/
8497 @Override
Grace Chen70990072017-03-24 17:21:30 -07008498 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008499 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008500 Phone phone = PhoneFactory.getPhone(slotIndex);
8501
vagdeviaf9a5b92018-08-15 16:01:53 -07008502 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8503
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008504 final long identity = Binder.clearCallingIdentity();
8505 try {
8506 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008507 phone.setSimPowerState(state, null, workSource);
8508 }
8509 } finally {
8510 Binder.restoreCallingIdentity(identity);
8511 }
8512 }
8513
8514 /**
8515 * Set SIM card power state.
8516 *
8517 * @param slotIndex SIM slot id.
8518 * @param state State of SIM (power down, power up, pass through)
8519 * @param callback callback to trigger after success or failure
8520 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8521 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8522 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8523 *
8524 **/
8525 @Override
8526 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8527 IIntegerConsumer callback) {
8528 enforceModifyPermission();
8529 Phone phone = PhoneFactory.getPhone(slotIndex);
8530
8531 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8532
8533 final long identity = Binder.clearCallingIdentity();
8534 try {
8535 if (phone != null) {
8536 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8537 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008538 }
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008541 }
8542 }
Shuo Qiandd210312017-04-12 22:11:33 +00008543
Tyler Gunn65d45c22017-06-05 11:22:26 -07008544 private boolean isUssdApiAllowed(int subId) {
8545 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008546 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008547 if (configManager == null) {
8548 return false;
8549 }
8550 PersistableBundle pb = configManager.getConfigForSubId(subId);
8551 if (pb == null) {
8552 return false;
8553 }
8554 return pb.getBoolean(
8555 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8556 }
8557
Shuo Qiandd210312017-04-12 22:11:33 +00008558 /**
8559 * Check if phone is in emergency callback mode
8560 * @return true if phone is in emergency callback mode
8561 * @param subId sub id
8562 */
goneil9c5f4872017-12-05 14:07:56 -08008563 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008564 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008565 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008566 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008567
8568 final long identity = Binder.clearCallingIdentity();
8569 try {
8570 if (phone != null) {
8571 return phone.isInEcm();
8572 } else {
8573 return false;
8574 }
8575 } finally {
8576 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008577 }
8578 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008579
8580 /**
8581 * Get the current signal strength information for the given subscription.
8582 * Because this information is not updated when the device is in a low power state
8583 * it should not be relied-upon to be current.
8584 * @param subId Subscription index
8585 * @return the most recent cached signal strength info from the modem
8586 */
8587 @Override
8588 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008589 final long identity = Binder.clearCallingIdentity();
8590 try {
8591 Phone p = getPhone(subId);
8592 if (p == null) {
8593 return null;
8594 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 return p.getSignalStrength();
8597 } finally {
8598 Binder.restoreCallingIdentity(identity);
8599 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008600 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008601
Pengquan Meng77b7f132018-08-22 14:49:57 -07008602 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008603 * Get the current modem radio state for the given slot.
8604 * @param slotIndex slot index.
8605 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008606 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008607 * @return the current radio power state from the modem
8608 */
8609 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008610 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008611 Phone phone = PhoneFactory.getPhone(slotIndex);
8612 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8614 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008615 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8616 }
8617
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 return phone.getRadioPowerState();
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
8625 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8626 }
8627
8628 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008629 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8630 *
8631 * <p>Requires one of the following permissions:
8632 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8633 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8634 * privileges.
8635 *
8636 * @param subId subscription id
8637 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8638 * {@code false}.
8639 */
8640 @Override
8641 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008642 try {
8643 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8644 null);
8645 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008646 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008647 mApp, subId, "isDataRoamingEnabled");
8648 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008649
Pengquan Menga1bb6272018-09-06 09:59:22 -07008650 boolean isEnabled = false;
8651 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008652 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008653 Phone phone = getPhone(subId);
8654 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008655 } finally {
8656 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008657 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008658 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008659 }
8660
8661
8662 /**
8663 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8664 *
8665 * <p> Requires permission:
8666 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8667 * privileges.
8668 *
8669 * @param subId subscription id
8670 * @param isEnabled {@code true} means enable, {@code false} means disable.
8671 */
8672 @Override
8673 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8675 mApp, subId, "setDataRoamingEnabled");
8676
Pengquan Menga1bb6272018-09-06 09:59:22 -07008677 final long identity = Binder.clearCallingIdentity();
8678 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008679 Phone phone = getPhone(subId);
8680 if (phone != null) {
8681 phone.setDataRoamingEnabled(isEnabled);
8682 }
8683 } finally {
8684 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008685 }
8686 }
8687
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008688 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008689 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008690 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008691 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008692 mApp, subId, "isManualNetworkSelectionAllowed");
8693
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008694 boolean isAllowed = true;
8695 final long identity = Binder.clearCallingIdentity();
8696 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008697 Phone phone = getPhone(subId);
8698 if (phone != null) {
8699 isAllowed = phone.isCspPlmnEnabled();
8700 }
8701 } finally {
8702 Binder.restoreCallingIdentity(identity);
8703 }
8704 return isAllowed;
8705 }
8706
8707 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008708 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008709 // Verify that tha callingPackage belongs to the calling UID
8710 mApp.getSystemService(AppOpsManager.class)
8711 .checkPackage(Binder.getCallingUid(), callingPackage);
8712
Jordan Liu1e142fc2019-04-22 15:10:43 -07008713 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008714 try {
8715 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008716 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008717 } catch (SecurityException e) {
8718 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8719 // has carrier privileges on an active UICC
8720 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8721 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008722 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008723 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008724 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008725
8726 final long identity = Binder.clearCallingIdentity();
8727 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008728 UiccController uiccController = UiccController.getInstance();
8729 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008730 if (hasReadPermission) {
8731 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008732 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008733
8734 // Remove private info if the caller doesn't have access
8735 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8736 for (UiccCardInfo cardInfo : cardInfos) {
8737 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8738 // is available
8739 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8740 if (card == null || card.getUiccProfile() == null) {
8741 // assume no access if the card or profile is unavailable
8742 filteredInfos.add(cardInfo.getUnprivileged());
8743 continue;
8744 }
8745 UiccProfile profile = card.getUiccProfile();
8746 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8747 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8748 filteredInfos.add(cardInfo);
8749 } else {
8750 filteredInfos.add(cardInfo.getUnprivileged());
8751 }
8752 }
8753 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
8758
8759 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008760 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008761 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008763 final long identity = Binder.clearCallingIdentity();
8764 try {
8765 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8766 if (slots == null) {
8767 Rlog.i(LOG_TAG, "slots is null.");
8768 return null;
8769 }
8770
8771 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8772 for (int i = 0; i < slots.length; i++) {
8773 UiccSlot slot = slots[i];
8774 if (slot == null) {
8775 continue;
8776 }
8777
Jordan Liu7be7e652019-05-06 18:55:02 +00008778 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008779 UiccCard card = slot.getUiccCard();
8780 if (card != null) {
8781 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008782 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008783 cardId = slot.getEid();
8784 if (TextUtils.isEmpty(cardId)) {
8785 cardId = slot.getIccId();
8786 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008787 }
8788
Jordan Liu857451f2019-05-09 16:35:35 -07008789 if (cardId != null) {
8790 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8791 // if cardId is an EID, it's all digits so this is fine
8792 cardId = IccUtils.stripTrailingFs(cardId);
8793 }
8794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008795 int cardState = 0;
8796 switch (slot.getCardState()) {
8797 case CARDSTATE_ABSENT:
8798 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8799 break;
8800 case CARDSTATE_PRESENT:
8801 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8802 break;
8803 case CARDSTATE_ERROR:
8804 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8805 break;
8806 case CARDSTATE_RESTRICTED:
8807 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8808 break;
8809 default:
8810 break;
8811
8812 }
8813
8814 infos[i] = new UiccSlotInfo(
8815 slot.isActive(),
8816 slot.isEuicc(),
8817 cardId,
8818 cardState,
8819 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008820 slot.isExtendedApduSupported(),
8821 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008822 }
8823 return infos;
8824 } finally {
8825 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008826 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008827 }
8828
8829 @Override
8830 public boolean switchSlots(int[] physicalSlots) {
8831 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008832
8833 final long identity = Binder.clearCallingIdentity();
8834 try {
8835 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8836 } finally {
8837 Binder.restoreCallingIdentity(identity);
8838 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008839 }
Jack Yu4c988042018-02-27 15:30:01 -08008840
8841 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008842 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008843 final long identity = Binder.clearCallingIdentity();
8844 try {
8845 return UiccController.getInstance().getCardIdForDefaultEuicc();
8846 } finally {
8847 Binder.restoreCallingIdentity(identity);
8848 }
8849 }
8850
Pengquan Meng85728fb2018-03-12 16:31:21 -07008851 /**
goneil47ffb6e2018-04-06 15:40:58 -07008852 * A test API to reload the UICC profile.
8853 *
8854 * <p>Requires that the calling app has permission
8855 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8856 * @hide
8857 */
8858 @Override
8859 public void refreshUiccProfile(int subId) {
8860 enforceModifyPermission();
8861
8862 final long identity = Binder.clearCallingIdentity();
8863 try {
8864 Phone phone = getPhone(subId);
8865 if (phone == null) {
8866 return;
8867 }
8868 UiccCard uiccCard = phone.getUiccCard();
8869 if (uiccCard == null) {
8870 return;
8871 }
8872 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8873 if (uiccProfile == null) {
8874 return;
8875 }
8876 uiccProfile.refresh();
8877 } finally {
8878 Binder.restoreCallingIdentity(identity);
8879 }
8880 }
8881
8882 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008883 * Returns false if the mobile data is disabled by default, otherwise return true.
8884 */
8885 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008886 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008887 }
8888
8889 /**
8890 * Returns true if the data roaming is enabled by default, i.e the system property
8891 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8892 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8893 */
8894 private boolean getDefaultDataRoamingEnabled(int subId) {
8895 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008896 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008897 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008898 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8899 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8900 return isDataRoamingEnabled;
8901 }
8902
8903 /**
8904 * Returns the default network type for the given {@code subId}, if the default network type is
8905 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8906 */
8907 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008908 List<Integer> list = TelephonyProperties.default_network();
8909 int phoneId = mSubscriptionController.getPhoneId(subId);
8910 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8911 return list.get(phoneId);
8912 }
8913 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008914 }
fionaxua13278b2018-03-21 00:08:13 -07008915
8916 @Override
8917 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008918 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008919 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008920
8921 final long identity = Binder.clearCallingIdentity();
8922 try {
8923 final Phone phone = getPhone(subId);
8924 if (phone == null) {
8925 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8926 return;
8927 }
chen xueaba88a2019-03-15 13:15:10 -07008928 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8929 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008930 if (carrierPrivilegeRules == null) {
8931 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8932 } else {
8933 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8934 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008935 } finally {
8936 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008937 }
fionaxua13278b2018-03-21 00:08:13 -07008938 }
8939
8940 @Override
8941 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008942 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008943
8944 final long identity = Binder.clearCallingIdentity();
8945 try {
8946 final Phone phone = getPhone(subId);
8947 if (phone == null) {
8948 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8949 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8950 }
8951 return phone.getCarrierIdListVersion();
8952 } finally {
8953 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008954 }
fionaxua13278b2018-03-21 00:08:13 -07008955 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008956
8957 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008958 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8959 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008961 mApp, subId, callingPackage, callingFeatureId,
8962 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008963 return -1;
8964 }
8965
8966 final long identity = Binder.clearCallingIdentity();
8967 try {
8968 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8969 } finally {
8970 Binder.restoreCallingIdentity(identity);
8971 }
8972 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008973
8974 @Override
8975 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008976 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008977 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008978 mApp, subId, "getCdmaRoamingMode");
8979
8980 final long identity = Binder.clearCallingIdentity();
8981 try {
8982 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8983 } finally {
8984 Binder.restoreCallingIdentity(identity);
8985 }
8986 }
8987
8988 @Override
8989 public boolean setCdmaRoamingMode(int subId, int mode) {
8990 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8991 mApp, subId, "setCdmaRoamingMode");
8992
8993 final long identity = Binder.clearCallingIdentity();
8994 try {
8995 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8996 } finally {
8997 Binder.restoreCallingIdentity(identity);
8998 }
8999 }
9000
9001 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009002 public int getCdmaSubscriptionMode(int subId) {
9003 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009004 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009005 mApp, subId, "getCdmaSubscriptionMode");
9006
9007 final long identity = Binder.clearCallingIdentity();
9008 try {
9009 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9010 } finally {
9011 Binder.restoreCallingIdentity(identity);
9012 }
9013 }
9014
9015 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009016 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9018 mApp, subId, "setCdmaSubscriptionMode");
9019
9020 final long identity = Binder.clearCallingIdentity();
9021 try {
9022 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009027
sqianc5eccab2018-10-19 18:46:41 -07009028 @Override
sqian8c685422019-02-22 15:55:18 -08009029 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009030 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009031 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009032 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9033 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009034 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9035 }
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
sqian854d44b2018-12-12 16:48:18 -08009038 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9039 for (Phone phone: PhoneFactory.getPhones()) {
9040 if (phone.getEmergencyNumberTracker() != null
9041 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9042 emergencyNumberListInternal.put(
9043 phone.getSubId(),
9044 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9045 }
sqian11b7a0e2018-12-05 18:48:28 -08009046 }
sqian854d44b2018-12-12 16:48:18 -08009047 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009048 } finally {
9049 Binder.restoreCallingIdentity(identity);
9050 }
sqianc5eccab2018-10-19 18:46:41 -07009051 }
9052
9053 @Override
sqian8c685422019-02-22 15:55:18 -08009054 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009055 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009056 if (!exactMatch) {
9057 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009058 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009059 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009060 }
9061 final long identity = Binder.clearCallingIdentity();
9062 try {
sqian854d44b2018-12-12 16:48:18 -08009063 for (Phone phone: PhoneFactory.getPhones()) {
9064 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009065 && phone.getEmergencyNumberTracker()
9066 .isEmergencyNumber(number, exactMatch)) {
9067 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009068 }
sqian11b7a0e2018-12-05 18:48:28 -08009069 }
9070 return false;
9071 } finally {
9072 Binder.restoreCallingIdentity(identity);
9073 }
9074 }
9075
sqianf4ca7ed2019-01-15 18:32:07 -08009076 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009077 * Start emergency callback mode for GsmCdmaPhone for testing.
9078 */
9079 @Override
9080 public void startEmergencyCallbackMode() {
9081 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9082 "startEmergencyCallbackMode");
9083 enforceModifyPermission();
9084 final long identity = Binder.clearCallingIdentity();
9085 try {
9086 for (Phone phone : PhoneFactory.getPhones()) {
9087 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9088 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9089 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9090 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9091 gsmCdmaPhone.obtainMessage(
9092 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9093 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9094 }
9095 }
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
9100
9101 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009102 * Update emergency number list for test mode.
9103 */
9104 @Override
9105 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9106 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9107 "updateEmergencyNumberListTestMode");
9108
9109 final long identity = Binder.clearCallingIdentity();
9110 try {
9111 for (Phone phone: PhoneFactory.getPhones()) {
9112 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9113 if (tracker != null) {
9114 tracker.executeEmergencyNumberTestModeCommand(action, num);
9115 }
9116 }
9117 } finally {
9118 Binder.restoreCallingIdentity(identity);
9119 }
9120 }
9121
9122 /**
9123 * Get the full emergency number list for test mode.
9124 */
9125 @Override
9126 public List<String> getEmergencyNumberListTestMode() {
9127 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9128 "getEmergencyNumberListTestMode");
9129
9130 final long identity = Binder.clearCallingIdentity();
9131 try {
9132 Set<String> emergencyNumbers = new HashSet<>();
9133 for (Phone phone: PhoneFactory.getPhones()) {
9134 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9135 if (tracker != null) {
9136 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9137 emergencyNumbers.add(num.getNumber());
9138 }
9139 }
9140 }
9141 return new ArrayList<>(emergencyNumbers);
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
9144 }
9145 }
9146
chen xud6b45bd2018-10-30 22:27:10 -07009147 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009148 public int getEmergencyNumberDbVersion(int subId) {
9149 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9150
9151 final long identity = Binder.clearCallingIdentity();
9152 try {
9153 final Phone phone = getPhone(subId);
9154 if (phone == null) {
9155 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9156 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9157 }
9158 return phone.getEmergencyNumberDbVersion();
9159 } finally {
9160 Binder.restoreCallingIdentity(identity);
9161 }
9162 }
9163
9164 @Override
9165 public void notifyOtaEmergencyNumberDbInstalled() {
9166 enforceModifyPermission();
9167
9168 final long identity = Binder.clearCallingIdentity();
9169 try {
9170 for (Phone phone: PhoneFactory.getPhones()) {
9171 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9172 if (tracker != null) {
9173 tracker.updateOtaEmergencyNumberDatabase();
9174 }
9175 }
9176 } finally {
9177 Binder.restoreCallingIdentity(identity);
9178 }
9179 }
9180
9181 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009182 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009183 enforceActiveEmergencySessionPermission();
9184
9185 final long identity = Binder.clearCallingIdentity();
9186 try {
9187 for (Phone phone: PhoneFactory.getPhones()) {
9188 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9189 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009190 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9191 }
9192 }
9193 } finally {
9194 Binder.restoreCallingIdentity(identity);
9195 }
9196 }
9197
9198 @Override
9199 public void resetOtaEmergencyNumberDbFilePath() {
9200 enforceActiveEmergencySessionPermission();
9201
9202 final long identity = Binder.clearCallingIdentity();
9203 try {
9204 for (Phone phone: PhoneFactory.getPhones()) {
9205 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9206 if (tracker != null) {
9207 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009208 }
9209 }
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
9214
9215 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009216 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9217 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9218 Phone phone = getPhone(subId);
9219 if (phone == null) {
9220 return null;
9221 }
9222 final long identity = Binder.clearCallingIdentity();
9223 try {
9224 UiccProfile profile = UiccController.getInstance()
9225 .getUiccProfileForPhone(phone.getPhoneId());
9226 if (profile != null) {
9227 return profile.getCertsFromCarrierPrivilegeAccessRules();
9228 }
9229 } finally {
9230 Binder.restoreCallingIdentity(identity);
9231 }
9232 return null;
9233 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009234
9235 /**
9236 * Enable or disable a modem stack.
9237 */
9238 @Override
9239 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9240 enforceModifyPermission();
9241
9242 final long identity = Binder.clearCallingIdentity();
9243 try {
9244 Phone phone = PhoneFactory.getPhone(slotIndex);
9245 if (phone == null) {
9246 return false;
9247 } else {
9248 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9249 }
9250 } finally {
9251 Binder.restoreCallingIdentity(identity);
9252 }
9253 }
Michelecea4cf22018-12-21 15:00:11 -08009254
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009255 /**
9256 * Whether a modem stack is enabled or not.
9257 */
9258 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009259 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9260 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009261 Phone phone = PhoneFactory.getPhone(slotIndex);
9262 if (phone == null) return false;
9263
9264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009265 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9266 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009267 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9268 }
9269
9270 final long identity = Binder.clearCallingIdentity();
9271 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009272 try {
9273 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9274 } catch (NoSuchElementException ex) {
9275 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9276 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009277 } finally {
9278 Binder.restoreCallingIdentity(identity);
9279 }
9280 }
9281
Michelecea4cf22018-12-21 15:00:11 -08009282 @Override
Michele0ea7d782019-03-19 14:58:42 -07009283 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009284 enforceModifyPermission();
9285
9286 final long identity = Binder.clearCallingIdentity();
9287 try {
9288 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009289 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009290 .commit();
9291 } finally {
9292 Binder.restoreCallingIdentity(identity);
9293 }
9294 }
9295
9296 @Override
Michele0ea7d782019-03-19 14:58:42 -07009297 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009298 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009300 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9301 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009302 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009303 }
Michelecea4cf22018-12-21 15:00:11 -08009304
9305 final long identity = Binder.clearCallingIdentity();
9306 try {
Michele0ea7d782019-03-19 14:58:42 -07009307 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009308 } finally {
9309 Binder.restoreCallingIdentity(identity);
9310 }
9311 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009312
Michele0ea7d782019-03-19 14:58:42 -07009313 @TelephonyManager.IsMultiSimSupportedResult
9314 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009315 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9316 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9317 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009318 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9319 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009320 }
9321 // Check if the hardware supports multisim functionality. If usage of multisim is not
9322 // supported by the modem, indicate that it is restricted.
9323 PhoneCapability staticCapability =
9324 mPhoneConfigurationManager.getStaticPhoneCapability();
9325 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009326 loge("isMultiSimSupportedInternal: no static configuration available");
9327 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009328 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009329 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009330 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9331 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009332 }
9333 // Check if support of multiple SIMs is restricted by carrier
9334 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009335 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009336 }
9337
Michele0ea7d782019-03-19 14:58:42 -07009338 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009339 }
9340
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009341 /**
9342 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009343 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9344 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9345 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009346 * @param numOfSims number of active sims we want to switch to
9347 */
9348 @Override
9349 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009350 if (numOfSims == 1) {
9351 enforceModifyPermission();
9352 } else {
9353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9354 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9355 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009356 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009357
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009358 try {
Michele30b57b22019-03-01 12:01:14 -08009359 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009360 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009361 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9362 return;
9363 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009364 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9365 } finally {
9366 Binder.restoreCallingIdentity(identity);
9367 }
9368 }
9369
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009370 @Override
9371 public boolean isApplicationOnUicc(int subId, int appType) {
9372 enforceReadPrivilegedPermission("isApplicationOnUicc");
9373 Phone phone = getPhone(subId);
9374 if (phone == null) {
9375 return false;
9376 }
9377 final long identity = Binder.clearCallingIdentity();
9378 try {
9379 UiccCard uiccCard = phone.getUiccCard();
9380 if (uiccCard == null) {
9381 return false;
9382 }
9383 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9384 if (uiccProfile == null) {
9385 return false;
9386 }
9387 if (TelephonyManager.APPTYPE_SIM <= appType
9388 && appType <= TelephonyManager.APPTYPE_ISIM) {
9389 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9390 }
9391 return false;
9392 } finally {
9393 Binder.restoreCallingIdentity(identity);
9394 }
9395 }
9396
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009397 /**
chen xub4baa772019-04-03 10:23:41 -07009398 * Get whether making changes to modem configurations will trigger reboot.
9399 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009400 */
9401 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009402 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9403 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009404 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009405 mApp, subId, callingPackage, callingFeatureId,
9406 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009407 return false;
9408 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009409 final long identity = Binder.clearCallingIdentity();
9410 try {
9411 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9412 } finally {
9413 Binder.restoreCallingIdentity(identity);
9414 }
9415 }
9416
Nathan Harold29f5f052019-02-15 13:41:57 -08009417 private void updateModemStateMetrics() {
9418 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9419 // TODO: check the state for each modem if the api is ready.
9420 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9421 }
9422
Pengquan Meng3889a572019-01-23 11:16:29 -08009423 @Override
9424 public int[] getSlotsMapping() {
9425 enforceReadPrivilegedPermission("getSlotsMapping");
9426
9427 final long identity = Binder.clearCallingIdentity();
9428 try {
9429 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9430 // All logical slots should have a mapping to a physical slot.
9431 int[] logicalSlotsMapping = new int[phoneCount];
9432 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9433 for (int i = 0; i < slotInfos.length; i++) {
9434 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9435 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9436 }
9437 }
9438 return logicalSlotsMapping;
9439 } finally {
9440 Binder.restoreCallingIdentity(identity);
9441 }
9442 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009443
9444 /**
9445 * Get the IRadio HAL Version
9446 */
9447 @Override
9448 public int getRadioHalVersion() {
9449 Phone phone = getDefaultPhone();
9450 if (phone == null) return -1;
9451 HalVersion hv = phone.getHalVersion();
9452 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9453 return hv.major * 100 + hv.minor;
9454 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009455
9456 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009457 * Get the current calling package name.
9458 * @return the current calling package name
9459 */
9460 @Override
9461 public String getCurrentPackageName() {
9462 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9463 }
9464
9465 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009466 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9467 * corresponding network requests on a subId.
9468 *
9469 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009470 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009471 * 2) APN is un-metered for this subscription, or
9472 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009473 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009474 *
9475 * @return whether data is allowed for a apn type.
9476 *
9477 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009478 */
9479 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009480 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009481 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9482 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009483
9484 // Now that all security checks passes, perform the operation as ourselves.
9485 final long identity = Binder.clearCallingIdentity();
9486 try {
9487 Phone phone = getPhone(subId);
9488 if (phone == null) return false;
9489
Jack Yu41407ee2019-05-13 16:54:09 -07009490 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009491 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9492 } finally {
9493 Binder.restoreCallingIdentity(identity);
9494 }
9495 }
9496
9497 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009498 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009499 enforceReadPrivilegedPermission("isApnMetered");
9500
9501 // Now that all security checks passes, perform the operation as ourselves.
9502 final long identity = Binder.clearCallingIdentity();
9503 try {
9504 Phone phone = getPhone(subId);
9505 if (phone == null) return true; // By default return true.
9506
Jack Yu41407ee2019-05-13 16:54:09 -07009507 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009512
9513 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009514 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9515 int subscriptionId, IBooleanConsumer resultCallback) {
9516 enforceModifyPermission();
9517 long token = Binder.clearCallingIdentity();
9518 try {
9519 Phone phone = getPhone(subscriptionId);
9520 if (phone == null) {
9521 try {
9522 if (resultCallback != null) {
9523 resultCallback.accept(false);
9524 }
9525 } catch (RemoteException e) {
9526 // ignore
9527 }
9528 return;
9529 }
9530 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9531 Pair.create(specifiers, (x) -> {
9532 try {
9533 if (resultCallback != null) {
9534 resultCallback.accept(x);
9535 }
9536 } catch (RemoteException e) {
9537 // ignore
9538 }
9539 });
9540 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9541 } finally {
9542 Binder.restoreCallingIdentity(token);
9543 }
9544 }
9545
9546 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009547 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9548 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009549 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009550 mApp, subId, "getSystemSelectionChannels");
9551 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9552 final long identity = Binder.clearCallingIdentity();
9553 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009554 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9555 if (result instanceof IllegalStateException) {
9556 throw (IllegalStateException) result;
9557 }
9558 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009559 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9560 return specifiers;
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
9565
9566 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009567 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009568 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009569 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9570 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9571 if (iccRecords == null) {
9572 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9573 return false;
9574 }
9575 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9576 }
9577
9578 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009579 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9580 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009581 if (callingPackage == null) {
9582 callingPackage = getCurrentPackageName();
9583 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009584 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9585 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009586 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9587 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009588 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9589 }
9590 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9591 Intent intent = new Intent();
9592 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9593 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9594 // Bring up choose default SMS subscription dialog right now
9595 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9596 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9597 mApp.startActivity(intent);
9598 }
chen xud5ca2d52019-05-28 15:20:57 -07009599
9600 @Override
9601 public String getMmsUAProfUrl(int subId) {
9602 //TODO investigate if this API should require proper permission check in R b/133791609
9603 final long identity = Binder.clearCallingIdentity();
9604 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009605 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9606 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9607 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9608 return carrierUAProfUrl;
9609 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009610 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9611 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009612 } finally {
9613 Binder.restoreCallingIdentity(identity);
9614 }
9615 }
9616
9617 @Override
9618 public String getMmsUserAgent(int subId) {
9619 //TODO investigate if this API should require proper permission check in R b/133791609
9620 final long identity = Binder.clearCallingIdentity();
9621 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009622 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9623 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9624 if (!TextUtils.isEmpty(carrierUserAgent)) {
9625 return carrierUserAgent;
9626 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009627 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9628 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009629 } finally {
9630 Binder.restoreCallingIdentity(identity);
9631 }
9632 }
Jack Yub07d4972019-05-28 16:12:25 -07009633
9634 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009635 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9636 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009637
Jack Yub07d4972019-05-28 16:12:25 -07009638 final long identity = Binder.clearCallingIdentity();
9639 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009640 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009641 if (phone == null) return false;
9642
Hall Liua62f5da2020-09-25 10:42:19 -07009643 switch (policy) {
9644 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9645 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9646 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9647 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9648 default:
9649 throw new IllegalArgumentException(policy + " is not a valid policy");
9650 }
Jack Yub07d4972019-05-28 16:12:25 -07009651 } finally {
9652 Binder.restoreCallingIdentity(identity);
9653 }
9654 }
9655
9656 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009657 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009658 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009659 enforceModifyPermission();
9660
changbettyd5c246e2019-12-24 15:40:37 +08009661 final long identity = Binder.clearCallingIdentity();
9662 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009663 Phone phone = getPhone(subscriptionId);
9664 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009665
Hall Liua62f5da2020-09-25 10:42:19 -07009666 switch (policy) {
9667 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9668 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9669 break;
9670 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9671 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9672 break;
9673 default:
9674 throw new IllegalArgumentException(policy + " is not a valid policy");
9675 }
changbettyd5c246e2019-12-24 15:40:37 +08009676 } finally {
9677 Binder.restoreCallingIdentity(identity);
9678 }
9679 }
9680
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009681 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009682 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009683 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9684 * otherwise.
9685 */
9686 @Override
9687 public void setCepEnabled(boolean isCepEnabled) {
9688 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9689
9690 final long identity = Binder.clearCallingIdentity();
9691 try {
9692 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9693 for (Phone phone : PhoneFactory.getPhones()) {
9694 Phone defaultPhone = phone.getImsPhone();
9695 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9696 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9697 ImsPhoneCallTracker imsPhoneCallTracker =
9698 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9699 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9700 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9701 + imsPhone.getMsisdn());
9702 }
9703 }
9704 } finally {
9705 Binder.restoreCallingIdentity(identity);
9706 }
9707 }
allenwtsu46dcc572020-01-08 18:24:03 +08009708
9709 /**
9710 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9711 *
9712 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9713 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9714 * before being read.
9715 */
9716 @Override
9717 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9718 isCompressed) {
9719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9720 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009721 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9722 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9723 }
9724 if (!isImsAvailableOnDevice()) {
9725 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9726 "IMS not available on device.");
9727 }
9728
9729 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009730 try {
Hui Wang761a6682020-10-31 05:12:53 +00009731 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9732 } finally {
9733 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009734 }
9735 }
zoey chene02881a2019-12-30 16:11:23 +08009736
9737 @Override
9738 public boolean isIccLockEnabled(int subId) {
9739 enforceReadPrivilegedPermission("isIccLockEnabled");
9740
9741 // Now that all security checks passes, perform the operation as ourselves.
9742 final long identity = Binder.clearCallingIdentity();
9743 try {
9744 Phone phone = getPhone(subId);
9745 if (phone != null && phone.getIccCard() != null) {
9746 return phone.getIccCard().getIccLockEnabled();
9747 } else {
9748 return false;
9749 }
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
9752 }
9753 }
9754
9755 /**
9756 * Set the ICC pin lock enabled or disabled.
9757 *
9758 * @return an integer representing the status of IccLock enabled or disabled in the following
9759 * three cases:
9760 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9761 * successfully.
9762 * - Positive number and zero for remaining password attempts.
9763 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9764 *
9765 */
9766 @Override
9767 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9768 enforceModifyPermission();
9769
9770 Phone phone = getPhone(subId);
9771 if (phone == null) {
9772 return 0;
9773 }
9774 // Now that all security checks passes, perform the operation as ourselves.
9775 final long identity = Binder.clearCallingIdentity();
9776 try {
9777 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9778 new Pair<Boolean, String>(enabled, password), phone, null);
9779 return attemptsRemaining;
9780
9781 } catch (Exception e) {
9782 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9783 } finally {
9784 Binder.restoreCallingIdentity(identity);
9785 }
9786 return 0;
9787 }
9788
9789 /**
9790 * Change the ICC password used in ICC pin lock.
9791 *
9792 * @return an integer representing the status of IccLock changed in the following three cases:
9793 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9794 * - Positive number and zero for remaining password attempts.
9795 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9796 *
9797 */
9798 @Override
9799 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9800 enforceModifyPermission();
9801
9802 Phone phone = getPhone(subId);
9803 if (phone == null) {
9804 return 0;
9805 }
9806 // Now that all security checks passes, perform the operation as ourselves.
9807 final long identity = Binder.clearCallingIdentity();
9808 try {
9809 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9810 new Pair<String, String>(oldPassword, newPassword), phone, null);
9811 return attemptsRemaining;
9812
9813 } catch (Exception e) {
9814 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9815 } finally {
9816 Binder.restoreCallingIdentity(identity);
9817 }
9818 return 0;
9819 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009820
9821 /**
9822 * Request for receiving user activity notification
9823 */
9824 @Override
9825 public void requestUserActivityNotification() {
9826 if (!mNotifyUserActivity.get()
9827 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9828 mNotifyUserActivity.set(true);
9829 }
9830 }
9831
9832 /**
9833 * Called when userActivity is signalled in the power manager.
9834 * This is safe to call from any thread, with any window manager locks held or not.
9835 */
9836 @Override
9837 public void userActivity() {
9838 // ***************************************
9839 // * Inherited from PhoneWindowManager *
9840 // ***************************************
9841 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9842 // WITH ITS LOCKS HELD.
9843 //
9844 // This code must be VERY careful about the locks
9845 // it acquires.
9846 // In fact, the current code acquires way too many,
9847 // and probably has lurking deadlocks.
9848
9849 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9850 throw new SecurityException("Only the OS may call notifyUserActivity()");
9851 }
9852
9853 if (mNotifyUserActivity.getAndSet(false)) {
9854 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9855 USER_ACTIVITY_NOTIFICATION_DELAY);
9856 }
9857 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009858
9859 @Override
9860 public boolean canConnectTo5GInDsdsMode() {
9861 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9862 }
Jack Yud10cdd42020-09-28 20:28:01 -07009863
9864 @Override
9865 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9866 String callingFeatureId) {
9867 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9868 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9869 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9870 }
9871
9872 Phone phone = getPhone(subId);
9873 if (phone == null) {
9874 throw new RuntimeException("phone is not available");
9875 }
9876 // Now that all security checks passes, perform the operation as ourselves.
9877 final long identity = Binder.clearCallingIdentity();
9878 try {
9879 return phone.getEquivalentHomePlmns();
9880 } finally {
9881 Binder.restoreCallingIdentity(identity);
9882 }
9883 }
Daniel Bright59e67312020-11-13 11:49:37 -08009884
9885 @Override
9886 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009887 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9888 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009889 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009890 if (radioInterfaceCapabilities == null) {
9891 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009892 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009893 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009894 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009895
Hui Wang641e81c2020-10-12 12:14:23 -07009896 @Override
9897 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9898 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009899 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9900 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9901 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9902 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9903 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009904 if (DBG) {
9905 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9906 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9907 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9908 }
9909
9910 if (!SubscriptionManager.isValidSubscriptionId(subId)
9911 || appType < TelephonyManager.APPTYPE_UNKNOWN
9912 || appType > TelephonyManager.APPTYPE_ISIM
9913 || nafUrl == null || securityProtocol == null || callback == null) {
9914 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9915 if (callback != null) {
9916 try {
9917 callback.onAuthenticationFailure(
9918 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9919 } catch (RemoteException exception) {
9920 log("Fail to notify onAuthenticationFailure due to " + exception);
9921 }
9922 return;
9923 }
9924 }
9925
9926 final long token = Binder.clearCallingIdentity();
9927 try {
9928 getGbaManager(subId).bootstrapAuthenticationRequest(
9929 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9930 forceBootStrapping, callback));
9931 } finally {
9932 Binder.restoreCallingIdentity(token);
9933 }
9934 }
9935
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009936 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009937 * Attempts to set the radio power state for all phones for thermal reason.
9938 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009939 * requested radio power state will actually be set. See {@link
9940 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9941 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009942 * @param enable {@code true} if trying to turn radio on.
9943 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9944 * false}.
9945 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009946 private boolean setRadioPowerForThermal(boolean enable) {
9947 boolean isPhoneAvailable = false;
9948 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9949 Phone phone = PhoneFactory.getPhone(i);
9950 if (phone != null) {
9951 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9952 isPhoneAvailable = true;
9953 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009954 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009955
9956 // return true if successfully informed the phone object about the thermal radio power
9957 // request.
9958 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009959 }
9960
9961 private int handleDataThrottlingRequest(int subId,
9962 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009963 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9964 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9965 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9966 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9967 throw new IllegalArgumentException("modem does not support data throttling");
9968 }
9969
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009970 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9971 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009972 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009973 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9974 }
9975
9976 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9977
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009978 if (isDataThrottlingSupported) {
9979 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009980 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009981 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9982 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9983 } else if (thermalMitigationResult
9984 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009985 log("Modem likely does not support data throttling on secondary carrier. Data " +
9986 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9987 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009988 }
9989 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009990 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009991
9992 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009993 }
9994
Jack Nudelman644b91a2021-03-12 14:09:48 -08009995 private static List<String> getThermalMitigationAllowlist(Context context) {
9996 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9997 for (String pckg : context.getResources()
9998 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9999 sThermalMitigationAllowlistedPackages.add(pckg);
10000 }
10001 }
10002
10003 return sThermalMitigationAllowlistedPackages;
10004 }
10005
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010006 private boolean isAnyPhoneInEmergencyState() {
10007 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10008 if (tm.isInEmergencyCall()) {
10009 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10010 return true;
10011 }
10012 for (Phone phone : PhoneFactory.getPhones()) {
10013 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10014 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10015 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10016 + phone.isInEcm());
10017 return true;
10018 }
10019 }
10020
10021 return false;
10022 }
10023
Jack Nudelman644b91a2021-03-12 14:09:48 -080010024 /**
10025 * Used by shell commands to add an authorized package name for thermal mitigation.
10026 * @param packageName name of package to be allowlisted
10027 * @param context
10028 */
10029 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10030 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10031 sThermalMitigationAllowlistedPackages.add(packageName);
10032 }
10033
10034 /**
10035 * Used by shell commands to remove an authorized package name for thermal mitigation.
10036 * @param packageName name of package to remove from allowlist
10037 * @param context
10038 */
10039 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10040 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10041 sThermalMitigationAllowlistedPackages.remove(packageName);
10042 }
10043
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010044 /**
10045 * Thermal mitigation request to control functionalities at modem.
10046 *
10047 * @param subId the id of the subscription.
10048 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010049 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010050 *
10051 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10052 */
10053 @Override
10054 @ThermalMitigationResult
10055 public int sendThermalMitigationRequest(
10056 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010057 ThermalMitigationRequest thermalMitigationRequest,
10058 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010059 enforceModifyPermission();
10060
Jack Nudelman644b91a2021-03-12 14:09:48 -080010061 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10062 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10063 .contains(callingPackage)) {
10064 throw new SecurityException("Calling package must be configured in the device config. "
10065 + "calling package: " + callingPackage);
10066 }
10067
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010068 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10069 final long identity = Binder.clearCallingIdentity();
10070
10071 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10072 try {
10073 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10074 switch (thermalMitigationAction) {
10075 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10076 thermalMitigationResult =
10077 handleDataThrottlingRequest(subId,
10078 thermalMitigationRequest.getDataThrottlingRequest());
10079 break;
10080 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10081 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10082 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10083 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10084 }
10085
10086 // Ensure that radio is on. If not able to power on due to phone being
10087 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010088 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010089 thermalMitigationResult =
10090 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10091 break;
10092 }
10093
10094 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10095 false);
10096 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10097 break;
10098 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10099 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10100 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10101 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10102 }
10103
10104 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10105 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010106 Phone phone = getPhone(subId);
10107 if (phone == null) {
10108 thermalMitigationResult =
10109 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10110 break;
10111 }
10112
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010113 TelephonyConnectionService service =
10114 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010115 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010116 Log.e(LOG_TAG, "An emergency call is pending");
10117 thermalMitigationResult =
10118 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10119 break;
10120 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010121 thermalMitigationResult =
10122 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10123 break;
10124 }
10125 } else {
10126 thermalMitigationResult =
10127 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10128 break;
10129 }
10130
10131 // Turn radio off. If not able to power off due to phone being unavailable,
10132 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010133 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010134 thermalMitigationResult =
10135 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10136 break;
10137 }
10138 thermalMitigationResult =
10139 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10140 break;
10141 default:
10142 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10143 + "not exist. Requested action: " + thermalMitigationAction);
10144 }
10145 } catch (IllegalArgumentException e) {
10146 throw e;
10147 } catch (Exception e) {
10148 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10149 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10150 } finally {
10151 Binder.restoreCallingIdentity(identity);
10152 }
10153
10154 if (DBG) {
10155 log("thermalMitigationRequest returning with thermalMitigationResult: "
10156 + thermalMitigationResult);
10157 }
10158
10159 return thermalMitigationResult;
10160 }
Hui Wang641e81c2020-10-12 12:14:23 -070010161
10162 /**
10163 * Set the GbaService Package Name that Telephony will bind to.
10164 *
10165 * @param subId The sim that the GbaService is associated with.
10166 * @param packageName The name of the package to be replaced with.
10167 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10168 */
10169 @Override
10170 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10171 enforceModifyPermission();
10172
10173 final long identity = Binder.clearCallingIdentity();
10174 try {
10175 return getGbaManager(subId).overrideServicePackage(packageName);
10176 } finally {
10177 Binder.restoreCallingIdentity(identity);
10178 }
10179 }
10180
10181 /**
10182 * Return the package name of the currently bound GbaService.
10183 *
10184 * @param subId The sim that the GbaService is associated with.
10185 * @return the package name of the GbaService configuration, null if GBA is not supported.
10186 */
10187 @Override
10188 public String getBoundGbaService(int subId) {
10189 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10190
10191 final long identity = Binder.clearCallingIdentity();
10192 try {
10193 return getGbaManager(subId).getServicePackage();
10194 } finally {
10195 Binder.restoreCallingIdentity(identity);
10196 }
10197 }
10198
10199 /**
10200 * Set the release time for telephony to unbind GbaService.
10201 *
10202 * @param subId The sim that the GbaService is associated with.
10203 * @param interval The release time to unbind GbaService by millisecond.
10204 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10205 */
10206 @Override
10207 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10208 enforceModifyPermission();
10209
10210 final long identity = Binder.clearCallingIdentity();
10211 try {
10212 return getGbaManager(subId).overrideReleaseTime(interval);
10213 } finally {
10214 Binder.restoreCallingIdentity(identity);
10215 }
10216 }
10217
10218 /**
10219 * Return the release time for telephony to unbind GbaService.
10220 *
10221 * @param subId The sim that the GbaService is associated with.
10222 * @return The release time to unbind GbaService by millisecond.
10223 */
10224 @Override
10225 public int getGbaReleaseTime(int subId) {
10226 enforceReadPrivilegedPermission("getGbaReleaseTime");
10227
10228 final long identity = Binder.clearCallingIdentity();
10229 try {
10230 return getGbaManager(subId).getReleaseTime();
10231 } finally {
10232 Binder.restoreCallingIdentity(identity);
10233 }
10234 }
10235
10236 private GbaManager getGbaManager(int subId) {
10237 GbaManager instance = GbaManager.getInstance(subId);
10238 if (instance == null) {
10239 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10240 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10241 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10242 }
10243 return instance;
10244 }
Hui Wang761a6682020-10-31 05:12:53 +000010245
10246 /**
10247 * indicate whether the device and the carrier can support
10248 * RCS VoLTE single registration.
10249 */
10250 @Override
10251 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010252 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10253 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10254 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10255 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010256
10257 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10258 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10259 }
10260
10261 final long identity = Binder.clearCallingIdentity();
10262 try {
10263 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10264 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010265 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10266 if (isCapable != null) {
10267 return isCapable;
10268 }
Hui Wang761a6682020-10-31 05:12:53 +000010269 }
Hui Wang67af90e2021-06-04 16:57:15 -070010270 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10271 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010272 } finally {
10273 Binder.restoreCallingIdentity(identity);
10274 }
10275 }
10276
10277 /**
10278 * Register RCS provisioning callback.
10279 */
10280 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010281 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010282 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010283 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010284 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010285 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10286 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010287
10288 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10289 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10290 }
10291 if (!isImsAvailableOnDevice()) {
10292 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10293 "IMS not available on device.");
10294 }
10295
10296 final long identity = Binder.clearCallingIdentity();
10297 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010298 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010299 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010300 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10301 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010302 }
Hui Wang761a6682020-10-31 05:12:53 +000010303 } finally {
10304 Binder.restoreCallingIdentity(identity);
10305 }
10306 }
10307
10308 /**
10309 * Unregister RCS provisioning callback.
10310 */
10311 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010312 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010313 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010314 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010315 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010316 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10317 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010318
10319 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10320 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10321 }
10322 if (!isImsAvailableOnDevice()) {
10323 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10324 "IMS not available on device.");
10325 }
10326
10327 final long identity = Binder.clearCallingIdentity();
10328 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010329 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010330 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010331 } finally {
10332 Binder.restoreCallingIdentity(identity);
10333 }
10334 }
10335
10336 /**
10337 * trigger RCS reconfiguration.
10338 */
10339 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010340 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10341 "triggerRcsReconfiguration",
10342 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010343
10344 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10345 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10346 }
10347 if (!isImsAvailableOnDevice()) {
10348 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10349 "IMS not available on device.");
10350 }
10351
10352 final long identity = Binder.clearCallingIdentity();
10353 try {
10354 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10355 } finally {
10356 Binder.restoreCallingIdentity(identity);
10357 }
10358 }
10359
10360 /**
10361 * Provide the client configuration parameters of the RCS application.
10362 */
10363 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010364 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10365 "setRcsClientConfiguration",
10366 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010367
10368 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10369 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10370 }
10371 if (!isImsAvailableOnDevice()) {
10372 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10373 "IMS not available on device.");
10374 }
10375
10376 final long identity = Binder.clearCallingIdentity();
10377
10378 try {
10379 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10380 if (configBinder == null) {
10381 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010382 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10383 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010384 } else {
10385 configBinder.setRcsClientConfiguration(rcc);
10386 }
10387 } catch (RemoteException e) {
10388 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010389 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10390 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010391 } finally {
10392 Binder.restoreCallingIdentity(identity);
10393 }
10394 }
10395
10396 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010397 * Enables or disables the test mode for RCS VoLTE single registration.
10398 */
10399 @Override
10400 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10401 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10402 "setRcsSingleRegistrationTestModeEnabled");
10403
10404 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10405 }
10406
10407 /**
10408 * Gets the test mode for RCS VoLTE single registration.
10409 */
10410 @Override
10411 public boolean getRcsSingleRegistrationTestModeEnabled() {
10412 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10413 "getRcsSingleRegistrationTestModeEnabled");
10414
10415 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10416 }
10417
10418 /**
Hui Wang761a6682020-10-31 05:12:53 +000010419 * Overrides the config of RCS VoLTE single registration enabled for the device.
10420 */
10421 @Override
10422 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10423 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10424 "setDeviceSingleRegistrationEnabledOverride");
10425 enforceModifyPermission();
10426
10427 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10428 : Boolean.parseBoolean(enabledStr);
10429 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010430 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010431 }
10432
10433 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010434 * Sends a device to device communication message. Only usable via shell.
10435 * @param message message to send.
10436 * @param value message value.
10437 */
10438 @Override
10439 public void sendDeviceToDeviceMessage(int message, int value) {
10440 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010441 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010442 enforceModifyPermission();
10443
10444 final long identity = Binder.clearCallingIdentity();
10445 try {
10446 TelephonyConnectionService service =
10447 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10448 if (service == null) {
10449 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10450 return;
10451 }
10452 service.sendTestDeviceToDeviceMessage(message, value);
10453 } finally {
10454 Binder.restoreCallingIdentity(identity);
10455 }
10456 }
10457
Tyler Gunnbabbda02021-02-10 11:05:02 -080010458 /**
10459 * Sets the specified device to device transport active.
10460 * @param transport The transport to set active.
10461 */
10462 @Override
10463 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10464 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10465 "setActiveDeviceToDeviceTransport");
10466 enforceModifyPermission();
10467
10468 final long identity = Binder.clearCallingIdentity();
10469 try {
10470 TelephonyConnectionService service =
10471 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10472 if (service == null) {
10473 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10474 return;
10475 }
10476 service.setActiveDeviceToDeviceTransport(transport);
10477 } finally {
10478 Binder.restoreCallingIdentity(identity);
10479 }
10480 }
Tyler Gunn92479152021-01-20 16:30:10 -080010481
Tyler Gunnd4339262021-05-03 14:46:49 -070010482 @Override
10483 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10484 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10485 "setDeviceToDeviceForceEnabled");
10486
10487 final long identity = Binder.clearCallingIdentity();
10488 try {
10489 Arrays.stream(PhoneFactory.getPhones()).forEach(
10490 p -> {
10491 Phone thePhone = p.getImsPhone();
10492 if (thePhone != null && thePhone instanceof ImsPhone) {
10493 ImsPhone imsPhone = (ImsPhone) thePhone;
10494 CallTracker tracker = imsPhone.getCallTracker();
10495 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10496 ImsPhoneCallTracker imsPhoneCallTracker =
10497 (ImsPhoneCallTracker) tracker;
10498 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10499 }
10500 }
10501 }
10502 );
10503 } finally {
10504 Binder.restoreCallingIdentity(identity);
10505 }
10506 }
10507
Tyler Gunn92479152021-01-20 16:30:10 -080010508 /**
Hui Wang761a6682020-10-31 05:12:53 +000010509 * Gets the config of RCS VoLTE single registration enabled for the device.
10510 */
10511 @Override
10512 public boolean getDeviceSingleRegistrationEnabled() {
10513 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10514 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10515 }
10516
10517 /**
10518 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10519 */
10520 @Override
10521 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10522 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10523 "setCarrierSingleRegistrationEnabledOverride");
10524 enforceModifyPermission();
10525
10526 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10527 : Boolean.parseBoolean(enabledStr);
10528 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10529 subId, enabled);
10530 }
10531
10532 /**
10533 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10534 */
10535 @Override
10536 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10537 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10538 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10539 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010540
10541 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010542 * Overrides the ims feature validation result
10543 */
10544 @Override
10545 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10546 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10547 "setImsFeatureValidationOverride");
10548
10549 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10550 : Boolean.parseBoolean(enabledStr);
10551 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10552 subId, enabled);
10553 }
10554
10555 /**
10556 * Gets the ims feature validation override value
10557 */
10558 @Override
10559 public boolean getImsFeatureValidationOverride(int subId) {
10560 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10561 "getImsFeatureValidationOverride");
10562 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10563 }
10564
10565 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010566 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10567 * their mobile plan.
10568 */
10569 @Override
10570 public String getMobileProvisioningUrl() {
10571 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10572 final long identity = Binder.clearCallingIdentity();
10573 try {
10574 return getDefaultPhone().getMobileProvisioningUrl();
10575 } finally {
10576 Binder.restoreCallingIdentity(identity);
10577 }
10578 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010579
James.cf Linbcdf8b32021-01-14 16:44:13 +080010580 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010581 * Get the EAB contact from the EAB database.
10582 */
10583 @Override
10584 public String getContactFromEab(String contact) {
10585 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10586 enforceModifyPermission();
10587 final long identity = Binder.clearCallingIdentity();
10588 try {
10589 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10590 } finally {
10591 Binder.restoreCallingIdentity(identity);
10592 }
10593 }
10594
10595 /**
Calvin Pana1434322021-07-01 19:27:01 +080010596 * Get the EAB capability from the EAB database.
10597 */
10598 @Override
10599 public String getCapabilityFromEab(String contact) {
10600 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10601 enforceModifyPermission();
10602 final long identity = Binder.clearCallingIdentity();
10603 try {
10604 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10605 } finally {
10606 Binder.restoreCallingIdentity(identity);
10607 }
10608 }
10609
10610 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010611 * Remove the EAB contacts from the EAB database.
10612 */
10613 @Override
10614 public int removeContactFromEab(int subId, String contacts) {
10615 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10616 enforceModifyPermission();
10617 final long identity = Binder.clearCallingIdentity();
10618 try {
10619 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10620 } finally {
10621 Binder.restoreCallingIdentity(identity);
10622 }
10623 }
10624
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010625 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010626 public boolean getDeviceUceEnabled() {
10627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10628 final long identity = Binder.clearCallingIdentity();
10629 try {
10630 return mApp.getDeviceUceEnabled();
10631 } finally {
10632 Binder.restoreCallingIdentity(identity);
10633 }
10634 }
10635
10636 @Override
10637 public void setDeviceUceEnabled(boolean isEnabled) {
10638 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10639 final long identity = Binder.clearCallingIdentity();
10640 try {
10641 mApp.setDeviceUceEnabled(isEnabled);
10642 } finally {
10643 Binder.restoreCallingIdentity(identity);
10644 }
10645 }
10646
Brad Ebinger14d467f2021-02-12 06:18:28 +000010647 /**
10648 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10649 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10650 */
10651 // Used for SHELL command only right now.
10652 @Override
10653 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10654 List<String> featureTags) {
10655 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10656 "addUceRegistrationOverrideShell");
10657 final long identity = Binder.clearCallingIdentity();
10658 try {
10659 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10660 new ArraySet<>(featureTags));
10661 } catch (ImsException e) {
10662 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10663 } finally {
10664 Binder.restoreCallingIdentity(identity);
10665 }
10666 }
10667
10668 /**
10669 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10670 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10671 */
10672 // Used for SHELL command only right now.
10673 @Override
10674 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10675 List<String> featureTags) {
10676 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10677 "removeUceRegistrationOverrideShell");
10678 final long identity = Binder.clearCallingIdentity();
10679 try {
10680 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10681 new ArraySet<>(featureTags));
10682 } catch (ImsException e) {
10683 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10684 } finally {
10685 Binder.restoreCallingIdentity(identity);
10686 }
10687 }
10688
10689 /**
10690 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10691 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10692 */
10693 // Used for SHELL command only right now.
10694 @Override
10695 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10696 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10697 "clearUceRegistrationOverrideShell");
10698 final long identity = Binder.clearCallingIdentity();
10699 try {
10700 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10701 } catch (ImsException e) {
10702 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10703 } finally {
10704 Binder.restoreCallingIdentity(identity);
10705 }
10706 }
10707
10708 /**
10709 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10710 */
10711 // Used for SHELL command only right now.
10712 @Override
10713 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10714 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10715 "getLatestRcsContactUceCapabilityShell");
10716 final long identity = Binder.clearCallingIdentity();
10717 try {
10718 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10719 } catch (ImsException e) {
10720 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10721 } finally {
10722 Binder.restoreCallingIdentity(identity);
10723 }
10724 }
10725
10726 /**
10727 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10728 * device does not have an active PUBLISH.
10729 */
10730 // Used for SHELL command only right now.
10731 @Override
10732 public String getLastUcePidfXmlShell(int subId) {
10733 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10734 final long identity = Binder.clearCallingIdentity();
10735 try {
10736 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10737 } catch (ImsException e) {
10738 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10739 } finally {
10740 Binder.restoreCallingIdentity(identity);
10741 }
10742 }
10743
James.cf Line8713a42021-04-29 16:04:26 +080010744 /**
10745 * Remove UCE requests cannot be sent to the network status.
10746 */
10747 // Used for SHELL command only right now.
10748 @Override
10749 public boolean removeUceRequestDisallowedStatus(int subId) {
10750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10751 final long identity = Binder.clearCallingIdentity();
10752 try {
10753 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10754 } catch (ImsException e) {
10755 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10756 } finally {
10757 Binder.restoreCallingIdentity(identity);
10758 }
10759 }
10760
James.cf Lin18bb9002021-05-25 01:37:38 +080010761 /**
10762 * Remove UCE requests cannot be sent to the network status.
10763 */
10764 // Used for SHELL command only.
10765 @Override
10766 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10767 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10768 final long identity = Binder.clearCallingIdentity();
10769 try {
10770 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10771 } catch (ImsException e) {
10772 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10773 } finally {
10774 Binder.restoreCallingIdentity(identity);
10775 }
10776 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010777
James.cf Lin4b784aa2021-01-31 03:25:15 +080010778 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010779 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10780 String callingPackage) {
10781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10782 mApp, subId, "setSignalStrengthUpdateRequest");
10783
10784 final int callingUid = Binder.getCallingUid();
10785 // Verify that tha callingPackage belongs to the calling UID
10786 mApp.getSystemService(AppOpsManager.class)
10787 .checkPackage(callingUid, callingPackage);
10788
10789 validateSignalStrengthUpdateRequest(request, callingUid);
10790
10791 final long identity = Binder.clearCallingIdentity();
10792 try {
10793 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10794 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10795
10796 if (result instanceof IllegalStateException) {
10797 throw (IllegalStateException) result;
10798 }
10799 } finally {
10800 Binder.restoreCallingIdentity(identity);
10801 }
10802 }
10803
10804 @Override
10805 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10806 String callingPackage) {
10807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10808 mApp, subId, "clearSignalStrengthUpdateRequest");
10809
10810 final int callingUid = Binder.getCallingUid();
10811 // Verify that tha callingPackage belongs to the calling UID
10812 mApp.getSystemService(AppOpsManager.class)
10813 .checkPackage(callingUid, callingPackage);
10814
10815 final long identity = Binder.clearCallingIdentity();
10816 try {
10817 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10818 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10819
10820 if (result instanceof IllegalStateException) {
10821 throw (IllegalStateException) result;
10822 }
10823 } finally {
10824 Binder.restoreCallingIdentity(identity);
10825 }
10826 }
10827
10828 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10829 int callingUid) {
10830 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10831 // phone/system process do not have further restriction on request
10832 return;
10833 }
10834
10835 // Applications has restrictions on how to use the request:
10836 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10837 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10838 // This is not system caller which has been checked above
10839 throw new IllegalArgumentException(
10840 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10841 }
10842
10843 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10844 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10845 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10846 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10847 || info.isEnabled()) {
10848 throw new IllegalArgumentException(
10849 "Only system can set hide fields in SignalThresholdInfo");
10850 }
10851
10852 // Thresholds length for each RAN need in range. This has been validated in
10853 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10854 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10855 final int[] thresholds = info.getThresholds();
10856 Objects.requireNonNull(thresholds);
10857 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10858 || thresholds.length
10859 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10860 throw new IllegalArgumentException(
10861 "thresholds length is out of range: " + thresholds.length);
10862 }
10863 }
10864 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010865
10866 /**
10867 * Gets the current phone capability.
10868 *
10869 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10870 * @return the PhoneCapability which describes the data connection capability of modem.
10871 * It's used to evaluate possible phone config change, for example from single
10872 * SIM device to multi-SIM device.
10873 */
10874 @Override
10875 public PhoneCapability getPhoneCapability() {
10876 enforceReadPrivilegedPermission("getPhoneCapability");
10877 final long identity = Binder.clearCallingIdentity();
10878 try {
10879 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10880 } finally {
10881 Binder.restoreCallingIdentity(identity);
10882 }
10883 }
Michele Berionne5e411512020-11-13 02:36:59 +000010884
10885 /**
10886 * Prepare TelephonyManager for an unattended reboot. The reboot is
10887 * required to be done shortly after the API is invoked.
10888 */
10889 @Override
10890 @TelephonyManager.PrepareUnattendedRebootResult
10891 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010892 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010893 enforceRebootPermission();
10894
10895 final long identity = Binder.clearCallingIdentity();
10896 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010897 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010898 } finally {
10899 Binder.restoreCallingIdentity(identity);
10900 }
10901 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010902
10903 /**
10904 * Request to get the current slicing configuration including URSP rules and
10905 * NSSAIs (configured, allowed and rejected).
10906 *
10907 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10908 */
10909 @Override
10910 public void getSlicingConfig(ResultReceiver callback) {
10911 enforceReadPrivilegedPermission("getSlicingConfig");
10912
10913 final long identity = Binder.clearCallingIdentity();
10914 try {
10915 Phone phone = getDefaultPhone();
10916 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10917 } finally {
10918 Binder.restoreCallingIdentity(identity);
10919 }
10920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010921}