blob: 6b20539233d1257609b6a821958cd06315e9fde4 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4575212021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700189import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800192import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000193import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800194import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700195import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800197import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800198import com.android.phone.callcomposer.CallComposerPictureManager;
199import com.android.phone.callcomposer.CallComposerPictureTransfer;
200import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700201import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800203import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700205import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800206import com.android.services.telephony.TelecomAccountRegistry;
207import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800208import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800209
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700211import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.IOException;
213import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700214import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800217import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800218import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800219import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100220import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700222import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800226import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800227import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229/**
230 * Implementation of the ITelephony interface.
231 */
Santos Cordon117fee72014-05-16 17:56:12 -0700232public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 private static final String LOG_TAG = "PhoneInterfaceManager";
234 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
235 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238 // Message codes used with mMainThreadHandler
239 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700240 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
241 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242 private static final int CMD_OPEN_CHANNEL = 9;
243 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
244 private static final int CMD_CLOSE_CHANNEL = 11;
245 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800246 private static final int CMD_NV_READ_ITEM = 13;
247 private static final int EVENT_NV_READ_ITEM_DONE = 14;
248 private static final int CMD_NV_WRITE_ITEM = 15;
249 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
250 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
251 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700252 private static final int CMD_RESET_MODEM_CONFIG = 19;
253 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800254 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
255 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800256 private static final int CMD_SEND_ENVELOPE = 25;
257 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000258 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
259 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700260 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
261 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
262 private static final int CMD_EXCHANGE_SIM_IO = 31;
263 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
265 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700266 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
267 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700268 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
269 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700270 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
271 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
272 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
273 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700274 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
275 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
276 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
277 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700278 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800279 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
280 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000281 private static final int CMD_SWITCH_SLOTS = 50;
282 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700283 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
284 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
285 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
286 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
287 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
288 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
289 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
290 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700291 private static final int CMD_GET_ALL_CELL_INFO = 60;
292 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
293 private static final int CMD_GET_CELL_LOCATION = 62;
294 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700295 private static final int CMD_MODEM_REBOOT = 64;
296 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700297 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
298 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800299 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
300 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700301 private static final int CMD_GET_MODEM_STATUS = 70;
302 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700303 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
304 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700305 private static final int CMD_ERASE_MODEM_CONFIG = 74;
306 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800307 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
308 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
309 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
310 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800311 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
312 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800314 private static final int CMD_GET_CALL_FORWARDING = 83;
315 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
316 private static final int CMD_SET_CALL_FORWARDING = 85;
317 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
318 private static final int CMD_GET_CALL_WAITING = 87;
319 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
320 private static final int CMD_SET_CALL_WAITING = 89;
321 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700322 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
323 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
324 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
325 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700326 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
327 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800328 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
329 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800330 private static final int CMD_SET_DATA_THROTTLING = 99;
331 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800332 private static final int CMD_SET_SIM_POWER = 101;
333 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800334 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
335 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
336 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
337 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800338 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
339 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000340 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800341 private static final int CMD_GET_SLICING_CONFIG = 110;
342 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800343 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700344 private static final int CMD_ENABLE_VONR = 113;
345 private static final int EVENT_ENABLE_VONR_DONE = 114;
346 private static final int CMD_IS_VONR_ENABLED = 115;
347 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800349 // Parameters of select command.
350 private static final int SELECT_COMMAND = 0xA4;
351 private static final int SELECT_P1 = 0x04;
352 private static final int SELECT_P2 = 0;
353 private static final int SELECT_P3 = 0x10;
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 /** The singleton instance. */
356 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800357 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800361 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700362 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700364 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800365 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800366 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700368 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800369 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Peter Wangdafb9ac2020-01-15 14:13:38 -0800371 /** User Activity */
372 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
374
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700375 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
376
Derek Tan97ebb422014-09-05 16:55:38 -0700377 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
378 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800379 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800380 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700381
Michelecea4cf22018-12-21 15:00:11 -0800382 // String to store multi SIM allowed
383 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
384
Derek Tan740e1672017-06-27 14:56:27 -0700385 // The AID of ISD-R.
386 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
387
yinxub1bed742017-04-17 11:45:04 -0700388 private NetworkScanRequestTracker mNetworkScanRequestTracker;
389
David Kelly5e06a7f2018-03-12 14:10:59 +0000390 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
391 private static final int MANUFACTURER_CODE_LENGTH = 8;
392
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800393 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800394 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395
Derek Tan89e89d42014-07-08 17:00:10 -0700396 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700397 * Experiment flag to enable erase modem config on reset network, default value is false
398 */
399 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
400 "reset_network_erase_modem_config_enabled";
401
Rambo Wang0f050d82021-02-12 11:43:36 -0800402 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
403
Naina Nallurid63128d2019-09-17 14:10:30 -0700404 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 * A request object to use for transmitting data to an ICC.
406 */
407 private static final class IccAPDUArgument {
408 public int channel, cla, command, p1, p2, p3;
409 public String data;
410
411 public IccAPDUArgument(int channel, int cla, int command,
412 int p1, int p2, int p3, String data) {
413 this.channel = channel;
414 this.cla = cla;
415 this.command = command;
416 this.p1 = p1;
417 this.p2 = p2;
418 this.p3 = p3;
419 this.data = data;
420 }
421 }
422
423 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700424 * A request object to use for transmitting data to an ICC.
425 */
426 private static final class ManualNetworkSelectionArgument {
427 public OperatorInfo operatorInfo;
428 public boolean persistSelection;
429
430 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
431 this.operatorInfo = operatorInfo;
432 this.persistSelection = persistSelection;
433 }
434 }
435
436 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
438 * request after sending. The main thread will notify the request when it is complete.
439 */
440 private static final class MainThreadRequest {
441 /** The argument to use for the request */
442 public Object argument;
443 /** The result of the request that is run on the main thread */
444 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800445 // The subscriber id that this request applies to. Defaults to
446 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
447 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Nathan Harold92bed182018-10-12 18:16:49 -0700449 // In cases where subId is unavailable, the caller needs to specify the phone.
450 public Phone phone;
451
vagdeviaf9a5b92018-08-15 16:01:53 -0700452 public WorkSource workSource;
453
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 public MainThreadRequest(Object argument) {
455 this.argument = argument;
456 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800457
Nathan Harold92bed182018-10-12 18:16:49 -0700458 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
459 this.argument = argument;
460 if (phone != null) {
461 this.phone = phone;
462 }
463 this.workSource = workSource;
464 }
465
vagdeviaf9a5b92018-08-15 16:01:53 -0700466 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800467 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800468 if (subId != null) {
469 this.subId = subId;
470 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700471 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 }
474
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800475 private static final class IncomingThirdPartyCallArgs {
476 public final ComponentName component;
477 public final String callId;
478 public final String callerDisplayName;
479
480 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
481 String callerDisplayName) {
482 this.component = component;
483 this.callId = callId;
484 this.callerDisplayName = callerDisplayName;
485 }
486 }
487
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 /**
489 * A handler that processes messages on the main thread in the phone process. Since many
490 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
491 * inbound binder threads to the main thread in the phone process. The Binder thread
492 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
493 * on, which will be notified when the operation completes and will contain the result of the
494 * request.
495 *
496 * <p>If a MainThreadRequest object is provided in the msg.obj field,
497 * note that request.result must be set to something non-null for the calling thread to
498 * unblock.
499 */
500 private final class MainThreadHandler extends Handler {
501 @Override
502 public void handleMessage(Message msg) {
503 MainThreadRequest request;
504 Message onCompleted;
505 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800508 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509
510 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 case CMD_HANDLE_USSD_REQUEST: {
512 request = (MainThreadRequest) msg.obj;
513 final Phone phone = getPhoneFromRequest(request);
514 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
515 String ussdRequest = ussdObject.first;
516 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700517
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 if (!isUssdApiAllowed(request.subId)) {
519 // Carrier does not support use of this API, return failure.
520 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
521 UssdResponse response = new UssdResponse(ussdRequest, null);
522 Bundle returnData = new Bundle();
523 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
524 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700525
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 request.result = true;
527 notifyRequester(request);
528 return;
529 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700530
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 try {
532 request.result = phone != null
533 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
534 } catch (CallStateException cse) {
535 request.result = false;
536 }
537 // Wake up the requesting thread
538 notifyRequester(request);
539 break;
pkanwar32d516d2016-10-14 19:37:38 -0700540 }
541
Yorke Lee716f67e2015-06-17 15:39:16 -0700542 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 final Phone phone = getPhoneFromRequest(request);
545 request.result = phone != null ?
546 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
547 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("iccTransmitApduLogicalChannel: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
563 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 iccArgument.channel, iccArgument.cla, iccArgument.command,
566 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 break;
570
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
574 if (ar.exception == null && ar.result != null) {
575 request.result = ar.result;
576 } else {
577 request.result = new IccIoResult(0x6F, 0, (byte[])null);
578 if (ar.result == null) {
579 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800580 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800582 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
584 loge("iccTransmitApduLogicalChannel: Unknown exception");
585 }
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
591 request = (MainThreadRequest) msg.obj;
592 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 if (uiccCard == null) {
595 loge("iccTransmitApduBasicChannel: No UICC");
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 } else {
599 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
600 request);
601 uiccCard.iccTransmitApduBasicChannel(
602 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
603 iccArgument.p3, iccArgument.data, onCompleted);
604 }
605 break;
606
607 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
610 if (ar.exception == null && ar.result != null) {
611 request.result = ar.result;
612 } else {
613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
614 if (ar.result == null) {
615 loge("iccTransmitApduBasicChannel: Empty response");
616 } else if (ar.exception instanceof CommandException) {
617 loge("iccTransmitApduBasicChannel: CommandException: " +
618 ar.exception);
619 } else {
620 loge("iccTransmitApduBasicChannel: Unknown exception");
621 }
622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 break;
625
626 case CMD_EXCHANGE_SIM_IO:
627 request = (MainThreadRequest) msg.obj;
628 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (uiccCard == null) {
631 loge("iccExchangeSimIO: No UICC");
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
636 request);
637 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
638 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
639 iccArgument.data, onCompleted);
640 }
641 break;
642
643 case EVENT_EXCHANGE_SIM_IO_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
648 } else {
649 request.result = new IccIoResult(0x6f, 0, (byte[])null);
650 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 break;
653
Derek Tan4d5e5c12014-02-04 11:54:58 -0800654 case CMD_SEND_ENVELOPE:
655 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800656 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 if (uiccCard == null) {
658 loge("sendEnvelopeWithStatus: No UICC");
659 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 } else {
662 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
663 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
664 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 break;
666
667 case EVENT_SEND_ENVELOPE_DONE:
668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800672 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700673 request.result = new IccIoResult(0x6F, 0, (byte[])null);
674 if (ar.result == null) {
675 loge("sendEnvelopeWithStatus: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("sendEnvelopeWithStatus: CommandException: " +
678 ar.exception);
679 } else {
680 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
681 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 break;
685
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 case CMD_OPEN_CHANNEL:
687 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800688 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800689 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 if (uiccCard == null) {
691 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800692 request.result = new IccOpenLogicalChannelResponse(-1,
693 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800697 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
698 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 break;
701
702 case EVENT_OPEN_CHANNEL_DONE:
703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 int[] result = (int[]) ar.result;
708 int channelId = result[0];
709 byte[] selectResponse = null;
710 if (result.length > 1) {
711 selectResponse = new byte[result.length - 1];
712 for (int i = 1; i < result.length; ++i) {
713 selectResponse[i - 1] = (byte) result[i];
714 }
715 }
716 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 if (ar.result == null) {
720 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 if (ar.exception != null) {
723 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
724 }
725
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700726 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700727 if (ar.exception instanceof CommandException) {
728 CommandException.Error error =
729 ((CommandException) (ar.exception)).getCommandError();
730 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700731 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700732 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700733 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 }
735 }
736 openChannelResp = new IccOpenLogicalChannelResponse(
737 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700739 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 break;
742
743 case CMD_CLOSE_CHANNEL:
744 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800745 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 if (uiccCard == null) {
747 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900748 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
752 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
753 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 break;
755
756 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800757 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
758 break;
759
760 case CMD_NV_READ_ITEM:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
764 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800765 break;
766
767 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 ar = (AsyncResult) msg.obj;
769 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800770 if (ar.exception == null && ar.result != null) {
771 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800773 request.result = "";
774 if (ar.result == null) {
775 loge("nvReadItem: Empty response");
776 } else if (ar.exception instanceof CommandException) {
777 loge("nvReadItem: CommandException: " +
778 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800780 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 }
782 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700783 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
Jake Hambye994d462014-02-03 13:10:13 -0800786 case CMD_NV_WRITE_ITEM:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
789 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700791 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800792 break;
793
794 case EVENT_NV_WRITE_ITEM_DONE:
795 handleNullReturnEvent(msg, "nvWriteItem");
796 break;
797
798 case CMD_NV_WRITE_CDMA_PRL:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800801 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800802 break;
803
804 case EVENT_NV_WRITE_CDMA_PRL_DONE:
805 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
806 break;
807
chen xu6dac5ab2018-10-26 17:39:23 -0700808 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800809 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700810 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800811 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
chen xu6dac5ab2018-10-26 17:39:23 -0700814 case EVENT_RESET_MODEM_CONFIG_DONE:
815 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
Sooraj Sasindran37444802020-08-11 10:40:43 -0700818 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
821 request);
822 Phone phone = getPhoneFromRequest(request);
823 if (phone != null) {
824 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
825 } else {
826 loge("isNRDualConnectivityEnabled: No phone object");
827 request.result = false;
828 notifyRequester(request);
829 }
830 break;
831 }
832
833 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 // request.result must be set to something non-null
840 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700841 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700842 request.result = ar.result;
843 } else {
844 request.result = false;
845 }
846 if (ar.result == null) {
847 loge("isNRDualConnectivityEnabled: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("isNRDualConnectivityEnabled: CommandException: "
850 + ar.exception);
851 } else {
852 loge("isNRDualConnectivityEnabled: Unknown exception");
853 }
854 }
855 notifyRequester(request);
856 break;
857
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700858 case CMD_IS_VONR_ENABLED: {
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
861 request);
862 Phone phone = getPhoneFromRequest(request);
863 if (phone != null) {
864 phone.isVoNrEnabled(onCompleted, request.workSource);
865 } else {
866 loge("isVoNrEnabled: No phone object");
867 request.result = false;
868 notifyRequester(request);
869 }
870 break;
871 }
872
873 case EVENT_IS_VONR_ENABLED_DONE:
874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null && ar.result != null) {
877 request.result = ar.result;
878 } else {
879 // request.result must be set to something non-null
880 // for the calling thread to unblock
881 if (ar.result != null) {
882 request.result = ar.result;
883 } else {
884 request.result = false;
885 }
886 if (ar.result == null) {
887 loge("isVoNrEnabled: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("isVoNrEnabled: CommandException: "
890 + ar.exception);
891 } else {
892 loge("isVoNrEnabled: Unknown exception");
893 }
894 }
895 notifyRequester(request);
896 break;
897
Sooraj Sasindran37444802020-08-11 10:40:43 -0700898 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
901 Phone phone = getPhoneFromRequest(request);
902 if (phone != null) {
903 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
904 request.workSource);
905 } else {
906 loge("enableNrDualConnectivity: No phone object");
907 request.result =
908 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
909 notifyRequester(request);
910 }
911 break;
912 }
913
914 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
917 if (ar.exception == null) {
918 request.result =
919 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
920 } else {
921 request.result =
922 TelephonyManager
923 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
924 if (ar.exception instanceof CommandException) {
925 CommandException.Error error =
926 ((CommandException) (ar.exception)).getCommandError();
927 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
928 request.result =
929 TelephonyManager
930 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000931 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
932 request.result =
933 TelephonyManager
934 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700935 }
936 loge("enableNrDualConnectivity" + ": CommandException: "
937 + ar.exception);
938 } else {
939 loge("enableNrDualConnectivity" + ": Unknown exception");
940 }
941 }
942 notifyRequester(request);
943 break;
944 }
945
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700946 case CMD_ENABLE_VONR: {
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
949 Phone phone = getPhoneFromRequest(request);
950 if (phone != null) {
951 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
952 request.workSource);
953 } else {
954 loge("setVoNrEnabled: No phone object");
955 request.result =
956 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
957 notifyRequester(request);
958 }
959 break;
960 }
961
962 case EVENT_ENABLE_VONR_DONE: {
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null) {
966 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
967 } else {
968 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
969 if (ar.exception instanceof CommandException) {
970 CommandException.Error error =
971 ((CommandException) (ar.exception)).getCommandError();
972 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
973 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
974 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
975 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
976 } else {
977 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
978 }
979 loge("setVoNrEnabled" + ": CommandException: "
980 + ar.exception);
981 } else {
982 loge("setVoNrEnabled" + ": Unknown exception");
983 }
984 }
985 notifyRequester(request);
986 break;
987 }
988
SongFerngWang3ef3e072020-12-21 16:41:52 +0800989 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800990 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800991 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
992 request);
993 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800994 break;
995
SongFerngWang3ef3e072020-12-21 16:41:52 +0800996 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception == null && ar.result != null) {
1000 request.result = ar.result; // Integer
1001 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301002 // request.result must be set to something non-null
1003 // for the calling thread to unblock
1004 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001005 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001006 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001007 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 loge("getAllowedNetworkTypesBitmask: CommandException: "
1009 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001010 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 }
1013 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001014 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 break;
1016
SongFerngWang3ef3e072020-12-21 16:41:52 +08001017 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001019 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1020 request);
1021 Pair<Integer, Long> reasonWithNetworkTypes =
1022 (Pair<Integer, Long>) request.argument;
1023 getPhoneFromRequest(request).setAllowedNetworkTypes(
1024 reasonWithNetworkTypes.first,
1025 reasonWithNetworkTypes.second,
1026 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 break;
1028
SongFerngWang3ef3e072020-12-21 16:41:52 +08001029 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1030 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 break;
1032
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001033 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1034 request = (MainThreadRequest)msg.obj;
1035 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001036 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001037 break;
1038
1039 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1040 ar = (AsyncResult)msg.obj;
1041 request = (MainThreadRequest)ar.userObj;
1042 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001043 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001044 break;
1045
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001046 case CMD_SET_VOICEMAIL_NUMBER:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1049 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001050 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1051 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001052 break;
1053
1054 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1055 handleNullReturnEvent(msg, "setVoicemailNumber");
1056 break;
1057
Stuart Scott54788802015-03-30 13:18:01 -07001058 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1061 request);
1062 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1063 break;
1064
1065 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1066 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1067 break;
1068
Shishir Agrawal302c8692015-06-19 13:49:39 -07001069 case CMD_PERFORM_NETWORK_SCAN:
1070 request = (MainThreadRequest) msg.obj;
1071 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1072 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1073 break;
1074
Hall Liu27d24262020-09-18 19:04:59 -07001075 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001078 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1079 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1080 request.argument;
1081 int callForwardingReason = args.first;
1082 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001083 break;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
1085 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001088 TelephonyManager.CallForwardingInfoCallback callback =
1089 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1090 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001091 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001092 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1094 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1095 // Service Class is a bit mask per 3gpp 27.007. Search for
1096 // any service for voice call.
1097 if ((callForwardInfo.serviceClass
1098 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001099 callForwardingInfo = new CallForwardingInfo(true,
1100 callForwardInfo.reason,
1101 callForwardInfo.number,
1102 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001103 break;
1104 }
1105 }
1106 // Didn't find a call forward info for voice call.
1107 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001108 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1109 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001110 }
Hall Liu27d24262020-09-18 19:04:59 -07001111 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001112 } else {
1113 if (ar.result == null) {
1114 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1115 }
1116 if (ar.exception != null) {
1117 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1118 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001119 int errorCode = TelephonyManager
1120 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001121 if (ar.exception instanceof CommandException) {
1122 CommandException.Error error =
1123 ((CommandException) (ar.exception)).getCommandError();
1124 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001125 errorCode = TelephonyManager
1126 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001128 errorCode = TelephonyManager
1129 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001130 }
1131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
Shuo Qian4a594052020-01-23 11:59:30 -08001134 break;
Hall Liu27d24262020-09-18 19:04:59 -07001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136
Hall Liu27d24262020-09-18 19:04:59 -07001137 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001140 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001141 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001142 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1143 request.argument).first;
1144 request.phone.setCallForwardingOption(
1145 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001146 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001147 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001148 callForwardingInfoToSet.getReason(),
1149 callForwardingInfoToSet.getNumber(),
1150 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1151 break;
Hall Liu27d24262020-09-18 19:04:59 -07001152 }
Shuo Qian4a594052020-01-23 11:59:30 -08001153
Hall Liu27d24262020-09-18 19:04:59 -07001154 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001157 Consumer<Integer> callback =
1158 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1159 request.argument).second;
1160 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001162 int errorCode = TelephonyManager.CallForwardingInfoCallback
1163 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001164 if (ar.exception instanceof CommandException) {
1165 CommandException.Error error =
1166 ((CommandException) (ar.exception)).getCommandError();
1167 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001168 errorCode = TelephonyManager.CallForwardingInfoCallback
1169 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001170 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001171 errorCode = TelephonyManager.CallForwardingInfoCallback
1172 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001173 }
1174 }
1175 callback.accept(errorCode);
1176 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001177 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001178 }
Shuo Qian4a594052020-01-23 11:59:30 -08001179 break;
Hall Liu27d24262020-09-18 19:04:59 -07001180 }
Shuo Qian4a594052020-01-23 11:59:30 -08001181
Hall Liu27d24262020-09-18 19:04:59 -07001182 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001183 request = (MainThreadRequest) msg.obj;
1184 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1185 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1186 break;
Hall Liu27d24262020-09-18 19:04:59 -07001187 }
Shuo Qian4a594052020-01-23 11:59:30 -08001188
Hall Liu27d24262020-09-18 19:04:59 -07001189 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001190 ar = (AsyncResult) msg.obj;
1191 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001192 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001193 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1194 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001195 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 // Service Class is a bit mask per 3gpp 27.007.
1197 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001198 if (callForwardResults.length > 1
1199 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001200 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001201 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001202 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1203 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001205 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 }
1207 } else {
1208 if (ar.result == null) {
1209 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1210 }
1211 if (ar.exception != null) {
1212 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1213 }
1214 if (ar.exception instanceof CommandException) {
1215 CommandException.Error error =
1216 ((CommandException) (ar.exception)).getCommandError();
1217 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1218 callForwardingStatus =
1219 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1220 }
1221 }
1222 }
Hall Liu27d24262020-09-18 19:04:59 -07001223 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001224 break;
Hall Liu27d24262020-09-18 19:04:59 -07001225 }
Shuo Qian4a594052020-01-23 11:59:30 -08001226
Hall Liu27d24262020-09-18 19:04:59 -07001227 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001230 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1231 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001232 break;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234
Hall Liu27d24262020-09-18 19:04:59 -07001235 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001238 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1239 Consumer<Integer> callback =
1240 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1241 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001242 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001243 if (ar.exception instanceof CommandException) {
1244 CommandException.Error error =
1245 ((CommandException) (ar.exception)).getCommandError();
1246 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1247 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1248 } else {
1249 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1250 }
1251 } else {
1252 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1253 }
1254 } else {
1255 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1256 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001260 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
1263 CellNetworkScanResult cellScanResult;
1264 if (ar.exception == null && ar.result != null) {
1265 cellScanResult = new CellNetworkScanResult(
1266 CellNetworkScanResult.STATUS_SUCCESS,
1267 (List<OperatorInfo>) ar.result);
1268 } else {
1269 if (ar.result == null) {
1270 loge("getCellNetworkScanResults: Empty response");
1271 }
1272 if (ar.exception != null) {
1273 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1274 }
1275 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1276 if (ar.exception instanceof CommandException) {
1277 CommandException.Error error =
1278 ((CommandException) (ar.exception)).getCommandError();
1279 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1280 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1281 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1282 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1283 }
1284 }
1285 cellScanResult = new CellNetworkScanResult(errorCode, null);
1286 }
1287 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001288 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001289 break;
1290
1291 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1292 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001293 ManualNetworkSelectionArgument selArg =
1294 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001295 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1296 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001297 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1298 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001299 break;
1300
1301 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null) {
1305 request.result = true;
1306 } else {
1307 request.result = false;
1308 loge("setNetworkSelectionModeManual " + ar.exception);
1309 }
1310 notifyRequester(request);
1311 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001312 break;
1313
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001314 case CMD_GET_MODEM_ACTIVITY_INFO:
1315 request = (MainThreadRequest) msg.obj;
1316 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001317 if (defaultPhone != null) {
1318 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001319 } else {
1320 ResultReceiver result = (ResultReceiver) request.argument;
1321 Bundle bundle = new Bundle();
1322 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001323 new ModemActivityInfo(0, 0, 0,
1324 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001325 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001326 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001327 break;
1328
Hall Liud0f208c2020-10-14 16:54:44 -07001329 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001332 ResultReceiver result = (ResultReceiver) request.argument;
1333
Hall Liud0f208c2020-10-14 16:54:44 -07001334 ModemActivityInfo ret = null;
1335 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001336 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001337 // Update the last modem activity info and the result of the request.
1338 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1339 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001340 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001341 int[] txTimeMs = info.getTransmitTimeMillis();
1342 int[] lastModemTxTimeMs = mLastModemActivityInfo
1343 .getTransmitTimeMillis();
1344 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1345 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1346 }
Hall Liu49656c02020-10-09 19:00:11 -07001347 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001348 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1349 + mLastModemActivityInfo.getSleepTimeMillis());
1350 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1351 + mLastModemActivityInfo.getIdleTimeMillis());
1352 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1353 mLastModemActivityInfo.setReceiveTimeMillis(
1354 info.getReceiveTimeMillis()
1355 + mLastModemActivityInfo.getReceiveTimeMillis());
1356 }
Hall Liu49656c02020-10-09 19:00:11 -07001357 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 mLastModemActivityInfo.getSleepTimeMillis(),
1359 mLastModemActivityInfo.getIdleTimeMillis(),
1360 mLastModemActivityInfo.getTransmitTimeMillis(),
1361 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001362 } else {
1363 if (ar.result == null) {
1364 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001365 error = TelephonyManager.ModemActivityInfoException
1366 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001367 } else if (ar.exception instanceof CommandException) {
1368 loge("queryModemActivityInfo: CommandException: " +
1369 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001370 error = TelephonyManager.ModemActivityInfoException
1371 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001372 } else {
1373 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001374 error = TelephonyManager.ModemActivityInfoException
1375 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001376 }
1377 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001378 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001379 if (ret != null) {
1380 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1381 } else {
1382 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1383 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001384 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001385 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001386 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001387 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388
Meng Wang1a7c35a2016-05-05 20:56:15 -07001389 case CMD_SET_ALLOWED_CARRIERS:
1390 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001391 CarrierRestrictionRules argument =
1392 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001393 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001394 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001395 break;
1396
1397 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 if (ar.exception == null && ar.result != null) {
1401 request.result = ar.result;
1402 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001403 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1404 if (ar.exception instanceof CommandException) {
1405 loge("setAllowedCarriers: CommandException: " + ar.exception);
1406 CommandException.Error error =
1407 ((CommandException) (ar.exception)).getCommandError();
1408 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1409 request.result =
1410 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1411 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001412 } else {
1413 loge("setAllowedCarriers: Unknown exception");
1414 }
1415 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001416 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001417 break;
1418
1419 case CMD_GET_ALLOWED_CARRIERS:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001422 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001423 break;
1424
1425 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 if (ar.exception == null && ar.result != null) {
1429 request.result = ar.result;
1430 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001431 request.result = new IllegalStateException(
1432 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001433 if (ar.result == null) {
1434 loge("getAllowedCarriers: Empty response");
1435 } else if (ar.exception instanceof CommandException) {
1436 loge("getAllowedCarriers: CommandException: " +
1437 ar.exception);
1438 } else {
1439 loge("getAllowedCarriers: Unknown exception");
1440 }
1441 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001442 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001443 break;
1444
Nathan Haroldb3014052017-01-25 15:57:32 -08001445 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 if (ar.exception == null && ar.result != null) {
1449 request.result = ar.result;
1450 } else {
1451 request.result = new IllegalArgumentException(
1452 "Failed to retrieve Forbidden Plmns");
1453 if (ar.result == null) {
1454 loge("getForbiddenPlmns: Empty response");
1455 } else {
1456 loge("getForbiddenPlmns: Unknown exception");
1457 }
1458 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001459 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001460 break;
1461
1462 case CMD_GET_FORBIDDEN_PLMNS:
1463 request = (MainThreadRequest) msg.obj;
1464 uiccCard = getUiccCardFromRequest(request);
1465 if (uiccCard == null) {
1466 loge("getForbiddenPlmns() UiccCard is null");
1467 request.result = new IllegalArgumentException(
1468 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001469 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001470 break;
1471 }
1472 Integer appType = (Integer) request.argument;
1473 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1474 if (uiccApp == null) {
1475 loge("getForbiddenPlmns() no app with specified type -- "
1476 + appType);
1477 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001478 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001479 break;
1480 } else {
1481 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1482 + " specified type -- " + appType);
1483 }
1484 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1485 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1486 onCompleted);
1487 break;
1488
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001489 case CMD_SWITCH_SLOTS:
1490 request = (MainThreadRequest) msg.obj;
1491 int[] physicalSlots = (int[]) request.argument;
1492 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1493 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1494 break;
1495
1496 case EVENT_SWITCH_SLOTS_DONE:
1497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
1499 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 notifyRequester(request);
1501 break;
1502 case CMD_GET_NETWORK_SELECTION_MODE:
1503 request = (MainThreadRequest) msg.obj;
1504 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1505 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1506 break;
1507
1508 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 if (ar.exception != null) {
1512 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1513 } else {
1514 int mode = ((int[]) ar.result)[0];
1515 if (mode == 0) {
1516 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1517 } else {
1518 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1519 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
1522 break;
1523 case CMD_GET_CDMA_ROAMING_MODE:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1526 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1527 break;
1528 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 if (ar.exception != null) {
1532 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1533 } else {
1534 request.result = ((int[]) ar.result)[0];
1535 }
1536 notifyRequester(request);
1537 break;
1538 case CMD_SET_CDMA_ROAMING_MODE:
1539 request = (MainThreadRequest) msg.obj;
1540 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1541 int mode = (int) request.argument;
1542 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1543 break;
1544 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1545 ar = (AsyncResult) msg.obj;
1546 request = (MainThreadRequest) ar.userObj;
1547 request.result = ar.exception == null;
1548 notifyRequester(request);
1549 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001550 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1551 request = (MainThreadRequest) msg.obj;
1552 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1553 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1554 break;
1555 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1556 ar = (AsyncResult) msg.obj;
1557 request = (MainThreadRequest) ar.userObj;
1558 if (ar.exception != null) {
1559 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1560 } else {
1561 request.result = ((int[]) ar.result)[0];
1562 }
1563 notifyRequester(request);
1564 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001565 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1566 request = (MainThreadRequest) msg.obj;
1567 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1568 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001569 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1570 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 break;
1572 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 request.result = ar.exception == null;
1576 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001577 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001578 case CMD_GET_ALL_CELL_INFO:
1579 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001580 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001581 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001583 case EVENT_GET_ALL_CELL_INFO_DONE:
1584 ar = (AsyncResult) msg.obj;
1585 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001586 // If a timeout occurs, the response will be null
1587 request.result = (ar.exception == null && ar.result != null)
1588 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001589 synchronized (request) {
1590 request.notifyAll();
1591 }
1592 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001593 case CMD_REQUEST_CELL_INFO_UPDATE:
1594 request = (MainThreadRequest) msg.obj;
1595 request.phone.requestCellInfoUpdate(request.workSource,
1596 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1597 break;
1598 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1602 try {
1603 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001604 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001605 cb.onError(
1606 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1607 ar.exception.getClass().getName(),
1608 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001609 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001611 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 } else {
1613 // use the result as returned
1614 cb.onCellInfo((List<CellInfo>) ar.result);
1615 }
1616 } catch (RemoteException re) {
1617 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1618 }
1619 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001620 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001621 request = (MainThreadRequest) msg.obj;
1622 WorkSource ws = (WorkSource) request.argument;
1623 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001624 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001625 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001626 }
1627 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001628 ar = (AsyncResult) msg.obj;
1629 request = (MainThreadRequest) ar.userObj;
1630 if (ar.exception == null) {
1631 request.result = ar.result;
1632 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001633 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001634 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001635 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001636 }
1637
1638 synchronized (request) {
1639 request.notifyAll();
1640 }
1641 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001642 }
chen xu6dac5ab2018-10-26 17:39:23 -07001643 case CMD_MODEM_REBOOT:
1644 request = (MainThreadRequest) msg.obj;
1645 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001646 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001647 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001648 case EVENT_CMD_MODEM_REBOOT_DONE:
1649 handleNullReturnEvent(msg, "rebootModem");
1650 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001651 case CMD_REQUEST_ENABLE_MODEM:
1652 request = (MainThreadRequest) msg.obj;
1653 boolean enable = (boolean) request.argument;
1654 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001655 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001656 PhoneConfigurationManager.getInstance()
1657 .enablePhone(request.phone, enable, onCompleted);
1658 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001659 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
1662 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001663 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001664 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001665 if ((boolean) request.result) {
1666 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1667 updateModemStateMetrics();
1668 } else {
1669 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1670 + ar.exception);
1671 }
1672 notifyRequester(request);
1673 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001674 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001675 case CMD_GET_MODEM_STATUS:
1676 request = (MainThreadRequest) msg.obj;
1677 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1678 PhoneConfigurationManager.getInstance()
1679 .getPhoneStatusFromModem(request.phone, onCompleted);
1680 break;
1681 case EVENT_GET_MODEM_STATUS_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 int id = request.phone.getPhoneId();
1685 if (ar.exception == null && ar.result != null) {
1686 request.result = ar.result;
1687 //update the cache as modem status has changed
1688 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1689 (boolean) request.result);
1690 } else {
1691 // Return true if modem status cannot be retrieved. For most cases,
1692 // modem status is on. And for older version modems, GET_MODEM_STATUS
1693 // and disable modem are not supported. Modem is always on.
1694 // TODO: this should be fixed in R to support a third
1695 // status UNKNOWN b/131631629
1696 request.result = true;
1697 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1698 + ar.exception);
1699 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001700 notifyRequester(request);
1701 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001702 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1705 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1706 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1707 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1708 break;
1709 }
1710 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1711 ar = (AsyncResult) msg.obj;
1712 request = (MainThreadRequest) ar.userObj;
1713 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1714 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1715 args.second.accept(ar.exception == null);
1716 notifyRequester(request);
1717 break;
1718 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001719 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1722 Phone phone = getPhoneFromRequest(request);
1723 if (phone != null) {
1724 phone.getSystemSelectionChannels(onCompleted);
1725 } else {
1726 loge("getSystemSelectionChannels: No phone object");
1727 request.result = new ArrayList<RadioAccessSpecifier>();
1728 notifyRequester(request);
1729 }
1730 break;
1731 }
1732 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception == null && ar.result != null) {
1736 request.result = ar.result;
1737 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001738 request.result = new IllegalStateException(
1739 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 if (ar.result == null) {
1741 loge("getSystemSelectionChannels: Empty response");
1742 } else {
1743 loge("getSystemSelectionChannels: Unknown exception");
1744 }
1745 }
1746 notifyRequester(request);
1747 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001748 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
1751 if (ar.exception == null && ar.result != null) {
1752 request.result = ar.result;
1753 } else {
1754 request.result = -1;
1755 loge("Failed to set Forbidden Plmns");
1756 if (ar.result == null) {
1757 loge("setForbidenPlmns: Empty response");
1758 } else if (ar.exception != null) {
1759 loge("setForbiddenPlmns: Exception: " + ar.exception);
1760 request.result = -1;
1761 } else {
1762 loge("setForbiddenPlmns: Unknown exception");
1763 }
1764 }
1765 notifyRequester(request);
1766 break;
1767 case CMD_SET_FORBIDDEN_PLMNS:
1768 request = (MainThreadRequest) msg.obj;
1769 uiccCard = getUiccCardFromRequest(request);
1770 if (uiccCard == null) {
1771 loge("setForbiddenPlmns: UiccCard is null");
1772 request.result = -1;
1773 notifyRequester(request);
1774 break;
1775 }
1776 Pair<Integer, List<String>> setFplmnsArgs =
1777 (Pair<Integer, List<String>>) request.argument;
1778 appType = setFplmnsArgs.first;
1779 List<String> fplmns = setFplmnsArgs.second;
1780 uiccApp = uiccCard.getApplicationByType(appType);
1781 if (uiccApp == null) {
1782 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1783 request.result = -1;
1784 loge("Failed to get UICC App");
1785 notifyRequester(request);
1786 } else {
1787 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1788 ((SIMRecords) uiccApp.getIccRecords())
1789 .setForbiddenPlmns(onCompleted, fplmns);
1790 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001791 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001792 case CMD_ERASE_MODEM_CONFIG:
1793 request = (MainThreadRequest) msg.obj;
1794 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1795 defaultPhone.eraseModemConfig(onCompleted);
1796 break;
1797 case EVENT_ERASE_MODEM_CONFIG_DONE:
1798 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001799 break;
zoey chene02881a2019-12-30 16:11:23 +08001800
Kai Shif70f46f2021-03-03 13:59:46 -08001801 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1802 request = (MainThreadRequest) msg.obj;
1803 request.result = defaultPhone.eraseDataInSharedPreferences();
1804 notifyRequester(request);
1805 break;
1806
zoey chene02881a2019-12-30 16:11:23 +08001807 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1808 request = (MainThreadRequest) msg.obj;
1809 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1810 Pair<String, String> changed = (Pair<String, String>) request.argument;
1811 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1812 changed.first, changed.second, onCompleted);
1813 break;
1814 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 if (ar.exception == null) {
1818 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001819 // If the operation is successful, update the PIN storage
1820 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1821 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivackbb777522021-10-06 20:53:09 +00001822 UiccController.getInstance().getPinStorage()
1823 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001824 } else {
1825 request.result = msg.arg1;
1826 }
1827 notifyRequester(request);
1828 break;
1829
Michele Berionne5e411512020-11-13 02:36:59 +00001830 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001831 request = (MainThreadRequest) msg.obj;
1832 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1833 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1834 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1835 enabled.first, enabled.second, onCompleted);
1836 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001837 }
zoey chene02881a2019-12-30 16:11:23 +08001838 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1839 ar = (AsyncResult) msg.obj;
1840 request = (MainThreadRequest) ar.userObj;
1841 if (ar.exception == null) {
1842 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001843 // If the operation is successful, update the PIN storage
1844 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1845 int phoneId = getPhoneFromRequest(request).getPhoneId();
1846 if (enabled.first) {
Jon Spivackbb777522021-10-06 20:53:09 +00001847 UiccController.getInstance().getPinStorage()
1848 .storePin(enabled.second, phoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00001849 } else {
1850 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1851 }
zoey chene02881a2019-12-30 16:11:23 +08001852 } else {
1853 request.result = msg.arg1;
1854 }
Michele Berionne5e411512020-11-13 02:36:59 +00001855
1856
zoey chene02881a2019-12-30 16:11:23 +08001857 notifyRequester(request);
1858 break;
1859
Peter Wangdafb9ac2020-01-15 14:13:38 -08001860 case MSG_NOTIFY_USER_ACTIVITY:
1861 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001862 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001863 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1864 getDefaultPhone().getContext().sendBroadcastAsUser(
1865 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1866 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001867
1868 case CMD_SET_DATA_THROTTLING: {
1869 request = (MainThreadRequest) msg.obj;
1870 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1871 DataThrottlingRequest dataThrottlingRequest =
1872 (DataThrottlingRequest) request.argument;
1873 Phone phone = getPhoneFromRequest(request);
1874 if (phone != null) {
1875 phone.setDataThrottling(onCompleted,
1876 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1877 dataThrottlingRequest.getCompletionDurationMillis());
1878 } else {
1879 loge("setDataThrottling: No phone object");
1880 request.result =
1881 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1882 notifyRequester(request);
1883 }
1884
1885 break;
1886 }
1887 case EVENT_SET_DATA_THROTTLING_DONE:
1888 ar = (AsyncResult) msg.obj;
1889 request = (MainThreadRequest) ar.userObj;
1890
1891 if (ar.exception == null) {
1892 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1893 } else if (ar.exception instanceof CommandException) {
1894 loge("setDataThrottling: CommandException: " + ar.exception);
1895 CommandException.Error error =
1896 ((CommandException) (ar.exception)).getCommandError();
1897
1898 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1899 request.result = TelephonyManager
1900 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1901 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1902 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001903 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1904 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001905 } else {
1906 request.result =
1907 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1908 }
1909 } else {
1910 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1911 }
1912 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1913 notifyRequester(request);
1914 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001915
1916 case CMD_SET_SIM_POWER: {
1917 request = (MainThreadRequest) msg.obj;
1918 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1919 request = (MainThreadRequest) msg.obj;
1920 int stateToSet =
1921 ((Pair<Integer, IIntegerConsumer>)
1922 request.argument).first;
1923 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1924 break;
1925 }
1926 case EVENT_SET_SIM_POWER_DONE: {
1927 ar = (AsyncResult) msg.obj;
1928 request = (MainThreadRequest) ar.userObj;
1929 IIntegerConsumer callback =
1930 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1931 if (ar.exception != null) {
1932 loge("setSimPower exception: " + ar.exception);
1933 int errorCode = TelephonyManager.CallForwardingInfoCallback
1934 .RESULT_ERROR_UNKNOWN;
1935 if (ar.exception instanceof CommandException) {
1936 CommandException.Error error =
1937 ((CommandException) (ar.exception)).getCommandError();
1938 if (error == CommandException.Error.SIM_ERR) {
1939 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1940 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1941 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1942 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1943 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1944 } else {
1945 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1946 }
1947 }
1948 try {
1949 callback.accept(errorCode);
1950 } catch (RemoteException e) {
1951 // Ignore if the remote process is no longer available to call back.
1952 Log.w(LOG_TAG, "setSimPower: callback not available.");
1953 }
1954 } else {
1955 try {
1956 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1957 } catch (RemoteException e) {
1958 // Ignore if the remote process is no longer available to call back.
1959 Log.w(LOG_TAG, "setSimPower: callback not available.");
1960 }
1961 }
1962 break;
1963 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001964 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1965 request = (MainThreadRequest) msg.obj;
1966
1967 final Phone phone = getPhoneFromRequest(request);
1968 if (phone == null || phone.getServiceStateTracker() == null) {
1969 request.result = new IllegalStateException("Phone or SST is null");
1970 notifyRequester(request);
1971 break;
1972 }
1973
1974 Pair<Integer, SignalStrengthUpdateRequest> pair =
1975 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1976 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1977 request);
Rambo Wang6568f172021-02-03 16:56:47 -08001978 phone.getSignalStrengthController().setSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001979 request.subId, pair.first /*callingUid*/,
1980 pair.second /*request*/, onCompleted);
1981 break;
1982 }
1983 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1984 ar = (AsyncResult) msg.obj;
1985 request = (MainThreadRequest) ar.userObj;
1986 // request.result will be the exception of ar if present, true otherwise.
1987 // Be cautious not to leave result null which will wait() forever
1988 request.result = ar.exception != null ? ar.exception : true;
1989 notifyRequester(request);
1990 break;
1991 }
1992 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1993 request = (MainThreadRequest) msg.obj;
1994
1995 Phone phone = getPhoneFromRequest(request);
1996 if (phone == null || phone.getServiceStateTracker() == null) {
1997 request.result = new IllegalStateException("Phone or SST is null");
1998 notifyRequester(request);
1999 break;
2000 }
2001
2002 Pair<Integer, SignalStrengthUpdateRequest> pair =
2003 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2004 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2005 request);
Rambo Wang6568f172021-02-03 16:56:47 -08002006 phone.getSignalStrengthController().clearSignalStrengthUpdateRequest(
Rambo Wanga5cc9b72021-01-07 10:51:54 -08002007 request.subId, pair.first /*callingUid*/,
2008 pair.second /*request*/, onCompleted);
2009 break;
2010 }
2011 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2012 ar = (AsyncResult) msg.obj;
2013 request = (MainThreadRequest) ar.userObj;
2014 request.result = ar.exception != null ? ar.exception : true;
2015 notifyRequester(request);
2016 break;
2017 }
Jordan Liu109698e2020-11-24 14:50:34 -08002018
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002019 case CMD_GET_SLICING_CONFIG: {
2020 request = (MainThreadRequest) msg.obj;
2021 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2022 request.phone.getSlicingConfig(onCompleted);
2023 break;
2024 }
2025 case EVENT_GET_SLICING_CONFIG_DONE: {
2026 ar = (AsyncResult) msg.obj;
2027 request = (MainThreadRequest) ar.userObj;
2028 ResultReceiver result = (ResultReceiver) request.argument;
2029
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002030 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002031 Bundle bundle = new Bundle();
2032 int resultCode = 0;
2033 if (ar.exception != null) {
2034 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2035 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002036 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002037 } else if (ar.result == null) {
2038 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002039 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 } else {
2041 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002042 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2043 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002044 }
2045
2046 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002047 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002048 }
2049 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2050 result.send(resultCode, bundle);
2051 notifyRequester(request);
2052 break;
2053 }
2054
Michele Berionne5e411512020-11-13 02:36:59 +00002055 case CMD_PREPARE_UNATTENDED_REBOOT:
2056 request = (MainThreadRequest) msg.obj;
2057 request.result =
2058 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
2059 notifyRequester(request);
2060 break;
2061
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 default:
2063 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2064 break;
2065 }
2066 }
Jake Hambye994d462014-02-03 13:10:13 -08002067
Pengquan Menga1bb6272018-09-06 09:59:22 -07002068 private void notifyRequester(MainThreadRequest request) {
2069 synchronized (request) {
2070 request.notifyAll();
2071 }
2072 }
2073
Jake Hambye994d462014-02-03 13:10:13 -08002074 private void handleNullReturnEvent(Message msg, String command) {
2075 AsyncResult ar = (AsyncResult) msg.obj;
2076 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2077 if (ar.exception == null) {
2078 request.result = true;
2079 } else {
2080 request.result = false;
2081 if (ar.exception instanceof CommandException) {
2082 loge(command + ": CommandException: " + ar.exception);
2083 } else {
2084 loge(command + ": Unknown exception");
2085 }
2086 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002087 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 }
2090
2091 /**
2092 * Posts the specified command to be executed on the main thread,
2093 * waits for the request to complete, and returns the result.
2094 * @see #sendRequestAsync
2095 */
2096 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002097 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2098 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002099 }
2100
2101 /**
2102 * Posts the specified command to be executed on the main thread,
2103 * waits for the request to complete, and returns the result.
2104 * @see #sendRequestAsync
2105 */
2106 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2107 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002108 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002109 }
2110
2111 /**
2112 * Posts the specified command to be executed on the main thread,
2113 * waits for the request to complete, and returns the result.
2114 * @see #sendRequestAsync
2115 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002116 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002117 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2118 }
2119
2120 /**
2121 * Posts the specified command to be executed on the main thread,
2122 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2123 * if not timeout or null otherwise.
2124 * @see #sendRequestAsync
2125 */
2126 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2127 long timeoutInMs) {
2128 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002129 }
2130
2131 /**
2132 * Posts the specified command to be executed on the main thread,
2133 * waits for the request to complete, and returns the result.
2134 * @see #sendRequestAsync
2135 */
Nathan Harold92bed182018-10-12 18:16:49 -07002136 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002137 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002138 }
2139
2140 /**
2141 * Posts the specified command to be executed on the main thread,
2142 * waits for the request to complete, and returns the result.
2143 * @see #sendRequestAsync
2144 */
2145 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002146 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2147 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002148 }
2149
2150 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002151 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2152 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2153 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002154 * @see #sendRequestAsync
2155 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002156 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2157 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2159 throw new RuntimeException("This method will deadlock if called from the main thread.");
2160 }
2161
Nathan Harold92bed182018-10-12 18:16:49 -07002162 MainThreadRequest request = null;
2163 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2164 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2165 } else if (phone != null) {
2166 request = new MainThreadRequest(argument, phone, workSource);
2167 } else {
2168 request = new MainThreadRequest(argument, subId, workSource);
2169 }
2170
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 Message msg = mMainThreadHandler.obtainMessage(command, request);
2172 msg.sendToTarget();
2173
Rambo Wang0f050d82021-02-12 11:43:36 -08002174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002176 if (timeoutInMs >= 0) {
2177 // Wait for at least timeoutInMs before returning null request result
2178 long now = SystemClock.elapsedRealtime();
2179 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002180 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002181 try {
2182 request.wait(deadline - now);
2183 } catch (InterruptedException e) {
2184 // Do nothing, go back and check if request is completed or timeout
2185 } finally {
2186 now = SystemClock.elapsedRealtime();
2187 }
2188 }
2189 } else {
2190 // Wait for the request to complete
2191 while (request.result == null) {
2192 try {
2193 request.wait();
2194 } catch (InterruptedException e) {
2195 // Do nothing, go back and wait until the request is complete
2196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198 }
2199 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002200 if (request.result == null) {
2201 Log.wtf(LOG_TAG,
2202 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 return request.result;
2205 }
2206
2207 /**
2208 * Asynchronous ("fire and forget") version of sendRequest():
2209 * Posts the specified command to be executed on the main thread, and
2210 * returns immediately.
2211 * @see #sendRequest
2212 */
2213 private void sendRequestAsync(int command) {
2214 mMainThreadHandler.sendEmptyMessage(command);
2215 }
2216
2217 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002218 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002219 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002220 */
2221 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002222 sendRequestAsync(command, argument, null, null);
2223 }
2224
2225 /**
2226 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2227 * @see {@link #sendRequest(int,Object)}
2228 */
2229 private void sendRequestAsync(
2230 int command, Object argument, Phone phone, WorkSource workSource) {
2231 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002232 Message msg = mMainThreadHandler.obtainMessage(command, request);
2233 msg.sendToTarget();
2234 }
2235
2236 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 * Initialize the singleton PhoneInterfaceManager instance.
2238 * This is only done once, at startup, from PhoneApp.onCreate().
2239 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002240 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 synchronized (PhoneInterfaceManager.class) {
2242 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002243 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 } else {
2245 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2246 }
2247 return sInstance;
2248 }
2249 }
2250
2251 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002252 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002255 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002256 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002258 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002260 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002261 mTelephonySharedPreferences =
2262 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002263 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002264 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002265 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002266 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002267
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 publish();
2269 }
2270
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002271 private Phone getDefaultPhone() {
2272 Phone thePhone = getPhone(getDefaultSubscription());
2273 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2274 }
2275
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 private void publish() {
2277 if (DBG) log("publish: " + this);
2278
Peter Wangc035ce42020-01-08 21:00:22 -08002279 TelephonyFrameworkInitializer
2280 .getTelephonyServiceManager()
2281 .getTelephonyServiceRegisterer()
2282 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 }
2284
Stuart Scott584921c2015-01-15 17:10:34 -08002285 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002286 if (request.phone != null) {
2287 return request.phone;
2288 } else {
2289 return getPhoneFromSubId(request.subId);
2290 }
2291 }
2292
2293 private Phone getPhoneFromSubId(int subId) {
2294 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2295 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002296 }
2297
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002298 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2299 Phone phone = getPhoneFromRequest(request);
2300 return phone == null ? null :
2301 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2302 }
2303
Wink Saville36469e72014-06-11 15:17:00 -07002304 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002305 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002306 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002307 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002308
Kai Shif70f46f2021-03-03 13:59:46 -08002309 private void sendEraseModemConfig(@NonNull Phone phone) {
2310 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2311 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2312 }
2313
2314 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2315 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2316 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002317 }
2318
Peter Wang44b186e2020-01-13 23:33:09 -08002319 private boolean isImsAvailableOnDevice() {
2320 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2321 if (pm == null) {
2322 // For some reason package manger is not available.. This will fail internally anyway,
2323 // so do not throw error and allow.
2324 return true;
2325 }
2326 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2327 }
2328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002330 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002331 }
2332
Wink Savilleb564aae2014-10-23 10:18:09 -07002333 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 if (DBG) log("dial: " + number);
2335 // No permission check needed here: This is just a wrapper around the
2336 // ACTION_DIAL intent, which is available to any app since it puts up
2337 // the UI before it does anything.
2338
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 String url = createTelUrl(number);
2342 if (url == null) {
2343 return;
2344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346 // PENDING: should we just silently fail if phone is offhook or ringing?
2347 PhoneConstants.State state = mCM.getState(subId);
2348 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2349 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2350 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2351 mApp.startActivity(intent);
2352 }
2353 } finally {
2354 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 }
2356 }
2357
2358 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002359 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002360 }
2361
Wink Savilleb564aae2014-10-23 10:18:09 -07002362 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 if (DBG) log("call: " + number);
2364
2365 // This is just a wrapper around the ACTION_CALL intent, but we still
2366 // need to do a permission check since we're calling startActivity()
2367 // from the context of the phone app.
2368 enforceCallPermission();
2369
Jordan Liu1617b712019-07-10 15:06:26 -07002370 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 != AppOpsManager.MODE_ALLOWED) {
2372 return;
2373 }
2374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375 final long identity = Binder.clearCallingIdentity();
2376 try {
2377 String url = createTelUrl(number);
2378 if (url == null) {
2379 return;
2380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382 boolean isValid = false;
2383 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2384 if (slist != null) {
2385 for (SubscriptionInfo subInfoRecord : slist) {
2386 if (subInfoRecord.getSubscriptionId() == subId) {
2387 isValid = true;
2388 break;
2389 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002390 }
Wink Saville08874612014-08-31 19:19:58 -07002391 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002392 if (!isValid) {
2393 return;
2394 }
Wink Saville08874612014-08-31 19:19:58 -07002395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2397 intent.putExtra(SUBSCRIPTION_KEY, subId);
2398 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2399 mApp.startActivity(intent);
2400 } finally {
2401 Binder.restoreCallingIdentity(identity);
2402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Wink Savilleb564aae2014-10-23 10:18:09 -07002405 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002406 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002407 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2408 }
2409
Wink Savilleb564aae2014-10-23 10:18:09 -07002410 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002411 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002412 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2413 }
2414
Wink Savilleb564aae2014-10-23 10:18:09 -07002415 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002417
2418 final long identity = Binder.clearCallingIdentity();
2419 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002420 Phone phone = getPhone(subId);
2421 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 checkSimPin.start();
2423 return checkSimPin.unlockSim(null, pin);
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 }
2428
Wink Savilleb564aae2014-10-23 10:18:09 -07002429 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431
2432 final long identity = Binder.clearCallingIdentity();
2433 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002434 Phone phone = getPhone(subId);
2435 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 checkSimPuk.start();
2437 return checkSimPuk.unlockSim(puk, pin);
2438 } finally {
2439 Binder.restoreCallingIdentity(identity);
2440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 }
2442
2443 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002444 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 * a synchronous one.
2446 */
2447 private static class UnlockSim extends Thread {
2448
2449 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002450 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451
2452 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002453 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2454 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
2456 // For replies from SimCard interface
2457 private Handler mHandler;
2458
2459 // For async handler to identify request type
2460 private static final int SUPPLY_PIN_COMPLETE = 100;
2461
Michele Berionne5e411512020-11-13 02:36:59 +00002462 UnlockSim(int phoneId, IccCard simCard) {
2463 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 mSimCard = simCard;
2465 }
2466
2467 @Override
2468 public void run() {
2469 Looper.prepare();
2470 synchronized (UnlockSim.this) {
2471 mHandler = new Handler() {
2472 @Override
2473 public void handleMessage(Message msg) {
2474 AsyncResult ar = (AsyncResult) msg.obj;
2475 switch (msg.what) {
2476 case SUPPLY_PIN_COMPLETE:
2477 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2478 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002479 mRetryCount = msg.arg1;
2480 if (ar.exception != null) {
2481 if (ar.exception instanceof CommandException &&
2482 ((CommandException)(ar.exception)).getCommandError()
2483 == CommandException.Error.PASSWORD_INCORRECT) {
2484 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002485 } //When UiccCardApp dispose,handle message and return exception
2486 else if (ar.exception instanceof CommandException &&
2487 ((CommandException) (ar.exception)).getCommandError()
2488 == CommandException.Error.ABORTED) {
2489 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002490 } else {
2491 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2492 }
2493 } else {
2494 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 mDone = true;
2497 UnlockSim.this.notifyAll();
2498 }
2499 break;
2500 }
2501 }
2502 };
2503 UnlockSim.this.notifyAll();
2504 }
2505 Looper.loop();
2506 }
2507
2508 /*
2509 * Use PIN or PUK to unlock SIM card
2510 *
2511 * If PUK is null, unlock SIM card with PIN
2512 *
2513 * If PUK is not null, unlock SIM card with PUK and set PIN code
2514 */
Wink Saville9de0f752013-10-22 19:04:03 -07002515 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516
2517 while (mHandler == null) {
2518 try {
2519 wait();
2520 } catch (InterruptedException e) {
2521 Thread.currentThread().interrupt();
2522 }
2523 }
2524 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2525
2526 if (puk == null) {
2527 mSimCard.supplyPin(pin, callback);
2528 } else {
2529 mSimCard.supplyPuk(puk, pin, callback);
2530 }
2531
2532 while (!mDone) {
2533 try {
2534 Log.d(LOG_TAG, "wait for done");
2535 wait();
2536 } catch (InterruptedException e) {
2537 // Restore the interrupted status
2538 Thread.currentThread().interrupt();
2539 }
2540 }
2541 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002542 int[] resultArray = new int[2];
2543 resultArray[0] = mResult;
2544 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002545
2546 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivackbb777522021-10-06 20:53:09 +00002547 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002548 }
2549
Wink Saville9de0f752013-10-22 19:04:03 -07002550 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002551 }
2552 }
2553
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002554 /**
2555 * This method has been removed due to privacy and stability concerns.
2556 */
2557 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002559 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2560 return;
Wink Saville36469e72014-06-11 15:17:00 -07002561 }
2562
Nathan Harold1f889d82020-06-04 17:05:26 -07002563 @Override
2564 public void updateServiceLocationWithPackageName(String callingPackage) {
2565 mApp.getSystemService(AppOpsManager.class)
2566 .checkPackage(Binder.getCallingUid(), callingPackage);
2567
Nathan Haroldf096d982020-11-18 17:18:06 -08002568 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002569 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2570 // Callers targeting S have no business invoking this method.
2571 return;
2572 }
2573
2574 LocationAccessPolicy.LocationPermissionResult locationResult =
2575 LocationAccessPolicy.checkLocationPermission(mApp,
2576 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2577 .setCallingPackage(callingPackage)
2578 .setCallingFeatureId(null)
2579 .setCallingPid(Binder.getCallingPid())
2580 .setCallingUid(Binder.getCallingUid())
2581 .setMethod("updateServiceLocation")
2582 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2583 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2584 .build());
2585 // Apps that lack location permission have no business calling this method;
2586 // however, because no permission was declared in the public API, denials must
2587 // all be "soft".
2588 switch (locationResult) {
2589 case DENIED_HARD: /* fall through */
2590 case DENIED_SOFT:
2591 return;
2592 }
2593
2594 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 final long identity = Binder.clearCallingIdentity();
2596 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002597 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002599 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002600 }
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 }
2605
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002606 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002607 @Override
2608 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002609 return isRadioOnWithFeature(callingPackage, null);
2610 }
2611
2612
2613 @Override
2614 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2615 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2616 callingFeatureId);
2617 }
2618
2619 @Deprecated
2620 @Override
2621 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2622 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002623 }
2624
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002625 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002626 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2627 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002629 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002630 return false;
2631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 return isRadioOnForSubscriber(subId);
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002639 }
2640
2641 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 final Phone phone = getPhone(subId);
2645 if (phone != null) {
2646 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2647 } else {
2648 return false;
2649 }
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 }
2654
2655 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002656 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
Wink Saville36469e72014-06-11 15:17:00 -07002658
Wink Savilleb564aae2014-10-23 10:18:09 -07002659 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 final Phone phone = getPhone(subId);
2665 if (phone != null) {
2666 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2667 }
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002670 }
Wink Saville36469e72014-06-11 15:17:00 -07002671 }
2672
2673 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002674 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002675 }
2676
Wink Savilleb564aae2014-10-23 10:18:09 -07002677 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679
2680 final long identity = Binder.clearCallingIdentity();
2681 try {
2682 final Phone phone = getPhone(subId);
2683 if (phone == null) {
2684 return false;
2685 }
2686 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2687 toggleRadioOnOffForSubscriber(subId);
2688 }
2689 return true;
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
Wink Saville36469e72014-06-11 15:17:00 -07002694
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002695 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002696 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002697 /*
2698 * If any of the Radios are available, it will need to be
2699 * shutdown. So return true if any Radio is available.
2700 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2704 Phone phone = PhoneFactory.getPhone(i);
2705 if (phone != null && phone.isRadioAvailable()) return true;
2706 }
2707 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2708 return false;
2709 } finally {
2710 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002711 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002712 }
2713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002715 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716 enforceModifyPermission();
2717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2721 logv("Shutting down Phone " + i);
2722 shutdownRadioUsingPhoneId(i);
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002726 }
2727 }
2728
2729 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002730 Phone phone = PhoneFactory.getPhone(phoneId);
2731 if (phone != null && phone.isRadioAvailable()) {
2732 phone.shutdownRadio();
2733 }
2734 }
2735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2742 if (defaultPhone != null) {
2743 defaultPhone.setRadioPower(turnOn);
2744 return true;
2745 } else {
2746 loge("There's no default phone.");
2747 return false;
2748 }
2749 } finally {
2750 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002751 }
Wink Saville36469e72014-06-11 15:17:00 -07002752 }
2753
Wink Savilleb564aae2014-10-23 10:18:09 -07002754 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756
2757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 final Phone phone = getPhone(subId);
2760 if (phone != null) {
2761 phone.setRadioPower(turnOn);
2762 return true;
2763 } else {
2764 return false;
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
Wink Saville36469e72014-06-11 15:17:00 -07002771 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002772 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002773 public boolean enableDataConnectivity() {
2774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775
2776 final long identity = Binder.clearCallingIdentity();
2777 try {
2778 int subId = mSubscriptionController.getDefaultDataSubId();
2779 final Phone phone = getPhone(subId);
2780 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002781 phone.getDataEnabledSettings().setDataEnabled(
2782 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 return true;
2784 } else {
2785 return false;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002790 }
2791
Wink Saville36469e72014-06-11 15:17:00 -07002792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002794 public boolean disableDataConnectivity() {
2795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 int subId = mSubscriptionController.getDefaultDataSubId();
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002802 phone.getDataEnabledSettings().setDataEnabled(
2803 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002804 return true;
2805 } else {
2806 return false;
2807 }
2808 } finally {
2809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811 }
2812
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002814 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 final Phone phone = getPhone(subId);
2818 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002819 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002820 } else {
2821 return false;
2822 }
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 }
2827
2828 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002829 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002830 }
2831
pkanwarae03a6b2016-11-06 20:37:09 -08002832 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 enforceCallPermission();
2834
2835 final long identity = Binder.clearCallingIdentity();
2836 try {
2837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2838 return;
2839 }
2840 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2841 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
2844 }
pkanwar32d516d2016-10-14 19:37:38 -07002845 };
2846
Wink Savilleb564aae2014-10-23 10:18:09 -07002847 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2853 return false;
2854 }
2855 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002861 /**
2862 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2863 * tag on getCallState Binder call.
2864 */
2865 @Deprecated
2866 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002867 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002868 if (CompatChanges.isChangeEnabled(
2869 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2870 Binder.getCallingUid())) {
2871 // Do not allow this API to be called on API version 31+, it should only be
2872 // called on old apps using this Binder call directly.
2873 throw new SecurityException("This method can only be used for applications "
2874 + "targeting API version 30 or less.");
2875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876 final long identity = Binder.clearCallingIdentity();
2877 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002878 Phone phone = getPhone(getDefaultSubscription());
2879 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2880 PhoneConstantConversions.convertCallState(phone.getState());
2881 } finally {
2882 Binder.restoreCallingIdentity(identity);
2883 }
2884 }
2885
2886 @Override
2887 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2888 if (CompatChanges.isChangeEnabled(
2889 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2890 Binder.getCallingUid())) {
2891 // Check READ_PHONE_STATE for API version 31+
2892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2893 featureId, "getCallStateForSubscription")) {
2894 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2895 + "targeting API level 31+.");
2896 }
2897 }
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2902 PhoneConstantConversions.convertCallState(phone.getState());
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
2905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
Sanket Padawe356d7632015-06-22 14:03:32 -07002908 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002909 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002910 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2911 }
2912
2913 @Override
2914 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915 final long identity = Binder.clearCallingIdentity();
2916 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002917 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002918 if (phone != null) {
2919 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2920 } else {
2921 return PhoneConstantConversions.convertDataState(
2922 PhoneConstants.DataState.DISCONNECTED);
2923 }
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002926 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927 }
2928
Sanket Padawe356d7632015-06-22 14:03:32 -07002929 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002930 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002931 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2932 }
2933
2934 @Override
2935 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002936 final long identity = Binder.clearCallingIdentity();
2937 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002938 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 if (phone != null) {
2940 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2941 } else {
2942 return TelephonyManager.DATA_ACTIVITY_NONE;
2943 }
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947 }
2948
2949 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002950 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002952 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002953
2954 LocationAccessPolicy.LocationPermissionResult locationResult =
2955 LocationAccessPolicy.checkLocationPermission(mApp,
2956 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2957 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002958 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002959 .setCallingPid(Binder.getCallingPid())
2960 .setCallingUid(Binder.getCallingUid())
2961 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002962 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002963 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2964 .build());
2965 switch (locationResult) {
2966 case DENIED_HARD:
2967 throw new SecurityException("Not allowed to access cell location");
2968 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002969 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2970 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
2972
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002977 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002978 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
Svetoslav64fad262015-04-14 14:35:21 -07002982 }
2983
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002984 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002985 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002986 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2987 // registered cell info, so return a NULL country instead.
2988 final long identity = Binder.clearCallingIdentity();
2989 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002990 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2991 // Get default phone in this case.
2992 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2993 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002994 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002996 if (phone == null) return "";
2997 ServiceStateTracker sst = phone.getServiceStateTracker();
2998 if (sst == null) return "";
2999 LocaleTracker lt = sst.getLocaleTracker();
3000 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003001 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003005 }
3006
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003007 /**
3008 * This method was removed due to potential issues caused by performing partial
3009 * updates of service state, and lack of a credible use case.
3010 *
3011 * This has the ability to break the telephony implementation by disabling notification of
3012 * changes in device connectivity. DO NOT USE THIS!
3013 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003014 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003015 public void enableLocationUpdates() {
3016 mApp.enforceCallingOrSelfPermission(
3017 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 }
3019
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003020 /**
3021 * This method was removed due to potential issues caused by performing partial
3022 * updates of service state, and lack of a credible use case.
3023 *
3024 * This has the ability to break the telephony implementation by disabling notification of
3025 * changes in device connectivity. DO NOT USE THIS!
3026 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003027 @Override
3028 public void disableLocationUpdates() {
3029 mApp.enforceCallingOrSelfPermission(
3030 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003031 }
3032
3033 @Override
3034 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003035 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3036 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003037 try {
3038 mApp.getSystemService(AppOpsManager.class)
3039 .checkPackage(Binder.getCallingUid(), callingPackage);
3040 } catch (SecurityException e) {
3041 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3042 throw e;
3043 }
3044
Nathan Haroldf096d982020-11-18 17:18:06 -08003045 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003046 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3047 throw new SecurityException(
3048 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3049 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003050
Jordan Liu1617b712019-07-10 15:06:26 -07003051 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3053 return null;
3054 }
Svetoslav64fad262015-04-14 14:35:21 -07003055
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003056 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003057
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003058 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003059 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060
Nathan Haroldf180aac2018-06-01 18:43:55 -07003061 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3062 for (CellInfo ci : info) {
3063 if (ci instanceof CellInfoGsm) {
3064 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3065 } else if (ci instanceof CellInfoWcdma) {
3066 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003068 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003069 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003070 }
3071
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003072 private List<CellInfo> getCachedCellInfo() {
3073 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3074 for (Phone phone : PhoneFactory.getPhones()) {
3075 List<CellInfo> info = phone.getAllCellInfo();
3076 if (info != null) cellInfos.addAll(info);
3077 }
3078 return cellInfos;
3079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080
3081 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003082 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003083 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003084 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003085
3086 LocationAccessPolicy.LocationPermissionResult locationResult =
3087 LocationAccessPolicy.checkLocationPermission(mApp,
3088 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3089 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003090 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003091 .setCallingPid(Binder.getCallingPid())
3092 .setCallingUid(Binder.getCallingUid())
3093 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003094 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003095 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3096 .build());
3097 switch (locationResult) {
3098 case DENIED_HARD:
3099 throw new SecurityException("Not allowed to access cell info");
3100 case DENIED_SOFT:
3101 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003102 }
3103
Nathan Haroldf096d982020-11-18 17:18:06 -08003104 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003105 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3106 return getCachedCellInfo();
3107 }
3108
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003109 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003110 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3114 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003115 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003116 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117 if (info != null) cellInfos.addAll(info);
3118 }
3119 return cellInfos;
3120 } finally {
3121 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003122 }
3123 }
3124
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003125 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003126 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3127 String callingFeatureId) {
3128 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3129 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003130 }
3131
3132 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003133 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3134 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003135 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003136 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003137 }
3138
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003139 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3140 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003141 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003142 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003143
3144 LocationAccessPolicy.LocationPermissionResult locationResult =
3145 LocationAccessPolicy.checkLocationPermission(mApp,
3146 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3147 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003148 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003149 .setCallingPid(Binder.getCallingPid())
3150 .setCallingUid(Binder.getCallingUid())
3151 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003152 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3153 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003154 .build());
3155 switch (locationResult) {
3156 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003157 if (TelephonyPermissions
3158 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003159 // Safetynet logging for b/154934934
3160 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3161 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003162 throw new SecurityException("Not allowed to access cell info");
3163 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003164 if (TelephonyPermissions
3165 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003166 // Safetynet logging for b/154934934
3167 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3168 }
Nathan Harold5320c422019-05-09 10:26:08 -07003169 try {
3170 cb.onCellInfo(new ArrayList<CellInfo>());
3171 } catch (RemoteException re) {
3172 // Drop without consequences
3173 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003174 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003175 }
3176
Nathan Harolda939a962019-05-09 10:13:47 -07003177
3178 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003179 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3180
3181 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3182 }
3183
3184 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003185 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003186 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003187 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188
3189 final long identity = Binder.clearCallingIdentity();
3190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003195 }
3196
Shishir Agrawala9f32182016-04-12 12:00:16 -07003197 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003198 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003199 Phone phone = PhoneFactory.getPhone(slotIndex);
3200 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003201 return null;
3202 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003203 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003204 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003205 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003206 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003207 return null;
3208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 return phone.getImei();
3213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003216 }
3217
3218 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003219 public String getTypeAllocationCodeForSlot(int slotIndex) {
3220 Phone phone = PhoneFactory.getPhone(slotIndex);
3221 String tac = null;
3222 if (phone != null) {
3223 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003224 try {
3225 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3226 } catch (IndexOutOfBoundsException e) {
3227 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3228 return null;
3229 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003230 }
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();
Vala Zadehab005552021-09-21 15:54:29 -07003268 try {
3269 manufacturerCode =
3270 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3271 } catch (IndexOutOfBoundsException e) {
3272 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3273 return null;
3274 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003275 }
3276 return manufacturerCode;
3277 }
3278
3279 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003280 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3281 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003282 Phone phone = PhoneFactory.getPhone(slotIndex);
3283 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003284 return null;
3285 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003286 int subId = phone.getSubId();
3287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003288 mApp, subId, callingPackage, callingFeatureId,
3289 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003290 return null;
3291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003292
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 return phone.getDeviceSvn();
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003299 }
3300
fionaxu43304da2017-11-27 22:51:16 -08003301 @Override
3302 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303 final long identity = Binder.clearCallingIdentity();
3304 try {
3305 final Phone phone = getPhone(subId);
3306 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3307 } finally {
3308 Binder.restoreCallingIdentity(identity);
3309 }
fionaxu43304da2017-11-27 22:51:16 -08003310 }
3311
3312 @Override
3313 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 final Phone phone = getPhone(subId);
3317 return phone == null ? null : phone.getCarrierName();
3318 } finally {
3319 Binder.restoreCallingIdentity(identity);
3320 }
fionaxu43304da2017-11-27 22:51:16 -08003321 }
3322
calvinpanffe225e2018-11-01 19:43:06 +08003323 @Override
chen xu0026ca62019-03-06 15:28:50 -08003324 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 final Phone phone = getPhone(subId);
3328 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003329 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
3333 }
3334
3335 @Override
chen xu0026ca62019-03-06 15:28:50 -08003336 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003340 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
3344 }
3345
chen xu651eec72018-11-11 19:03:44 -08003346 @Override
chen xu864e11c2018-12-06 22:10:03 -08003347 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3348 if (!isSubscriptionMccMnc) {
3349 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3350 }
chen xu651eec72018-11-11 19:03:44 -08003351 final Phone phone = PhoneFactory.getPhone(slotIndex);
3352 if (phone == null) {
3353 return TelephonyManager.UNKNOWN_CARRIER_ID;
3354 }
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
3360 }
3361 }
3362
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003363 //
3364 // Internal helper methods.
3365 //
3366
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003367 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003368 * Make sure the caller is the calling package itself
3369 *
3370 * @throws SecurityException if the caller is not the calling package
3371 */
3372 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3373 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003374 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3375 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003376 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003377 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003378 } catch (PackageManager.NameNotFoundException e) {
3379 // packageUid is -1
3380 }
3381 if (packageUid != callingUid) {
3382 throw new SecurityException(message + ": Package " + callingPackage
3383 + " does not belong to " + callingUid);
3384 }
3385 }
3386
3387 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3389 *
3390 * @throws SecurityException if the caller does not have the required permission
3391 */
3392 private void enforceModifyPermission() {
3393 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3394 }
3395
Shuo Qiancd19c462020-01-16 20:51:11 -08003396 /**
3397 * Make sure the caller is system.
3398 *
3399 * @throws SecurityException if the caller is not system.
3400 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003401 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003402 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3403 throw new SecurityException("Caller must be system");
3404 }
3405 }
3406
Shuo Qian3b6ee772019-11-13 17:43:31 -08003407 private void enforceActiveEmergencySessionPermission() {
3408 mApp.enforceCallingOrSelfPermission(
3409 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3410 }
3411
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003412 /**
3413 * Make sure the caller has the CALL_PHONE permission.
3414 *
3415 * @throws SecurityException if the caller does not have the required permission
3416 */
3417 private void enforceCallPermission() {
3418 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3419 }
3420
paulhu5a773602019-08-23 19:17:33 +08003421 private void enforceSettingsPermission() {
3422 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003423 }
3424
Michele Berionne5e411512020-11-13 02:36:59 +00003425 private void enforceRebootPermission() {
3426 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3427 }
3428
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003429 private String createTelUrl(String number) {
3430 if (TextUtils.isEmpty(number)) {
3431 return null;
3432 }
3433
Jake Hambye994d462014-02-03 13:10:13 -08003434 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003435 }
3436
Ihab Awadf9e92732013-12-05 18:02:52 -08003437 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003438 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3439 }
3440
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003441 private static void logv(String msg) {
3442 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3443 }
3444
Ihab Awadf9e92732013-12-05 18:02:52 -08003445 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003446 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3447 }
3448
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003449 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003450 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003451 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003452 }
3453
Sanket Padawe356d7632015-06-22 14:03:32 -07003454 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003455 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 final Phone phone = PhoneFactory.getPhone(slotIndex);
3459 if (phone == null) {
3460 return PhoneConstants.PHONE_TYPE_NONE;
3461 } else {
3462 return phone.getPhoneType();
3463 }
3464 } finally {
3465 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003467 }
3468
3469 /**
3470 * Returns the CDMA ERI icon index to display
3471 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003473 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3474 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3475 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003476 }
3477
Sanket Padawe356d7632015-06-22 14:03:32 -07003478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003479 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3480 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003482 mApp, subId, callingPackage, callingFeatureId,
3483 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003484 return -1;
3485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003486
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 final Phone phone = getPhone(subId);
3490 if (phone != null) {
3491 return phone.getCdmaEriIconIndex();
3492 } else {
3493 return -1;
3494 }
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003498 }
3499
3500 /**
3501 * Returns the CDMA ERI icon mode,
3502 * 0 - ON
3503 * 1 - FLASHING
3504 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003505 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003506 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3507 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3508 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003509 }
3510
Sanket Padawe356d7632015-06-22 14:03:32 -07003511 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003512 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3513 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003515 mApp, subId, callingPackage, callingFeatureId,
3516 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003517 return -1;
3518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003519
3520 final long identity = Binder.clearCallingIdentity();
3521 try {
3522 final Phone phone = getPhone(subId);
3523 if (phone != null) {
3524 return phone.getCdmaEriIconMode();
3525 } else {
3526 return -1;
3527 }
3528 } finally {
3529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531 }
3532
3533 /**
3534 * Returns the CDMA ERI text,
3535 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003537 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3538 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3539 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003540 }
3541
Sanket Padawe356d7632015-06-22 14:03:32 -07003542 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003543 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3544 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003546 mApp, subId, callingPackage, callingFeatureId,
3547 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003548 return null;
3549 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550
3551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 final Phone phone = getPhone(subId);
3554 if (phone != null) {
3555 return phone.getCdmaEriText();
3556 } else {
3557 return null;
3558 }
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003562 }
3563
3564 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003565 * Returns the CDMA MDN.
3566 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003567 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003568 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3570 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571
3572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003575 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576 return phone.getLine1Number();
3577 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003578 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 return null;
3580 }
3581 } finally {
3582 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003583 }
3584 }
3585
3586 /**
3587 * Returns the CDMA MIN.
3588 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003589 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003590 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003591 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3592 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593
3594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 final Phone phone = getPhone(subId);
3597 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3598 return phone.getCdmaMin();
3599 } else {
3600 return null;
3601 }
3602 } finally {
3603 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003604 }
3605 }
3606
Hall Liud892bec2018-11-30 14:51:45 -08003607 @Override
3608 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3609 INumberVerificationCallback callback, String callingPackage) {
3610 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3611 != PERMISSION_GRANTED) {
3612 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3613 }
3614 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3615
3616 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3617 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003618 throw new SecurityException("Calling package must be configured in the device config: "
3619 + "calling package: " + callingPackage
3620 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003621 }
3622
3623 if (range == null) {
3624 throw new NullPointerException("Range must be non-null");
3625 }
3626
3627 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003628 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003629
3630 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3631 }
3632
Junda Liuca05d5d2014-08-14 22:36:34 -07003633 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003634 * Returns true if CDMA provisioning needs to run.
3635 */
3636 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637 final long identity = Binder.clearCallingIdentity();
3638 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003639 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003643 }
3644
3645 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003646 * Sets the voice mail number of a given subId.
3647 */
3648 @Override
3649 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003650 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3651 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003652
3653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3656 new Pair<String, String>(alphaTag, number), new Integer(subId));
3657 return success;
3658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003661 }
3662
Ta-wei Yen87c49842016-05-13 21:19:52 -07003663 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003664 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003666 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3667 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003668 if (!TextUtils.equals(callingPackage, systemDialer)) {
3669 throw new SecurityException("caller must be system dialer");
3670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3675 if (phoneAccountHandle == null) {
3676 return null;
3677 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003678 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003679 } finally {
3680 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003681 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003682 }
3683
3684 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003685 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3686 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003687 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003689 mApp, subId, callingPackage, callingFeatureId,
3690 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003691 return null;
3692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003694 final long identity = Binder.clearCallingIdentity();
3695 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003696 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003697 } finally {
3698 Binder.restoreCallingIdentity(identity);
3699 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003700 }
3701
3702 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003703 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3704 VisualVoicemailSmsFilterSettings settings) {
3705 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003706
3707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003710 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003714 }
3715
3716 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003717 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3718 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003727 }
3728
3729 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003730 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3731 String callingPackage, int subId) {
3732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733
3734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003737 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003741 }
3742
3743 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003744 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003746
3747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003750 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 } finally {
3752 Binder.restoreCallingIdentity(identity);
3753 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003754 }
3755
3756 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003757 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3758 String callingAttributionTag, int subId, String number, int port, String text,
3759 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003760 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003761 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003762 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003763 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003764 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3765 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003766 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003767
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003768 /**
fionaxu0152e512016-11-14 13:36:14 -08003769 * Sets the voice activation state of a given subId.
3770 */
3771 @Override
3772 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3774 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003775
3776 final long identity = Binder.clearCallingIdentity();
3777 try {
3778 final Phone phone = getPhone(subId);
3779 if (phone != null) {
3780 phone.setVoiceActivationState(activationState);
3781 } else {
3782 loge("setVoiceActivationState fails with invalid subId: " + subId);
3783 }
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003786 }
3787 }
3788
3789 /**
3790 * Sets the data activation state of a given subId.
3791 */
3792 @Override
3793 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3795 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003796
3797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 final Phone phone = getPhone(subId);
3800 if (phone != null) {
3801 phone.setDataActivationState(activationState);
3802 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003803 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 }
3805 } finally {
3806 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003807 }
3808 }
3809
3810 /**
3811 * Returns the voice activation state of a given subId.
3812 */
3813 @Override
3814 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003816
fionaxu0152e512016-11-14 13:36:14 -08003817 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003818 final long identity = Binder.clearCallingIdentity();
3819 try {
3820 if (phone != null) {
3821 return phone.getVoiceActivationState();
3822 } else {
3823 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3824 }
3825 } finally {
3826 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003827 }
3828 }
3829
3830 /**
3831 * Returns the data activation state of a given subId.
3832 */
3833 @Override
3834 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836
fionaxu0152e512016-11-14 13:36:14 -08003837 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 if (phone != null) {
3841 return phone.getDataActivationState();
3842 } else {
3843 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3844 }
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003847 }
3848 }
3849
3850 /**
Wink Saville36469e72014-06-11 15:17:00 -07003851 * Returns the unread count of voicemails for a subId
3852 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003853 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003854 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3855 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003856 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003857 mApp, subId, callingPackage, callingFeatureId,
3858 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003859 return 0;
3860 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 final Phone phone = getPhone(subId);
3864 if (phone != null) {
3865 return phone.getVoiceMessageCount();
3866 } else {
3867 return 0;
3868 }
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003872 }
3873
3874 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003875 * returns true, if the device is in a state where both voice and data
3876 * are supported simultaneously. This can change based on location or network condition.
3877 */
3878 @Override
3879 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003880 final long identity = Binder.clearCallingIdentity();
3881 try {
3882 final Phone phone = getPhone(subId);
3883 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3884 } finally {
3885 Binder.restoreCallingIdentity(identity);
3886 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003887 }
3888
3889 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003890 * Send the dialer code if called from the current default dialer or the caller has
3891 * carrier privilege.
3892 * @param inputCode The dialer code to send
3893 */
3894 @Override
3895 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003896 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003897 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003898 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3899 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003900 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003901 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003902 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904
3905 final long identity = Binder.clearCallingIdentity();
3906 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003907 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 } finally {
3909 Binder.restoreCallingIdentity(identity);
3910 }
fionaxu235cc5e2017-03-06 22:25:57 -08003911 }
3912
Pengquan Menga1bb6272018-09-06 09:59:22 -07003913 @Override
3914 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003915 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003916 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003917 mApp, subId, "getNetworkSelectionMode");
3918 final long identity = Binder.clearCallingIdentity();
3919 try {
3920 if (!isActiveSubscription(subId)) {
3921 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3922 }
3923 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003927 }
3928
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003930 public boolean isInEmergencySmsMode() {
3931 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 for (Phone phone : PhoneFactory.getPhones()) {
3935 if (phone.isInEmergencySmsMode()) {
3936 return true;
3937 }
3938 }
3939 } finally {
3940 Binder.restoreCallingIdentity(identity);
3941 }
3942 return false;
3943 }
3944
shilu366312e2019-12-17 09:28:10 -08003945 /**
3946 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3947 * @param subId The subscription to use to check the configuration.
3948 * @param c The callback that will be used to send the result.
3949 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003950 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003951 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3952 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003953 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003954 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003955
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003956 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3957 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3958 "IMS not available on device.");
3959 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003960 final long token = Binder.clearCallingIdentity();
3961 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003962 int slotId = getSlotIndexOrException(subId);
3963 verifyImsMmTelConfiguredOrThrow(slotId);
3964 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003965 } catch (ImsException e) {
3966 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 } finally {
3968 Binder.restoreCallingIdentity(token);
3969 }
3970 }
3971
shilu366312e2019-12-17 09:28:10 -08003972 /**
3973 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3974 * @param subId The subscription to use to check the configuration.
3975 * @param c The callback that will be used to send the result.
3976 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003978 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003979 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003980 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003981 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3982 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3983 }
Meng Wangafbc5852019-09-19 17:37:13 -07003984 final long token = Binder.clearCallingIdentity();
3985 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003986 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3987 .removeRegistrationCallbackForSubscription(c, subId);
3988 } catch (ImsException e) {
3989 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3990 + "is inactive, ignoring unregister.");
3991 // If the subscription is no longer active, just return, since the callback
3992 // will already have been removed internally.
3993 } finally {
3994 Binder.restoreCallingIdentity(token);
3995 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 }
3997
Brad Ebingera34a6c22019-10-22 17:36:18 -07003998 /**
3999 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4000 */
4001 @Override
4002 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4003 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4004 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4005 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4006 "IMS not available on device.");
4007 }
4008 final long token = Binder.clearCallingIdentity();
4009 try {
4010 Phone phone = getPhone(subId);
4011 if (phone == null) {
4012 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4013 + subId + "'");
4014 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4015 }
4016 phone.getImsRegistrationState(regState -> {
4017 try {
4018 consumer.accept((regState == null)
4019 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4020 } catch (RemoteException e) {
4021 // Ignore if the remote process is no longer available to call back.
4022 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4023 }
4024 });
4025 } finally {
4026 Binder.restoreCallingIdentity(token);
4027 }
4028 }
4029
4030 /**
4031 * Get the transport type for the IMS service registration state.
4032 */
4033 @Override
4034 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004035 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004036 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004037 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4038 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4039 "IMS not available on device.");
4040 }
4041 final long token = Binder.clearCallingIdentity();
4042 try {
4043 Phone phone = getPhone(subId);
4044 if (phone == null) {
4045 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4046 + subId + "'");
4047 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4048 }
4049 phone.getImsRegistrationTech(regTech -> {
4050 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4051 int regTechConverted = (regTech == null)
4052 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4053 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4054 regTechConverted);
4055 try {
4056 consumer.accept(regTechConverted);
4057 } catch (RemoteException e) {
4058 // Ignore if the remote process is no longer available to call back.
4059 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4060 }
4061 });
4062 } finally {
4063 Binder.restoreCallingIdentity(token);
4064 }
4065 }
4066
shilu366312e2019-12-17 09:28:10 -08004067 /**
4068 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4069 * @param subId The subscription to use to check the configuration.
4070 * @param c The callback that will be used to send the result.
4071 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004073 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4074 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004075 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004076 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004077 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4078 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4079 "IMS not available on device.");
4080 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 final long token = Binder.clearCallingIdentity();
4082 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004083 int slotId = getSlotIndexOrException(subId);
4084 verifyImsMmTelConfiguredOrThrow(slotId);
4085 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004086 } catch (ImsException e) {
4087 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 } finally {
4089 Binder.restoreCallingIdentity(token);
4090 }
4091 }
4092
shilu366312e2019-12-17 09:28:10 -08004093 /**
4094 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4095 * @param subId The subscription to use to check the configuration.
4096 * @param c The callback that will be used to send the result.
4097 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004099 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004100 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004101 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004102 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4103 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4104 }
Meng Wangafbc5852019-09-19 17:37:13 -07004105
4106 final long token = Binder.clearCallingIdentity();
4107 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004108 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004109 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004110 } catch (ImsException e) {
4111 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4112 + "is inactive, ignoring unregister.");
4113 // If the subscription is no longer active, just return, since the callback
4114 // will already have been removed internally.
4115 } finally {
4116 Binder.restoreCallingIdentity(token);
4117 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 }
4119
4120 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004121 public boolean isCapable(int subId, int capability, int regTech) {
4122 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 final long token = Binder.clearCallingIdentity();
4124 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004125 int slotId = getSlotIndexOrException(subId);
4126 verifyImsMmTelConfiguredOrThrow(slotId);
4127 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004128 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4130 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004131 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004132 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4133 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 } finally {
4135 Binder.restoreCallingIdentity(token);
4136 }
4137 }
4138
4139 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004140 public boolean isAvailable(int subId, int capability, int regTech) {
4141 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 final long token = Binder.clearCallingIdentity();
4143 try {
4144 Phone phone = getPhone(subId);
4145 if (phone == null) return false;
4146 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004147 } catch (com.android.ims.ImsException e) {
4148 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4149 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 } finally {
4151 Binder.restoreCallingIdentity(token);
4152 }
4153 }
4154
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004155 /**
4156 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4157 * subscription.
4158 * @param subId The subscription to use to check the configuration.
4159 * @param callback The callback that will be used to send the result.
4160 * @param capability The MmTelFeature capability that will be used to send the result.
4161 * @param transportType The transport type of the MmTelFeature capability.
4162 */
4163 @Override
4164 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4165 int transportType) {
4166 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4167 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4168 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4169 "IMS not available on device.");
4170 }
4171 final long token = Binder.clearCallingIdentity();
4172 try {
4173 int slotId = getSlotIndex(subId);
4174 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4175 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4176 + subId + "'");
4177 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4178 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004179 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004180 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4181 transportType, aBoolean -> {
4182 try {
4183 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4184 } catch (RemoteException e) {
4185 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4186 + "running. Ignore");
4187 }
4188 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004189 } catch (ImsException e) {
4190 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004191 } finally {
4192 Binder.restoreCallingIdentity(token);
4193 }
4194 }
4195
shilu366312e2019-12-17 09:28:10 -08004196 /**
4197 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4198 * @param subId The subscription to use to check the configuration.
4199 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 @Override
4201 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004202 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004203 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004204
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 final long token = Binder.clearCallingIdentity();
4206 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004207 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004208 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004209 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004210 } catch (ImsException e) {
4211 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 } finally {
4213 Binder.restoreCallingIdentity(token);
4214 }
4215 }
4216
4217 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004218 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004220 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 final long identity = Binder.clearCallingIdentity();
4222 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004223 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004224 // This setting doesn't require an active ImsService connection, so do not verify. The
4225 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004226 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004227 } catch (ImsException e) {
4228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 } finally {
4230 Binder.restoreCallingIdentity(identity);
4231 }
4232 }
4233
shilu366312e2019-12-17 09:28:10 -08004234 /**
4235 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4236 * @param subId The subscription to use to check the configuration.
4237 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004238 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004239 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004240 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004241 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 final long identity = Binder.clearCallingIdentity();
4243 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004244 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004245 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004246 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004247 } catch (ImsException e) {
4248 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
4252 }
4253
4254 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004255 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004257 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 final long identity = Binder.clearCallingIdentity();
4259 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004260 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004261 // This setting doesn't require an active ImsService connection, so do not verify. The
4262 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004263 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004264 } catch (ImsException e) {
4265 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
4269 }
4270
shilu366312e2019-12-17 09:28:10 -08004271 /**
4272 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4273 * @param subId The subscription to use to check the configuration.
4274 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004275 @Override
4276 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004277 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004278 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 final long identity = Binder.clearCallingIdentity();
4280 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004281 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004282 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004283 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004284 } catch (ImsException e) {
4285 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
4289 }
4290
4291 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004292 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004294 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004295 final long identity = Binder.clearCallingIdentity();
4296 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004297 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004298 // This setting doesn't require an active ImsService connection, so do not verify. The
4299 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004300 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004301 } catch (ImsException e) {
4302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004303 } finally {
4304 Binder.restoreCallingIdentity(identity);
4305 }
4306 }
4307
shilu366312e2019-12-17 09:28:10 -08004308 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004309 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4310 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4311 * @param subId The subscription to use to check the configuration.
4312 */
4313 @Override
4314 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004315 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004316 mApp, subId, "isCrossSimCallingEnabledByUser");
4317 final long identity = Binder.clearCallingIdentity();
4318 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004319 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004320 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004321 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004322 } catch (ImsException e) {
4323 throw new ServiceSpecificException(e.getCode());
4324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
4327 }
4328
4329 /**
4330 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4331 * Requires MODIFY_PHONE_STATE permission.
4332 * @param subId The subscription to use to check the configuration.
4333 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4334 * false otherwise
4335 */
4336 @Override
4337 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4339 "setCrossSimCallingEnabled");
4340 final long identity = Binder.clearCallingIdentity();
4341 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004342 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004343 // This setting doesn't require an active ImsService connection, so do not verify. The
4344 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004345 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004346 } catch (ImsException e) {
4347 throw new ServiceSpecificException(e.getCode());
4348 } finally {
4349 Binder.restoreCallingIdentity(identity);
4350 }
4351 }
4352
4353 /**
shilu366312e2019-12-17 09:28:10 -08004354 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4355 * @param subId The subscription to use to check the configuration.
4356 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004357 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004358
Brad Ebinger35c841c2018-10-01 10:40:55 -07004359 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004360 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004361 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004362 final long identity = Binder.clearCallingIdentity();
4363 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004364 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004365 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004366 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004367 } catch (ImsException e) {
4368 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004369 } finally {
4370 Binder.restoreCallingIdentity(identity);
4371 }
4372 }
4373
4374 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004375 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004377 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 final long identity = Binder.clearCallingIdentity();
4379 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004380 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004381 // This setting doesn't require an active ImsService connection, so do not verify. The
4382 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004383 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004384 } catch (ImsException e) {
4385 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004386 } finally {
4387 Binder.restoreCallingIdentity(identity);
4388 }
4389 }
4390
4391 @Override
4392 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4394 "setVoWiFiNonPersistent");
4395 final long identity = Binder.clearCallingIdentity();
4396 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004397 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004398 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004399 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004400 } catch (ImsException e) {
4401 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
4405 }
4406
shilu366312e2019-12-17 09:28:10 -08004407 /**
4408 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4409 * @param subId The subscription to use to check the configuration.
4410 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004411 @Override
4412 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004413 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004414 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004415 final long identity = Binder.clearCallingIdentity();
4416 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004417 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004418 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004419 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004420 } catch (ImsException e) {
4421 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004422 } finally {
4423 Binder.restoreCallingIdentity(identity);
4424 }
4425 }
4426
4427 @Override
4428 public void setVoWiFiModeSetting(int subId, int mode) {
4429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4430 "setVoWiFiModeSetting");
4431 final long identity = Binder.clearCallingIdentity();
4432 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004433 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004434 // This setting doesn't require an active ImsService connection, so do not verify. The
4435 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004436 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004437 } catch (ImsException e) {
4438 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004439 } finally {
4440 Binder.restoreCallingIdentity(identity);
4441 }
4442 }
4443
4444 @Override
4445 public int getVoWiFiRoamingModeSetting(int subId) {
4446 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4447 final long identity = Binder.clearCallingIdentity();
4448 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004449 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004450 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004451 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004452 } catch (ImsException e) {
4453 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004454 } finally {
4455 Binder.restoreCallingIdentity(identity);
4456 }
4457 }
4458
4459 @Override
4460 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4462 "setVoWiFiRoamingModeSetting");
4463 final long identity = Binder.clearCallingIdentity();
4464 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004465 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004466 // This setting doesn't require an active ImsService connection, so do not verify. The
4467 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004468 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004469 } catch (ImsException e) {
4470 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
4474 }
4475
4476 @Override
4477 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4479 "setRttCapabilityEnabled");
4480 final long identity = Binder.clearCallingIdentity();
4481 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004482 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004483 // This setting doesn't require an active ImsService connection, so do not verify. The
4484 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004485 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004486 } catch (ImsException e) {
4487 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004488 } finally {
4489 Binder.restoreCallingIdentity(identity);
4490 }
4491 }
4492
shilu366312e2019-12-17 09:28:10 -08004493 /**
4494 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4495 * @param subId The subscription to use to check the configuration.
4496 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004497 @Override
4498 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004499 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004500 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004501 final long identity = Binder.clearCallingIdentity();
4502 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004503 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004504 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004505 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004506 } catch (ImsException e) {
4507 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004508 } finally {
4509 Binder.restoreCallingIdentity(identity);
4510 }
4511 }
4512
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004513 @Override
4514 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4515 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4516 final long identity = Binder.clearCallingIdentity();
4517 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004518 if (!isImsAvailableOnDevice()) {
4519 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4520 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004521 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004522 int slotId = getSlotIndexOrException(subId);
4523 verifyImsMmTelConfiguredOrThrow(slotId);
4524 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004525 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004526 } catch (ImsException e) {
4527 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004528 } finally {
4529 Binder.restoreCallingIdentity(identity);
4530 }
4531 }
4532
4533 @Override
4534 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4535 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4536 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004537 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4538 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4539 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004540 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004541 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004542 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004543 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004544 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4545 + "is inactive, ignoring unregister.");
4546 // If the subscription is no longer active, just return, since the callback will already
4547 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004548 } finally {
4549 Binder.restoreCallingIdentity(identity);
4550 }
4551 }
4552
allenwtsu99c623b2020-01-03 18:24:23 +08004553
4554 private void checkModifyPhoneStatePermission(int subId, String message) {
4555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4556 message);
4557 }
4558
4559 private boolean isImsProvisioningRequired(int subId, int capability,
4560 boolean isMmtelCapability) {
4561 Phone phone = getPhone(subId);
4562 if (phone == null) {
4563 loge("phone instance null for subid " + subId);
4564 return false;
4565 }
4566 if (isMmtelCapability) {
4567 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4568 return false;
4569 }
4570 } else {
4571 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4572 return false;
4573 }
4574 }
4575 return true;
4576 }
4577
4578 @Override
4579 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4580 boolean isProvisioned) {
4581 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4582
4583 final long identity = Binder.clearCallingIdentity();
4584 try {
4585 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4586 if (!isImsProvisioningRequired(subId, capability, false)) {
4587 return;
4588 }
4589
4590 // this capability requires provisioning, route to the correct API.
4591 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4592 switch (capability) {
4593 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4594 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4595 ims.setEabProvisioned(isProvisioned);
4596 break;
4597 default: {
4598 throw new IllegalArgumentException("Tried to set provisioning for "
4599 + "rcs capability '" + capability + "', which does not require "
4600 + "provisioning.");
4601 }
4602 }
4603 } finally {
4604 Binder.restoreCallingIdentity(identity);
4605 }
4606
4607 }
4608
4609
4610 @Override
4611 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4612 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4613 final long identity = Binder.clearCallingIdentity();
4614 try {
4615 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4616 if (!isImsProvisioningRequired(subId, capability, false)) {
4617 return true;
4618 }
4619
4620 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4621 switch (capability) {
4622 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4623 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4624 return ims.isEabProvisionedOnDevice();
4625
4626 default: {
4627 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4628 + "capability '" + capability + "', which does not require "
4629 + "provisioning.");
4630 }
4631 }
4632
4633 } finally {
4634 Binder.restoreCallingIdentity(identity);
4635 }
4636 }
4637
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004638 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004639 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4640 boolean isProvisioned) {
4641 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004642 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4643 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4644 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004645 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4646 }
allenwtsu99c623b2020-01-03 18:24:23 +08004647 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004648 final long identity = Binder.clearCallingIdentity();
4649 try {
4650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004651 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004652 return;
4653 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004654 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4655 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4656 loge("setImsProvisioningStatusForCapability: called for technology that does "
4657 + "not support provisioning - " + tech);
4658 return;
4659 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004660
4661 // this capability requires provisioning, route to the correct API.
4662 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4663 switch (capability) {
4664 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4665 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4666 ims.setVolteProvisioned(isProvisioned);
4667 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4668 ims.setWfcProvisioned(isProvisioned);
4669 }
4670 break;
4671 }
4672 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4673 // There is currently no difference in VT provisioning type.
4674 ims.setVtProvisioned(isProvisioned);
4675 break;
4676 }
4677 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4678 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4679 // change the capability of the feature instead if needed.
4680 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4681 == isProvisioned) {
4682 // No change in provisioning.
4683 return;
4684 }
4685 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4686 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004687 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004688 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004689 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4690 + ", Exception" + e.getMessage());
4691 }
4692 break;
4693 }
4694 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004695 throw new IllegalArgumentException("Tried to set provisioning for "
4696 + "MmTel capability '" + capability + "', which does not require "
4697 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004698 }
4699 }
4700
4701 } finally {
4702 Binder.restoreCallingIdentity(identity);
4703 }
4704 }
4705
4706 @Override
4707 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4708 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004709 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4710 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4711 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004712 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4713 }
4714 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4715 final long identity = Binder.clearCallingIdentity();
4716 try {
4717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004718 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004719 return true;
4720 }
4721
Brad Ebinger0d79c572021-04-17 15:20:49 -07004722 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4723 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4724 loge("getImsProvisioningStatusForCapability: called for technology that does "
4725 + "not support provisioning - " + tech);
4726 return true;
4727 }
4728
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004729 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4730 switch (capability) {
4731 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4732 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4733 return ims.isVolteProvisionedOnDevice();
4734 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4735 return ims.isWfcProvisionedOnDevice();
4736 }
4737 // This should never happen, since we are checking tech above to make sure it
4738 // is either LTE or IWLAN.
4739 throw new IllegalArgumentException("Invalid radio technology for voice "
4740 + "capability.");
4741 }
4742 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4743 // There is currently no difference in VT provisioning type.
4744 return ims.isVtProvisionedOnDevice();
4745 }
4746 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4747 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4748 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4749 }
4750 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004751 throw new IllegalArgumentException(
4752 "Tried to get provisioning for MmTel capability '" + capability
4753 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004754 }
4755 }
4756
4757 } finally {
4758 Binder.restoreCallingIdentity(identity);
4759 }
4760 }
4761
4762 @Override
4763 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4764 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4765 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4766 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4767 }
4768 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4769 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4770 return (provisionedBits & capability) > 0;
4771 }
4772
4773 @Override
4774 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4775 boolean isProvisioned) {
4776 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4777 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4778 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4779 }
4780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4781 "setProvisioningStatusForCapability");
4782 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4783 // If the current provisioning status for capability already matches isProvisioned,
4784 // do nothing.
4785 if (((provisionedBits & capability) > 0) == isProvisioned) {
4786 return;
4787 }
4788 if (isProvisioned) {
4789 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4790 } else {
4791 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4792 }
4793 }
4794
4795 /**
4796 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4797 * technology. The bitfield should mirror the bitfield defined by
4798 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4799 */
4800 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4801 String key = getMmTelProvisioningKey(subId, tech);
4802 // Default is no capabilities are provisioned.
4803 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4804 }
4805
4806 /**
4807 * Sets the MmTel capability provisioning bitfield (defined by
4808 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4809 * technology specified.
4810 *
4811 * Note: This is a synchronous command and should not be called on UI thread.
4812 */
4813 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4814 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4815 String key = getMmTelProvisioningKey(subId, tech);
4816 editor.putInt(key, newField);
4817 editor.commit();
4818 }
4819
4820 private static String getMmTelProvisioningKey(int subId, int tech) {
4821 // resulting key is provision_ims_mmtel_{subId}_{tech}
4822 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4823 }
4824
4825 /**
4826 * Query CarrierConfig to see if the specified capability requires provisioning for the
4827 * carrier associated with the subscription id.
4828 */
4829 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4830 int capability) {
4831 CarrierConfigManager configManager = new CarrierConfigManager(context);
4832 PersistableBundle c = configManager.getConfigForSubId(subId);
4833 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004834 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004835 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4836 false);
4837 boolean requireVoiceVtProvisioning = c.getBoolean(
4838 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4839
4840 // First check to make sure that the capability requires provisioning.
4841 switch (capability) {
4842 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4843 // intentional fallthrough
4844 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4845 if (requireVoiceVtProvisioning) {
4846 // Voice and Video requires provisioning
4847 return true;
4848 }
4849 break;
4850 }
4851 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4852 if (requireUtProvisioning) {
4853 // UT requires provisioning
4854 return true;
4855 }
4856 break;
4857 }
4858 }
4859 return false;
4860 }
4861
allenwtsu99c623b2020-01-03 18:24:23 +08004862 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4863 int capability) {
4864 CarrierConfigManager configManager = new CarrierConfigManager(context);
4865 PersistableBundle c = configManager.getConfigForSubId(subId);
4866
4867 boolean requireRcsProvisioning = c.getBoolean(
4868 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4869
4870 // First check to make sure that the capability requires provisioning.
4871 switch (capability) {
4872 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4873 // intentional fallthrough
4874 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4875 if (requireRcsProvisioning) {
4876 // OPTION or PRESENCE requires provisioning
4877 return true;
4878 }
4879 break;
4880 }
4881 }
4882 return false;
4883 }
4884
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004885 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004886 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4888 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4889 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004890 enforceReadPrivilegedPermission("getImsProvisioningInt");
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004894 int slotId = getSlotIndex(subId);
4895 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4896 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4897 + subId + "' for key:" + key);
4898 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4899 }
calvinpanb5a34062021-02-08 19:59:36 +08004900 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004901 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004902 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4903 + subId + "' for key:" + key);
4904 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004905 } finally {
4906 Binder.restoreCallingIdentity(identity);
4907 }
4908 }
4909
4910 @Override
4911 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004912 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4913 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4914 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004915 enforceReadPrivilegedPermission("getImsProvisioningString");
4916 final long identity = Binder.clearCallingIdentity();
4917 try {
4918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004919 int slotId = getSlotIndex(subId);
4920 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4921 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4922 + subId + "' for key:" + key);
4923 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4924 }
calvinpanb5a34062021-02-08 19:59:36 +08004925 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004926 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004927 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4928 + subId + "' for key:" + key);
4929 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
4933 }
4934
4935 @Override
4936 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4938 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4939 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4941 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004942 final long identity = Binder.clearCallingIdentity();
4943 try {
4944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004945 int slotId = getSlotIndex(subId);
4946 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4947 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4948 + subId + "' for key:" + key);
4949 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4950 }
calvinpanb5a34062021-02-08 19:59:36 +08004951 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4952 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004953 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004954 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004955 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
4959 }
4960
4961 @Override
4962 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004963 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4964 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4965 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4967 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004968 final long identity = Binder.clearCallingIdentity();
4969 try {
4970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004971 int slotId = getSlotIndex(subId);
4972 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4973 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4974 + subId + "' for key:" + key);
4975 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4976 }
calvinpanb5a34062021-02-08 19:59:36 +08004977 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4978 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004979 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004980 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004981 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004982 } finally {
4983 Binder.restoreCallingIdentity(identity);
4984 }
4985 }
4986
Brad Ebinger919631e2021-06-02 17:46:35 -07004987 /**
4988 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4989 * for the given slot ID or no ImsResolver instance has been created.
4990 * @param slotId The slot ID that the IMS service is created for.
4991 * @throws ImsException If there is no ImsService configured for this slot.
4992 */
4993 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4994 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4995 ImsFeature.FEATURE_MMTEL)) {
4996 throw new ImsException("This subscription does not support MMTEL over IMS",
4997 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4998 }
4999 }
5000
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005001 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005002 int slotId = SubscriptionManager.getSlotIndex(subId);
5003 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005004 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5005 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005006 }
5007 return slotId;
5008 }
5009
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005010 private int getSlotIndex(int subId) {
5011 int slotId = SubscriptionManager.getSlotIndex(subId);
5012 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5013 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5014 }
5015 return slotId;
5016 }
5017
Wink Saville36469e72014-06-11 15:17:00 -07005018 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005019 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005020 */
5021 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005022 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5023 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005024 try {
5025 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5026 } catch (SecurityException se) {
5027 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5028 throw new SecurityException("Package " + callingPackage + " does not belong to "
5029 + Binder.getCallingUid());
5030 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005031 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005032 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005033 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005034 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005035 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005036 mApp, subId, callingPackage, callingFeatureId,
5037 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005038 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5039 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 final long identity = Binder.clearCallingIdentity();
5042 try {
5043 final Phone phone = getPhone(subId);
5044 if (phone != null) {
5045 return phone.getServiceState().getDataNetworkType();
5046 } else {
5047 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5048 }
5049 } finally {
5050 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005051 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005052 }
5053
5054 /**
5055 * Returns the data network type
5056 */
5057 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005058 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005059 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5060 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005061 }
5062
5063 /**
5064 * Returns the data network type for a subId
5065 */
5066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005067 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5068 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005070 mApp, subId, callingPackage, callingFeatureId,
5071 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005072 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5073 }
5074
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 final Phone phone = getPhone(subId);
5078 if (phone != null) {
5079 return phone.getServiceState().getDataNetworkType();
5080 } else {
5081 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5082 }
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005086 }
5087
5088 /**
Wink Saville36469e72014-06-11 15:17:00 -07005089 * Returns the Voice network type for a subId
5090 */
5091 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005092 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5093 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005095 mApp, subId, callingPackage, callingFeatureId,
5096 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005097 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5098 }
5099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 final long identity = Binder.clearCallingIdentity();
5101 try {
5102 final Phone phone = getPhone(subId);
5103 if (phone != null) {
5104 return phone.getServiceState().getVoiceNetworkType();
5105 } else {
5106 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5107 }
5108 } finally {
5109 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005111 }
5112
5113 /**
5114 * @return true if a ICC card is present
5115 */
5116 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005117 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005118 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5119 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005120 }
5121
5122 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005123 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005124 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005125 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005126 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005127 final long identity = Binder.clearCallingIdentity();
5128 try {
5129 final Phone phone = PhoneFactory.getPhone(slotIndex);
5130 if (phone != null) {
5131 return phone.getIccCard().hasIccCard();
5132 } else {
5133 return false;
5134 }
5135 } finally {
5136 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005137 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005138 }
5139
5140 /**
5141 * Return if the current radio is LTE on CDMA. This
5142 * is a tri-state return value as for a period of time
5143 * the mode may be unknown.
5144 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005145 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005146 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005147 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005148 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005149 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005150 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5151 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5152 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005153 }
5154
Sanket Padawe356d7632015-06-22 14:03:32 -07005155 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005156 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5157 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005158 try {
5159 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5160 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005161 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5162 }
5163
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 final long identity = Binder.clearCallingIdentity();
5165 try {
5166 final Phone phone = getPhone(subId);
5167 if (phone == null) {
5168 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5169 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005170 return TelephonyProperties.lte_on_cdma_device()
5171 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005172 }
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005175 }
Wink Saville36469e72014-06-11 15:17:00 -07005176 }
5177
Wink Saville36469e72014-06-11 15:17:00 -07005178 /**
5179 * {@hide}
5180 * Returns Default subId, 0 in the case of single standby.
5181 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005182 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005183 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005184 }
5185
Shishir Agrawala9f32182016-04-12 12:00:16 -07005186 private int getSlotForDefaultSubscription() {
5187 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5188 }
5189
Wink Savilleb564aae2014-10-23 10:18:09 -07005190 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005191 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005192 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005193
Pengquan Menge92a50d2018-09-21 15:54:48 -07005194 private boolean isActiveSubscription(int subId) {
5195 return mSubscriptionController.isActiveSubId(subId);
5196 }
5197
Ihab Awadf2177b72013-11-25 13:33:23 -08005198 /**
5199 * @see android.telephony.TelephonyManager.WifiCallingChoices
5200 */
5201 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202 final long identity = Binder.clearCallingIdentity();
5203 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005204 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5206 getWhenToMakeWifiCallsDefaultPreference());
5207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005210 }
5211
5212 /**
5213 * @see android.telephony.TelephonyManager.WifiCallingChoices
5214 */
5215 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 final long identity = Binder.clearCallingIdentity();
5217 try {
5218 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005219 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005220 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005224 }
5225
Sailesh Nepald1e68152013-12-12 19:08:02 -08005226 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005227 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005228 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005229 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005230
Jordan Liu4c733742019-02-28 12:03:40 -08005231 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5232 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5233 if (phoneId == -1) {
5234 throw new IllegalArgumentException("Given slot index: " + slotIndex
5235 + " does not correspond to an active phone");
5236 }
5237 return PhoneFactory.getPhone(phoneId);
5238 }
5239
Shishir Agrawal566b7612013-10-28 14:41:00 -07005240 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005241 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5242 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5244 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005246 if (DBG) {
5247 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5248 }
5249 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5250 p2);
5251 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005252
Jordan Liu4c733742019-02-28 12:03:40 -08005253
5254 @Override
5255 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5256 int slotIndex, String callingPackage, String aid, int p2) {
5257 enforceModifyPermission();
5258 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5259 if (DBG) {
5260 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5261 }
5262 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5263 callingPackage, aid, p2);
5264 }
5265
5266 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5267 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 if (TextUtils.equals(ISDR_AID, aid)) {
5271 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005272 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5273 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005274 if (bestComponent == null
5275 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5276 loge("The calling package is not allowed to access ISD-R.");
5277 throw new SecurityException(
5278 "The calling package is not allowed to access ISD-R.");
5279 }
Derek Tan740e1672017-06-27 14:56:27 -07005280 }
Derek Tan740e1672017-06-27 14:56:27 -07005281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005283 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5284 null /* workSource */);
5285 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 return response;
5287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005290 }
5291
5292 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005293 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5295 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005296 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5297 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5298 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005299
Jordan Liu4c733742019-02-28 12:03:40 -08005300 @Override
5301 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5302 enforceModifyPermission();
5303 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5304 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5305 channel);
5306 }
5307
5308 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 final long identity = Binder.clearCallingIdentity();
5310 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 if (channel < 0) {
5312 return false;
5313 }
Jordan Liu4c733742019-02-28 12:03:40 -08005314 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5315 null /* workSource */);
5316 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 return success;
5318 } finally {
5319 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005320 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005321 }
5322
5323 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005324 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005325 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5327 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005328 if (DBG) {
5329 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5330 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5331 + p3 + " data=" + data);
5332 }
5333 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5334 command, p1, p2, p3, data);
5335 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005336
Jordan Liu4c733742019-02-28 12:03:40 -08005337 @Override
5338 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5339 int command, int p1, int p2, int p3, String data) {
5340 enforceModifyPermission();
5341 if (DBG) {
5342 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5343 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5344 + p3 + " data=" + data);
5345 }
5346 return iccTransmitApduLogicalChannelWithPermission(
5347 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5348 data);
5349 }
5350
5351 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5352 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 final long identity = Binder.clearCallingIdentity();
5354 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005355 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 return "";
5357 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005360 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5361 null /* workSource */);
5362 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005363
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 // Append the returned status code to the end of the response payload.
5365 String s = Integer.toHexString(
5366 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5367 if (response.payload != null) {
5368 s = IccUtils.bytesToHexString(response.payload) + s;
5369 }
5370 return s;
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005373 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005374 }
Jake Hambye994d462014-02-03 13:10:13 -08005375
Evan Charltonc66da362014-05-16 14:06:40 -07005376 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005377 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5378 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5380 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005381 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005382 if (DBG) {
5383 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5384 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5385 }
5386 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5387 cla, command, p1, p2, p3, data);
5388 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005389
Jordan Liu4c733742019-02-28 12:03:40 -08005390 @Override
5391 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5392 int command, int p1, int p2, int p3, String data) {
5393 enforceModifyPermission();
5394 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5395 if (DBG) {
5396 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5397 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5398 + " data=" + data);
5399 }
5400
5401 return iccTransmitApduBasicChannelWithPermission(
5402 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5403 p2, p3, data);
5404 }
5405
5406 // open APDU basic channel assuming the caller has sufficient permissions
5407 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5408 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409 final long identity = Binder.clearCallingIdentity();
5410 try {
5411 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5412 && TextUtils.equals(ISDR_AID, data)) {
5413 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005414 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5415 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 if (bestComponent == null
5417 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5418 loge("The calling package is not allowed to select ISD-R.");
5419 throw new SecurityException(
5420 "The calling package is not allowed to select ISD-R.");
5421 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005422 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005424 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005425 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5426 null /* workSource */);
5427 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 // Append the returned status code to the end of the response payload.
5430 String s = Integer.toHexString(
5431 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5432 if (response.payload != null) {
5433 s = IccUtils.bytesToHexString(response.payload) + s;
5434 }
5435 return s;
5436 } finally {
5437 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005438 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005439 }
5440
5441 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005442 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005443 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005444 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5445 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 final long identity = Binder.clearCallingIdentity();
5448 try {
5449 if (DBG) {
5450 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5451 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5452 }
5453
5454 IccIoResult response =
5455 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5456 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5457 subId);
5458
5459 if (DBG) {
5460 log("Exchange SIM_IO [R]" + response);
5461 }
5462
5463 byte[] result = null;
5464 int length = 2;
5465 if (response.payload != null) {
5466 length = 2 + response.payload.length;
5467 result = new byte[length];
5468 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5469 } else {
5470 result = new byte[length];
5471 }
5472
5473 result[length - 1] = (byte) response.sw2;
5474 result[length - 2] = (byte) response.sw1;
5475 return result;
5476 } finally {
5477 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005478 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005479 }
5480
Nathan Haroldb3014052017-01-25 15:57:32 -08005481 /**
5482 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5483 * on a particular subscription
5484 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005485 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5486 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005488 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005489 return null;
5490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491
5492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 if (appType != TelephonyManager.APPTYPE_USIM
5495 && appType != TelephonyManager.APPTYPE_SIM) {
5496 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5497 return null;
5498 }
5499 Object response = sendRequest(
5500 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5501 if (response instanceof String[]) {
5502 return (String[]) response;
5503 }
yincheng zhao2737e882019-09-06 17:06:54 -07005504 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005506 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 } finally {
5508 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005509 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005510 }
5511
yincheng zhao2737e882019-09-06 17:06:54 -07005512 /**
5513 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5514 * subscription.
5515 *
5516 * @param subId the id of the subscription.
5517 * @param appType the uicc app type, must be USIM or SIM.
5518 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5519 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005520 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005521 * @return number of fplmns that is successfully written to the SIM.
5522 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005523 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5524 String callingFeatureId) {
Jayachandran C5b0d75a2021-10-21 22:15:27 -07005525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5526 mApp, subId, "setForbiddenPlmns");
5527
yincheng zhao2737e882019-09-06 17:06:54 -07005528 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5529 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5530 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5531 }
5532 if (fplmns == null) {
5533 throw new IllegalArgumentException("Fplmn List provided is null");
5534 }
5535 for (String fplmn : fplmns) {
5536 if (!CellIdentity.isValidPlmn(fplmn)) {
5537 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5538 }
5539 }
5540 final long identity = Binder.clearCallingIdentity();
5541 try {
5542 Object response = sendRequest(
5543 CMD_SET_FORBIDDEN_PLMNS,
5544 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5545 subId);
5546 return (int) response;
5547 } finally {
5548 Binder.restoreCallingIdentity(identity);
5549 }
5550 }
5551
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005552 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005553 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5555 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 final long identity = Binder.clearCallingIdentity();
5558 try {
5559 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5560 if (response.payload == null) {
5561 return "";
5562 }
Evan Charltonc66da362014-05-16 14:06:40 -07005563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 // Append the returned status code to the end of the response payload.
5565 String s = Integer.toHexString(
5566 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5567 s = IccUtils.bytesToHexString(response.payload) + s;
5568 return s;
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Evan Charltonc66da362014-05-16 14:06:40 -07005572 }
5573
Jake Hambye994d462014-02-03 13:10:13 -08005574 /**
5575 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5576 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5577 *
5578 * @param itemID the ID of the item to read
5579 * @return the NV item as a String, or null on error.
5580 */
5581 @Override
5582 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005583 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5585 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586
5587 final long identity = Binder.clearCallingIdentity();
5588 try {
5589 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005590 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5592 return value;
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
Jake Hambye994d462014-02-03 13:10:13 -08005596 }
5597
5598 /**
5599 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5600 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5601 *
5602 * @param itemID the ID of the item to read
5603 * @param itemValue the value to write, as a String
5604 * @return true on success; false on any failure
5605 */
5606 @Override
5607 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005608 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5610 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611
5612 final long identity = Binder.clearCallingIdentity();
5613 try {
5614 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5615 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005616 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5618 return success;
5619 } finally {
5620 Binder.restoreCallingIdentity(identity);
5621 }
Jake Hambye994d462014-02-03 13:10:13 -08005622 }
5623
5624 /**
5625 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5626 * Used for device configuration by some CDMA operators.
5627 *
5628 * @param preferredRoamingList byte array containing the new PRL
5629 * @return true on success; false on any failure
5630 */
5631 @Override
5632 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5634 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
5636 final long identity = Binder.clearCallingIdentity();
5637 try {
5638 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5639 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5640 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5641 return success;
5642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
Jake Hambye994d462014-02-03 13:10:13 -08005645 }
5646
5647 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005648 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005649 * Used for device configuration by some CDMA operators.
5650 *
chen xu6dac5ab2018-10-26 17:39:23 -07005651 * @param slotIndex - device slot.
5652 *
Jake Hambye994d462014-02-03 13:10:13 -08005653 * @return true on success; false on any failure
5654 */
5655 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005656 public boolean resetModemConfig(int slotIndex) {
5657 Phone phone = PhoneFactory.getPhone(slotIndex);
5658 if (phone != null) {
5659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5660 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661
chen xu6dac5ab2018-10-26 17:39:23 -07005662 final long identity = Binder.clearCallingIdentity();
5663 try {
5664 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5665 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5666 return success;
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 }
chen xu6dac5ab2018-10-26 17:39:23 -07005671 return false;
5672 }
5673
5674 /**
5675 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5676 *
5677 * @param slotIndex - device slot.
5678 *
5679 * @return true on success; false on any failure
5680 */
5681 @Override
5682 public boolean rebootModem(int slotIndex) {
5683 Phone phone = PhoneFactory.getPhone(slotIndex);
5684 if (phone != null) {
5685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5686 mApp, phone.getSubId(), "rebootModem");
5687
5688 final long identity = Binder.clearCallingIdentity();
5689 try {
5690 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5691 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5692 return success;
5693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
5696 }
5697 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005698 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005699
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005700 public String[] getPcscfAddress(String apnType, String callingPackage,
5701 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005702 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5704 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005705 return new String[0];
5706 }
5707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 final long identity = Binder.clearCallingIdentity();
5709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005710 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
Wink Saville36469e72014-06-11 15:17:00 -07005714 }
5715
Brad Ebinger51f743a2017-01-23 13:50:20 -08005716 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005717 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5718 * {@link #disableIms(int)}.
5719 * @param slotIndex device slot.
5720 */
5721 public void resetIms(int slotIndex) {
5722 enforceModifyPermission();
5723
5724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 if (mImsResolver == null) {
5727 // may happen if the does not support IMS.
5728 return;
5729 }
5730 mImsResolver.disableIms(slotIndex);
5731 mImsResolver.enableIms(slotIndex);
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
5735 }
5736
5737 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005738 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5739 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005740 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005741 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005742 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743
5744 final long identity = Binder.clearCallingIdentity();
5745 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005746 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005747 // may happen if the device does not support IMS.
5748 return;
5749 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005750 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 } finally {
5752 Binder.restoreCallingIdentity(identity);
5753 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005754 }
5755
5756 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005757 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5758 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005759 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005760 public void disableIms(int slotId) {
5761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762
5763 final long identity = Binder.clearCallingIdentity();
5764 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005765 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005766 // may happen if the device does not support IMS.
5767 return;
5768 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005769 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005773 }
5774
5775 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005776 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5777 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005778 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005779 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005780 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782
5783 final long identity = Binder.clearCallingIdentity();
5784 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005785 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005786 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5787 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005788 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005789 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 } finally {
5791 Binder.restoreCallingIdentity(identity);
5792 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005793 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005794 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005795 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5796 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005797 @Override
5798 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005799 enforceModifyPermission();
5800
5801 final long identity = Binder.clearCallingIdentity();
5802 try {
5803 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005804 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005805 } finally {
5806 Binder.restoreCallingIdentity(identity);
5807 }
5808 }
5809
5810 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005811 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005812 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005813 */
5814 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5815 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816
5817 final long identity = Binder.clearCallingIdentity();
5818 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005819 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005820 // may happen if the device does not support IMS.
5821 return null;
5822 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005823 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005827 }
5828
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005829 /**
5830 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005831 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005832 */
5833 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835
5836 final long identity = Binder.clearCallingIdentity();
5837 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005838 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005839 // may happen if the device does not support IMS.
5840 return null;
5841 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005842 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843 } finally {
5844 Binder.restoreCallingIdentity(identity);
5845 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005846 }
5847
Brad Ebinger884c07b2018-02-15 16:17:40 -08005848 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005849 * Sets the ImsService Package Name that Telephony will bind to.
5850 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005851 * @param slotIndex the slot ID that the ImsService should bind for.
5852 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005853 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005854 * @param featureTypes An integer array of feature types associated with a packageName.
5855 * @param packageName The name of the package that the current configuration will be replaced
5856 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005857 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005858 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005859 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5860 int[] featureTypes, String packageName) {
5861 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5864 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005865 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005867 final long identity = Binder.clearCallingIdentity();
5868 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005869 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005870 // may happen if the device does not support IMS.
5871 return false;
5872 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005873 Map<Integer, String> featureConfig = new HashMap<>();
5874 for (int featureType : featureTypes) {
5875 featureConfig.put(featureType, packageName);
5876 }
5877 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5878 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 } finally {
5880 Binder.restoreCallingIdentity(identity);
5881 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005882 }
5883
5884 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005885 * Clears any carrier ImsService overrides for the slot index specified that were previously
5886 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5887 *
5888 * This should only be used for testing.
5889 *
5890 * @param slotIndex the slot ID that the ImsService should bind for.
5891 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5892 */
5893 @Override
5894 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5895 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5896 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5897 "clearCarrierImsServiceOverride");
5898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5899 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5900 "clearCarrierImsServiceOverride");
5901
5902 final long identity = Binder.clearCallingIdentity();
5903 try {
5904 if (mImsResolver == null) {
5905 // may happen if the device does not support IMS.
5906 return false;
5907 }
5908 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
5912 }
5913
5914 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005915 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005916 *
5917 * @param slotId The slot that the ImsService is associated with.
5918 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5919 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005920 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005921 * @return the package name of the ImsService configuration.
5922 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005923 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5924 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005925 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005926 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005927 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005928 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5929 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 final long identity = Binder.clearCallingIdentity();
5932 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005933 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005934 // may happen if the device does not support IMS.
5935 return "";
5936 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005937 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005938 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5939 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 } finally {
5941 Binder.restoreCallingIdentity(identity);
5942 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005943 }
5944
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005945 /**
5946 * Get the MmTelFeature state associated with the requested subscription id.
5947 * @param subId The subscription that the MmTelFeature is associated with.
5948 * @param callback A callback with an integer containing the
5949 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5950 */
5951 @Override
5952 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5953 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5954 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5955 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5956 "IMS not available on device.");
5957 }
5958 final long token = Binder.clearCallingIdentity();
5959 try {
5960 int slotId = getSlotIndex(subId);
5961 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5962 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5963 + subId + "'");
5964 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5965 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005966 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005967 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5968 try {
5969 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5970 } catch (RemoteException e) {
5971 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5972 + "Ignore");
5973 }
5974 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005975 } catch (ImsException e) {
5976 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005977 } finally {
5978 Binder.restoreCallingIdentity(token);
5979 }
5980 }
5981
Daniel Brightbb5840b2021-01-12 15:48:18 -08005982 /**
5983 * Sets the ims registration state on all valid {@link Phone}s.
5984 */
5985 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005986 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987
5988 final long identity = Binder.clearCallingIdentity();
5989 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005990 // NOTE: Before S, this method only set the default phone.
5991 for (final Phone phone : PhoneFactory.getPhones()) {
5992 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5993 phone.setImsRegistrationState(registered);
5994 }
5995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005996 } finally {
5997 Binder.restoreCallingIdentity(identity);
5998 }
Wink Saville36469e72014-06-11 15:17:00 -07005999 }
6000
6001 /**
Stuart Scott54788802015-03-30 13:18:01 -07006002 * Set the network selection mode to automatic.
6003 *
6004 */
6005 @Override
6006 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6008 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009
6010 final long identity = Binder.clearCallingIdentity();
6011 try {
shilufc958392020-01-20 11:36:01 -08006012 if (!isActiveSubscription(subId)) {
6013 return;
6014 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006016 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6017 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
Stuart Scott54788802015-03-30 13:18:01 -07006021 }
6022
Jack Yud10cdd42020-09-28 20:28:01 -07006023 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006024 * Ask the radio to connect to the input network and change selection mode to manual.
6025 *
6026 * @param subId the id of the subscription.
6027 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6028 * the operator to attach to.
6029 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6030 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6031 * normal network selection next time.
6032 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006033 */
6034 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006035 public boolean setNetworkSelectionModeManual(
6036 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6038 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006039
6040 if (!isActiveSubscription(subId)) {
6041 return false;
6042 }
6043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006046 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006048 if (DBG) {
6049 log("setNetworkSelectionModeManual: subId: " + subId
6050 + " operator: " + operatorInfo);
6051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6053 } finally {
6054 Binder.restoreCallingIdentity(identity);
6055 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006056 }
shilu84f6e8b2019-12-19 13:58:01 -08006057 /**
6058 * Get the manual network selection
6059 *
6060 * @param subId the id of the subscription.
6061 *
6062 * @return the previously saved user selected PLMN
6063 */
6064 @Override
6065 public String getManualNetworkSelectionPlmn(int subId) {
6066 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006067 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006068 mApp, subId, "getManualNetworkSelectionPlmn");
6069
6070 final long identity = Binder.clearCallingIdentity();
6071 try {
6072 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006073 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006074 }
6075
6076 final Phone phone = getPhone(subId);
6077 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006078 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006079 }
6080 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6081 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6082 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6083 } finally {
6084 Binder.restoreCallingIdentity(identity);
6085 }
6086 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006087
6088 /**
6089 * Scans for available networks.
6090 */
6091 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006092 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6093 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6095 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006096 LocationAccessPolicy.LocationPermissionResult locationResult =
6097 LocationAccessPolicy.checkLocationPermission(mApp,
6098 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6099 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006100 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006101 .setCallingPid(Binder.getCallingPid())
6102 .setCallingUid(Binder.getCallingUid())
6103 .setMethod("getCellNetworkScanResults")
6104 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006105 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6106 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006107 .build());
6108 switch (locationResult) {
6109 case DENIED_HARD:
6110 throw new SecurityException("Not allowed to access scan results -- location");
6111 case DENIED_SOFT:
6112 return null;
6113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114
Pengquan Menga1bb6272018-09-06 09:59:22 -07006115 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 try {
6117 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006118 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120 } finally {
6121 Binder.restoreCallingIdentity(identity);
6122 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006123 }
6124
6125 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006126 * Get the call forwarding info, given the call forwarding reason.
6127 */
6128 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006129 public void getCallForwarding(int subId, int callForwardingReason,
6130 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006131 enforceReadPrivilegedPermission("getCallForwarding");
6132 long identity = Binder.clearCallingIdentity();
6133 try {
6134 if (DBG) {
6135 log("getCallForwarding: subId " + subId
6136 + " callForwardingReason" + callForwardingReason);
6137 }
Hall Liu27d24262020-09-18 19:04:59 -07006138
6139 Phone phone = getPhone(subId);
6140 if (phone == null) {
6141 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006142 callback.onError(
6143 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006144 } catch (RemoteException e) {
6145 // ignore
6146 }
6147 return;
6148 }
6149
6150 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6151 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6152 @Override
6153 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6154 try {
6155 callback.onCallForwardingInfoAvailable(info);
6156 } catch (RemoteException e) {
6157 // ignore
6158 }
6159 }
6160
6161 @Override
6162 public void onError(int error) {
6163 try {
6164 callback.onError(error);
6165 } catch (RemoteException e) {
6166 // ignore
6167 }
6168 }
6169 });
6170 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
6174 }
6175
6176 /**
6177 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6178 * reason, the number to forward, and the timeout before the forwarding is attempted.
6179 */
6180 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006181 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6182 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006183 enforceModifyPermission();
6184 long identity = Binder.clearCallingIdentity();
6185 try {
6186 if (DBG) {
6187 log("setCallForwarding: subId " + subId
6188 + " callForwardingInfo" + callForwardingInfo);
6189 }
Hall Liu27d24262020-09-18 19:04:59 -07006190
6191 Phone phone = getPhone(subId);
6192 if (phone == null) {
6193 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006194 callback.accept(
6195 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006196 } catch (RemoteException e) {
6197 // ignore
6198 }
6199 return;
6200 }
6201
6202 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6203 FunctionalUtils.ignoreRemoteException(callback::accept));
6204
6205 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006206 } finally {
6207 Binder.restoreCallingIdentity(identity);
6208 }
6209 }
6210
6211 /**
Hall Liu27d24262020-09-18 19:04:59 -07006212 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006213 */
6214 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006215 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006216 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006217 long identity = Binder.clearCallingIdentity();
6218 try {
Hall Liu27d24262020-09-18 19:04:59 -07006219 Phone phone = getPhone(subId);
6220 if (phone == null) {
6221 try {
6222 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6223 } catch (RemoteException e) {
6224 // ignore
6225 }
6226 return;
6227 }
SongFerngWang0e767992021-03-31 22:08:45 +08006228 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6229 PersistableBundle c = configManager.getConfigForSubId(subId);
6230 boolean requireUssd = c.getBoolean(
6231 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006232
Shuo Qian4a594052020-01-23 11:59:30 -08006233 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006234 if (requireUssd) {
6235 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6236 getSubscriptionCarrierId(subId));
6237 String newUssdCommand = "";
6238 try {
6239 newUssdCommand = carrierXmlParser.getFeature(
6240 CarrierXmlParser.FEATURE_CALL_WAITING)
6241 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6242 } catch (NullPointerException e) {
6243 loge("Failed to generate USSD number" + e);
6244 }
6245 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6246 mMainThreadHandler, callback, carrierXmlParser,
6247 CarrierXmlParser.SsEntry.SSAction.QUERY);
6248 final String ussdCommand = newUssdCommand;
6249 Executors.newSingleThreadExecutor().execute(() -> {
6250 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6251 });
6252 } else {
6253 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6254 callback::accept);
6255 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6256 }
Shuo Qian4a594052020-01-23 11:59:30 -08006257 } finally {
6258 Binder.restoreCallingIdentity(identity);
6259 }
6260 }
6261
6262 /**
Hall Liu27d24262020-09-18 19:04:59 -07006263 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006264 */
6265 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006266 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006267 enforceModifyPermission();
6268 long identity = Binder.clearCallingIdentity();
6269 try {
Hall Liu27d24262020-09-18 19:04:59 -07006270 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6271
6272 Phone phone = getPhone(subId);
6273 if (phone == null) {
6274 try {
6275 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6276 } catch (RemoteException e) {
6277 // ignore
6278 }
6279 return;
6280 }
6281
SongFerngWang0e767992021-03-31 22:08:45 +08006282 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6283 PersistableBundle c = configManager.getConfigForSubId(subId);
6284 boolean requireUssd = c.getBoolean(
6285 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006286
SongFerngWang0e767992021-03-31 22:08:45 +08006287 if (DBG) log("getCallWaitingStatus: subId " + subId);
6288 if (requireUssd) {
6289 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6290 getSubscriptionCarrierId(subId));
6291 CarrierXmlParser.SsEntry.SSAction ssAction =
6292 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6293 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6294 String newUssdCommand = "";
6295 try {
6296 newUssdCommand = carrierXmlParser.getFeature(
6297 CarrierXmlParser.FEATURE_CALL_WAITING)
6298 .makeCommand(ssAction, null);
6299 } catch (NullPointerException e) {
6300 loge("Failed to generate USSD number" + e);
6301 }
6302 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6303 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6304 final String ussdCommand = newUssdCommand;
6305 Executors.newSingleThreadExecutor().execute(() -> {
6306 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6307 });
6308 } else {
6309 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6310 FunctionalUtils.ignoreRemoteException(callback::accept));
6311
6312 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6313 }
Shuo Qian4a594052020-01-23 11:59:30 -08006314 } finally {
6315 Binder.restoreCallingIdentity(identity);
6316 }
6317 }
6318
6319 /**
yinxub1bed742017-04-17 11:45:04 -07006320 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006321 *
yinxub1bed742017-04-17 11:45:04 -07006322 * @param subId id of the subscription
6323 * @param request contains the radio access networks with bands/channels to scan
6324 * @param messenger callback messenger for scan results or errors
6325 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006326 * @return the id of the requested scan which can be used to stop the scan.
6327 */
6328 @Override
6329 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006330 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6332 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006333 LocationAccessPolicy.LocationPermissionResult locationResult =
6334 LocationAccessPolicy.checkLocationPermission(mApp,
6335 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6336 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006337 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006338 .setCallingPid(Binder.getCallingPid())
6339 .setCallingUid(Binder.getCallingUid())
6340 .setMethod("requestNetworkScan")
6341 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006342 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6343 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006344 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006345 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006346 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6347 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006348 if (e != null) {
6349 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6350 throw e;
6351 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006352 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006353 return TelephonyScanManager.INVALID_SCAN_ID;
6354 }
6355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 }
Hall Liu912dfd32019-04-25 14:02:26 -07006357 int callingUid = Binder.getCallingUid();
6358 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006359 final long identity = Binder.clearCallingIdentity();
6360 try {
6361 return mNetworkScanRequestTracker.startNetworkScan(
6362 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006363 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006364 } finally {
6365 Binder.restoreCallingIdentity(identity);
6366 }
yinxu504e1392017-04-12 16:03:22 -07006367 }
6368
Hall Liub2ac8ef2019-02-28 15:56:23 -08006369 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006370 NetworkScanRequest request, int subId, String callingPackage) {
6371 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006372 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6373 boolean hasNetworkScanPermission =
6374 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6375 == PERMISSION_GRANTED;
6376
6377 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6378 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6379 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006380 }
6381
6382 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6383 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006384 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6385 return new SecurityException("Specific channels must not be"
6386 + " scanned without location access.");
6387 }
6388 }
6389 }
6390
Hall Liub2ac8ef2019-02-28 15:56:23 -08006391 return null;
6392 }
6393
yinxu504e1392017-04-12 16:03:22 -07006394 /**
6395 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006396 *
6397 * @param subId id of the subscription
6398 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006399 */
6400 @Override
6401 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6403 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404
Hall Liu912dfd32019-04-25 14:02:26 -07006405 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006406 final long identity = Binder.clearCallingIdentity();
6407 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006408 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409 } finally {
6410 Binder.restoreCallingIdentity(identity);
6411 }
yinxu504e1392017-04-12 16:03:22 -07006412 }
6413
6414 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006415 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006416 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006417 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006418 */
6419 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006420 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006421 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006422 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006423 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424
6425 final long identity = Binder.clearCallingIdentity();
6426 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006427 if (DBG) log("getAllowedNetworkTypesBitmask");
6428 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6429 int networkTypesBitmask = (result != null ? result[0] : -1);
6430 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6431 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 } finally {
6433 Binder.restoreCallingIdentity(identity);
6434 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006435 }
6436
6437 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006438 * Get the allowed network types for certain reason.
6439 *
6440 * @param subId the id of the subscription.
6441 * @param reason the reason the allowed network type change is taking place
6442 * @return the allowed network types.
6443 */
6444 @Override
6445 public long getAllowedNetworkTypesForReason(int subId,
6446 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006447 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006448 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006449 final long identity = Binder.clearCallingIdentity();
6450 try {
6451 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6452 } finally {
6453 Binder.restoreCallingIdentity(identity);
6454 }
6455 }
6456
6457 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006458 * Enable/Disable E-UTRA-NR Dual Connectivity
6459 * @param subId subscription id of the sim card
6460 * @param nrDualConnectivityState expected NR dual connectivity state
6461 * This can be passed following states
6462 * <ol>
6463 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6464 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6465 * <li>Disable NR dual connectivity and force secondary cell to be released
6466 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6467 * </ol>
6468 * @return operation result.
6469 */
6470 @Override
6471 public int setNrDualConnectivityState(int subId,
6472 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6474 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006475 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006476 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6477 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6478 }
6479
Sooraj Sasindran37444802020-08-11 10:40:43 -07006480 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6481 final long identity = Binder.clearCallingIdentity();
6482 try {
6483 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6484 nrDualConnectivityState, subId,
6485 workSource);
6486 if (DBG) log("enableNRDualConnectivity result: " + result);
6487 return result;
6488 } finally {
6489 Binder.restoreCallingIdentity(identity);
6490 }
6491 }
6492
6493 /**
6494 * Is E-UTRA-NR Dual Connectivity enabled
6495 * @return true if dual connectivity is enabled else false
6496 */
6497 @Override
6498 public boolean isNrDualConnectivityEnabled(int subId) {
6499 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006500 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006501 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006502 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006503 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6504 return false;
6505 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006506 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6507 final long identity = Binder.clearCallingIdentity();
6508 try {
6509 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6510 null, subId, workSource);
6511 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6512 return isEnabled;
6513 } finally {
6514 Binder.restoreCallingIdentity(identity);
6515 }
6516 }
6517
6518 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006519 * Set the allowed network types of the device and
6520 * provide the reason triggering the allowed network change.
6521 *
6522 * @param subId the id of the subscription.
6523 * @param reason the reason the allowed network type change is taking place
6524 * @param allowedNetworkTypes the allowed network types.
6525 * @return true on success; false on any failure.
6526 */
6527 @Override
6528 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006529 @TelephonyManager.AllowedNetworkTypesReason int reason,
6530 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6532 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006533 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006534 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6535 return false;
6536 }
6537 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6538 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006539 return false;
6540 }
6541
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006542 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6543 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6544
6545
6546 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6547 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6548 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006549 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006550
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006551 final long identity = Binder.clearCallingIdentity();
6552 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006553 Boolean success = (Boolean) sendRequest(
6554 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6555 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6556
6557 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6558 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
6562 }
6563
6564 /**
Miaoa84611c2019-03-15 09:21:10 +08006565 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006566 *
Miaoa84611c2019-03-15 09:21:10 +08006567 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006568 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006569 * @hide
6570 */
6571 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006572 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006575 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 try {
Miaoa84611c2019-03-15 09:21:10 +08006577 if (phone != null) {
6578 return phone.hasMatchedTetherApnSetting();
6579 } else {
6580 return false;
6581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 } finally {
6583 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006584 }
Junda Liu475951f2014-11-07 16:45:03 -08006585 }
6586
6587 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006588 * Enable or disable always reporting signal strength changes from radio.
6589 *
6590 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6591 */
6592 @Override
6593 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6594 enforceModifyPermission();
6595 enforceSystemCaller();
6596
6597 final long identity = Binder.clearCallingIdentity();
6598 final Phone phone = getPhone(subId);
6599 try {
6600 if (phone != null) {
6601 if (DBG) {
6602 log("setAlwaysReportSignalStrength: subId=" + subId
6603 + " isEnable=" + isEnable);
6604 }
6605 phone.setAlwaysReportSignalStrength(isEnable);
6606 } else {
6607 loge("setAlwaysReportSignalStrength: no phone found for subId="
6608 + subId);
6609 }
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
6613 }
6614
6615 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006616 * Get the user enabled state of Mobile Data.
6617 *
6618 * TODO: remove and use isUserDataEnabled.
6619 * This can't be removed now because some vendor codes
6620 * calls through ITelephony directly while they should
6621 * use TelephonyManager.
6622 *
6623 * @return true on enabled
6624 */
6625 @Override
6626 public boolean getDataEnabled(int subId) {
6627 return isUserDataEnabled(subId);
6628 }
6629
6630 /**
6631 * Get whether mobile data is enabled per user setting.
6632 *
6633 * There are other factors deciding whether mobile data is actually enabled, but they are
6634 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006635 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006636 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006637 *
6638 * @return {@code true} if data is enabled else {@code false}
6639 */
6640 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006641 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006642 try {
6643 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6644 null);
6645 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6647 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649
6650 final long identity = Binder.clearCallingIdentity();
6651 try {
6652 int phoneId = mSubscriptionController.getPhoneId(subId);
6653 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6654 Phone phone = PhoneFactory.getPhone(phoneId);
6655 if (phone != null) {
6656 boolean retVal = phone.isUserDataEnabled();
6657 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6658 return retVal;
6659 } else {
6660 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6661 return false;
6662 }
6663 } finally {
6664 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006665 }
6666 }
6667
6668 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006669 * Checks if the device is capable of mobile data by considering whether whether the
6670 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6671 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006672 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006673 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006674 */
6675 @Override
6676 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006677 try {
6678 try {
6679 mApp.enforceCallingOrSelfPermission(
6680 android.Manifest.permission.ACCESS_NETWORK_STATE,
6681 null);
6682 } catch (Exception e) {
6683 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6684 "isDataEnabled");
6685 }
6686 } catch (Exception e) {
6687 enforceReadPrivilegedPermission("isDataEnabled");
6688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689
6690 final long identity = Binder.clearCallingIdentity();
6691 try {
6692 int phoneId = mSubscriptionController.getPhoneId(subId);
6693 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6694 Phone phone = PhoneFactory.getPhone(phoneId);
6695 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006696 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6698 return retVal;
6699 } else {
6700 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6701 return false;
6702 }
6703 } finally {
6704 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006705 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006706 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006707
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006708 /**
6709 * Check if data is enabled for a specific reason
6710 * @param subId Subscription index
6711 * @param reason the reason the data enable change is taking place
6712 * @return {@code true} if the overall data is enabled; {@code false} if not.
6713 */
6714 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006715 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006716 @TelephonyManager.DataEnabledReason int reason) {
6717 try {
6718 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6719 null);
6720 } catch (Exception e) {
6721 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006722 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006723 }
6724
6725
6726 final long identity = Binder.clearCallingIdentity();
6727 try {
6728 int phoneId = mSubscriptionController.getPhoneId(subId);
6729 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006730 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006731 + " reason=" + reason);
6732 }
6733 Phone phone = PhoneFactory.getPhone(phoneId);
6734 if (phone != null) {
6735 boolean retVal;
6736 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6737 retVal = phone.isUserDataEnabled();
6738 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006739 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006740 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006741 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006742 return retVal;
6743 } else {
6744 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006745 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006746 + subId + " retVal=false");
6747 }
6748 return false;
6749 }
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
6753 }
6754
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006755 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006756 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006757 if (uid == Process.PHONE_UID) {
6758 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6759 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006760 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6761 }
6762
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006763 //load access rules from carrier configs, and check those as well: b/139133814
6764 SubscriptionController subController = SubscriptionController.getInstance();
6765 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6766 || subController == null) return privilegeFromSim;
6767
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006768 PackageManager pkgMgr = phone.getContext().getPackageManager();
6769 String[] packages = pkgMgr.getPackagesForUid(uid);
6770
6771 final long identity = Binder.clearCallingIdentity();
6772 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006773 int subId = phone.getSubId();
6774 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6775 // A test override is in place for the privileges for this subId, so don't try to
6776 // read the subscription privileges.
6777 return privilegeFromSim;
6778 }
6779 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006780 SubscriptionManager subManager = (SubscriptionManager)
6781 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6782 for (String pkg : packages) {
6783 if (subManager.canManageSubscription(subInfo, pkg)) {
6784 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6785 }
6786 }
6787 return privilegeFromSim;
6788 } finally {
6789 Binder.restoreCallingIdentity(identity);
6790 }
6791 }
6792
6793 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6794 String pkgName) {
6795 //load access rules from carrier configs, and check those as well: b/139133814
6796 SubscriptionController subController = SubscriptionController.getInstance();
6797 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6798 || subController == null) return privilegeFromSim;
6799
6800 final long identity = Binder.clearCallingIdentity();
6801 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006802 int subId = phone.getSubId();
6803 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6804 // A test override is in place for the privileges for this subId, so don't try to
6805 // read the subscription privileges.
6806 return privilegeFromSim;
6807 }
6808 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006809 SubscriptionManager subManager = (SubscriptionManager)
6810 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6811 return subManager.canManageSubscription(subInfo, pkgName)
6812 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6813 } finally {
6814 Binder.restoreCallingIdentity(identity);
6815 }
6816 }
6817
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006818 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006819 public int getCarrierPrivilegeStatus(int subId) {
6820 final Phone phone = getPhone(subId);
6821 if (phone == null) {
6822 loge("getCarrierPrivilegeStatus: Invalid subId");
6823 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6824 }
6825 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006826 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006827 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006828 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6829 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006830
6831 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6832 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006833 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006834 }
Junda Liu29340342014-07-10 15:23:27 -07006835
6836 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006837 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006838 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006839 final Phone phone = getPhone(subId);
6840 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006841 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006842 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6843 }
6844 UiccProfile profile =
6845 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6846 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006847 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006848 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6849 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006850 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006851 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006852 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006853 }
6854
6855 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006856 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006857 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006858 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006859 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006860 }
6861
6862 int phoneId = SubscriptionManager.getPhoneId(subId);
6863 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006864 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006865 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006866 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6867 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006868 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6869 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6870 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006871 }
6872
6873 @Override
6874 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006875 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006876 if (TextUtils.isEmpty(pkgName))
6877 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006878 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6879 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6880 UiccCard card = UiccController.getInstance().getUiccCard(i);
6881 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006882 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006883 continue;
6884 }
6885
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006886 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6887 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6888 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006889 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6890 break;
6891 }
6892 }
6893
6894 return result;
Junda Liu29340342014-07-10 15:23:27 -07006895 }
Derek Tan89e89d42014-07-08 17:00:10 -07006896
6897 @Override
Junda Liue64de782015-04-16 17:19:16 -07006898 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006899 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006900 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6901 loge("phoneId " + phoneId + " is not valid.");
6902 return null;
6903 }
6904 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006905 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006906 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006907 return null ;
6908 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006909 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006910 }
6911
Amith Yamasani6e118872016-02-19 12:53:51 -08006912 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006913 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006914 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006915 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006916 List<String> privilegedPackages = new ArrayList<>();
6917 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006918 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6919 // has UICC in that slot.
6920 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006921 if (card.hasCarrierPrivilegeRules()) {
6922 if (packages == null) {
6923 // Only check packages in user 0 for now
6924 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006925 PackageManager.MATCH_DISABLED_COMPONENTS
6926 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006927 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006928 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006929 }
6930 for (int p = packages.size() - 1; p >= 0; p--) {
6931 PackageInfo pkgInfo = packages.get(p);
6932 if (pkgInfo != null && pkgInfo.packageName != null
Sooraj Sasindran6c442bf2021-09-28 21:37:29 +00006933 && getCarrierPrivilegeStatusFromCarrierConfigRules(
6934 card.getCarrierPrivilegeStatus(pkgInfo),
6935 getPhone(phoneId), pkgInfo.packageName)
chen xuf7e9fe82019-05-09 19:31:02 -07006936 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006937 privilegedPackages.add(pkgInfo.packageName);
6938 }
6939 }
6940 }
6941 }
6942 return privilegedPackages;
6943 }
6944
chen xuf7e9fe82019-05-09 19:31:02 -07006945 @Override
6946 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006947 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6948
6949 final long identity = Binder.clearCallingIdentity();
6950
chen xuf7e9fe82019-05-09 19:31:02 -07006951 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006952 try {
6953 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6954 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6955 }
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006958 }
6959 return privilegedPackages;
6960 }
6961
Wink Savilleb564aae2014-10-23 10:18:09 -07006962 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006963 final Phone phone = getPhone(subId);
6964 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006965 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006966 return null;
6967 }
6968 String iccId = card.getIccId();
6969 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006970 return null;
6971 }
6972 return iccId;
6973 }
6974
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006975 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006976 public void setCallComposerStatus(int subId, int status) {
6977 enforceModifyPermission();
6978
6979 final long identity = Binder.clearCallingIdentity();
6980 try {
6981 Phone phone = getPhone(subId);
6982 if (phone != null) {
6983 Phone defaultPhone = phone.getImsPhone();
6984 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6985 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6986 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006987 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6988 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006989 }
6990 }
Shuo Qian284ae752020-12-22 19:10:14 -08006991 } catch (ImsException e) {
6992 throw new ServiceSpecificException(e.getCode());
6993 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006994 Binder.restoreCallingIdentity(identity);
6995 }
6996 }
6997
6998 @Override
6999 public int getCallComposerStatus(int subId) {
7000 enforceReadPrivilegedPermission("getCallComposerStatus");
7001
7002 final long identity = Binder.clearCallingIdentity();
7003 try {
7004 Phone phone = getPhone(subId);
7005 if (phone != null) {
7006 Phone defaultPhone = phone.getImsPhone();
7007 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7008 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7009 return imsPhone.getCallComposerStatus();
7010 }
7011 }
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
7014 }
7015 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7016 }
7017
7018 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007019 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7020 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007021 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007022 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007023
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 final long identity = Binder.clearCallingIdentity();
7025 try {
7026 final String iccId = getIccId(subId);
7027 final Phone phone = getPhone(subId);
7028 if (phone == null) {
7029 return false;
7030 }
7031 final String subscriberId = phone.getSubscriberId();
7032
7033 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007034 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 + subscriberId + " to " + number);
7036 }
7037
7038 if (TextUtils.isEmpty(iccId)) {
7039 return false;
7040 }
7041
7042 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7043
7044 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7045 if (alphaTag == null) {
7046 editor.remove(alphaTagPrefKey);
7047 } else {
7048 editor.putString(alphaTagPrefKey, alphaTag);
7049 }
7050
7051 // Record both the line number and IMSI for this ICCID, since we need to
7052 // track all merged IMSIs based on line number
7053 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7054 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7055 if (number == null) {
7056 editor.remove(numberPrefKey);
7057 editor.remove(subscriberPrefKey);
7058 } else {
7059 editor.putString(numberPrefKey, number);
7060 editor.putString(subscriberPrefKey, subscriberId);
7061 }
7062
7063 editor.commit();
7064 return true;
7065 } finally {
7066 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007067 }
Derek Tan7226c842014-07-02 17:42:23 -07007068 }
7069
7070 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007071 public String getLine1NumberForDisplay(int subId, String callingPackage,
7072 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007073 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007075 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007076 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007077 return null;
7078 }
Derek Tan97ebb422014-09-05 16:55:38 -07007079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007080 final long identity = Binder.clearCallingIdentity();
7081 try {
7082 String iccId = getIccId(subId);
7083 if (iccId != null) {
7084 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7085 if (DBG_MERGE) {
7086 log("getLine1NumberForDisplay returning "
7087 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7088 }
7089 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7092 return null;
7093 } finally {
7094 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007095 }
Derek Tan7226c842014-07-02 17:42:23 -07007096 }
7097
7098 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007099 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7100 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007102 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007103 return null;
7104 }
Derek Tan97ebb422014-09-05 16:55:38 -07007105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 String iccId = getIccId(subId);
7109 if (iccId != null) {
7110 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7111 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7112 }
7113 return null;
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007116 }
Derek Tan7226c842014-07-02 17:42:23 -07007117 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007118
7119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007120 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7121 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007122 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7123 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007124 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007125 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007126 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007127 return null;
7128 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007129
Jordan Liub49b04b2019-05-06 14:45:15 -07007130 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7131 // the process, where TelephonyManager was instantiated.
7132 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007133 final long identity = Binder.clearCallingIdentity();
7134 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007135 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 final TelephonyManager tele = TelephonyManager.from(context);
7137 final SubscriptionManager sub = SubscriptionManager.from(context);
7138
7139 // Figure out what subscribers are currently active
7140 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141
Jordan Liub49b04b2019-05-06 14:45:15 -07007142 // Only consider subs which match the current subId
7143 // This logic can be simplified. See b/131189269 for progress.
7144 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007145 activeSubscriberIds.add(tele.getSubscriberId(subId));
7146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147
7148 // First pass, find a number override for an active subscriber
7149 String mergeNumber = null;
7150 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7151 for (String key : prefs.keySet()) {
7152 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7153 final String subscriberId = (String) prefs.get(key);
7154 if (activeSubscriberIds.contains(subscriberId)) {
7155 final String iccId = key.substring(
7156 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7157 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7158 mergeNumber = (String) prefs.get(numberKey);
7159 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007160 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 + " for active subscriber " + subscriberId);
7162 }
7163 if (!TextUtils.isEmpty(mergeNumber)) {
7164 break;
7165 }
7166 }
7167 }
7168 }
7169
7170 // Shortcut when no active merged subscribers
7171 if (TextUtils.isEmpty(mergeNumber)) {
7172 return null;
7173 }
7174
7175 // Second pass, find all subscribers under that line override
7176 final ArraySet<String> result = new ArraySet<>();
7177 for (String key : prefs.keySet()) {
7178 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7179 final String number = (String) prefs.get(key);
7180 if (mergeNumber.equals(number)) {
7181 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7182 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7183 final String subscriberId = (String) prefs.get(subscriberKey);
7184 if (!TextUtils.isEmpty(subscriberId)) {
7185 result.add(subscriberId);
7186 }
7187 }
7188 }
7189 }
7190
7191 final String[] resultArray = result.toArray(new String[result.size()]);
7192 Arrays.sort(resultArray);
7193 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007194 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7196 }
7197 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007198 } finally {
7199 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007200 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007201 }
7202
7203 @Override
zoey chen38003472019-12-13 17:16:31 +08007204 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7205 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007206
7207 final long identity = Binder.clearCallingIdentity();
7208 try {
7209 final TelephonyManager telephonyManager = mApp.getSystemService(
7210 TelephonyManager.class);
7211 String subscriberId = telephonyManager.getSubscriberId(subId);
7212 if (subscriberId == null) {
7213 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007214 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007215 + subId);
7216 }
7217 return null;
7218 }
7219
7220 final SubscriptionInfo info = SubscriptionController.getInstance()
7221 .getSubscriptionInfo(subId);
7222 final ParcelUuid groupUuid = info.getGroupUuid();
7223 // If it doesn't belong to any group, return just subscriberId of itself.
7224 if (groupUuid == null) {
7225 return new String[]{subscriberId};
7226 }
7227
7228 // Get all subscriberIds from the group.
7229 final List<String> mergedSubscriberIds = new ArrayList<>();
7230 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007231 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007232 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007233 for (SubscriptionInfo subInfo : groupInfos) {
7234 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7235 if (subscriberId != null) {
7236 mergedSubscriberIds.add(subscriberId);
7237 }
7238 }
7239
7240 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243
7244 }
7245 }
7246
7247 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007248 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007249 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007250 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251
7252 final long identity = Binder.clearCallingIdentity();
7253 try {
7254 final Phone phone = getPhone(subId);
7255 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7256 } finally {
7257 Binder.restoreCallingIdentity(identity);
7258 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007259 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007260
7261 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007262 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007263 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7264 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007265 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7266 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007267
7268 final long identity = Binder.clearCallingIdentity();
7269 try {
7270 final Phone phone = getPhone(subId);
7271 if (phone == null) {
7272 return false;
7273 }
7274 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7275 cdmaNonRoamingList);
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007278 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007279 }
7280
7281 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007282 @Deprecated
7283 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7284 enforceModifyPermission();
7285
7286 int returnValue = 0;
7287 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007288 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007289 if(result.exception == null) {
7290 if (result.result != null) {
7291 byte[] responseData = (byte[])(result.result);
7292 if(responseData.length > oemResp.length) {
7293 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7294 responseData.length + "bytes. Buffer Size is " +
7295 oemResp.length + "bytes.");
7296 }
7297 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7298 returnValue = responseData.length;
7299 }
7300 } else {
7301 CommandException ex = (CommandException) result.exception;
7302 returnValue = ex.getCommandError().ordinal();
7303 if(returnValue > 0) returnValue *= -1;
7304 }
7305 } catch (RuntimeException e) {
7306 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7307 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7308 if(returnValue > 0) returnValue *= -1;
7309 }
7310
7311 return returnValue;
7312 }
7313
7314 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007315 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007316 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007317 try {
7318 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007319 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007320 mApp, phone.getSubId(), "getRadioAccessFamily");
7321 } catch (SecurityException e) {
7322 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7323 throw e;
7324 }
chen xub97461a2018-10-26 14:17:57 -07007325 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007326 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007327 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 final long identity = Binder.clearCallingIdentity();
7330 try {
chen xub97461a2018-10-26 14:17:57 -07007331 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007332 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007333 mApp, phone.getSubId(), "getRadioAccessFamily");
7334 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 } finally {
7336 Binder.restoreCallingIdentity(identity);
7337 }
chen xub97461a2018-10-26 14:17:57 -07007338 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007339 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007340
7341 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007342 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007343 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007344 try {
7345 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7346 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007347 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007348 }
7349 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007350 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007351 }
7352 RoleManager rm = mApp.getSystemService(RoleManager.class);
7353 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7354 if (!dialerRoleHolders.contains(callingPackage)) {
7355 throw new SecurityException("App must be the dialer role holder to"
7356 + " upload a call composer pic");
7357 }
7358
7359 Executors.newSingleThreadExecutor().execute(() -> {
7360 ByteArrayOutputStream output = new ByteArrayOutputStream(
7361 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7362 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7363 boolean readUntilEnd = false;
7364 int totalBytesRead = 0;
7365 byte[] buffer = new byte[16 * 1024];
7366 while (true) {
7367 int numRead;
7368 try {
7369 numRead = input.read(buffer);
7370 } catch (IOException e) {
7371 try {
7372 fd.checkError();
7373 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7374 null);
7375 } catch (IOException e1) {
7376 // This means that the other side closed explicitly with an error. If this
7377 // happens, log and ignore.
7378 loge("Remote end of call composer picture pipe closed: " + e1);
7379 }
7380 break;
7381 }
7382 if (numRead == -1) {
7383 readUntilEnd = true;
7384 break;
7385 }
7386 totalBytesRead += numRead;
7387 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7388 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7389 try {
7390 input.close();
7391 } catch (IOException e) {
7392 // ignore
7393 }
7394 break;
7395 }
7396 output.write(buffer, 0, numRead);
7397 }
7398 // Generally, the remote end will close the file descriptors. The only case where we
7399 // close is above, where the picture size is too big.
7400
7401 try {
7402 fd.checkError();
7403 } catch (IOException e) {
7404 loge("Remote end for call composer closed with an error: " + e);
7405 return;
7406 }
7407
Hall Liuaa4211e2021-01-20 15:43:39 -08007408 if (!readUntilEnd) {
7409 loge("Did not finish reading entire image; aborting");
7410 return;
7411 }
Hall Liu82694d52020-12-11 18:22:04 -08007412
Hall Liuaa4211e2021-01-20 15:43:39 -08007413 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7414 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7415 new CallComposerPictureTransfer.Factory() {},
7416 imageData,
7417 (result) -> {
7418 if (result.first != null) {
7419 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7420 Bundle outputResult = new Bundle();
7421 outputResult.putParcelable(
7422 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7423 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7424 outputResult);
7425 } else {
7426 callback.send(result.second, null);
7427 }
7428 }
7429 );
Hall Liu82694d52020-12-11 18:22:04 -08007430 });
7431 }
7432
7433 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007434 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007436 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437
7438 final long identity = Binder.clearCallingIdentity();
7439 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007440 ImsManager.getInstance(defaultPhone.getContext(),
7441 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007442 } finally {
7443 Binder.restoreCallingIdentity(identity);
7444 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007445 }
7446
7447 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007448 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007449 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7451 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007452 return false;
7453 }
Svet Ganovb320e182015-04-16 12:30:10 -07007454
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007455 final long identity = Binder.clearCallingIdentity();
7456 try {
7457 // Check the user preference and the system-level IMS setting. Even if the user has
7458 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7459 // In the long run, we may instead need to check if there exists a connection service
7460 // which can support video calling.
7461 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007462 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 return imsManager.isVtEnabledByPlatform()
7464 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7465 && imsManager.isVtEnabledByUser();
7466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007469 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007470
Andrew Leea1239f22015-03-02 17:44:07 -08007471 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007472 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7473 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007475 mApp, subId, callingPackage, callingFeatureId,
7476 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007477 return false;
7478 }
7479
7480 final long identity = Binder.clearCallingIdentity();
7481 try {
7482 CarrierConfigManager configManager =
7483 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007484 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007485 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7486 } finally {
7487 Binder.restoreCallingIdentity(identity);
7488 }
Andrew Leea1239f22015-03-02 17:44:07 -08007489 }
7490
7491 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007492 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007494 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 return false;
7496 }
7497
7498 final long identity = Binder.clearCallingIdentity();
7499 try {
7500 CarrierConfigManager configManager =
7501 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007502 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007503 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7504 } finally {
7505 Binder.restoreCallingIdentity(identity);
7506 }
Andrew Leea1239f22015-03-02 17:44:07 -08007507 }
7508
Andrew Lee9431b832015-03-09 18:46:45 -07007509 @Override
7510 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007511 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007512 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007513 }
7514
7515 @Override
7516 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 final long identity = Binder.clearCallingIdentity();
7518 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007519 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
Andrew Lee9431b832015-03-09 18:46:45 -07007523 }
7524
Hall Liuf6668912018-10-31 17:05:23 -07007525 /**
7526 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7527 * support for the feature and device firmware support.
7528 *
7529 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7530 */
7531 @Override
7532 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007534 final Phone phone = getPhone(subscriptionId);
7535 if (phone == null) {
7536 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7537 return false;
7538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007539 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7542 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007543 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007544 return isCarrierSupported && isDeviceSupported;
7545 } finally {
7546 Binder.restoreCallingIdentity(identity);
7547 }
Hall Liu98187582018-01-22 19:15:32 -08007548 }
7549
Hall Liuf6668912018-10-31 17:05:23 -07007550 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007551 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7552 * RTT setting, will return true if the device and carrier both support RTT.
7553 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007554 */
7555 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556 final long identity = Binder.clearCallingIdentity();
7557 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007558 boolean isRttSupported = isRttSupported(subscriptionId);
7559 boolean isUserRttSettingOn = Settings.Secure.getInt(
7560 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7561 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7562 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7563 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 } finally {
7565 Binder.restoreCallingIdentity(identity);
7566 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007567 }
7568
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007569 @Deprecated
7570 @Override
7571 public String getDeviceId(String callingPackage) {
7572 return getDeviceIdWithFeature(callingPackage, null);
7573 }
7574
Sanket Padawe7310cc72015-01-14 09:53:20 -08007575 /**
7576 * Returns the unique device ID of phone, for example, the IMEI for
7577 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7578 *
7579 * <p>Requires Permission:
7580 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7581 */
7582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007583 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007584 try {
7585 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7586 } catch (SecurityException se) {
7587 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7588 throw new SecurityException("Package " + callingPackage + " does not belong to "
7589 + Binder.getCallingUid());
7590 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007591 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007592 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007593 return null;
7594 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007595 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007596 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007597 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007598 return null;
7599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600
7601 final long identity = Binder.clearCallingIdentity();
7602 try {
7603 return phone.getDeviceId();
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
7606 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007607 }
7608
Ping Sunc67b7c22016-03-02 19:16:45 +08007609 /**
7610 * {@hide}
7611 * Returns the IMS Registration Status on a particular subid
7612 *
7613 * @param subId
7614 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007615 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007616 Phone phone = getPhone(subId);
7617 if (phone != null) {
7618 return phone.isImsRegistered();
7619 } else {
7620 return false;
7621 }
7622 }
7623
Santos Cordon7a1885b2015-02-03 11:15:19 -08007624 @Override
7625 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007626 final long identity = Binder.clearCallingIdentity();
7627 try {
7628 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007632 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007633
Tyler Gunnf70ed162019-04-03 15:28:53 -07007634 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007635 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007636 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007638 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007639 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7640 }
7641 final long identity = Binder.clearCallingIdentity();
7642 try {
7643 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7644 } finally {
7645 Binder.restoreCallingIdentity(identity);
7646 }
7647 }
7648
7649 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007650 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007651 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007652 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007653 mApp,
7654 subscriptionId,
7655 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007656 final long identity = Binder.clearCallingIdentity();
7657 try {
7658 Phone phone = getPhone(subscriptionId);
7659 if (phone == null) {
7660 return null;
7661 }
7662 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7663 } finally {
7664 Binder.restoreCallingIdentity(identity);
7665 }
7666 }
7667
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007668 /**
7669 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007670 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007671 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 final long identity = Binder.clearCallingIdentity();
7673 try {
7674 Phone phone = getPhone(subId);
7675 if (phone != null) {
7676 return phone.isWifiCallingEnabled();
7677 } else {
7678 return false;
7679 }
7680 } finally {
7681 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007682 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007683 }
7684
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007685 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007686 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007687 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007688 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 Phone phone = getPhone(subId);
7692 if (phone != null) {
7693 return phone.isVideoEnabled();
7694 } else {
7695 return false;
7696 }
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007699 }
7700 }
7701
7702 /**
7703 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7704 * defined in {@link ImsRegistrationImplBase}.
7705 */
7706 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 final long identity = Binder.clearCallingIdentity();
7708 try {
7709 Phone phone = getPhone(subId);
7710 if (phone != null) {
7711 return phone.getImsRegistrationTech();
7712 } else {
7713 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7714 }
7715 } finally {
7716 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007717 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007718 }
7719
Stuart Scott8eef64f2015-04-08 15:13:54 -07007720 @Override
7721 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007722 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007723 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7724 return;
7725 }
Kai Shif70f46f2021-03-03 13:59:46 -08007726 Phone defaultPhone = getDefaultPhone();
7727 if (defaultPhone != null) {
7728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7729 mApp, getDefaultPhone().getSubId(), "factoryReset");
7730 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007731 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007732
Svet Ganovcc087f82015-05-12 20:35:54 -07007733 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007734 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7735 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007736 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007737 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007738 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007739 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007740 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007742 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007743 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007744 // There has been issues when Sms raw table somehow stores orphan
7745 // fragments. They lead to garbled message when new fragments come
7746 // in and combined with those stale ones. In case this happens again,
7747 // user can reset all network settings which will clean up this table.
7748 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007749 // Clean up IMS settings as well here.
7750 int slotId = getSlotIndex(subId);
7751 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7752 ImsManager.getInstance(mApp, slotId).factoryReset();
7753 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007754
Kai Shif70f46f2021-03-03 13:59:46 -08007755 if (defaultPhone == null) {
7756 return;
7757 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007758 // Erase modem config if erase modem on network setting is enabled.
7759 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7760 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7761 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007762 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007763 }
Kai Shif70f46f2021-03-03 13:59:46 -08007764
7765 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007766 } finally {
7767 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007768 }
7769 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007770
SongFerngWangfd89b102021-05-27 22:44:54 +08007771 @VisibleForTesting
7772 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7773 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7774 return;
7775 }
7776 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7777 RILConstants.PREFERRED_NETWORK_MODE);
7778 SubscriptionManager.setSubscriptionProperty(subId,
7779 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7780 "user=" + defaultNetworkType);
7781 phone.loadAllowedNetworksFromSubscriptionDatabase();
7782 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7783 defaultNetworkType, null);
7784 }
7785
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007786 private void cleanUpSmsRawTable(Context context) {
7787 ContentResolver resolver = context.getContentResolver();
7788 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7789 resolver.delete(uri, null, null);
7790 }
7791
Narayan Kamath1c496c22015-04-16 14:40:19 +01007792 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007793 public String getSimLocaleForSubscriber(int subId) {
7794 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7795 final Phone phone = getPhone(subId);
7796 if (phone == null) {
7797 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007798 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007800 final long identity = Binder.clearCallingIdentity();
7801 try {
chen xu5d3637b2019-01-21 23:31:38 -08007802 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007803 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007804 if (info == null) {
7805 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7806 return null;
7807 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808 // Try and fetch the locale from the carrier properties or from the SIM language
7809 // preferences (EF-PL and EF-LI)...
7810 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007812 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7813 if (localeFromDefaultSim != null) {
7814 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7815 if (DBG) log("Using locale from subId: " + subId + " locale: "
7816 + localeFromDefaultSim);
7817 return localeFromDefaultSim.toLanguageTag();
7818 } else {
7819 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820 }
7821 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 // The SIM language preferences only store a language (e.g. fr = French), not an
7824 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7825 // the SIM and carrier preferences does not include a country we add the country
7826 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007827 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007828 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007829 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 return mccLocale.toLanguageTag();
7831 }
7832
7833 if (DBG) log("No locale found - returning null");
7834 return null;
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007838 }
7839
7840 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007841 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007842 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007843 }
7844
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007845 /**
7846 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7847 */
7848 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007849 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007850 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007851 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007852
Chenjie Yu1ba97252018-01-11 18:16:20 -08007853 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007854 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007855
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007856 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007857 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7858 * representing the state of the modem.
7859 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007860 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7861 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007862 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007863 */
7864 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007865 public void requestModemActivityInfo(ResultReceiver result) {
7866 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007867 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007868
7869 final long identity = Binder.clearCallingIdentity();
7870 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007871 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007872 } finally {
7873 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007874 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007875 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007876
Siddharth Rayb8114062018-06-17 15:02:38 -07007877 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7878 // less than total activity duration.
7879 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7880 if (info == null) {
7881 return false;
7882 }
7883 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007884 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7885 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7886
Siddharth Rayb8114062018-06-17 15:02:38 -07007887 return (info.isValid()
7888 && (info.getSleepTimeMillis() <= activityDurationMs)
7889 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007890 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007891 && (totalTxTimeMs <= activityDurationMs));
7892 }
7893
Jack Yu85bd38a2015-11-09 11:34:32 -08007894 /**
7895 * {@hide}
7896 * Returns the service state information on specified subscription.
7897 */
7898 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007899 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7900 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007901 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007902 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007903 return null;
7904 }
7905
Hall Liuf19c44f2018-11-27 14:38:17 -08007906 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7907 LocationAccessPolicy.checkLocationPermission(mApp,
7908 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7909 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007910 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007911 .setCallingPid(Binder.getCallingPid())
7912 .setCallingUid(Binder.getCallingUid())
7913 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007914 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007915 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007916 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7917 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007918 .build());
7919
7920 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7921 LocationAccessPolicy.checkLocationPermission(mApp,
7922 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7923 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007924 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007925 .setCallingPid(Binder.getCallingPid())
7926 .setCallingUid(Binder.getCallingUid())
7927 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007928 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007929 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007930 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7931 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007932 .build());
7933 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7934 boolean hasFinePermission =
7935 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7936 boolean hasCoarsePermission =
7937 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7938
Jack Yu479f40e2020-10-27 21:29:25 -07007939 final Phone phone = getPhone(subId);
7940 if (phone == null) {
7941 return null;
7942 }
7943
Jordan Liu0f2bc442020-11-18 16:47:37 -08007944 final long identity = Binder.clearCallingIdentity();
7945
Jack Yu479f40e2020-10-27 21:29:25 -07007946 boolean isCallingPackageDataService = phone.getDataServicePackages()
7947 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007949 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7950 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7951 Rlog.d(LOG_TAG,
7952 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7953 return null;
7954 }
7955
Hall Liuf19c44f2018-11-27 14:38:17 -08007956 ServiceState ss = phone.getServiceState();
7957
7958 // Scrub out the location info in ServiceState depending on what level of access
7959 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007960 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007961 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7962 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 } finally {
7964 Binder.restoreCallingIdentity(identity);
7965 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007966 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007967
7968 /**
7969 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7970 *
7971 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7972 * voicemail ringtone.
7973 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7974 * PhoneAccount.
7975 */
7976 @Override
7977 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 final long identity = Binder.clearCallingIdentity();
7979 try {
7980 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7981 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007982 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007984
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7986 } finally {
7987 Binder.restoreCallingIdentity(identity);
7988 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007989 }
7990
7991 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007992 * Sets the per-account voicemail ringtone.
7993 *
7994 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7995 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7996 *
7997 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7998 * voicemail ringtone.
7999 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
8000 * PhoneAccount.
8001 */
8002 @Override
8003 public void setVoicemailRingtoneUri(String callingPackage,
8004 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008005 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008006 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008007 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8008 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8010 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8011 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008013
8014 final long identity = Binder.clearCallingIdentity();
8015 try {
8016 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8017 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008018 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008019 }
8020 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8021 } finally {
8022 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008023 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008024 }
8025
8026 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008027 * Returns whether vibration is set for voicemail notification in Phone settings.
8028 *
8029 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8030 * voicemail vibration setting.
8031 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8032 */
8033 @Override
8034 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008035 final long identity = Binder.clearCallingIdentity();
8036 try {
8037 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8038 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008039 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008042 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8043 } finally {
8044 Binder.restoreCallingIdentity(identity);
8045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008046 }
8047
Youhan Wange64578a2016-05-02 15:32:42 -07008048 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008049 * Sets the per-account voicemail vibration.
8050 *
8051 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8052 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8053 *
8054 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8055 * voicemail vibration setting.
8056 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8057 * specific PhoneAccount.
8058 */
8059 @Override
8060 public void setVoicemailVibrationEnabled(String callingPackage,
8061 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008062 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008064 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8065 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8067 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8068 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008069 }
8070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008071 final long identity = Binder.clearCallingIdentity();
8072 try {
8073 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8074 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008075 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008076 }
8077 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8078 } finally {
8079 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008080 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008081 }
8082
8083 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008084 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8085 *
8086 * @throws SecurityException if the caller does not have the required permission
8087 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008088 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008089 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008090 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008091 }
8092
8093 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008094 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8095 * permission.
8096 *
8097 * @throws SecurityException if the caller does not have the required permission
8098 */
8099 private void enforceSendSmsPermission() {
8100 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8101 }
8102
8103 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008104 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008105 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008106 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008107 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008108 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008109 final long identity = Binder.clearCallingIdentity();
8110 try {
8111 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008112 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008113 if (componentName == null) {
8114 throw new SecurityException(
8115 "Caller not current active visual voicemail package[null]");
8116 }
8117 String vvmPackage = componentName.getPackageName();
8118 if (!callingPackage.equals(vvmPackage)) {
8119 throw new SecurityException("Caller not current active visual voicemail package["
8120 + vvmPackage + "]");
8121 }
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008124 }
8125 }
8126
8127 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008128 * Return the application ID for the app type.
8129 *
8130 * @param subId the subscription ID that this request applies to.
8131 * @param appType the uicc app type.
8132 * @return Application ID for specificied app type, or null if no uicc.
8133 */
8134 @Override
8135 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008136 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008137 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008138
8139 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008140 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008141 if (phone == null) {
8142 return null;
8143 }
8144 String aid = null;
8145 try {
8146 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8147 .getApplicationByType(appType).getAid();
8148 } catch (Exception e) {
8149 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8150 }
8151 return aid;
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008154 }
Youhan Wange64578a2016-05-02 15:32:42 -07008155 }
8156
Youhan Wang4001d252016-05-11 10:29:41 -07008157 /**
8158 * Return the Electronic Serial Number.
8159 *
8160 * @param subId the subscription ID that this request applies to.
8161 * @return ESN or null if error.
8162 */
8163 @Override
8164 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008165 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008166 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167
8168 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008169 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008170 if (phone == null) {
8171 return null;
8172 }
8173 String esn = null;
8174 try {
8175 esn = phone.getEsn();
8176 } catch (Exception e) {
8177 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8178 }
8179 return esn;
8180 } finally {
8181 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008182 }
Youhan Wang4001d252016-05-11 10:29:41 -07008183 }
8184
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008185 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008186 * Return the Preferred Roaming List Version.
8187 *
8188 * @param subId the subscription ID that this request applies to.
8189 * @return PRLVersion or null if error.
8190 */
8191 @Override
8192 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008193 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008194 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008195
8196 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008197 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008198 if (phone == null) {
8199 return null;
8200 }
8201 String cdmaPrlVersion = null;
8202 try {
8203 cdmaPrlVersion = phone.getCdmaPrlVersion();
8204 } catch (Exception e) {
8205 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8206 }
8207 return cdmaPrlVersion;
8208 } finally {
8209 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008210 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008211 }
8212
8213 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008214 * Get snapshot of Telephony histograms
8215 * @return List of Telephony histograms
8216 * @hide
8217 */
8218 @Override
8219 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8221 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008222
8223 final long identity = Binder.clearCallingIdentity();
8224 try {
8225 return RIL.getTelephonyRILTimingHistograms();
8226 } finally {
8227 Binder.restoreCallingIdentity(identity);
8228 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008229 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008230
8231 /**
8232 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008233 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8234 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008235 * Require system privileges. In the future we may add this to carrier APIs.
8236 *
Michele Berionne482f8202018-11-27 18:57:59 -08008237 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008238 */
8239 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008240 @TelephonyManager.SetCarrierRestrictionResult
8241 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008242 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008243 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008244
Michele Berionne482f8202018-11-27 18:57:59 -08008245 if (carrierRestrictionRules == null) {
8246 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008247 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008249 final long identity = Binder.clearCallingIdentity();
8250 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008251 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008252 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253 } finally {
8254 Binder.restoreCallingIdentity(identity);
8255 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008256 }
8257
8258 /**
8259 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008260 * Get the allowed carrier list and the excluded carrier list, including the priority between
8261 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008262 * Require system privileges. In the future we may add this to carrier APIs.
8263 *
Michele Berionne482f8202018-11-27 18:57:59 -08008264 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008265 */
8266 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008267 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008268 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008269 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270
8271 final long identity = Binder.clearCallingIdentity();
8272 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008273 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8274 if (response instanceof CarrierRestrictionRules) {
8275 return (CarrierRestrictionRules) response;
8276 }
8277 // Response is an Exception of some kind,
8278 // which is signalled to the user as a NULL retval
8279 return null;
8280 } catch (Exception e) {
8281 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8282 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008286 }
8287
fionaxu59545b42016-05-25 15:53:37 -07008288 /**
fionaxu59545b42016-05-25 15:53:37 -07008289 * Action set from carrier signalling broadcast receivers to enable/disable radio
8290 * @param subId the subscription ID that this action applies to.
8291 * @param enabled control enable or disable radio.
8292 * {@hide}
8293 */
8294 @Override
8295 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8296 enforceModifyPermission();
8297 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008298
8299 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008300 if (phone == null) {
8301 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8302 return;
8303 }
8304 try {
8305 phone.carrierActionSetRadioEnabled(enabled);
8306 } catch (Exception e) {
8307 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008308 } finally {
8309 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008310 }
8311 }
8312
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008313 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008314 * Enable or disable Voice over NR (VoNR)
8315 * @param subId the subscription ID that this action applies to.
8316 * @param enabled enable or disable VoNR.
8317 * @return operation result.
8318 */
8319 @Override
8320 public int setVoNrEnabled(int subId, boolean enabled) {
8321 enforceModifyPermission();
8322 final Phone phone = getPhone(subId);
8323
8324 final long identity = Binder.clearCallingIdentity();
8325 if (phone == null) {
8326 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8327 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8328 }
8329
8330 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8331 try {
8332 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8333 workSource);
8334 if (DBG) log("setVoNrEnabled result: " + result);
8335 return result;
8336 } finally {
8337 Binder.restoreCallingIdentity(identity);
8338 }
8339 }
8340
8341 /**
8342 * Is voice over NR enabled
8343 * @return true if VoNR is enabled else false
8344 */
8345 @Override
8346 public boolean isVoNrEnabled(int subId) {
8347 enforceReadPrivilegedPermission("isVoNrEnabled");
8348 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8349 final long identity = Binder.clearCallingIdentity();
8350 try {
8351 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8352 null, subId, workSource);
8353 if (DBG) log("isVoNrEnabled: " + isEnabled);
8354 return isEnabled;
8355 } finally {
8356 Binder.restoreCallingIdentity(identity);
8357 }
8358 }
8359
8360 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008361 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8362 * network status based on which carrier apps could apply actions accordingly,
8363 * enable/disable default url handler for example.
8364 *
8365 * @param subId the subscription ID that this action applies to.
8366 * @param report control start/stop reporting the default network status.
8367 * {@hide}
8368 */
8369 @Override
8370 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8371 enforceModifyPermission();
8372 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008373
8374 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008375 if (phone == null) {
8376 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8377 return;
8378 }
8379 try {
8380 phone.carrierActionReportDefaultNetworkStatus(report);
8381 } catch (Exception e) {
8382 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008383 } finally {
8384 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008385 }
8386 }
8387
8388 /**
fionaxud9622282017-07-17 17:51:30 -07008389 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8390 * @param subId the subscription ID that this action applies to.
8391 * {@hide}
8392 */
8393 @Override
8394 public void carrierActionResetAll(int subId) {
8395 enforceModifyPermission();
8396 final Phone phone = getPhone(subId);
8397 if (phone == null) {
8398 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8399 return;
8400 }
8401 try {
8402 phone.carrierActionResetAll();
8403 } catch (Exception e) {
8404 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8405 }
8406 }
8407
8408 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008409 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8410 * bug report is being generated.
8411 */
8412 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008413 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008414 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8415 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008416 writer.println("Permission Denial: can't dump Phone from pid="
8417 + Binder.getCallingPid()
8418 + ", uid=" + Binder.getCallingUid()
8419 + "without permission "
8420 + android.Manifest.permission.DUMP);
8421 return;
8422 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008423 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008424 }
Jack Yueb89b242016-06-22 13:27:47 -07008425
Brad Ebingerdac2f002018-04-03 15:17:52 -07008426 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008427 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8428 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8429 @NonNull String[] args) {
8430 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8431 this, in.getFileDescriptor(), out.getFileDescriptor(),
8432 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008433 }
8434
Jack Yueb89b242016-06-22 13:27:47 -07008435 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008436 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008437 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008438 * @param reason the reason the data enable change is taking place
8439 * @param enabled True if enabling the data, otherwise disabling.
8440 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008441 */
8442 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008443 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008444 boolean enabled) {
8445 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8446 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8447 try {
8448 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008449 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008450 } catch (SecurityException se) {
8451 enforceModifyPermission();
8452 }
8453 } else {
8454 enforceModifyPermission();
8455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456
8457 final long identity = Binder.clearCallingIdentity();
8458 try {
8459 Phone phone = getPhone(subId);
8460 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008461 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8462 phone.carrierActionSetMeteredApnsEnabled(enabled);
8463 } else {
8464 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8465 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 }
8467 } finally {
8468 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008469 }
8470 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008471
8472 /**
8473 * Get Client request stats
8474 * @return List of Client Request Stats
8475 * @hide
8476 */
8477 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008478 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8479 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008481 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008482 return null;
8483 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008484 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008486 final long identity = Binder.clearCallingIdentity();
8487 try {
8488 if (phone != null) {
8489 return phone.getClientRequestStats();
8490 }
8491
8492 return null;
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
8495 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008496 }
8497
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008498 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008499 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008500 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008501 }
Jack Yueb4124c2017-02-16 15:32:43 -08008502
8503 /**
Grace Chen70990072017-03-24 17:21:30 -07008504 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008505 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008506 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008507 * @param state State of SIM (power down, power up, pass through)
8508 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8509 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8510 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008511 *
8512 **/
8513 @Override
Grace Chen70990072017-03-24 17:21:30 -07008514 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008515 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008516 Phone phone = PhoneFactory.getPhone(slotIndex);
8517
vagdeviaf9a5b92018-08-15 16:01:53 -07008518 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008520 final long identity = Binder.clearCallingIdentity();
8521 try {
8522 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008523 phone.setSimPowerState(state, null, workSource);
8524 }
8525 } finally {
8526 Binder.restoreCallingIdentity(identity);
8527 }
8528 }
8529
8530 /**
8531 * Set SIM card power state.
8532 *
8533 * @param slotIndex SIM slot id.
8534 * @param state State of SIM (power down, power up, pass through)
8535 * @param callback callback to trigger after success or failure
8536 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8537 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8538 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8539 *
8540 **/
8541 @Override
8542 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8543 IIntegerConsumer callback) {
8544 enforceModifyPermission();
8545 Phone phone = PhoneFactory.getPhone(slotIndex);
8546
8547 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
8551 if (phone != null) {
8552 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8553 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008554 }
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008557 }
8558 }
Shuo Qiandd210312017-04-12 22:11:33 +00008559
Tyler Gunn65d45c22017-06-05 11:22:26 -07008560 private boolean isUssdApiAllowed(int subId) {
8561 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008562 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008563 if (configManager == null) {
8564 return false;
8565 }
8566 PersistableBundle pb = configManager.getConfigForSubId(subId);
8567 if (pb == null) {
8568 return false;
8569 }
8570 return pb.getBoolean(
8571 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8572 }
8573
Shuo Qiandd210312017-04-12 22:11:33 +00008574 /**
8575 * Check if phone is in emergency callback mode
8576 * @return true if phone is in emergency callback mode
8577 * @param subId sub id
8578 */
goneil9c5f4872017-12-05 14:07:56 -08008579 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008580 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008581 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008582 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008583
8584 final long identity = Binder.clearCallingIdentity();
8585 try {
8586 if (phone != null) {
8587 return phone.isInEcm();
8588 } else {
8589 return false;
8590 }
8591 } finally {
8592 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008593 }
8594 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008595
8596 /**
8597 * Get the current signal strength information for the given subscription.
8598 * Because this information is not updated when the device is in a low power state
8599 * it should not be relied-upon to be current.
8600 * @param subId Subscription index
8601 * @return the most recent cached signal strength info from the modem
8602 */
8603 @Override
8604 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 Phone p = getPhone(subId);
8608 if (p == null) {
8609 return null;
8610 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008612 return p.getSignalStrength();
8613 } finally {
8614 Binder.restoreCallingIdentity(identity);
8615 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008616 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008617
Pengquan Meng77b7f132018-08-22 14:49:57 -07008618 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008619 * Get the current modem radio state for the given slot.
8620 * @param slotIndex slot index.
8621 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008622 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008623 * @return the current radio power state from the modem
8624 */
8625 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008626 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008627 Phone phone = PhoneFactory.getPhone(slotIndex);
8628 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8630 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008631 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8632 }
8633
8634 final long identity = Binder.clearCallingIdentity();
8635 try {
8636 return phone.getRadioPowerState();
8637 } finally {
8638 Binder.restoreCallingIdentity(identity);
8639 }
8640 }
8641 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8642 }
8643
8644 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008645 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8646 *
8647 * <p>Requires one of the following permissions:
8648 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8649 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8650 * privileges.
8651 *
8652 * @param subId subscription id
8653 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8654 * {@code false}.
8655 */
8656 @Override
8657 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008658 try {
8659 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8660 null);
8661 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008662 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008663 mApp, subId, "isDataRoamingEnabled");
8664 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008665
Pengquan Menga1bb6272018-09-06 09:59:22 -07008666 boolean isEnabled = false;
8667 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008668 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008669 Phone phone = getPhone(subId);
8670 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008671 } finally {
8672 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008673 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008674 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008675 }
8676
8677
8678 /**
8679 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8680 *
8681 * <p> Requires permission:
8682 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8683 * privileges.
8684 *
8685 * @param subId subscription id
8686 * @param isEnabled {@code true} means enable, {@code false} means disable.
8687 */
8688 @Override
8689 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8691 mApp, subId, "setDataRoamingEnabled");
8692
Pengquan Menga1bb6272018-09-06 09:59:22 -07008693 final long identity = Binder.clearCallingIdentity();
8694 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008695 Phone phone = getPhone(subId);
8696 if (phone != null) {
8697 phone.setDataRoamingEnabled(isEnabled);
8698 }
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008701 }
8702 }
8703
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008704 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008705 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008706 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008707 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008708 mApp, subId, "isManualNetworkSelectionAllowed");
8709
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008710 boolean isAllowed = true;
8711 final long identity = Binder.clearCallingIdentity();
8712 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008713 Phone phone = getPhone(subId);
8714 if (phone != null) {
8715 isAllowed = phone.isCspPlmnEnabled();
8716 }
8717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 return isAllowed;
8721 }
8722
8723 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008724 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008725 // Verify that tha callingPackage belongs to the calling UID
8726 mApp.getSystemService(AppOpsManager.class)
8727 .checkPackage(Binder.getCallingUid(), callingPackage);
8728
Jordan Liu1e142fc2019-04-22 15:10:43 -07008729 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008730 try {
8731 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008732 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008733 } catch (SecurityException e) {
8734 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8735 // has carrier privileges on an active UICC
8736 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8737 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008738 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008739 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008740 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008741
8742 final long identity = Binder.clearCallingIdentity();
8743 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008744 UiccController uiccController = UiccController.getInstance();
8745 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008746 if (hasReadPermission) {
8747 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008748 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008749
8750 // Remove private info if the caller doesn't have access
8751 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8752 for (UiccCardInfo cardInfo : cardInfos) {
8753 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8754 // is available
8755 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8756 if (card == null || card.getUiccProfile() == null) {
8757 // assume no access if the card or profile is unavailable
8758 filteredInfos.add(cardInfo.getUnprivileged());
8759 continue;
8760 }
8761 UiccProfile profile = card.getUiccProfile();
8762 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8763 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8764 filteredInfos.add(cardInfo);
8765 } else {
8766 filteredInfos.add(cardInfo.getUnprivileged());
8767 }
8768 }
8769 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008770 } finally {
8771 Binder.restoreCallingIdentity(identity);
8772 }
8773 }
8774
8775 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008776 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008777 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008779 final long identity = Binder.clearCallingIdentity();
8780 try {
8781 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8782 if (slots == null) {
8783 Rlog.i(LOG_TAG, "slots is null.");
8784 return null;
8785 }
8786
8787 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8788 for (int i = 0; i < slots.length; i++) {
8789 UiccSlot slot = slots[i];
8790 if (slot == null) {
8791 continue;
8792 }
8793
Jordan Liu7be7e652019-05-06 18:55:02 +00008794 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008795 UiccCard card = slot.getUiccCard();
8796 if (card != null) {
8797 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008798 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008799 cardId = slot.getEid();
8800 if (TextUtils.isEmpty(cardId)) {
8801 cardId = slot.getIccId();
8802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008803 }
8804
Jordan Liu857451f2019-05-09 16:35:35 -07008805 if (cardId != null) {
8806 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8807 // if cardId is an EID, it's all digits so this is fine
8808 cardId = IccUtils.stripTrailingFs(cardId);
8809 }
8810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008811 int cardState = 0;
8812 switch (slot.getCardState()) {
8813 case CARDSTATE_ABSENT:
8814 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8815 break;
8816 case CARDSTATE_PRESENT:
8817 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8818 break;
8819 case CARDSTATE_ERROR:
8820 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8821 break;
8822 case CARDSTATE_RESTRICTED:
8823 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8824 break;
8825 default:
8826 break;
8827
8828 }
8829
8830 infos[i] = new UiccSlotInfo(
8831 slot.isActive(),
8832 slot.isEuicc(),
8833 cardId,
8834 cardState,
8835 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008836 slot.isExtendedApduSupported(),
8837 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008838 }
8839 return infos;
8840 } finally {
8841 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008842 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008843 }
8844
8845 @Override
8846 public boolean switchSlots(int[] physicalSlots) {
8847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008848
8849 final long identity = Binder.clearCallingIdentity();
8850 try {
8851 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8852 } finally {
8853 Binder.restoreCallingIdentity(identity);
8854 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008855 }
Jack Yu4c988042018-02-27 15:30:01 -08008856
8857 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008858 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008859 final long identity = Binder.clearCallingIdentity();
8860 try {
8861 return UiccController.getInstance().getCardIdForDefaultEuicc();
8862 } finally {
8863 Binder.restoreCallingIdentity(identity);
8864 }
8865 }
8866
Pengquan Meng85728fb2018-03-12 16:31:21 -07008867 /**
goneil47ffb6e2018-04-06 15:40:58 -07008868 * A test API to reload the UICC profile.
8869 *
8870 * <p>Requires that the calling app has permission
8871 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8872 * @hide
8873 */
8874 @Override
8875 public void refreshUiccProfile(int subId) {
8876 enforceModifyPermission();
8877
8878 final long identity = Binder.clearCallingIdentity();
8879 try {
8880 Phone phone = getPhone(subId);
8881 if (phone == null) {
8882 return;
8883 }
8884 UiccCard uiccCard = phone.getUiccCard();
8885 if (uiccCard == null) {
8886 return;
8887 }
8888 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8889 if (uiccProfile == null) {
8890 return;
8891 }
8892 uiccProfile.refresh();
8893 } finally {
8894 Binder.restoreCallingIdentity(identity);
8895 }
8896 }
8897
8898 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008899 * Returns false if the mobile data is disabled by default, otherwise return true.
8900 */
8901 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008902 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008903 }
8904
8905 /**
8906 * Returns true if the data roaming is enabled by default, i.e the system property
8907 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8908 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8909 */
8910 private boolean getDefaultDataRoamingEnabled(int subId) {
8911 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008912 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008913 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008914 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8915 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8916 return isDataRoamingEnabled;
8917 }
8918
8919 /**
8920 * Returns the default network type for the given {@code subId}, if the default network type is
8921 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8922 */
8923 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008924 List<Integer> list = TelephonyProperties.default_network();
8925 int phoneId = mSubscriptionController.getPhoneId(subId);
8926 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8927 return list.get(phoneId);
8928 }
8929 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008930 }
fionaxua13278b2018-03-21 00:08:13 -07008931
8932 @Override
8933 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008934 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008935 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008936
8937 final long identity = Binder.clearCallingIdentity();
8938 try {
8939 final Phone phone = getPhone(subId);
8940 if (phone == null) {
8941 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8942 return;
8943 }
chen xueaba88a2019-03-15 13:15:10 -07008944 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8945 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008946 if (carrierPrivilegeRules == null) {
8947 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8948 } else {
8949 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008951 } finally {
8952 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008953 }
fionaxua13278b2018-03-21 00:08:13 -07008954 }
8955
8956 @Override
8957 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008958 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008959
8960 final long identity = Binder.clearCallingIdentity();
8961 try {
8962 final Phone phone = getPhone(subId);
8963 if (phone == null) {
8964 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8965 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8966 }
8967 return phone.getCarrierIdListVersion();
8968 } finally {
8969 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008970 }
fionaxua13278b2018-03-21 00:08:13 -07008971 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008972
8973 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008974 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8975 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008977 mApp, subId, callingPackage, callingFeatureId,
8978 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008979 return -1;
8980 }
8981
8982 final long identity = Binder.clearCallingIdentity();
8983 try {
8984 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8985 } finally {
8986 Binder.restoreCallingIdentity(identity);
8987 }
8988 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008989
8990 @Override
8991 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008992 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008993 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008994 mApp, subId, "getCdmaRoamingMode");
8995
8996 final long identity = Binder.clearCallingIdentity();
8997 try {
8998 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
9001 }
9002 }
9003
9004 @Override
9005 public boolean setCdmaRoamingMode(int subId, int mode) {
9006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9007 mApp, subId, "setCdmaRoamingMode");
9008
9009 final long identity = Binder.clearCallingIdentity();
9010 try {
9011 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9012 } finally {
9013 Binder.restoreCallingIdentity(identity);
9014 }
9015 }
9016
9017 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009018 public int getCdmaSubscriptionMode(int subId) {
9019 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009020 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009021 mApp, subId, "getCdmaSubscriptionMode");
9022
9023 final long identity = Binder.clearCallingIdentity();
9024 try {
9025 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9026 } finally {
9027 Binder.restoreCallingIdentity(identity);
9028 }
9029 }
9030
9031 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009032 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9034 mApp, subId, "setCdmaSubscriptionMode");
9035
9036 final long identity = Binder.clearCallingIdentity();
9037 try {
9038 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9039 } finally {
9040 Binder.restoreCallingIdentity(identity);
9041 }
9042 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009043
sqianc5eccab2018-10-19 18:46:41 -07009044 @Override
sqian8c685422019-02-22 15:55:18 -08009045 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009046 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009048 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9049 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009050 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9051 }
9052 final long identity = Binder.clearCallingIdentity();
9053 try {
sqian854d44b2018-12-12 16:48:18 -08009054 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9055 for (Phone phone: PhoneFactory.getPhones()) {
9056 if (phone.getEmergencyNumberTracker() != null
9057 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9058 emergencyNumberListInternal.put(
9059 phone.getSubId(),
9060 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9061 }
sqian11b7a0e2018-12-05 18:48:28 -08009062 }
sqian854d44b2018-12-12 16:48:18 -08009063 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009064 } finally {
9065 Binder.restoreCallingIdentity(identity);
9066 }
sqianc5eccab2018-10-19 18:46:41 -07009067 }
9068
9069 @Override
sqian8c685422019-02-22 15:55:18 -08009070 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009071 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009072 if (!exactMatch) {
9073 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009074 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009075 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009076 }
9077 final long identity = Binder.clearCallingIdentity();
9078 try {
sqian854d44b2018-12-12 16:48:18 -08009079 for (Phone phone: PhoneFactory.getPhones()) {
9080 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009081 && phone.getEmergencyNumberTracker()
9082 .isEmergencyNumber(number, exactMatch)) {
9083 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009084 }
sqian11b7a0e2018-12-05 18:48:28 -08009085 }
9086 return false;
9087 } finally {
9088 Binder.restoreCallingIdentity(identity);
9089 }
9090 }
9091
sqianf4ca7ed2019-01-15 18:32:07 -08009092 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009093 * Start emergency callback mode for GsmCdmaPhone for testing.
9094 */
9095 @Override
9096 public void startEmergencyCallbackMode() {
9097 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9098 "startEmergencyCallbackMode");
9099 enforceModifyPermission();
9100 final long identity = Binder.clearCallingIdentity();
9101 try {
9102 for (Phone phone : PhoneFactory.getPhones()) {
9103 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9104 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9105 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9106 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9107 gsmCdmaPhone.obtainMessage(
9108 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9109 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9110 }
9111 }
9112 } finally {
9113 Binder.restoreCallingIdentity(identity);
9114 }
9115 }
9116
9117 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009118 * Update emergency number list for test mode.
9119 */
9120 @Override
9121 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9123 "updateEmergencyNumberListTestMode");
9124
9125 final long identity = Binder.clearCallingIdentity();
9126 try {
9127 for (Phone phone: PhoneFactory.getPhones()) {
9128 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9129 if (tracker != null) {
9130 tracker.executeEmergencyNumberTestModeCommand(action, num);
9131 }
9132 }
9133 } finally {
9134 Binder.restoreCallingIdentity(identity);
9135 }
9136 }
9137
9138 /**
9139 * Get the full emergency number list for test mode.
9140 */
9141 @Override
9142 public List<String> getEmergencyNumberListTestMode() {
9143 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9144 "getEmergencyNumberListTestMode");
9145
9146 final long identity = Binder.clearCallingIdentity();
9147 try {
9148 Set<String> emergencyNumbers = new HashSet<>();
9149 for (Phone phone: PhoneFactory.getPhones()) {
9150 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9151 if (tracker != null) {
9152 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9153 emergencyNumbers.add(num.getNumber());
9154 }
9155 }
9156 }
9157 return new ArrayList<>(emergencyNumbers);
9158 } finally {
9159 Binder.restoreCallingIdentity(identity);
9160 }
9161 }
9162
chen xud6b45bd2018-10-30 22:27:10 -07009163 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009164 public int getEmergencyNumberDbVersion(int subId) {
9165 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9166
9167 final long identity = Binder.clearCallingIdentity();
9168 try {
9169 final Phone phone = getPhone(subId);
9170 if (phone == null) {
9171 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9172 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9173 }
9174 return phone.getEmergencyNumberDbVersion();
9175 } finally {
9176 Binder.restoreCallingIdentity(identity);
9177 }
9178 }
9179
9180 @Override
9181 public void notifyOtaEmergencyNumberDbInstalled() {
9182 enforceModifyPermission();
9183
9184 final long identity = Binder.clearCallingIdentity();
9185 try {
9186 for (Phone phone: PhoneFactory.getPhones()) {
9187 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9188 if (tracker != null) {
9189 tracker.updateOtaEmergencyNumberDatabase();
9190 }
9191 }
9192 } finally {
9193 Binder.restoreCallingIdentity(identity);
9194 }
9195 }
9196
9197 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009198 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009199 enforceActiveEmergencySessionPermission();
9200
9201 final long identity = Binder.clearCallingIdentity();
9202 try {
9203 for (Phone phone: PhoneFactory.getPhones()) {
9204 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9205 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009206 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9207 }
9208 }
9209 } finally {
9210 Binder.restoreCallingIdentity(identity);
9211 }
9212 }
9213
9214 @Override
9215 public void resetOtaEmergencyNumberDbFilePath() {
9216 enforceActiveEmergencySessionPermission();
9217
9218 final long identity = Binder.clearCallingIdentity();
9219 try {
9220 for (Phone phone: PhoneFactory.getPhones()) {
9221 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9222 if (tracker != null) {
9223 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009224 }
9225 }
9226 } finally {
9227 Binder.restoreCallingIdentity(identity);
9228 }
9229 }
9230
9231 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009232 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9233 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9234 Phone phone = getPhone(subId);
9235 if (phone == null) {
9236 return null;
9237 }
9238 final long identity = Binder.clearCallingIdentity();
9239 try {
9240 UiccProfile profile = UiccController.getInstance()
9241 .getUiccProfileForPhone(phone.getPhoneId());
9242 if (profile != null) {
9243 return profile.getCertsFromCarrierPrivilegeAccessRules();
9244 }
9245 } finally {
9246 Binder.restoreCallingIdentity(identity);
9247 }
9248 return null;
9249 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009250
9251 /**
9252 * Enable or disable a modem stack.
9253 */
9254 @Override
9255 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9256 enforceModifyPermission();
9257
9258 final long identity = Binder.clearCallingIdentity();
9259 try {
9260 Phone phone = PhoneFactory.getPhone(slotIndex);
9261 if (phone == null) {
9262 return false;
9263 } else {
9264 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9265 }
9266 } finally {
9267 Binder.restoreCallingIdentity(identity);
9268 }
9269 }
Michelecea4cf22018-12-21 15:00:11 -08009270
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009271 /**
9272 * Whether a modem stack is enabled or not.
9273 */
9274 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009275 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9276 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009277 Phone phone = PhoneFactory.getPhone(slotIndex);
9278 if (phone == null) return false;
9279
9280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009281 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9282 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009283 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9284 }
9285
9286 final long identity = Binder.clearCallingIdentity();
9287 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009288 try {
9289 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9290 } catch (NoSuchElementException ex) {
9291 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9292 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009293 } finally {
9294 Binder.restoreCallingIdentity(identity);
9295 }
9296 }
9297
Michelecea4cf22018-12-21 15:00:11 -08009298 @Override
Michele0ea7d782019-03-19 14:58:42 -07009299 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009300 enforceModifyPermission();
9301
9302 final long identity = Binder.clearCallingIdentity();
9303 try {
9304 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009305 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009306 .commit();
9307 } finally {
9308 Binder.restoreCallingIdentity(identity);
9309 }
9310 }
9311
9312 @Override
Michele0ea7d782019-03-19 14:58:42 -07009313 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009314 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009316 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9317 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009318 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009319 }
Michelecea4cf22018-12-21 15:00:11 -08009320
9321 final long identity = Binder.clearCallingIdentity();
9322 try {
Michele0ea7d782019-03-19 14:58:42 -07009323 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009324 } finally {
9325 Binder.restoreCallingIdentity(identity);
9326 }
9327 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009328
Michele0ea7d782019-03-19 14:58:42 -07009329 @TelephonyManager.IsMultiSimSupportedResult
9330 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009331 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9332 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9333 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009334 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9335 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009336 }
9337 // Check if the hardware supports multisim functionality. If usage of multisim is not
9338 // supported by the modem, indicate that it is restricted.
9339 PhoneCapability staticCapability =
9340 mPhoneConfigurationManager.getStaticPhoneCapability();
9341 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009342 loge("isMultiSimSupportedInternal: no static configuration available");
9343 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009344 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009345 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009346 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9347 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009348 }
9349 // Check if support of multiple SIMs is restricted by carrier
9350 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009351 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009352 }
9353
Michele0ea7d782019-03-19 14:58:42 -07009354 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009355 }
9356
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009357 /**
9358 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009359 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9360 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9361 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009362 * @param numOfSims number of active sims we want to switch to
9363 */
9364 @Override
9365 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009366 if (numOfSims == 1) {
9367 enforceModifyPermission();
9368 } else {
9369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9370 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9371 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009372 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009373
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009374 try {
Michele30b57b22019-03-01 12:01:14 -08009375 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009376 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009377 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9378 return;
9379 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009380 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9381 } finally {
9382 Binder.restoreCallingIdentity(identity);
9383 }
9384 }
9385
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009386 @Override
9387 public boolean isApplicationOnUicc(int subId, int appType) {
9388 enforceReadPrivilegedPermission("isApplicationOnUicc");
9389 Phone phone = getPhone(subId);
9390 if (phone == null) {
9391 return false;
9392 }
9393 final long identity = Binder.clearCallingIdentity();
9394 try {
9395 UiccCard uiccCard = phone.getUiccCard();
9396 if (uiccCard == null) {
9397 return false;
9398 }
9399 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9400 if (uiccProfile == null) {
9401 return false;
9402 }
9403 if (TelephonyManager.APPTYPE_SIM <= appType
9404 && appType <= TelephonyManager.APPTYPE_ISIM) {
9405 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9406 }
9407 return false;
9408 } finally {
9409 Binder.restoreCallingIdentity(identity);
9410 }
9411 }
9412
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009413 /**
chen xub4baa772019-04-03 10:23:41 -07009414 * Get whether making changes to modem configurations will trigger reboot.
9415 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009416 */
9417 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009418 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9419 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009421 mApp, subId, callingPackage, callingFeatureId,
9422 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009423 return false;
9424 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009425 final long identity = Binder.clearCallingIdentity();
9426 try {
9427 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9428 } finally {
9429 Binder.restoreCallingIdentity(identity);
9430 }
9431 }
9432
Nathan Harold29f5f052019-02-15 13:41:57 -08009433 private void updateModemStateMetrics() {
9434 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9435 // TODO: check the state for each modem if the api is ready.
9436 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9437 }
9438
Pengquan Meng3889a572019-01-23 11:16:29 -08009439 @Override
9440 public int[] getSlotsMapping() {
9441 enforceReadPrivilegedPermission("getSlotsMapping");
9442
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
9445 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9446 // All logical slots should have a mapping to a physical slot.
9447 int[] logicalSlotsMapping = new int[phoneCount];
9448 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9449 for (int i = 0; i < slotInfos.length; i++) {
9450 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9451 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9452 }
9453 }
9454 return logicalSlotsMapping;
9455 } finally {
9456 Binder.restoreCallingIdentity(identity);
9457 }
9458 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009459
9460 /**
9461 * Get the IRadio HAL Version
9462 */
9463 @Override
9464 public int getRadioHalVersion() {
9465 Phone phone = getDefaultPhone();
9466 if (phone == null) return -1;
9467 HalVersion hv = phone.getHalVersion();
9468 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9469 return hv.major * 100 + hv.minor;
9470 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009471
9472 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009473 * Get the current calling package name.
9474 * @return the current calling package name
9475 */
9476 @Override
9477 public String getCurrentPackageName() {
9478 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9479 }
9480
9481 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009482 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9483 * corresponding network requests on a subId.
9484 *
9485 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009486 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009487 * 2) APN is un-metered for this subscription, or
9488 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009489 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009490 *
9491 * @return whether data is allowed for a apn type.
9492 *
9493 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009494 */
9495 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009496 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009497 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9498 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009499
9500 // Now that all security checks passes, perform the operation as ourselves.
9501 final long identity = Binder.clearCallingIdentity();
9502 try {
9503 Phone phone = getPhone(subId);
9504 if (phone == null) return false;
9505
Jack Yu41407ee2019-05-13 16:54:09 -07009506 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009507 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
9513 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009514 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009515 enforceReadPrivilegedPermission("isApnMetered");
9516
9517 // Now that all security checks passes, perform the operation as ourselves.
9518 final long identity = Binder.clearCallingIdentity();
9519 try {
9520 Phone phone = getPhone(subId);
9521 if (phone == null) return true; // By default return true.
9522
Jack Yu41407ee2019-05-13 16:54:09 -07009523 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009524 } finally {
9525 Binder.restoreCallingIdentity(identity);
9526 }
9527 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009528
9529 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009530 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9531 int subscriptionId, IBooleanConsumer resultCallback) {
9532 enforceModifyPermission();
9533 long token = Binder.clearCallingIdentity();
9534 try {
9535 Phone phone = getPhone(subscriptionId);
9536 if (phone == null) {
9537 try {
9538 if (resultCallback != null) {
9539 resultCallback.accept(false);
9540 }
9541 } catch (RemoteException e) {
9542 // ignore
9543 }
9544 return;
9545 }
9546 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9547 Pair.create(specifiers, (x) -> {
9548 try {
9549 if (resultCallback != null) {
9550 resultCallback.accept(x);
9551 }
9552 } catch (RemoteException e) {
9553 // ignore
9554 }
9555 });
9556 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9557 } finally {
9558 Binder.restoreCallingIdentity(token);
9559 }
9560 }
9561
9562 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009563 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9564 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009565 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009566 mApp, subId, "getSystemSelectionChannels");
9567 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9568 final long identity = Binder.clearCallingIdentity();
9569 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009570 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9571 if (result instanceof IllegalStateException) {
9572 throw (IllegalStateException) result;
9573 }
9574 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009575 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9576 return specifiers;
9577 } finally {
9578 Binder.restoreCallingIdentity(identity);
9579 }
9580 }
9581
9582 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009583 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009584 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009585 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9586 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9587 if (iccRecords == null) {
9588 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9589 return false;
9590 }
9591 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9592 }
9593
9594 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009595 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9596 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009597 if (callingPackage == null) {
9598 callingPackage = getCurrentPackageName();
9599 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009600 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9601 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009602 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9603 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009604 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9605 }
9606 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9607 Intent intent = new Intent();
9608 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9609 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9610 // Bring up choose default SMS subscription dialog right now
9611 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9612 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9613 mApp.startActivity(intent);
9614 }
chen xud5ca2d52019-05-28 15:20:57 -07009615
9616 @Override
9617 public String getMmsUAProfUrl(int subId) {
9618 //TODO investigate if this API should require proper permission check in R b/133791609
9619 final long identity = Binder.clearCallingIdentity();
9620 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009621 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9622 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9623 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9624 return carrierUAProfUrl;
9625 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009626 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9627 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009628 } finally {
9629 Binder.restoreCallingIdentity(identity);
9630 }
9631 }
9632
9633 @Override
9634 public String getMmsUserAgent(int subId) {
9635 //TODO investigate if this API should require proper permission check in R b/133791609
9636 final long identity = Binder.clearCallingIdentity();
9637 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009638 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9639 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9640 if (!TextUtils.isEmpty(carrierUserAgent)) {
9641 return carrierUserAgent;
9642 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009643 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9644 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009645 } finally {
9646 Binder.restoreCallingIdentity(identity);
9647 }
9648 }
Jack Yub07d4972019-05-28 16:12:25 -07009649
9650 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009651 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9652 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009653
Jack Yub07d4972019-05-28 16:12:25 -07009654 final long identity = Binder.clearCallingIdentity();
9655 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009656 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009657 if (phone == null) return false;
9658
Hall Liua62f5da2020-09-25 10:42:19 -07009659 switch (policy) {
9660 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9661 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9662 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9663 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9664 default:
9665 throw new IllegalArgumentException(policy + " is not a valid policy");
9666 }
Jack Yub07d4972019-05-28 16:12:25 -07009667 } finally {
9668 Binder.restoreCallingIdentity(identity);
9669 }
9670 }
9671
9672 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009673 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009674 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009675 enforceModifyPermission();
9676
changbettyd5c246e2019-12-24 15:40:37 +08009677 final long identity = Binder.clearCallingIdentity();
9678 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009679 Phone phone = getPhone(subscriptionId);
9680 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009681
Hall Liua62f5da2020-09-25 10:42:19 -07009682 switch (policy) {
9683 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9684 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9685 break;
9686 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9687 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9688 break;
9689 default:
9690 throw new IllegalArgumentException(policy + " is not a valid policy");
9691 }
changbettyd5c246e2019-12-24 15:40:37 +08009692 } finally {
9693 Binder.restoreCallingIdentity(identity);
9694 }
9695 }
9696
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009697 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009698 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009699 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9700 * otherwise.
9701 */
9702 @Override
9703 public void setCepEnabled(boolean isCepEnabled) {
9704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9705
9706 final long identity = Binder.clearCallingIdentity();
9707 try {
9708 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9709 for (Phone phone : PhoneFactory.getPhones()) {
9710 Phone defaultPhone = phone.getImsPhone();
9711 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9712 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9713 ImsPhoneCallTracker imsPhoneCallTracker =
9714 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9715 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9716 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9717 + imsPhone.getMsisdn());
9718 }
9719 }
9720 } finally {
9721 Binder.restoreCallingIdentity(identity);
9722 }
9723 }
allenwtsu46dcc572020-01-08 18:24:03 +08009724
9725 /**
9726 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9727 *
9728 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9729 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9730 * before being read.
9731 */
9732 @Override
9733 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9734 isCompressed) {
9735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9736 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9738 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9739 }
9740 if (!isImsAvailableOnDevice()) {
9741 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9742 "IMS not available on device.");
9743 }
9744
9745 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009746 try {
Hui Wang761a6682020-10-31 05:12:53 +00009747 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009750 }
9751 }
zoey chene02881a2019-12-30 16:11:23 +08009752
9753 @Override
9754 public boolean isIccLockEnabled(int subId) {
9755 enforceReadPrivilegedPermission("isIccLockEnabled");
9756
9757 // Now that all security checks passes, perform the operation as ourselves.
9758 final long identity = Binder.clearCallingIdentity();
9759 try {
9760 Phone phone = getPhone(subId);
9761 if (phone != null && phone.getIccCard() != null) {
9762 return phone.getIccCard().getIccLockEnabled();
9763 } else {
9764 return false;
9765 }
9766 } finally {
9767 Binder.restoreCallingIdentity(identity);
9768 }
9769 }
9770
9771 /**
9772 * Set the ICC pin lock enabled or disabled.
9773 *
9774 * @return an integer representing the status of IccLock enabled or disabled in the following
9775 * three cases:
9776 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9777 * successfully.
9778 * - Positive number and zero for remaining password attempts.
9779 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9780 *
9781 */
9782 @Override
9783 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9784 enforceModifyPermission();
9785
9786 Phone phone = getPhone(subId);
9787 if (phone == null) {
9788 return 0;
9789 }
9790 // Now that all security checks passes, perform the operation as ourselves.
9791 final long identity = Binder.clearCallingIdentity();
9792 try {
9793 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9794 new Pair<Boolean, String>(enabled, password), phone, null);
9795 return attemptsRemaining;
9796
9797 } catch (Exception e) {
9798 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9799 } finally {
9800 Binder.restoreCallingIdentity(identity);
9801 }
9802 return 0;
9803 }
9804
9805 /**
9806 * Change the ICC password used in ICC pin lock.
9807 *
9808 * @return an integer representing the status of IccLock changed in the following three cases:
9809 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9810 * - Positive number and zero for remaining password attempts.
9811 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9812 *
9813 */
9814 @Override
9815 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9816 enforceModifyPermission();
9817
9818 Phone phone = getPhone(subId);
9819 if (phone == null) {
9820 return 0;
9821 }
9822 // Now that all security checks passes, perform the operation as ourselves.
9823 final long identity = Binder.clearCallingIdentity();
9824 try {
9825 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9826 new Pair<String, String>(oldPassword, newPassword), phone, null);
9827 return attemptsRemaining;
9828
9829 } catch (Exception e) {
9830 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9831 } finally {
9832 Binder.restoreCallingIdentity(identity);
9833 }
9834 return 0;
9835 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009836
9837 /**
9838 * Request for receiving user activity notification
9839 */
9840 @Override
9841 public void requestUserActivityNotification() {
9842 if (!mNotifyUserActivity.get()
9843 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9844 mNotifyUserActivity.set(true);
9845 }
9846 }
9847
9848 /**
9849 * Called when userActivity is signalled in the power manager.
9850 * This is safe to call from any thread, with any window manager locks held or not.
9851 */
9852 @Override
9853 public void userActivity() {
9854 // ***************************************
9855 // * Inherited from PhoneWindowManager *
9856 // ***************************************
9857 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9858 // WITH ITS LOCKS HELD.
9859 //
9860 // This code must be VERY careful about the locks
9861 // it acquires.
9862 // In fact, the current code acquires way too many,
9863 // and probably has lurking deadlocks.
9864
9865 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9866 throw new SecurityException("Only the OS may call notifyUserActivity()");
9867 }
9868
9869 if (mNotifyUserActivity.getAndSet(false)) {
9870 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9871 USER_ACTIVITY_NOTIFICATION_DELAY);
9872 }
9873 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009874
9875 @Override
9876 public boolean canConnectTo5GInDsdsMode() {
9877 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9878 }
Jack Yud10cdd42020-09-28 20:28:01 -07009879
9880 @Override
9881 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9882 String callingFeatureId) {
9883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9884 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9885 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9886 }
9887
9888 Phone phone = getPhone(subId);
9889 if (phone == null) {
9890 throw new RuntimeException("phone is not available");
9891 }
9892 // Now that all security checks passes, perform the operation as ourselves.
9893 final long identity = Binder.clearCallingIdentity();
9894 try {
9895 return phone.getEquivalentHomePlmns();
9896 } finally {
9897 Binder.restoreCallingIdentity(identity);
9898 }
9899 }
Daniel Bright59e67312020-11-13 11:49:37 -08009900
9901 @Override
9902 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009903 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9904 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009905 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009906 if (radioInterfaceCapabilities == null) {
9907 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009908 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009909 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009910 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009911
Hui Wang641e81c2020-10-12 12:14:23 -07009912 @Override
9913 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9914 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009915 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9916 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9917 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9918 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9919 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009920 if (DBG) {
9921 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9922 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9923 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9924 }
9925
9926 if (!SubscriptionManager.isValidSubscriptionId(subId)
9927 || appType < TelephonyManager.APPTYPE_UNKNOWN
9928 || appType > TelephonyManager.APPTYPE_ISIM
9929 || nafUrl == null || securityProtocol == null || callback == null) {
9930 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9931 if (callback != null) {
9932 try {
9933 callback.onAuthenticationFailure(
9934 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9935 } catch (RemoteException exception) {
9936 log("Fail to notify onAuthenticationFailure due to " + exception);
9937 }
9938 return;
9939 }
9940 }
9941
9942 final long token = Binder.clearCallingIdentity();
9943 try {
9944 getGbaManager(subId).bootstrapAuthenticationRequest(
9945 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9946 forceBootStrapping, callback));
9947 } finally {
9948 Binder.restoreCallingIdentity(token);
9949 }
9950 }
9951
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009952 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009953 * Attempts to set the radio power state for all phones for thermal reason.
9954 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009955 * requested radio power state will actually be set. See {@link
9956 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9957 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009958 * @param enable {@code true} if trying to turn radio on.
9959 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9960 * false}.
9961 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009962 private boolean setRadioPowerForThermal(boolean enable) {
9963 boolean isPhoneAvailable = false;
9964 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9965 Phone phone = PhoneFactory.getPhone(i);
9966 if (phone != null) {
9967 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9968 isPhoneAvailable = true;
9969 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009970 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009971
9972 // return true if successfully informed the phone object about the thermal radio power
9973 // request.
9974 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009975 }
9976
9977 private int handleDataThrottlingRequest(int subId,
9978 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009979 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9980 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9981 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9982 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9983 throw new IllegalArgumentException("modem does not support data throttling");
9984 }
9985
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009986 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9987 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009988 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009989 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9990 }
9991
9992 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9993
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009994 if (isDataThrottlingSupported) {
9995 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009996 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009997 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9998 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9999 } else if (thermalMitigationResult
10000 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -070010001 log("Modem likely does not support data throttling on secondary carrier. Data " +
10002 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
10003 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010004 }
10005 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010006 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -080010007
10008 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010009 }
10010
Jack Nudelman644b91a2021-03-12 14:09:48 -080010011 private static List<String> getThermalMitigationAllowlist(Context context) {
10012 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10013 for (String pckg : context.getResources()
10014 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10015 sThermalMitigationAllowlistedPackages.add(pckg);
10016 }
10017 }
10018
10019 return sThermalMitigationAllowlistedPackages;
10020 }
10021
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010022 private boolean isAnyPhoneInEmergencyState() {
10023 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10024 if (tm.isInEmergencyCall()) {
10025 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10026 return true;
10027 }
10028 for (Phone phone : PhoneFactory.getPhones()) {
10029 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10030 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10031 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10032 + phone.isInEcm());
10033 return true;
10034 }
10035 }
10036
10037 return false;
10038 }
10039
Jack Nudelman644b91a2021-03-12 14:09:48 -080010040 /**
10041 * Used by shell commands to add an authorized package name for thermal mitigation.
10042 * @param packageName name of package to be allowlisted
10043 * @param context
10044 */
10045 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10046 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10047 sThermalMitigationAllowlistedPackages.add(packageName);
10048 }
10049
10050 /**
10051 * Used by shell commands to remove an authorized package name for thermal mitigation.
10052 * @param packageName name of package to remove from allowlist
10053 * @param context
10054 */
10055 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10056 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10057 sThermalMitigationAllowlistedPackages.remove(packageName);
10058 }
10059
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010060 /**
10061 * Thermal mitigation request to control functionalities at modem.
10062 *
10063 * @param subId the id of the subscription.
10064 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010065 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010066 *
10067 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10068 */
10069 @Override
10070 @ThermalMitigationResult
10071 public int sendThermalMitigationRequest(
10072 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010073 ThermalMitigationRequest thermalMitigationRequest,
10074 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010075 enforceModifyPermission();
10076
Jack Nudelman644b91a2021-03-12 14:09:48 -080010077 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10078 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10079 .contains(callingPackage)) {
10080 throw new SecurityException("Calling package must be configured in the device config. "
10081 + "calling package: " + callingPackage);
10082 }
10083
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010084 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10085 final long identity = Binder.clearCallingIdentity();
10086
10087 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10088 try {
10089 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10090 switch (thermalMitigationAction) {
10091 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10092 thermalMitigationResult =
10093 handleDataThrottlingRequest(subId,
10094 thermalMitigationRequest.getDataThrottlingRequest());
10095 break;
10096 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10097 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10098 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10099 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10100 }
10101
10102 // Ensure that radio is on. If not able to power on due to phone being
10103 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010104 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010105 thermalMitigationResult =
10106 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10107 break;
10108 }
10109
10110 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10111 false);
10112 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10113 break;
10114 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10115 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10116 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10117 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10118 }
10119
10120 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10121 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010122 Phone phone = getPhone(subId);
10123 if (phone == null) {
10124 thermalMitigationResult =
10125 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10126 break;
10127 }
10128
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010129 TelephonyConnectionService service =
10130 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010131 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010132 Log.e(LOG_TAG, "An emergency call is pending");
10133 thermalMitigationResult =
10134 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10135 break;
10136 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010137 thermalMitigationResult =
10138 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10139 break;
10140 }
10141 } else {
10142 thermalMitigationResult =
10143 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10144 break;
10145 }
10146
10147 // Turn radio off. If not able to power off due to phone being unavailable,
10148 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010149 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010150 thermalMitigationResult =
10151 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10152 break;
10153 }
10154 thermalMitigationResult =
10155 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10156 break;
10157 default:
10158 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10159 + "not exist. Requested action: " + thermalMitigationAction);
10160 }
10161 } catch (IllegalArgumentException e) {
10162 throw e;
10163 } catch (Exception e) {
10164 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10165 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169
10170 if (DBG) {
10171 log("thermalMitigationRequest returning with thermalMitigationResult: "
10172 + thermalMitigationResult);
10173 }
10174
10175 return thermalMitigationResult;
10176 }
Hui Wang641e81c2020-10-12 12:14:23 -070010177
10178 /**
10179 * Set the GbaService Package Name that Telephony will bind to.
10180 *
10181 * @param subId The sim that the GbaService is associated with.
10182 * @param packageName The name of the package to be replaced with.
10183 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10184 */
10185 @Override
10186 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10187 enforceModifyPermission();
10188
10189 final long identity = Binder.clearCallingIdentity();
10190 try {
10191 return getGbaManager(subId).overrideServicePackage(packageName);
10192 } finally {
10193 Binder.restoreCallingIdentity(identity);
10194 }
10195 }
10196
10197 /**
10198 * Return the package name of the currently bound GbaService.
10199 *
10200 * @param subId The sim that the GbaService is associated with.
10201 * @return the package name of the GbaService configuration, null if GBA is not supported.
10202 */
10203 @Override
10204 public String getBoundGbaService(int subId) {
10205 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10206
10207 final long identity = Binder.clearCallingIdentity();
10208 try {
10209 return getGbaManager(subId).getServicePackage();
10210 } finally {
10211 Binder.restoreCallingIdentity(identity);
10212 }
10213 }
10214
10215 /**
10216 * Set the release time for telephony to unbind GbaService.
10217 *
10218 * @param subId The sim that the GbaService is associated with.
10219 * @param interval The release time to unbind GbaService by millisecond.
10220 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10221 */
10222 @Override
10223 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10224 enforceModifyPermission();
10225
10226 final long identity = Binder.clearCallingIdentity();
10227 try {
10228 return getGbaManager(subId).overrideReleaseTime(interval);
10229 } finally {
10230 Binder.restoreCallingIdentity(identity);
10231 }
10232 }
10233
10234 /**
10235 * Return the release time for telephony to unbind GbaService.
10236 *
10237 * @param subId The sim that the GbaService is associated with.
10238 * @return The release time to unbind GbaService by millisecond.
10239 */
10240 @Override
10241 public int getGbaReleaseTime(int subId) {
10242 enforceReadPrivilegedPermission("getGbaReleaseTime");
10243
10244 final long identity = Binder.clearCallingIdentity();
10245 try {
10246 return getGbaManager(subId).getReleaseTime();
10247 } finally {
10248 Binder.restoreCallingIdentity(identity);
10249 }
10250 }
10251
10252 private GbaManager getGbaManager(int subId) {
10253 GbaManager instance = GbaManager.getInstance(subId);
10254 if (instance == null) {
10255 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10256 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10257 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10258 }
10259 return instance;
10260 }
Hui Wang761a6682020-10-31 05:12:53 +000010261
10262 /**
10263 * indicate whether the device and the carrier can support
10264 * RCS VoLTE single registration.
10265 */
10266 @Override
10267 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010268 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10269 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10270 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10271 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010272
10273 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10274 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10275 }
10276
10277 final long identity = Binder.clearCallingIdentity();
10278 try {
10279 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10280 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010281 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10282 if (isCapable != null) {
10283 return isCapable;
10284 }
Hui Wang761a6682020-10-31 05:12:53 +000010285 }
Hui Wang67af90e2021-06-04 16:57:15 -070010286 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10287 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010288 } finally {
10289 Binder.restoreCallingIdentity(identity);
10290 }
10291 }
10292
10293 /**
10294 * Register RCS provisioning callback.
10295 */
10296 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010297 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010298 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010299 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010300 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010301 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10302 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010303
10304 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10305 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10306 }
10307 if (!isImsAvailableOnDevice()) {
10308 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10309 "IMS not available on device.");
10310 }
10311
10312 final long identity = Binder.clearCallingIdentity();
10313 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010314 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010315 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010316 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10317 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010318 }
Hui Wang761a6682020-10-31 05:12:53 +000010319 } finally {
10320 Binder.restoreCallingIdentity(identity);
10321 }
10322 }
10323
10324 /**
10325 * Unregister RCS provisioning callback.
10326 */
10327 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010328 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010329 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010330 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010331 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010332 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10333 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010334
10335 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10336 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10337 }
10338 if (!isImsAvailableOnDevice()) {
10339 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10340 "IMS not available on device.");
10341 }
10342
10343 final long identity = Binder.clearCallingIdentity();
10344 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010345 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010346 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010347 } finally {
10348 Binder.restoreCallingIdentity(identity);
10349 }
10350 }
10351
10352 /**
10353 * trigger RCS reconfiguration.
10354 */
10355 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010356 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10357 "triggerRcsReconfiguration",
10358 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010359
10360 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10361 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10362 }
10363 if (!isImsAvailableOnDevice()) {
10364 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10365 "IMS not available on device.");
10366 }
10367
10368 final long identity = Binder.clearCallingIdentity();
10369 try {
10370 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10371 } finally {
10372 Binder.restoreCallingIdentity(identity);
10373 }
10374 }
10375
10376 /**
10377 * Provide the client configuration parameters of the RCS application.
10378 */
10379 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010380 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10381 "setRcsClientConfiguration",
10382 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010383
10384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10385 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10386 }
10387 if (!isImsAvailableOnDevice()) {
10388 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10389 "IMS not available on device.");
10390 }
10391
10392 final long identity = Binder.clearCallingIdentity();
10393
10394 try {
10395 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10396 if (configBinder == null) {
10397 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010398 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10399 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010400 } else {
10401 configBinder.setRcsClientConfiguration(rcc);
10402 }
10403 } catch (RemoteException e) {
10404 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010405 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10406 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010407 } finally {
10408 Binder.restoreCallingIdentity(identity);
10409 }
10410 }
10411
10412 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010413 * Enables or disables the test mode for RCS VoLTE single registration.
10414 */
10415 @Override
10416 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10417 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10418 "setRcsSingleRegistrationTestModeEnabled");
10419
10420 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10421 }
10422
10423 /**
10424 * Gets the test mode for RCS VoLTE single registration.
10425 */
10426 @Override
10427 public boolean getRcsSingleRegistrationTestModeEnabled() {
10428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10429 "getRcsSingleRegistrationTestModeEnabled");
10430
10431 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10432 }
10433
10434 /**
Hui Wang761a6682020-10-31 05:12:53 +000010435 * Overrides the config of RCS VoLTE single registration enabled for the device.
10436 */
10437 @Override
10438 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10439 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10440 "setDeviceSingleRegistrationEnabledOverride");
10441 enforceModifyPermission();
10442
10443 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10444 : Boolean.parseBoolean(enabledStr);
10445 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010446 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010447 }
10448
10449 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010450 * Sends a device to device communication message. Only usable via shell.
10451 * @param message message to send.
10452 * @param value message value.
10453 */
10454 @Override
10455 public void sendDeviceToDeviceMessage(int message, int value) {
10456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010457 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010458 enforceModifyPermission();
10459
10460 final long identity = Binder.clearCallingIdentity();
10461 try {
10462 TelephonyConnectionService service =
10463 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10464 if (service == null) {
10465 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10466 return;
10467 }
10468 service.sendTestDeviceToDeviceMessage(message, value);
10469 } finally {
10470 Binder.restoreCallingIdentity(identity);
10471 }
10472 }
10473
Tyler Gunnbabbda02021-02-10 11:05:02 -080010474 /**
10475 * Sets the specified device to device transport active.
10476 * @param transport The transport to set active.
10477 */
10478 @Override
10479 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10480 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10481 "setActiveDeviceToDeviceTransport");
10482 enforceModifyPermission();
10483
10484 final long identity = Binder.clearCallingIdentity();
10485 try {
10486 TelephonyConnectionService service =
10487 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10488 if (service == null) {
10489 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10490 return;
10491 }
10492 service.setActiveDeviceToDeviceTransport(transport);
10493 } finally {
10494 Binder.restoreCallingIdentity(identity);
10495 }
10496 }
Tyler Gunn92479152021-01-20 16:30:10 -080010497
Tyler Gunnd4575212021-05-03 14:46:49 -070010498 @Override
10499 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10500 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10501 "setDeviceToDeviceForceEnabled");
10502
10503 final long identity = Binder.clearCallingIdentity();
10504 try {
10505 Arrays.stream(PhoneFactory.getPhones()).forEach(
10506 p -> {
10507 Phone thePhone = p.getImsPhone();
10508 if (thePhone != null && thePhone instanceof ImsPhone) {
10509 ImsPhone imsPhone = (ImsPhone) thePhone;
10510 CallTracker tracker = imsPhone.getCallTracker();
10511 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10512 ImsPhoneCallTracker imsPhoneCallTracker =
10513 (ImsPhoneCallTracker) tracker;
10514 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10515 }
10516 }
10517 }
10518 );
10519 } finally {
10520 Binder.restoreCallingIdentity(identity);
10521 }
10522 }
10523
Tyler Gunn92479152021-01-20 16:30:10 -080010524 /**
Hui Wang761a6682020-10-31 05:12:53 +000010525 * Gets the config of RCS VoLTE single registration enabled for the device.
10526 */
10527 @Override
10528 public boolean getDeviceSingleRegistrationEnabled() {
10529 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10530 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10531 }
10532
10533 /**
10534 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10535 */
10536 @Override
10537 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10538 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10539 "setCarrierSingleRegistrationEnabledOverride");
10540 enforceModifyPermission();
10541
10542 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10543 : Boolean.parseBoolean(enabledStr);
10544 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10545 subId, enabled);
10546 }
10547
10548 /**
10549 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10550 */
10551 @Override
10552 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10553 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10554 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10555 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010556
10557 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010558 * Overrides the ims feature validation result
10559 */
10560 @Override
10561 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10562 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10563 "setImsFeatureValidationOverride");
10564
10565 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10566 : Boolean.parseBoolean(enabledStr);
10567 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10568 subId, enabled);
10569 }
10570
10571 /**
10572 * Gets the ims feature validation override value
10573 */
10574 @Override
10575 public boolean getImsFeatureValidationOverride(int subId) {
10576 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10577 "getImsFeatureValidationOverride");
10578 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10579 }
10580
10581 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010582 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10583 * their mobile plan.
10584 */
10585 @Override
10586 public String getMobileProvisioningUrl() {
10587 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10588 final long identity = Binder.clearCallingIdentity();
10589 try {
10590 return getDefaultPhone().getMobileProvisioningUrl();
10591 } finally {
10592 Binder.restoreCallingIdentity(identity);
10593 }
10594 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010595
James.cf Linbcdf8b32021-01-14 16:44:13 +080010596 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010597 * Get the EAB contact from the EAB database.
10598 */
10599 @Override
10600 public String getContactFromEab(String contact) {
10601 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10602 enforceModifyPermission();
10603 final long identity = Binder.clearCallingIdentity();
10604 try {
10605 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10606 } finally {
10607 Binder.restoreCallingIdentity(identity);
10608 }
10609 }
10610
10611 /**
Calvin Pana1434322021-07-01 19:27:01 +080010612 * Get the EAB capability from the EAB database.
10613 */
10614 @Override
10615 public String getCapabilityFromEab(String contact) {
10616 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10617 enforceModifyPermission();
10618 final long identity = Binder.clearCallingIdentity();
10619 try {
10620 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10621 } finally {
10622 Binder.restoreCallingIdentity(identity);
10623 }
10624 }
10625
10626 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010627 * Remove the EAB contacts from the EAB database.
10628 */
10629 @Override
10630 public int removeContactFromEab(int subId, String contacts) {
10631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10632 enforceModifyPermission();
10633 final long identity = Binder.clearCallingIdentity();
10634 try {
10635 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10636 } finally {
10637 Binder.restoreCallingIdentity(identity);
10638 }
10639 }
10640
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010641 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010642 public boolean getDeviceUceEnabled() {
10643 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10644 final long identity = Binder.clearCallingIdentity();
10645 try {
10646 return mApp.getDeviceUceEnabled();
10647 } finally {
10648 Binder.restoreCallingIdentity(identity);
10649 }
10650 }
10651
10652 @Override
10653 public void setDeviceUceEnabled(boolean isEnabled) {
10654 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10655 final long identity = Binder.clearCallingIdentity();
10656 try {
10657 mApp.setDeviceUceEnabled(isEnabled);
10658 } finally {
10659 Binder.restoreCallingIdentity(identity);
10660 }
10661 }
10662
Brad Ebinger14d467f2021-02-12 06:18:28 +000010663 /**
10664 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10665 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10666 */
10667 // Used for SHELL command only right now.
10668 @Override
10669 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10670 List<String> featureTags) {
10671 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10672 "addUceRegistrationOverrideShell");
10673 final long identity = Binder.clearCallingIdentity();
10674 try {
10675 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10676 new ArraySet<>(featureTags));
10677 } catch (ImsException e) {
10678 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10679 } finally {
10680 Binder.restoreCallingIdentity(identity);
10681 }
10682 }
10683
10684 /**
10685 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10686 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10687 */
10688 // Used for SHELL command only right now.
10689 @Override
10690 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10691 List<String> featureTags) {
10692 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10693 "removeUceRegistrationOverrideShell");
10694 final long identity = Binder.clearCallingIdentity();
10695 try {
10696 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10697 new ArraySet<>(featureTags));
10698 } catch (ImsException e) {
10699 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10700 } finally {
10701 Binder.restoreCallingIdentity(identity);
10702 }
10703 }
10704
10705 /**
10706 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10707 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10708 */
10709 // Used for SHELL command only right now.
10710 @Override
10711 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10712 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10713 "clearUceRegistrationOverrideShell");
10714 final long identity = Binder.clearCallingIdentity();
10715 try {
10716 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10717 } catch (ImsException e) {
10718 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10719 } finally {
10720 Binder.restoreCallingIdentity(identity);
10721 }
10722 }
10723
10724 /**
10725 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10726 */
10727 // Used for SHELL command only right now.
10728 @Override
10729 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10730 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10731 "getLatestRcsContactUceCapabilityShell");
10732 final long identity = Binder.clearCallingIdentity();
10733 try {
10734 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10735 } catch (ImsException e) {
10736 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10737 } finally {
10738 Binder.restoreCallingIdentity(identity);
10739 }
10740 }
10741
10742 /**
10743 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10744 * device does not have an active PUBLISH.
10745 */
10746 // Used for SHELL command only right now.
10747 @Override
10748 public String getLastUcePidfXmlShell(int subId) {
10749 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10750 final long identity = Binder.clearCallingIdentity();
10751 try {
10752 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10753 } catch (ImsException e) {
10754 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10755 } finally {
10756 Binder.restoreCallingIdentity(identity);
10757 }
10758 }
10759
James.cf Line8713a42021-04-29 16:04:26 +080010760 /**
10761 * Remove UCE requests cannot be sent to the network status.
10762 */
10763 // Used for SHELL command only right now.
10764 @Override
10765 public boolean removeUceRequestDisallowedStatus(int subId) {
10766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10767 final long identity = Binder.clearCallingIdentity();
10768 try {
10769 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10770 } catch (ImsException e) {
10771 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10772 } finally {
10773 Binder.restoreCallingIdentity(identity);
10774 }
10775 }
10776
James.cf Lin0fc71b02021-05-25 01:37:38 +080010777 /**
10778 * Remove UCE requests cannot be sent to the network status.
10779 */
10780 // Used for SHELL command only.
10781 @Override
10782 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10783 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10784 final long identity = Binder.clearCallingIdentity();
10785 try {
10786 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10787 } catch (ImsException e) {
10788 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10789 } finally {
10790 Binder.restoreCallingIdentity(identity);
10791 }
10792 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010793
James.cf Lin4b784aa2021-01-31 03:25:15 +080010794 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010795 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10796 String callingPackage) {
10797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10798 mApp, subId, "setSignalStrengthUpdateRequest");
10799
10800 final int callingUid = Binder.getCallingUid();
10801 // Verify that tha callingPackage belongs to the calling UID
10802 mApp.getSystemService(AppOpsManager.class)
10803 .checkPackage(callingUid, callingPackage);
10804
10805 validateSignalStrengthUpdateRequest(request, callingUid);
10806
10807 final long identity = Binder.clearCallingIdentity();
10808 try {
10809 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10810 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10811
10812 if (result instanceof IllegalStateException) {
10813 throw (IllegalStateException) result;
10814 }
10815 } finally {
10816 Binder.restoreCallingIdentity(identity);
10817 }
10818 }
10819
10820 @Override
10821 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10822 String callingPackage) {
10823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10824 mApp, subId, "clearSignalStrengthUpdateRequest");
10825
10826 final int callingUid = Binder.getCallingUid();
10827 // Verify that tha callingPackage belongs to the calling UID
10828 mApp.getSystemService(AppOpsManager.class)
10829 .checkPackage(callingUid, callingPackage);
10830
10831 final long identity = Binder.clearCallingIdentity();
10832 try {
10833 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10834 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10835
10836 if (result instanceof IllegalStateException) {
10837 throw (IllegalStateException) result;
10838 }
10839 } finally {
10840 Binder.restoreCallingIdentity(identity);
10841 }
10842 }
10843
10844 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10845 int callingUid) {
10846 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10847 // phone/system process do not have further restriction on request
10848 return;
10849 }
10850
10851 // Applications has restrictions on how to use the request:
10852 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10853 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10854 // This is not system caller which has been checked above
10855 throw new IllegalArgumentException(
10856 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10857 }
10858
10859 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10860 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10861 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10862 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10863 || info.isEnabled()) {
10864 throw new IllegalArgumentException(
10865 "Only system can set hide fields in SignalThresholdInfo");
10866 }
10867
10868 // Thresholds length for each RAN need in range. This has been validated in
10869 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10870 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10871 final int[] thresholds = info.getThresholds();
10872 Objects.requireNonNull(thresholds);
10873 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10874 || thresholds.length
10875 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10876 throw new IllegalArgumentException(
10877 "thresholds length is out of range: " + thresholds.length);
10878 }
10879 }
10880 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010881
10882 /**
10883 * Gets the current phone capability.
10884 *
10885 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10886 * @return the PhoneCapability which describes the data connection capability of modem.
10887 * It's used to evaluate possible phone config change, for example from single
10888 * SIM device to multi-SIM device.
10889 */
10890 @Override
10891 public PhoneCapability getPhoneCapability() {
10892 enforceReadPrivilegedPermission("getPhoneCapability");
10893 final long identity = Binder.clearCallingIdentity();
10894 try {
10895 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10896 } finally {
10897 Binder.restoreCallingIdentity(identity);
10898 }
10899 }
Michele Berionne5e411512020-11-13 02:36:59 +000010900
10901 /**
10902 * Prepare TelephonyManager for an unattended reboot. The reboot is
10903 * required to be done shortly after the API is invoked.
10904 */
10905 @Override
10906 @TelephonyManager.PrepareUnattendedRebootResult
10907 public int prepareForUnattendedReboot() {
10908 enforceRebootPermission();
10909
10910 final long identity = Binder.clearCallingIdentity();
10911 try {
10912 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10913 } finally {
10914 Binder.restoreCallingIdentity(identity);
10915 }
10916 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010917
10918 /**
10919 * Request to get the current slicing configuration including URSP rules and
10920 * NSSAIs (configured, allowed and rejected).
10921 *
10922 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10923 */
10924 @Override
10925 public void getSlicingConfig(ResultReceiver callback) {
10926 enforceReadPrivilegedPermission("getSlicingConfig");
10927
10928 final long identity = Binder.clearCallingIdentity();
10929 try {
10930 Phone phone = getDefaultPhone();
10931 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10932 } finally {
10933 Binder.restoreCallingIdentity(identity);
10934 }
10935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010936}