blob: 29142351f26a0f9aed0fc4e1d89531b9a32d7d95 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng0e18b162021-04-07 16:52:18 +0800111import android.telephony.data.NetworkSlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
SongFerngWangfd89b102021-05-27 22:44:54 +0800140import com.android.internal.annotations.VisibleForTesting;
Shuo Qian4a594052020-01-23 11:59:30 -0800141import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700143import com.android.internal.telephony.CallStateException;
Tyler Gunnd4339262021-05-03 14:46:49 -0700144import com.android.internal.telephony.CallTracker;
chen xu651eec72018-11-11 19:03:44 -0800145import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700146import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800148import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700150import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800151import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800152import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800153import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700154import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800156import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700157import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800158import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700160import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700161import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700163import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800164import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700165import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700166import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700167import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700168import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800169import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800170import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700171import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700172import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800174import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800175import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800176import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700177import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700179import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800180import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700181import com.android.internal.telephony.imsphone.ImsPhone;
182import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800183import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700184import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800186import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700187import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700189import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700191import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800192import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000193import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800194import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700195import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700196import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800197import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800198import com.android.phone.callcomposer.CallComposerPictureManager;
199import com.android.phone.callcomposer.CallComposerPictureTransfer;
200import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700201import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800203import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700204import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700205import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800206import com.android.services.telephony.TelecomAccountRegistry;
207import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800208import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800209
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700211import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800212import java.io.IOException;
213import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700214import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800217import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800218import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800219import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100220import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700222import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800224import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800225import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800226import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800227import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700228
229/**
230 * Implementation of the ITelephony interface.
231 */
Santos Cordon117fee72014-05-16 17:56:12 -0700232public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700233 private static final String LOG_TAG = "PhoneInterfaceManager";
234 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
235 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800236 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237
238 // Message codes used with mMainThreadHandler
239 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700240 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
241 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700242 private static final int CMD_OPEN_CHANNEL = 9;
243 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
244 private static final int CMD_CLOSE_CHANNEL = 11;
245 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800246 private static final int CMD_NV_READ_ITEM = 13;
247 private static final int EVENT_NV_READ_ITEM_DONE = 14;
248 private static final int CMD_NV_WRITE_ITEM = 15;
249 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
250 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
251 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700252 private static final int CMD_RESET_MODEM_CONFIG = 19;
253 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800254 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
255 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800256 private static final int CMD_SEND_ENVELOPE = 25;
257 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000258 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
259 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700260 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
261 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
262 private static final int CMD_EXCHANGE_SIM_IO = 31;
263 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
265 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700266 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
267 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700268 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
269 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700270 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
271 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
272 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
273 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700274 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
275 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
276 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
277 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700278 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800279 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
280 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000281 private static final int CMD_SWITCH_SLOTS = 50;
282 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700283 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
284 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
285 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
286 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
287 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
288 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
289 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
290 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700291 private static final int CMD_GET_ALL_CELL_INFO = 60;
292 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
293 private static final int CMD_GET_CELL_LOCATION = 62;
294 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700295 private static final int CMD_MODEM_REBOOT = 64;
296 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700297 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
298 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800299 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
300 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700301 private static final int CMD_GET_MODEM_STATUS = 70;
302 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700303 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
304 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700305 private static final int CMD_ERASE_MODEM_CONFIG = 74;
306 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800307 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
308 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
309 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
310 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800311 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
312 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800313 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800314 private static final int CMD_GET_CALL_FORWARDING = 83;
315 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
316 private static final int CMD_SET_CALL_FORWARDING = 85;
317 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
318 private static final int CMD_GET_CALL_WAITING = 87;
319 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
320 private static final int CMD_SET_CALL_WAITING = 89;
321 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700322 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
323 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
324 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
325 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700326 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
327 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800328 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
329 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800330 private static final int CMD_SET_DATA_THROTTLING = 99;
331 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800332 private static final int CMD_SET_SIM_POWER = 101;
333 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800334 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
335 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
336 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
337 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800338 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
339 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000340 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800341 private static final int CMD_GET_SLICING_CONFIG = 110;
342 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800343 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700344 private static final int CMD_ENABLE_VONR = 113;
345 private static final int EVENT_ENABLE_VONR_DONE = 114;
346 private static final int CMD_IS_VONR_ENABLED = 115;
347 private static final int EVENT_IS_VONR_ENABLED_DONE = 116;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800349 // Parameters of select command.
350 private static final int SELECT_COMMAND = 0xA4;
351 private static final int SELECT_P1 = 0x04;
352 private static final int SELECT_P2 = 0;
353 private static final int SELECT_P3 = 0x10;
354
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 /** The singleton instance. */
356 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800357 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800361 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700362 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800363 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700364 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800365 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800366 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800367 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700368 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800369 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Peter Wangdafb9ac2020-01-15 14:13:38 -0800371 /** User Activity */
372 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800373 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
374
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700375 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
376
Derek Tan97ebb422014-09-05 16:55:38 -0700377 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
378 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800379 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800380 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700381
Michelecea4cf22018-12-21 15:00:11 -0800382 // String to store multi SIM allowed
383 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
384
Derek Tan740e1672017-06-27 14:56:27 -0700385 // The AID of ISD-R.
386 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
387
yinxub1bed742017-04-17 11:45:04 -0700388 private NetworkScanRequestTracker mNetworkScanRequestTracker;
389
David Kelly5e06a7f2018-03-12 14:10:59 +0000390 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
391 private static final int MANUFACTURER_CODE_LENGTH = 8;
392
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800393 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800394 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800395
Derek Tan89e89d42014-07-08 17:00:10 -0700396 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700397 * Experiment flag to enable erase modem config on reset network, default value is false
398 */
399 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
400 "reset_network_erase_modem_config_enabled";
401
Rambo Wang0f050d82021-02-12 11:43:36 -0800402 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
403
Naina Nallurid63128d2019-09-17 14:10:30 -0700404 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 * A request object to use for transmitting data to an ICC.
406 */
407 private static final class IccAPDUArgument {
408 public int channel, cla, command, p1, p2, p3;
409 public String data;
410
411 public IccAPDUArgument(int channel, int cla, int command,
412 int p1, int p2, int p3, String data) {
413 this.channel = channel;
414 this.cla = cla;
415 this.command = command;
416 this.p1 = p1;
417 this.p2 = p2;
418 this.p3 = p3;
419 this.data = data;
420 }
421 }
422
423 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700424 * A request object to use for transmitting data to an ICC.
425 */
426 private static final class ManualNetworkSelectionArgument {
427 public OperatorInfo operatorInfo;
428 public boolean persistSelection;
429
430 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
431 this.operatorInfo = operatorInfo;
432 this.persistSelection = persistSelection;
433 }
434 }
435
436 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
438 * request after sending. The main thread will notify the request when it is complete.
439 */
440 private static final class MainThreadRequest {
441 /** The argument to use for the request */
442 public Object argument;
443 /** The result of the request that is run on the main thread */
444 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800445 // The subscriber id that this request applies to. Defaults to
446 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
447 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Nathan Harold92bed182018-10-12 18:16:49 -0700449 // In cases where subId is unavailable, the caller needs to specify the phone.
450 public Phone phone;
451
vagdeviaf9a5b92018-08-15 16:01:53 -0700452 public WorkSource workSource;
453
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 public MainThreadRequest(Object argument) {
455 this.argument = argument;
456 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800457
Nathan Harold92bed182018-10-12 18:16:49 -0700458 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
459 this.argument = argument;
460 if (phone != null) {
461 this.phone = phone;
462 }
463 this.workSource = workSource;
464 }
465
vagdeviaf9a5b92018-08-15 16:01:53 -0700466 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800467 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800468 if (subId != null) {
469 this.subId = subId;
470 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700471 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700473 }
474
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800475 private static final class IncomingThirdPartyCallArgs {
476 public final ComponentName component;
477 public final String callId;
478 public final String callerDisplayName;
479
480 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
481 String callerDisplayName) {
482 this.component = component;
483 this.callId = callId;
484 this.callerDisplayName = callerDisplayName;
485 }
486 }
487
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488 /**
489 * A handler that processes messages on the main thread in the phone process. Since many
490 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
491 * inbound binder threads to the main thread in the phone process. The Binder thread
492 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
493 * on, which will be notified when the operation completes and will contain the result of the
494 * request.
495 *
496 * <p>If a MainThreadRequest object is provided in the msg.obj field,
497 * note that request.result must be set to something non-null for the calling thread to
498 * unblock.
499 */
500 private final class MainThreadHandler extends Handler {
501 @Override
502 public void handleMessage(Message msg) {
503 MainThreadRequest request;
504 Message onCompleted;
505 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800508 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509
510 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 case CMD_HANDLE_USSD_REQUEST: {
512 request = (MainThreadRequest) msg.obj;
513 final Phone phone = getPhoneFromRequest(request);
514 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
515 String ussdRequest = ussdObject.first;
516 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700517
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 if (!isUssdApiAllowed(request.subId)) {
519 // Carrier does not support use of this API, return failure.
520 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
521 UssdResponse response = new UssdResponse(ussdRequest, null);
522 Bundle returnData = new Bundle();
523 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
524 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700525
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 request.result = true;
527 notifyRequester(request);
528 return;
529 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700530
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 try {
532 request.result = phone != null
533 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
534 } catch (CallStateException cse) {
535 request.result = false;
536 }
537 // Wake up the requesting thread
538 notifyRequester(request);
539 break;
pkanwar32d516d2016-10-14 19:37:38 -0700540 }
541
Yorke Lee716f67e2015-06-17 15:39:16 -0700542 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 final Phone phone = getPhoneFromRequest(request);
545 request.result = phone != null ?
546 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
547 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700548 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700550 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700552
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("iccTransmitApduLogicalChannel: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
563 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 iccArgument.channel, iccArgument.cla, iccArgument.command,
566 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 break;
570
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
574 if (ar.exception == null && ar.result != null) {
575 request.result = ar.result;
576 } else {
577 request.result = new IccIoResult(0x6F, 0, (byte[])null);
578 if (ar.result == null) {
579 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800580 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800582 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 } else {
584 loge("iccTransmitApduLogicalChannel: Unknown exception");
585 }
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 break;
589
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
591 request = (MainThreadRequest) msg.obj;
592 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 if (uiccCard == null) {
595 loge("iccTransmitApduBasicChannel: No UICC");
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 } else {
599 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
600 request);
601 uiccCard.iccTransmitApduBasicChannel(
602 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
603 iccArgument.p3, iccArgument.data, onCompleted);
604 }
605 break;
606
607 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
610 if (ar.exception == null && ar.result != null) {
611 request.result = ar.result;
612 } else {
613 request.result = new IccIoResult(0x6F, 0, (byte[])null);
614 if (ar.result == null) {
615 loge("iccTransmitApduBasicChannel: Empty response");
616 } else if (ar.exception instanceof CommandException) {
617 loge("iccTransmitApduBasicChannel: CommandException: " +
618 ar.exception);
619 } else {
620 loge("iccTransmitApduBasicChannel: Unknown exception");
621 }
622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 break;
625
626 case CMD_EXCHANGE_SIM_IO:
627 request = (MainThreadRequest) msg.obj;
628 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 if (uiccCard == null) {
631 loge("iccExchangeSimIO: No UICC");
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
636 request);
637 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
638 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
639 iccArgument.data, onCompleted);
640 }
641 break;
642
643 case EVENT_EXCHANGE_SIM_IO_DONE:
644 ar = (AsyncResult) msg.obj;
645 request = (MainThreadRequest) ar.userObj;
646 if (ar.exception == null && ar.result != null) {
647 request.result = ar.result;
648 } else {
649 request.result = new IccIoResult(0x6f, 0, (byte[])null);
650 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700652 break;
653
Derek Tan4d5e5c12014-02-04 11:54:58 -0800654 case CMD_SEND_ENVELOPE:
655 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800656 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 if (uiccCard == null) {
658 loge("sendEnvelopeWithStatus: No UICC");
659 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700660 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 } else {
662 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
663 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
664 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 break;
666
667 case EVENT_SEND_ENVELOPE_DONE:
668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800672 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700673 request.result = new IccIoResult(0x6F, 0, (byte[])null);
674 if (ar.result == null) {
675 loge("sendEnvelopeWithStatus: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("sendEnvelopeWithStatus: CommandException: " +
678 ar.exception);
679 } else {
680 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
681 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800684 break;
685
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 case CMD_OPEN_CHANNEL:
687 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800688 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800689 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 if (uiccCard == null) {
691 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800692 request.result = new IccOpenLogicalChannelResponse(-1,
693 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700694 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700695 } else {
696 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800697 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
698 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700699 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 break;
701
702 case EVENT_OPEN_CHANNEL_DONE:
703 ar = (AsyncResult) msg.obj;
704 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700705 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 int[] result = (int[]) ar.result;
708 int channelId = result[0];
709 byte[] selectResponse = null;
710 if (result.length > 1) {
711 selectResponse = new byte[result.length - 1];
712 for (int i = 1; i < result.length; ++i) {
713 selectResponse[i - 1] = (byte) result[i];
714 }
715 }
716 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700719 if (ar.result == null) {
720 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700722 if (ar.exception != null) {
723 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
724 }
725
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700726 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700727 if (ar.exception instanceof CommandException) {
728 CommandException.Error error =
729 ((CommandException) (ar.exception)).getCommandError();
730 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700731 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700732 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700733 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700734 }
735 }
736 openChannelResp = new IccOpenLogicalChannelResponse(
737 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700738 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700739 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 break;
742
743 case CMD_CLOSE_CHANNEL:
744 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800745 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700746 if (uiccCard == null) {
747 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900748 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700749 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700750 } else {
751 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
752 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
753 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 break;
755
756 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800757 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
758 break;
759
760 case CMD_NV_READ_ITEM:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
764 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800765 break;
766
767 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 ar = (AsyncResult) msg.obj;
769 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800770 if (ar.exception == null && ar.result != null) {
771 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800773 request.result = "";
774 if (ar.result == null) {
775 loge("nvReadItem: Empty response");
776 } else if (ar.exception instanceof CommandException) {
777 loge("nvReadItem: CommandException: " +
778 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700779 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800780 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700781 }
782 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700783 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700784 break;
785
Jake Hambye994d462014-02-03 13:10:13 -0800786 case CMD_NV_WRITE_ITEM:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
789 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800790 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700791 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800792 break;
793
794 case EVENT_NV_WRITE_ITEM_DONE:
795 handleNullReturnEvent(msg, "nvWriteItem");
796 break;
797
798 case CMD_NV_WRITE_CDMA_PRL:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800801 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800802 break;
803
804 case EVENT_NV_WRITE_CDMA_PRL_DONE:
805 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
806 break;
807
chen xu6dac5ab2018-10-26 17:39:23 -0700808 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800809 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700810 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800811 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800812 break;
813
chen xu6dac5ab2018-10-26 17:39:23 -0700814 case EVENT_RESET_MODEM_CONFIG_DONE:
815 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800816 break;
817
Sooraj Sasindran37444802020-08-11 10:40:43 -0700818 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
821 request);
822 Phone phone = getPhoneFromRequest(request);
823 if (phone != null) {
824 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
825 } else {
826 loge("isNRDualConnectivityEnabled: No phone object");
827 request.result = false;
828 notifyRequester(request);
829 }
830 break;
831 }
832
833 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null && ar.result != null) {
837 request.result = ar.result;
838 } else {
839 // request.result must be set to something non-null
840 // for the calling thread to unblock
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700841 if (ar.result != null) {
Sooraj Sasindran37444802020-08-11 10:40:43 -0700842 request.result = ar.result;
843 } else {
844 request.result = false;
845 }
846 if (ar.result == null) {
847 loge("isNRDualConnectivityEnabled: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("isNRDualConnectivityEnabled: CommandException: "
850 + ar.exception);
851 } else {
852 loge("isNRDualConnectivityEnabled: Unknown exception");
853 }
854 }
855 notifyRequester(request);
856 break;
857
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700858 case CMD_IS_VONR_ENABLED: {
859 request = (MainThreadRequest) msg.obj;
860 onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE,
861 request);
862 Phone phone = getPhoneFromRequest(request);
863 if (phone != null) {
864 phone.isVoNrEnabled(onCompleted, request.workSource);
865 } else {
866 loge("isVoNrEnabled: No phone object");
867 request.result = false;
868 notifyRequester(request);
869 }
870 break;
871 }
872
873 case EVENT_IS_VONR_ENABLED_DONE:
874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null && ar.result != null) {
877 request.result = ar.result;
878 } else {
879 // request.result must be set to something non-null
880 // for the calling thread to unblock
881 if (ar.result != null) {
882 request.result = ar.result;
883 } else {
884 request.result = false;
885 }
886 if (ar.result == null) {
887 loge("isVoNrEnabled: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("isVoNrEnabled: CommandException: "
890 + ar.exception);
891 } else {
892 loge("isVoNrEnabled: Unknown exception");
893 }
894 }
895 notifyRequester(request);
896 break;
897
Sooraj Sasindran37444802020-08-11 10:40:43 -0700898 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
901 Phone phone = getPhoneFromRequest(request);
902 if (phone != null) {
903 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
904 request.workSource);
905 } else {
906 loge("enableNrDualConnectivity: No phone object");
907 request.result =
908 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
909 notifyRequester(request);
910 }
911 break;
912 }
913
914 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
917 if (ar.exception == null) {
918 request.result =
919 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
920 } else {
921 request.result =
922 TelephonyManager
923 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
924 if (ar.exception instanceof CommandException) {
925 CommandException.Error error =
926 ((CommandException) (ar.exception)).getCommandError();
927 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
928 request.result =
929 TelephonyManager
930 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000931 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
932 request.result =
933 TelephonyManager
934 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700935 }
936 loge("enableNrDualConnectivity" + ": CommandException: "
937 + ar.exception);
938 } else {
939 loge("enableNrDualConnectivity" + ": Unknown exception");
940 }
941 }
942 notifyRequester(request);
943 break;
944 }
945
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -0700946 case CMD_ENABLE_VONR: {
947 request = (MainThreadRequest) msg.obj;
948 onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request);
949 Phone phone = getPhoneFromRequest(request);
950 if (phone != null) {
951 phone.setVoNrEnabled((boolean) request.argument, onCompleted,
952 request.workSource);
953 } else {
954 loge("setVoNrEnabled: No phone object");
955 request.result =
956 TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
957 notifyRequester(request);
958 }
959 break;
960 }
961
962 case EVENT_ENABLE_VONR_DONE: {
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null) {
966 request.result = TelephonyManager.ENABLE_VONR_SUCCESS;
967 } else {
968 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
969 if (ar.exception instanceof CommandException) {
970 CommandException.Error error =
971 ((CommandException) (ar.exception)).getCommandError();
972 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
973 request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
974 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
975 request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED;
976 } else {
977 request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR;
978 }
979 loge("setVoNrEnabled" + ": CommandException: "
980 + ar.exception);
981 } else {
982 loge("setVoNrEnabled" + ": Unknown exception");
983 }
984 }
985 notifyRequester(request);
986 break;
987 }
988
SongFerngWang3ef3e072020-12-21 16:41:52 +0800989 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800990 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800991 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
992 request);
993 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800994 break;
995
SongFerngWang3ef3e072020-12-21 16:41:52 +0800996 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception == null && ar.result != null) {
1000 request.result = ar.result; // Integer
1001 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +05301002 // request.result must be set to something non-null
1003 // for the calling thread to unblock
1004 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -08001005 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001006 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -08001007 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001008 loge("getAllowedNetworkTypesBitmask: CommandException: "
1009 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -08001010 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +08001011 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -08001012 }
1013 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001014 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -08001015 break;
1016
SongFerngWang3ef3e072020-12-21 16:41:52 +08001017 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -08001018 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +08001019 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
1020 request);
1021 Pair<Integer, Long> reasonWithNetworkTypes =
1022 (Pair<Integer, Long>) request.argument;
1023 getPhoneFromRequest(request).setAllowedNetworkTypes(
1024 reasonWithNetworkTypes.first,
1025 reasonWithNetworkTypes.second,
1026 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -08001027 break;
1028
SongFerngWang3ef3e072020-12-21 16:41:52 +08001029 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
1030 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -08001031 break;
1032
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001033 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
1034 request = (MainThreadRequest)msg.obj;
1035 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001036 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001037 break;
1038
1039 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
1040 ar = (AsyncResult)msg.obj;
1041 request = (MainThreadRequest)ar.userObj;
1042 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001043 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00001044 break;
1045
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001046 case CMD_SET_VOICEMAIL_NUMBER:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
1049 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -08001050 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
1051 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001052 break;
1053
1054 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
1055 handleNullReturnEvent(msg, "setVoicemailNumber");
1056 break;
1057
Stuart Scott54788802015-03-30 13:18:01 -07001058 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
1059 request = (MainThreadRequest) msg.obj;
1060 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
1061 request);
1062 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
1063 break;
1064
1065 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
1066 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
1067 break;
1068
Shishir Agrawal302c8692015-06-19 13:49:39 -07001069 case CMD_PERFORM_NETWORK_SCAN:
1070 request = (MainThreadRequest) msg.obj;
1071 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
1072 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
1073 break;
1074
Hall Liu27d24262020-09-18 19:04:59 -07001075 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001076 request = (MainThreadRequest) msg.obj;
1077 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001078 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
1079 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1080 request.argument;
1081 int callForwardingReason = args.first;
1082 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001083 break;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
1085 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001088 TelephonyManager.CallForwardingInfoCallback callback =
1089 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1090 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001091 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001092 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001093 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1094 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1095 // Service Class is a bit mask per 3gpp 27.007. Search for
1096 // any service for voice call.
1097 if ((callForwardInfo.serviceClass
1098 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001099 callForwardingInfo = new CallForwardingInfo(true,
1100 callForwardInfo.reason,
1101 callForwardInfo.number,
1102 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001103 break;
1104 }
1105 }
1106 // Didn't find a call forward info for voice call.
1107 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001108 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1109 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001110 }
Hall Liu27d24262020-09-18 19:04:59 -07001111 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001112 } else {
1113 if (ar.result == null) {
1114 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1115 }
1116 if (ar.exception != null) {
1117 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1118 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001119 int errorCode = TelephonyManager
1120 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001121 if (ar.exception instanceof CommandException) {
1122 CommandException.Error error =
1123 ((CommandException) (ar.exception)).getCommandError();
1124 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001125 errorCode = TelephonyManager
1126 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001127 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001128 errorCode = TelephonyManager
1129 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001130 }
1131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 }
Shuo Qian4a594052020-01-23 11:59:30 -08001134 break;
Hall Liu27d24262020-09-18 19:04:59 -07001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136
Hall Liu27d24262020-09-18 19:04:59 -07001137 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001140 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001141 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001142 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1143 request.argument).first;
1144 request.phone.setCallForwardingOption(
1145 callForwardingInfoToSet.isEnabled()
Calvin Pan258f1f72021-07-28 21:46:56 +08001146 ? CommandsInterface.CF_ACTION_REGISTRATION
Hall Liu27d24262020-09-18 19:04:59 -07001147 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001148 callForwardingInfoToSet.getReason(),
1149 callForwardingInfoToSet.getNumber(),
1150 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1151 break;
Hall Liu27d24262020-09-18 19:04:59 -07001152 }
Shuo Qian4a594052020-01-23 11:59:30 -08001153
Hall Liu27d24262020-09-18 19:04:59 -07001154 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001155 ar = (AsyncResult) msg.obj;
1156 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001157 Consumer<Integer> callback =
1158 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1159 request.argument).second;
1160 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001161 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001162 int errorCode = TelephonyManager.CallForwardingInfoCallback
1163 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001164 if (ar.exception instanceof CommandException) {
1165 CommandException.Error error =
1166 ((CommandException) (ar.exception)).getCommandError();
1167 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001168 errorCode = TelephonyManager.CallForwardingInfoCallback
1169 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001170 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001171 errorCode = TelephonyManager.CallForwardingInfoCallback
1172 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001173 }
1174 }
1175 callback.accept(errorCode);
1176 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001177 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001178 }
Shuo Qian4a594052020-01-23 11:59:30 -08001179 break;
Hall Liu27d24262020-09-18 19:04:59 -07001180 }
Shuo Qian4a594052020-01-23 11:59:30 -08001181
Hall Liu27d24262020-09-18 19:04:59 -07001182 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001183 request = (MainThreadRequest) msg.obj;
1184 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1185 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1186 break;
Hall Liu27d24262020-09-18 19:04:59 -07001187 }
Shuo Qian4a594052020-01-23 11:59:30 -08001188
Hall Liu27d24262020-09-18 19:04:59 -07001189 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001190 ar = (AsyncResult) msg.obj;
1191 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001192 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001193 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1194 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001195 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001196 // Service Class is a bit mask per 3gpp 27.007.
1197 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001198 if (callForwardResults.length > 1
1199 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001200 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001201 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001202 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1203 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001204 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001205 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001206 }
1207 } else {
1208 if (ar.result == null) {
1209 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1210 }
1211 if (ar.exception != null) {
1212 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1213 }
1214 if (ar.exception instanceof CommandException) {
1215 CommandException.Error error =
1216 ((CommandException) (ar.exception)).getCommandError();
1217 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1218 callForwardingStatus =
1219 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1220 }
1221 }
1222 }
Hall Liu27d24262020-09-18 19:04:59 -07001223 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001224 break;
Hall Liu27d24262020-09-18 19:04:59 -07001225 }
Shuo Qian4a594052020-01-23 11:59:30 -08001226
Hall Liu27d24262020-09-18 19:04:59 -07001227 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001228 request = (MainThreadRequest) msg.obj;
1229 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001230 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1231 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001232 break;
Hall Liu27d24262020-09-18 19:04:59 -07001233 }
Shuo Qian4a594052020-01-23 11:59:30 -08001234
Hall Liu27d24262020-09-18 19:04:59 -07001235 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001236 ar = (AsyncResult) msg.obj;
1237 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001238 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1239 Consumer<Integer> callback =
1240 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1241 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001242 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001243 if (ar.exception instanceof CommandException) {
1244 CommandException.Error error =
1245 ((CommandException) (ar.exception)).getCommandError();
1246 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1247 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1248 } else {
1249 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1250 }
1251 } else {
1252 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1253 }
1254 } else {
1255 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1256 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001257 }
Shuo Qian4a594052020-01-23 11:59:30 -08001258 break;
Hall Liu27d24262020-09-18 19:04:59 -07001259 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001260 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1261 ar = (AsyncResult) msg.obj;
1262 request = (MainThreadRequest) ar.userObj;
1263 CellNetworkScanResult cellScanResult;
1264 if (ar.exception == null && ar.result != null) {
1265 cellScanResult = new CellNetworkScanResult(
1266 CellNetworkScanResult.STATUS_SUCCESS,
1267 (List<OperatorInfo>) ar.result);
1268 } else {
1269 if (ar.result == null) {
1270 loge("getCellNetworkScanResults: Empty response");
1271 }
1272 if (ar.exception != null) {
1273 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1274 }
1275 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1276 if (ar.exception instanceof CommandException) {
1277 CommandException.Error error =
1278 ((CommandException) (ar.exception)).getCommandError();
1279 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1280 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1281 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1282 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1283 }
1284 }
1285 cellScanResult = new CellNetworkScanResult(errorCode, null);
1286 }
1287 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001288 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001289 break;
1290
1291 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1292 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001293 ManualNetworkSelectionArgument selArg =
1294 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001295 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1296 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001297 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1298 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001299 break;
1300
1301 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null) {
1305 request.result = true;
1306 } else {
1307 request.result = false;
1308 loge("setNetworkSelectionModeManual " + ar.exception);
1309 }
1310 notifyRequester(request);
1311 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001312 break;
1313
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001314 case CMD_GET_MODEM_ACTIVITY_INFO:
1315 request = (MainThreadRequest) msg.obj;
1316 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001317 if (defaultPhone != null) {
1318 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001319 } else {
1320 ResultReceiver result = (ResultReceiver) request.argument;
1321 Bundle bundle = new Bundle();
1322 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001323 new ModemActivityInfo(0, 0, 0,
1324 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001325 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001326 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001327 break;
1328
Hall Liud0f208c2020-10-14 16:54:44 -07001329 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001330 ar = (AsyncResult) msg.obj;
1331 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001332 ResultReceiver result = (ResultReceiver) request.argument;
1333
Hall Liud0f208c2020-10-14 16:54:44 -07001334 ModemActivityInfo ret = null;
1335 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001336 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001337 // Update the last modem activity info and the result of the request.
1338 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1339 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001340 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001341 int[] txTimeMs = info.getTransmitTimeMillis();
1342 int[] lastModemTxTimeMs = mLastModemActivityInfo
1343 .getTransmitTimeMillis();
1344 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1345 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1346 }
Hall Liu49656c02020-10-09 19:00:11 -07001347 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001348 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1349 + mLastModemActivityInfo.getSleepTimeMillis());
1350 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1351 + mLastModemActivityInfo.getIdleTimeMillis());
1352 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1353 mLastModemActivityInfo.setReceiveTimeMillis(
1354 info.getReceiveTimeMillis()
1355 + mLastModemActivityInfo.getReceiveTimeMillis());
1356 }
Hall Liu49656c02020-10-09 19:00:11 -07001357 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001358 mLastModemActivityInfo.getSleepTimeMillis(),
1359 mLastModemActivityInfo.getIdleTimeMillis(),
1360 mLastModemActivityInfo.getTransmitTimeMillis(),
1361 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001362 } else {
1363 if (ar.result == null) {
1364 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001365 error = TelephonyManager.ModemActivityInfoException
1366 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001367 } else if (ar.exception instanceof CommandException) {
1368 loge("queryModemActivityInfo: CommandException: " +
1369 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001370 error = TelephonyManager.ModemActivityInfoException
1371 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001372 } else {
1373 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001374 error = TelephonyManager.ModemActivityInfoException
1375 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001376 }
1377 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001378 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001379 if (ret != null) {
1380 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1381 } else {
1382 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1383 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001384 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001385 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001386 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001387 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001388
Meng Wang1a7c35a2016-05-05 20:56:15 -07001389 case CMD_SET_ALLOWED_CARRIERS:
1390 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001391 CarrierRestrictionRules argument =
1392 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001393 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001394 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001395 break;
1396
1397 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1398 ar = (AsyncResult) msg.obj;
1399 request = (MainThreadRequest) ar.userObj;
1400 if (ar.exception == null && ar.result != null) {
1401 request.result = ar.result;
1402 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001403 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1404 if (ar.exception instanceof CommandException) {
1405 loge("setAllowedCarriers: CommandException: " + ar.exception);
1406 CommandException.Error error =
1407 ((CommandException) (ar.exception)).getCommandError();
1408 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1409 request.result =
1410 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1411 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001412 } else {
1413 loge("setAllowedCarriers: Unknown exception");
1414 }
1415 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001416 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001417 break;
1418
1419 case CMD_GET_ALLOWED_CARRIERS:
1420 request = (MainThreadRequest) msg.obj;
1421 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001422 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001423 break;
1424
1425 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 if (ar.exception == null && ar.result != null) {
1429 request.result = ar.result;
1430 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001431 request.result = new IllegalStateException(
1432 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001433 if (ar.result == null) {
1434 loge("getAllowedCarriers: Empty response");
1435 } else if (ar.exception instanceof CommandException) {
1436 loge("getAllowedCarriers: CommandException: " +
1437 ar.exception);
1438 } else {
1439 loge("getAllowedCarriers: Unknown exception");
1440 }
1441 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001442 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001443 break;
1444
Nathan Haroldb3014052017-01-25 15:57:32 -08001445 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 if (ar.exception == null && ar.result != null) {
1449 request.result = ar.result;
1450 } else {
1451 request.result = new IllegalArgumentException(
1452 "Failed to retrieve Forbidden Plmns");
1453 if (ar.result == null) {
1454 loge("getForbiddenPlmns: Empty response");
1455 } else {
1456 loge("getForbiddenPlmns: Unknown exception");
1457 }
1458 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001459 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001460 break;
1461
1462 case CMD_GET_FORBIDDEN_PLMNS:
1463 request = (MainThreadRequest) msg.obj;
1464 uiccCard = getUiccCardFromRequest(request);
1465 if (uiccCard == null) {
1466 loge("getForbiddenPlmns() UiccCard is null");
1467 request.result = new IllegalArgumentException(
1468 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001469 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001470 break;
1471 }
1472 Integer appType = (Integer) request.argument;
1473 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1474 if (uiccApp == null) {
1475 loge("getForbiddenPlmns() no app with specified type -- "
1476 + appType);
1477 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001478 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001479 break;
1480 } else {
1481 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1482 + " specified type -- " + appType);
1483 }
1484 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1485 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1486 onCompleted);
1487 break;
1488
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001489 case CMD_SWITCH_SLOTS:
1490 request = (MainThreadRequest) msg.obj;
1491 int[] physicalSlots = (int[]) request.argument;
1492 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1493 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1494 break;
1495
1496 case EVENT_SWITCH_SLOTS_DONE:
1497 ar = (AsyncResult) msg.obj;
1498 request = (MainThreadRequest) ar.userObj;
1499 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001500 notifyRequester(request);
1501 break;
1502 case CMD_GET_NETWORK_SELECTION_MODE:
1503 request = (MainThreadRequest) msg.obj;
1504 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1505 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1506 break;
1507
1508 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 if (ar.exception != null) {
1512 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1513 } else {
1514 int mode = ((int[]) ar.result)[0];
1515 if (mode == 0) {
1516 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1517 } else {
1518 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1519 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001521 notifyRequester(request);
1522 break;
1523 case CMD_GET_CDMA_ROAMING_MODE:
1524 request = (MainThreadRequest) msg.obj;
1525 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1526 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1527 break;
1528 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1529 ar = (AsyncResult) msg.obj;
1530 request = (MainThreadRequest) ar.userObj;
1531 if (ar.exception != null) {
1532 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1533 } else {
1534 request.result = ((int[]) ar.result)[0];
1535 }
1536 notifyRequester(request);
1537 break;
1538 case CMD_SET_CDMA_ROAMING_MODE:
1539 request = (MainThreadRequest) msg.obj;
1540 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1541 int mode = (int) request.argument;
1542 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1543 break;
1544 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1545 ar = (AsyncResult) msg.obj;
1546 request = (MainThreadRequest) ar.userObj;
1547 request.result = ar.exception == null;
1548 notifyRequester(request);
1549 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001550 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1551 request = (MainThreadRequest) msg.obj;
1552 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1553 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1554 break;
1555 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1556 ar = (AsyncResult) msg.obj;
1557 request = (MainThreadRequest) ar.userObj;
1558 if (ar.exception != null) {
1559 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1560 } else {
1561 request.result = ((int[]) ar.result)[0];
1562 }
1563 notifyRequester(request);
1564 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001565 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1566 request = (MainThreadRequest) msg.obj;
1567 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1568 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001569 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1570 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001571 break;
1572 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1573 ar = (AsyncResult) msg.obj;
1574 request = (MainThreadRequest) ar.userObj;
1575 request.result = ar.exception == null;
1576 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001577 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001578 case CMD_GET_ALL_CELL_INFO:
1579 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001580 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001581 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001582 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001583 case EVENT_GET_ALL_CELL_INFO_DONE:
1584 ar = (AsyncResult) msg.obj;
1585 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001586 // If a timeout occurs, the response will be null
1587 request.result = (ar.exception == null && ar.result != null)
1588 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001589 synchronized (request) {
1590 request.notifyAll();
1591 }
1592 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001593 case CMD_REQUEST_CELL_INFO_UPDATE:
1594 request = (MainThreadRequest) msg.obj;
1595 request.phone.requestCellInfoUpdate(request.workSource,
1596 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1597 break;
1598 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1599 ar = (AsyncResult) msg.obj;
1600 request = (MainThreadRequest) ar.userObj;
1601 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1602 try {
1603 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001604 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001605 cb.onError(
1606 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1607 ar.exception.getClass().getName(),
1608 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001609 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001611 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 } else {
1613 // use the result as returned
1614 cb.onCellInfo((List<CellInfo>) ar.result);
1615 }
1616 } catch (RemoteException re) {
1617 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1618 }
1619 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001620 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001621 request = (MainThreadRequest) msg.obj;
1622 WorkSource ws = (WorkSource) request.argument;
1623 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001624 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001625 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001626 }
1627 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001628 ar = (AsyncResult) msg.obj;
1629 request = (MainThreadRequest) ar.userObj;
1630 if (ar.exception == null) {
1631 request.result = ar.result;
1632 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001633 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001634 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001635 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001636 }
1637
1638 synchronized (request) {
1639 request.notifyAll();
1640 }
1641 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001642 }
chen xu6dac5ab2018-10-26 17:39:23 -07001643 case CMD_MODEM_REBOOT:
1644 request = (MainThreadRequest) msg.obj;
1645 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001646 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001647 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001648 case EVENT_CMD_MODEM_REBOOT_DONE:
1649 handleNullReturnEvent(msg, "rebootModem");
1650 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001651 case CMD_REQUEST_ENABLE_MODEM:
1652 request = (MainThreadRequest) msg.obj;
1653 boolean enable = (boolean) request.argument;
1654 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001655 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001656 PhoneConfigurationManager.getInstance()
1657 .enablePhone(request.phone, enable, onCompleted);
1658 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001659 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
1662 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001663 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001664 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001665 if ((boolean) request.result) {
1666 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1667 updateModemStateMetrics();
1668 } else {
1669 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1670 + ar.exception);
1671 }
1672 notifyRequester(request);
1673 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001674 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001675 case CMD_GET_MODEM_STATUS:
1676 request = (MainThreadRequest) msg.obj;
1677 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1678 PhoneConfigurationManager.getInstance()
1679 .getPhoneStatusFromModem(request.phone, onCompleted);
1680 break;
1681 case EVENT_GET_MODEM_STATUS_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 int id = request.phone.getPhoneId();
1685 if (ar.exception == null && ar.result != null) {
1686 request.result = ar.result;
1687 //update the cache as modem status has changed
1688 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1689 (boolean) request.result);
1690 } else {
1691 // Return true if modem status cannot be retrieved. For most cases,
1692 // modem status is on. And for older version modems, GET_MODEM_STATUS
1693 // and disable modem are not supported. Modem is always on.
1694 // TODO: this should be fixed in R to support a third
1695 // status UNKNOWN b/131631629
1696 request.result = true;
1697 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1698 + ar.exception);
1699 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001700 notifyRequester(request);
1701 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001702 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1705 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1706 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1707 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1708 break;
1709 }
1710 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1711 ar = (AsyncResult) msg.obj;
1712 request = (MainThreadRequest) ar.userObj;
1713 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1714 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1715 args.second.accept(ar.exception == null);
1716 notifyRequester(request);
1717 break;
1718 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001719 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1720 request = (MainThreadRequest) msg.obj;
1721 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1722 Phone phone = getPhoneFromRequest(request);
1723 if (phone != null) {
1724 phone.getSystemSelectionChannels(onCompleted);
1725 } else {
1726 loge("getSystemSelectionChannels: No phone object");
1727 request.result = new ArrayList<RadioAccessSpecifier>();
1728 notifyRequester(request);
1729 }
1730 break;
1731 }
1732 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1733 ar = (AsyncResult) msg.obj;
1734 request = (MainThreadRequest) ar.userObj;
1735 if (ar.exception == null && ar.result != null) {
1736 request.result = ar.result;
1737 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001738 request.result = new IllegalStateException(
1739 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001740 if (ar.result == null) {
1741 loge("getSystemSelectionChannels: Empty response");
1742 } else {
1743 loge("getSystemSelectionChannels: Unknown exception");
1744 }
1745 }
1746 notifyRequester(request);
1747 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001748 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
1751 if (ar.exception == null && ar.result != null) {
1752 request.result = ar.result;
1753 } else {
1754 request.result = -1;
1755 loge("Failed to set Forbidden Plmns");
1756 if (ar.result == null) {
1757 loge("setForbidenPlmns: Empty response");
1758 } else if (ar.exception != null) {
1759 loge("setForbiddenPlmns: Exception: " + ar.exception);
1760 request.result = -1;
1761 } else {
1762 loge("setForbiddenPlmns: Unknown exception");
1763 }
1764 }
1765 notifyRequester(request);
1766 break;
1767 case CMD_SET_FORBIDDEN_PLMNS:
1768 request = (MainThreadRequest) msg.obj;
1769 uiccCard = getUiccCardFromRequest(request);
1770 if (uiccCard == null) {
1771 loge("setForbiddenPlmns: UiccCard is null");
1772 request.result = -1;
1773 notifyRequester(request);
1774 break;
1775 }
1776 Pair<Integer, List<String>> setFplmnsArgs =
1777 (Pair<Integer, List<String>>) request.argument;
1778 appType = setFplmnsArgs.first;
1779 List<String> fplmns = setFplmnsArgs.second;
1780 uiccApp = uiccCard.getApplicationByType(appType);
1781 if (uiccApp == null) {
1782 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1783 request.result = -1;
1784 loge("Failed to get UICC App");
1785 notifyRequester(request);
1786 } else {
1787 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1788 ((SIMRecords) uiccApp.getIccRecords())
1789 .setForbiddenPlmns(onCompleted, fplmns);
1790 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001791 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001792 case CMD_ERASE_MODEM_CONFIG:
1793 request = (MainThreadRequest) msg.obj;
1794 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1795 defaultPhone.eraseModemConfig(onCompleted);
1796 break;
1797 case EVENT_ERASE_MODEM_CONFIG_DONE:
1798 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001799 break;
zoey chene02881a2019-12-30 16:11:23 +08001800
Kai Shif70f46f2021-03-03 13:59:46 -08001801 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1802 request = (MainThreadRequest) msg.obj;
1803 request.result = defaultPhone.eraseDataInSharedPreferences();
1804 notifyRequester(request);
1805 break;
1806
zoey chene02881a2019-12-30 16:11:23 +08001807 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1808 request = (MainThreadRequest) msg.obj;
1809 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1810 Pair<String, String> changed = (Pair<String, String>) request.argument;
1811 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1812 changed.first, changed.second, onCompleted);
1813 break;
1814 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1815 ar = (AsyncResult) msg.obj;
1816 request = (MainThreadRequest) ar.userObj;
1817 if (ar.exception == null) {
1818 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001819 // If the operation is successful, update the PIN storage
1820 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1821 int phoneId = getPhoneFromRequest(request).getPhoneId();
Jon Spivack9c3bc762021-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 Spivack9c3bc762021-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);
1978 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1979 request.subId, pair.first /*callingUid*/,
1980 pair.second /*request*/, onCompleted);
1981 break;
1982 }
1983 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1984 ar = (AsyncResult) msg.obj;
1985 request = (MainThreadRequest) ar.userObj;
1986 // request.result will be the exception of ar if present, true otherwise.
1987 // Be cautious not to leave result null which will wait() forever
1988 request.result = ar.exception != null ? ar.exception : true;
1989 notifyRequester(request);
1990 break;
1991 }
1992 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1993 request = (MainThreadRequest) msg.obj;
1994
1995 Phone phone = getPhoneFromRequest(request);
1996 if (phone == null || phone.getServiceStateTracker() == null) {
1997 request.result = new IllegalStateException("Phone or SST is null");
1998 notifyRequester(request);
1999 break;
2000 }
2001
2002 Pair<Integer, SignalStrengthUpdateRequest> pair =
2003 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
2004 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
2005 request);
2006 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
2007 request.subId, pair.first /*callingUid*/,
2008 pair.second /*request*/, onCompleted);
2009 break;
2010 }
2011 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
2012 ar = (AsyncResult) msg.obj;
2013 request = (MainThreadRequest) ar.userObj;
2014 request.result = ar.exception != null ? ar.exception : true;
2015 notifyRequester(request);
2016 break;
2017 }
Jordan Liu109698e2020-11-24 14:50:34 -08002018
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002019 case CMD_GET_SLICING_CONFIG: {
2020 request = (MainThreadRequest) msg.obj;
2021 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
2022 request.phone.getSlicingConfig(onCompleted);
2023 break;
2024 }
2025 case EVENT_GET_SLICING_CONFIG_DONE: {
2026 ar = (AsyncResult) msg.obj;
2027 request = (MainThreadRequest) ar.userObj;
2028 ResultReceiver result = (ResultReceiver) request.argument;
2029
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002030 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002031 Bundle bundle = new Bundle();
2032 int resultCode = 0;
2033 if (ar.exception != null) {
2034 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
2035 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002036 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002037 } else if (ar.result == null) {
2038 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002039 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002040 } else {
2041 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002042 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
2043 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002044 }
2045
2046 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08002047 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08002048 }
2049 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
2050 result.send(resultCode, bundle);
2051 notifyRequester(request);
2052 break;
2053 }
2054
Michele Berionne5e411512020-11-13 02:36:59 +00002055 case CMD_PREPARE_UNATTENDED_REBOOT:
2056 request = (MainThreadRequest) msg.obj;
2057 request.result =
Rafael Higuera Silvad9630642021-09-20 15:32:01 +00002058 UiccController.getInstance().getPinStorage()
2059 .prepareUnattendedReboot(request.workSource);
Michele Berionne5e411512020-11-13 02:36:59 +00002060 notifyRequester(request);
2061 break;
2062
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 default:
2064 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
2065 break;
2066 }
2067 }
Jake Hambye994d462014-02-03 13:10:13 -08002068
Pengquan Menga1bb6272018-09-06 09:59:22 -07002069 private void notifyRequester(MainThreadRequest request) {
2070 synchronized (request) {
2071 request.notifyAll();
2072 }
2073 }
2074
Jake Hambye994d462014-02-03 13:10:13 -08002075 private void handleNullReturnEvent(Message msg, String command) {
2076 AsyncResult ar = (AsyncResult) msg.obj;
2077 MainThreadRequest request = (MainThreadRequest) ar.userObj;
2078 if (ar.exception == null) {
2079 request.result = true;
2080 } else {
2081 request.result = false;
2082 if (ar.exception instanceof CommandException) {
2083 loge(command + ": CommandException: " + ar.exception);
2084 } else {
2085 loge(command + ": Unknown exception");
2086 }
2087 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07002088 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08002089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002090 }
2091
2092 /**
2093 * Posts the specified command to be executed on the main thread,
2094 * waits for the request to complete, and returns the result.
2095 * @see #sendRequestAsync
2096 */
2097 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002098 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2099 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002100 }
2101
2102 /**
2103 * Posts the specified command to be executed on the main thread,
2104 * waits for the request to complete, and returns the result.
2105 * @see #sendRequestAsync
2106 */
2107 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2108 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002109 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002110 }
2111
2112 /**
2113 * Posts the specified command to be executed on the main thread,
2114 * waits for the request to complete, and returns the result.
2115 * @see #sendRequestAsync
2116 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002117 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002118 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2119 }
2120
2121 /**
2122 * Posts the specified command to be executed on the main thread,
2123 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2124 * if not timeout or null otherwise.
2125 * @see #sendRequestAsync
2126 */
2127 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2128 long timeoutInMs) {
2129 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002130 }
2131
2132 /**
2133 * Posts the specified command to be executed on the main thread,
2134 * waits for the request to complete, and returns the result.
2135 * @see #sendRequestAsync
2136 */
Nathan Harold92bed182018-10-12 18:16:49 -07002137 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002138 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002139 }
2140
2141 /**
2142 * Posts the specified command to be executed on the main thread,
2143 * waits for the request to complete, and returns the result.
2144 * @see #sendRequestAsync
2145 */
2146 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002147 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2148 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002149 }
2150
2151 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002152 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2153 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2154 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002155 * @see #sendRequestAsync
2156 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002157 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2158 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2160 throw new RuntimeException("This method will deadlock if called from the main thread.");
2161 }
2162
Nathan Harold92bed182018-10-12 18:16:49 -07002163 MainThreadRequest request = null;
2164 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2165 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2166 } else if (phone != null) {
2167 request = new MainThreadRequest(argument, phone, workSource);
2168 } else {
2169 request = new MainThreadRequest(argument, subId, workSource);
2170 }
2171
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 Message msg = mMainThreadHandler.obtainMessage(command, request);
2173 msg.sendToTarget();
2174
Rambo Wang0f050d82021-02-12 11:43:36 -08002175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002177 if (timeoutInMs >= 0) {
2178 // Wait for at least timeoutInMs before returning null request result
2179 long now = SystemClock.elapsedRealtime();
2180 long deadline = now + timeoutInMs;
Grace Jia8a0a1e82021-05-23 22:59:52 -07002181 while (request.result == null && now < deadline) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002182 try {
2183 request.wait(deadline - now);
2184 } catch (InterruptedException e) {
2185 // Do nothing, go back and check if request is completed or timeout
2186 } finally {
2187 now = SystemClock.elapsedRealtime();
2188 }
2189 }
2190 } else {
2191 // Wait for the request to complete
2192 while (request.result == null) {
2193 try {
2194 request.wait();
2195 } catch (InterruptedException e) {
2196 // Do nothing, go back and wait until the request is complete
2197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 }
2199 }
2200 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002201 if (request.result == null) {
2202 Log.wtf(LOG_TAG,
2203 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 return request.result;
2206 }
2207
2208 /**
2209 * Asynchronous ("fire and forget") version of sendRequest():
2210 * Posts the specified command to be executed on the main thread, and
2211 * returns immediately.
2212 * @see #sendRequest
2213 */
2214 private void sendRequestAsync(int command) {
2215 mMainThreadHandler.sendEmptyMessage(command);
2216 }
2217
2218 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002219 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002220 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002221 */
2222 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002223 sendRequestAsync(command, argument, null, null);
2224 }
2225
2226 /**
2227 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2228 * @see {@link #sendRequest(int,Object)}
2229 */
2230 private void sendRequestAsync(
2231 int command, Object argument, Phone phone, WorkSource workSource) {
2232 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002233 Message msg = mMainThreadHandler.obtainMessage(command, request);
2234 msg.sendToTarget();
2235 }
2236
2237 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 * Initialize the singleton PhoneInterfaceManager instance.
2239 * This is only done once, at startup, from PhoneApp.onCreate().
2240 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002241 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 synchronized (PhoneInterfaceManager.class) {
2243 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002244 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 } else {
2246 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2247 }
2248 return sInstance;
2249 }
2250 }
2251
2252 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002253 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebingerd1947d82021-05-17 20:54:49 +00002256 mImsResolver = ImsResolver.getInstance();
Stuart Scott981d8582015-04-21 14:09:50 -07002257 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002259 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002261 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002262 mTelephonySharedPreferences =
2263 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002264 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002265 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002266 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002267 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002268
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 publish();
2270 }
2271
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002272 private Phone getDefaultPhone() {
2273 Phone thePhone = getPhone(getDefaultSubscription());
2274 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2275 }
2276
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 private void publish() {
2278 if (DBG) log("publish: " + this);
2279
Peter Wangc035ce42020-01-08 21:00:22 -08002280 TelephonyFrameworkInitializer
2281 .getTelephonyServiceManager()
2282 .getTelephonyServiceRegisterer()
2283 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 }
2285
Stuart Scott584921c2015-01-15 17:10:34 -08002286 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002287 if (request.phone != null) {
2288 return request.phone;
2289 } else {
2290 return getPhoneFromSubId(request.subId);
2291 }
2292 }
2293
2294 private Phone getPhoneFromSubId(int subId) {
2295 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2296 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002297 }
2298
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002299 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2300 Phone phone = getPhoneFromRequest(request);
2301 return phone == null ? null :
2302 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2303 }
2304
Wink Saville36469e72014-06-11 15:17:00 -07002305 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002306 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002307 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309
Kai Shif70f46f2021-03-03 13:59:46 -08002310 private void sendEraseModemConfig(@NonNull Phone phone) {
2311 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2312 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2313 }
2314
2315 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2316 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2317 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002318 }
2319
Peter Wang44b186e2020-01-13 23:33:09 -08002320 private boolean isImsAvailableOnDevice() {
2321 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2322 if (pm == null) {
2323 // For some reason package manger is not available.. This will fail internally anyway,
2324 // so do not throw error and allow.
2325 return true;
2326 }
2327 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2328 }
2329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002331 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002332 }
2333
Wink Savilleb564aae2014-10-23 10:18:09 -07002334 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002335 if (DBG) log("dial: " + number);
2336 // No permission check needed here: This is just a wrapper around the
2337 // ACTION_DIAL intent, which is available to any app since it puts up
2338 // the UI before it does anything.
2339
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340 final long identity = Binder.clearCallingIdentity();
2341 try {
2342 String url = createTelUrl(number);
2343 if (url == null) {
2344 return;
2345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347 // PENDING: should we just silently fail if phone is offhook or ringing?
2348 PhoneConstants.State state = mCM.getState(subId);
2349 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2350 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2351 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2352 mApp.startActivity(intent);
2353 }
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 }
2357 }
2358
2359 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002360 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002361 }
2362
Wink Savilleb564aae2014-10-23 10:18:09 -07002363 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 if (DBG) log("call: " + number);
2365
2366 // This is just a wrapper around the ACTION_CALL intent, but we still
2367 // need to do a permission check since we're calling startActivity()
2368 // from the context of the phone app.
2369 enforceCallPermission();
2370
Jordan Liu1617b712019-07-10 15:06:26 -07002371 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 != AppOpsManager.MODE_ALLOWED) {
2373 return;
2374 }
2375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 String url = createTelUrl(number);
2379 if (url == null) {
2380 return;
2381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002383 boolean isValid = false;
2384 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2385 if (slist != null) {
2386 for (SubscriptionInfo subInfoRecord : slist) {
2387 if (subInfoRecord.getSubscriptionId() == subId) {
2388 isValid = true;
2389 break;
2390 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002391 }
Wink Saville08874612014-08-31 19:19:58 -07002392 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393 if (!isValid) {
2394 return;
2395 }
Wink Saville08874612014-08-31 19:19:58 -07002396
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2398 intent.putExtra(SUBSCRIPTION_KEY, subId);
2399 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2400 mApp.startActivity(intent);
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 }
2405
Wink Savilleb564aae2014-10-23 10:18:09 -07002406 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002407 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002408 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2409 }
2410
Wink Savilleb564aae2014-10-23 10:18:09 -07002411 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002412 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002413 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2414 }
2415
Wink Savilleb564aae2014-10-23 10:18:09 -07002416 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002417 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418
2419 final long identity = Binder.clearCallingIdentity();
2420 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002421 Phone phone = getPhone(subId);
2422 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002423 checkSimPin.start();
2424 return checkSimPin.unlockSim(null, pin);
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
2427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
Wink Savilleb564aae2014-10-23 10:18:09 -07002430 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002435 Phone phone = getPhone(subId);
2436 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437 checkSimPuk.start();
2438 return checkSimPuk.unlockSim(puk, pin);
2439 } finally {
2440 Binder.restoreCallingIdentity(identity);
2441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002442 }
2443
2444 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002445 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 * a synchronous one.
2447 */
2448 private static class UnlockSim extends Thread {
2449
2450 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002451 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452
2453 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002454 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2455 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002456
2457 // For replies from SimCard interface
2458 private Handler mHandler;
2459
2460 // For async handler to identify request type
2461 private static final int SUPPLY_PIN_COMPLETE = 100;
2462
Michele Berionne5e411512020-11-13 02:36:59 +00002463 UnlockSim(int phoneId, IccCard simCard) {
2464 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 mSimCard = simCard;
2466 }
2467
2468 @Override
2469 public void run() {
2470 Looper.prepare();
2471 synchronized (UnlockSim.this) {
2472 mHandler = new Handler() {
2473 @Override
2474 public void handleMessage(Message msg) {
2475 AsyncResult ar = (AsyncResult) msg.obj;
2476 switch (msg.what) {
2477 case SUPPLY_PIN_COMPLETE:
2478 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2479 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002480 mRetryCount = msg.arg1;
2481 if (ar.exception != null) {
2482 if (ar.exception instanceof CommandException &&
2483 ((CommandException)(ar.exception)).getCommandError()
2484 == CommandException.Error.PASSWORD_INCORRECT) {
2485 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002486 } //When UiccCardApp dispose,handle message and return exception
2487 else if (ar.exception instanceof CommandException &&
2488 ((CommandException) (ar.exception)).getCommandError()
2489 == CommandException.Error.ABORTED) {
2490 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002491 } else {
2492 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2493 }
2494 } else {
2495 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 mDone = true;
2498 UnlockSim.this.notifyAll();
2499 }
2500 break;
2501 }
2502 }
2503 };
2504 UnlockSim.this.notifyAll();
2505 }
2506 Looper.loop();
2507 }
2508
2509 /*
2510 * Use PIN or PUK to unlock SIM card
2511 *
2512 * If PUK is null, unlock SIM card with PIN
2513 *
2514 * If PUK is not null, unlock SIM card with PUK and set PIN code
2515 */
Wink Saville9de0f752013-10-22 19:04:03 -07002516 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517
2518 while (mHandler == null) {
2519 try {
2520 wait();
2521 } catch (InterruptedException e) {
2522 Thread.currentThread().interrupt();
2523 }
2524 }
2525 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2526
2527 if (puk == null) {
2528 mSimCard.supplyPin(pin, callback);
2529 } else {
2530 mSimCard.supplyPuk(puk, pin, callback);
2531 }
2532
2533 while (!mDone) {
2534 try {
2535 Log.d(LOG_TAG, "wait for done");
2536 wait();
2537 } catch (InterruptedException e) {
2538 // Restore the interrupted status
2539 Thread.currentThread().interrupt();
2540 }
2541 }
2542 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002543 int[] resultArray = new int[2];
2544 resultArray[0] = mResult;
2545 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002546
2547 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
Jon Spivack9c3bc762021-10-06 20:53:09 +00002548 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
Michele Berionne5e411512020-11-13 02:36:59 +00002549 }
2550
Wink Saville9de0f752013-10-22 19:04:03 -07002551 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 }
2553 }
2554
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002555 /**
2556 * This method has been removed due to privacy and stability concerns.
2557 */
2558 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002559 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002560 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2561 return;
Wink Saville36469e72014-06-11 15:17:00 -07002562 }
2563
Nathan Harold1f889d82020-06-04 17:05:26 -07002564 @Override
2565 public void updateServiceLocationWithPackageName(String callingPackage) {
2566 mApp.getSystemService(AppOpsManager.class)
2567 .checkPackage(Binder.getCallingUid(), callingPackage);
2568
Nathan Haroldf096d982020-11-18 17:18:06 -08002569 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002570 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2571 // Callers targeting S have no business invoking this method.
2572 return;
2573 }
2574
2575 LocationAccessPolicy.LocationPermissionResult locationResult =
2576 LocationAccessPolicy.checkLocationPermission(mApp,
2577 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2578 .setCallingPackage(callingPackage)
2579 .setCallingFeatureId(null)
2580 .setCallingPid(Binder.getCallingPid())
2581 .setCallingUid(Binder.getCallingUid())
2582 .setMethod("updateServiceLocation")
2583 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2584 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2585 .build());
2586 // Apps that lack location permission have no business calling this method;
2587 // however, because no permission was declared in the public API, denials must
2588 // all be "soft".
2589 switch (locationResult) {
2590 case DENIED_HARD: /* fall through */
2591 case DENIED_SOFT:
2592 return;
2593 }
2594
2595 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 final long identity = Binder.clearCallingIdentity();
2597 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002598 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002600 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 }
2606
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002607 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002608 @Override
2609 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002610 return isRadioOnWithFeature(callingPackage, null);
2611 }
2612
2613
2614 @Override
2615 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2616 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2617 callingFeatureId);
2618 }
2619
2620 @Deprecated
2621 @Override
2622 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2623 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002624 }
2625
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002626 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002627 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2628 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002630 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002631 return false;
2632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633
2634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 return isRadioOnForSubscriber(subId);
2637 } finally {
2638 Binder.restoreCallingIdentity(identity);
2639 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002640 }
2641
2642 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 final Phone phone = getPhone(subId);
2646 if (phone != null) {
2647 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2648 } else {
2649 return false;
2650 }
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
2656 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002657 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
Wink Saville36469e72014-06-11 15:17:00 -07002659
Wink Savilleb564aae2014-10-23 10:18:09 -07002660 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662
2663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
2667 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002671 }
Wink Saville36469e72014-06-11 15:17:00 -07002672 }
2673
2674 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002675 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002676 }
2677
Wink Savilleb564aae2014-10-23 10:18:09 -07002678 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002679 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 final Phone phone = getPhone(subId);
2684 if (phone == null) {
2685 return false;
2686 }
2687 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2688 toggleRadioOnOffForSubscriber(subId);
2689 }
2690 return true;
2691 } finally {
2692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002694 }
Wink Saville36469e72014-06-11 15:17:00 -07002695
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002696 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002697 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002698 /*
2699 * If any of the Radios are available, it will need to be
2700 * shutdown. So return true if any Radio is available.
2701 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2705 Phone phone = PhoneFactory.getPhone(i);
2706 if (phone != null && phone.isRadioAvailable()) return true;
2707 }
2708 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2709 return false;
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002712 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002713 }
2714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002716 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 enforceModifyPermission();
2718
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2722 logv("Shutting down Phone " + i);
2723 shutdownRadioUsingPhoneId(i);
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002727 }
2728 }
2729
2730 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002731 Phone phone = PhoneFactory.getPhone(phoneId);
2732 if (phone != null && phone.isRadioAvailable()) {
2733 phone.shutdownRadio();
2734 }
2735 }
2736
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002738 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739
2740 final long identity = Binder.clearCallingIdentity();
2741 try {
2742 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2743 if (defaultPhone != null) {
2744 defaultPhone.setRadioPower(turnOn);
2745 return true;
2746 } else {
2747 loge("There's no default phone.");
2748 return false;
2749 }
2750 } finally {
2751 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002752 }
Wink Saville36469e72014-06-11 15:17:00 -07002753 }
2754
Wink Savilleb564aae2014-10-23 10:18:09 -07002755 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757
2758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 final Phone phone = getPhone(subId);
2761 if (phone != null) {
2762 phone.setRadioPower(turnOn);
2763 return true;
2764 } else {
2765 return false;
2766 }
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
Wink Saville36469e72014-06-11 15:17:00 -07002772 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 public boolean enableDataConnectivity() {
2775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776
2777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 int subId = mSubscriptionController.getDefaultDataSubId();
2780 final Phone phone = getPhone(subId);
2781 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002782 phone.getDataEnabledSettings().setDataEnabled(
2783 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784 return true;
2785 } else {
2786 return false;
2787 }
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002791 }
2792
Wink Saville36469e72014-06-11 15:17:00 -07002793 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 public boolean disableDataConnectivity() {
2796 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797
2798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 int subId = mSubscriptionController.getDefaultDataSubId();
2801 final Phone phone = getPhone(subId);
2802 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002803 phone.getDataEnabledSettings().setDataEnabled(
2804 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 return true;
2806 } else {
2807 return false;
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 }
2813
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002815 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 final Phone phone = getPhone(subId);
2819 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002820 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821 } else {
2822 return false;
2823 }
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 }
2828
2829 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002830 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002831 }
2832
pkanwarae03a6b2016-11-06 20:37:09 -08002833 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002834 enforceCallPermission();
2835
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2839 return;
2840 }
2841 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2842 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
pkanwar32d516d2016-10-14 19:37:38 -07002846 };
2847
Wink Savilleb564aae2014-10-23 10:18:09 -07002848 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850
2851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2854 return false;
2855 }
2856 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
2861
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002862 /**
2863 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2864 * tag on getCallState Binder call.
2865 */
2866 @Deprecated
2867 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002869 if (CompatChanges.isChangeEnabled(
2870 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2871 Binder.getCallingUid())) {
2872 // Do not allow this API to be called on API version 31+, it should only be
2873 // called on old apps using this Binder call directly.
2874 throw new SecurityException("This method can only be used for applications "
2875 + "targeting API version 30 or less.");
2876 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877 final long identity = Binder.clearCallingIdentity();
2878 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002879 Phone phone = getPhone(getDefaultSubscription());
2880 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2881 PhoneConstantConversions.convertCallState(phone.getState());
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
2885 }
2886
2887 @Override
2888 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2889 if (CompatChanges.isChangeEnabled(
2890 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2891 Binder.getCallingUid())) {
2892 // Check READ_PHONE_STATE for API version 31+
2893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2894 featureId, "getCallStateForSubscription")) {
2895 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2896 + "targeting API level 31+.");
2897 }
2898 }
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
2901 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002902 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2903 PhoneConstantConversions.convertCallState(phone.getState());
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002907 }
2908
Sanket Padawe356d7632015-06-22 14:03:32 -07002909 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002910 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002911 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2912 }
2913
2914 @Override
2915 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916 final long identity = Binder.clearCallingIdentity();
2917 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002918 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002919 if (phone != null) {
2920 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2921 } else {
2922 return PhoneConstantConversions.convertDataState(
2923 PhoneConstants.DataState.DISCONNECTED);
2924 }
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 }
2929
Sanket Padawe356d7632015-06-22 14:03:32 -07002930 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002931 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002932 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2933 }
2934
2935 @Override
2936 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002937 final long identity = Binder.clearCallingIdentity();
2938 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002939 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 if (phone != null) {
2941 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2942 } else {
2943 return TelephonyManager.DATA_ACTIVITY_NONE;
2944 }
2945 } finally {
2946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 }
2949
2950 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002951 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002952 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002953 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002954
2955 LocationAccessPolicy.LocationPermissionResult locationResult =
2956 LocationAccessPolicy.checkLocationPermission(mApp,
2957 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2958 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002959 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002960 .setCallingPid(Binder.getCallingPid())
2961 .setCallingUid(Binder.getCallingUid())
2962 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002963 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002964 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2965 .build());
2966 switch (locationResult) {
2967 case DENIED_HARD:
2968 throw new SecurityException("Not allowed to access cell location");
2969 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002970 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2971 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002972 }
2973
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002978 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002979 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
Svetoslav64fad262015-04-14 14:35:21 -07002983 }
2984
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002985 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002986 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002987 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2988 // registered cell info, so return a NULL country instead.
2989 final long identity = Binder.clearCallingIdentity();
2990 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002991 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2992 // Get default phone in this case.
2993 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2994 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002995 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002997 if (phone == null) return "";
2998 ServiceStateTracker sst = phone.getServiceStateTracker();
2999 if (sst == null) return "";
3000 LocaleTracker lt = sst.getLocaleTracker();
3001 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08003002 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003003 } finally {
3004 Binder.restoreCallingIdentity(identity);
3005 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003006 }
3007
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003008 /**
3009 * This method was removed due to potential issues caused by performing partial
3010 * updates of service state, and lack of a credible use case.
3011 *
3012 * This has the ability to break the telephony implementation by disabling notification of
3013 * changes in device connectivity. DO NOT USE THIS!
3014 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07003015 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003016 public void enableLocationUpdates() {
3017 mApp.enforceCallingOrSelfPermission(
3018 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 }
3020
Nathan Harold7c8d0f12020-05-28 20:40:31 -07003021 /**
3022 * This method was removed due to potential issues caused by performing partial
3023 * updates of service state, and lack of a credible use case.
3024 *
3025 * This has the ability to break the telephony implementation by disabling notification of
3026 * changes in device connectivity. DO NOT USE THIS!
3027 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003028 @Override
3029 public void disableLocationUpdates() {
3030 mApp.enforceCallingOrSelfPermission(
3031 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003032 }
3033
3034 @Override
3035 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003036 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
3037 String callingFeatureId) {
Nathan Haroldb55f63b2021-07-27 11:27:38 -07003038 try {
3039 mApp.getSystemService(AppOpsManager.class)
3040 .checkPackage(Binder.getCallingUid(), callingPackage);
3041 } catch (SecurityException e) {
3042 EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid());
3043 throw e;
3044 }
3045
Nathan Haroldf096d982020-11-18 17:18:06 -08003046 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07003047 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3048 throw new SecurityException(
3049 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
3050 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07003051
Jordan Liu1617b712019-07-10 15:06:26 -07003052 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003053 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3054 return null;
3055 }
Svetoslav64fad262015-04-14 14:35:21 -07003056
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003057 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003059 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07003060 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061
Nathan Haroldf180aac2018-06-01 18:43:55 -07003062 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
3063 for (CellInfo ci : info) {
3064 if (ci instanceof CellInfoGsm) {
3065 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
3066 } else if (ci instanceof CellInfoWcdma) {
3067 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
3068 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003069 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07003070 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003071 }
3072
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003073 private List<CellInfo> getCachedCellInfo() {
3074 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3075 for (Phone phone : PhoneFactory.getPhones()) {
3076 List<CellInfo> info = phone.getAllCellInfo();
3077 if (info != null) cellInfos.addAll(info);
3078 }
3079 return cellInfos;
3080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081
3082 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003083 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003084 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08003085 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003086
3087 LocationAccessPolicy.LocationPermissionResult locationResult =
3088 LocationAccessPolicy.checkLocationPermission(mApp,
3089 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3090 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003091 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003092 .setCallingPid(Binder.getCallingPid())
3093 .setCallingUid(Binder.getCallingUid())
3094 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08003095 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003096 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
3097 .build());
3098 switch (locationResult) {
3099 case DENIED_HARD:
3100 throw new SecurityException("Not allowed to access cell info");
3101 case DENIED_SOFT:
3102 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 }
3104
Nathan Haroldf096d982020-11-18 17:18:06 -08003105 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003106 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3107 return getCachedCellInfo();
3108 }
3109
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003110 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003111 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3115 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003116 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003117 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 if (info != null) cellInfos.addAll(info);
3119 }
3120 return cellInfos;
3121 } finally {
3122 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003123 }
3124 }
3125
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003126 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003127 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3128 String callingFeatureId) {
3129 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3130 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003131 }
3132
3133 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003134 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3135 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003136 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003137 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003138 }
3139
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003140 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3141 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003142 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003143 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003144
3145 LocationAccessPolicy.LocationPermissionResult locationResult =
3146 LocationAccessPolicy.checkLocationPermission(mApp,
3147 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3148 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003149 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003150 .setCallingPid(Binder.getCallingPid())
3151 .setCallingUid(Binder.getCallingUid())
3152 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003153 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3154 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003155 .build());
3156 switch (locationResult) {
3157 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003158 if (TelephonyPermissions
3159 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003160 // Safetynet logging for b/154934934
3161 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3162 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003163 throw new SecurityException("Not allowed to access cell info");
3164 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003165 if (TelephonyPermissions
3166 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003167 // Safetynet logging for b/154934934
3168 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3169 }
Nathan Harold5320c422019-05-09 10:26:08 -07003170 try {
3171 cb.onCellInfo(new ArrayList<CellInfo>());
3172 } catch (RemoteException re) {
3173 // Drop without consequences
3174 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003175 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003176 }
3177
Nathan Harolda939a962019-05-09 10:13:47 -07003178
3179 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003180 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3181
3182 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3183 }
3184
3185 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003187 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003188 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189
3190 final long identity = Binder.clearCallingIdentity();
3191 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003192 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003196 }
3197
Shishir Agrawala9f32182016-04-12 12:00:16 -07003198 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003199 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003200 Phone phone = PhoneFactory.getPhone(slotIndex);
3201 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003202 return null;
3203 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003204 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003205 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003206 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003207 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003208 return null;
3209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210
3211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 return phone.getImei();
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003217 }
3218
3219 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003220 public String getTypeAllocationCodeForSlot(int slotIndex) {
3221 Phone phone = PhoneFactory.getPhone(slotIndex);
3222 String tac = null;
3223 if (phone != null) {
3224 String imei = phone.getImei();
Vala Zadehab005552021-09-21 15:54:29 -07003225 try {
3226 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3227 } catch (IndexOutOfBoundsException e) {
3228 Log.e(LOG_TAG, "IMEI length shorter than upper index.");
3229 return null;
3230 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003231 }
3232 return tac;
3233 }
3234
3235 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003236 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07003237 try {
3238 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3239 } catch (SecurityException se) {
3240 EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid());
3241 throw new SecurityException("Package " + callingPackage + " does not belong to "
3242 + Binder.getCallingUid());
3243 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003244 Phone phone = PhoneFactory.getPhone(slotIndex);
3245 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003246 return null;
3247 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003248
Jeff Davidson913390f2018-02-23 17:11:49 -08003249 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003250 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003251 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003252 return null;
3253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003254
3255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 return phone.getMeid();
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
Jack Yu2af8d712017-03-15 17:14:14 -07003261 }
3262
3263 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003264 public String getManufacturerCodeForSlot(int slotIndex) {
3265 Phone phone = PhoneFactory.getPhone(slotIndex);
3266 String manufacturerCode = null;
3267 if (phone != null) {
3268 String meid = phone.getMeid();
Vala Zadehab005552021-09-21 15:54:29 -07003269 try {
3270 manufacturerCode =
3271 meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3272 } catch (IndexOutOfBoundsException e) {
3273 Log.e(LOG_TAG, "MEID length shorter than upper index.");
3274 return null;
3275 }
David Kelly5e06a7f2018-03-12 14:10:59 +00003276 }
3277 return manufacturerCode;
3278 }
3279
3280 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003281 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3282 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003283 Phone phone = PhoneFactory.getPhone(slotIndex);
3284 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003285 return null;
3286 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 int subId = phone.getSubId();
3288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003289 mApp, subId, callingPackage, callingFeatureId,
3290 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003291 return null;
3292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003293
3294 final long identity = Binder.clearCallingIdentity();
3295 try {
3296 return phone.getDeviceSvn();
3297 } finally {
3298 Binder.restoreCallingIdentity(identity);
3299 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003300 }
3301
fionaxu43304da2017-11-27 22:51:16 -08003302 @Override
3303 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 final Phone phone = getPhone(subId);
3307 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3308 } finally {
3309 Binder.restoreCallingIdentity(identity);
3310 }
fionaxu43304da2017-11-27 22:51:16 -08003311 }
3312
3313 @Override
3314 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 final Phone phone = getPhone(subId);
3318 return phone == null ? null : phone.getCarrierName();
3319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
fionaxu43304da2017-11-27 22:51:16 -08003322 }
3323
calvinpanffe225e2018-11-01 19:43:06 +08003324 @Override
chen xu0026ca62019-03-06 15:28:50 -08003325 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 final Phone phone = getPhone(subId);
3329 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003330 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
3334 }
3335
3336 @Override
chen xu0026ca62019-03-06 15:28:50 -08003337 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003338 final long identity = Binder.clearCallingIdentity();
3339 try {
3340 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003341 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003342 } finally {
3343 Binder.restoreCallingIdentity(identity);
3344 }
3345 }
3346
chen xu651eec72018-11-11 19:03:44 -08003347 @Override
chen xu864e11c2018-12-06 22:10:03 -08003348 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3349 if (!isSubscriptionMccMnc) {
3350 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3351 }
chen xu651eec72018-11-11 19:03:44 -08003352 final Phone phone = PhoneFactory.getPhone(slotIndex);
3353 if (phone == null) {
3354 return TelephonyManager.UNKNOWN_CARRIER_ID;
3355 }
3356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3359 } finally {
3360 Binder.restoreCallingIdentity(identity);
3361 }
3362 }
3363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003364 //
3365 // Internal helper methods.
3366 //
3367
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003368 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003369 * Make sure the caller is the calling package itself
3370 *
3371 * @throws SecurityException if the caller is not the calling package
3372 */
3373 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3374 int packageUid = -1;
Grace Jiadbefca02021-04-26 15:13:31 -07003375 PackageManager pm = mApp.getBaseContext().createContextAsUser(
3376 UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager();
Grace Jia0ddb3612021-04-22 13:35:26 -07003377 try {
Grace Jiadbefca02021-04-26 15:13:31 -07003378 packageUid = pm.getPackageUid(callingPackage, 0);
Grace Jia0ddb3612021-04-22 13:35:26 -07003379 } catch (PackageManager.NameNotFoundException e) {
3380 // packageUid is -1
3381 }
3382 if (packageUid != callingUid) {
3383 throw new SecurityException(message + ": Package " + callingPackage
3384 + " does not belong to " + callingUid);
3385 }
3386 }
3387
3388 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3390 *
3391 * @throws SecurityException if the caller does not have the required permission
3392 */
3393 private void enforceModifyPermission() {
3394 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3395 }
3396
Shuo Qiancd19c462020-01-16 20:51:11 -08003397 /**
3398 * Make sure the caller is system.
3399 *
3400 * @throws SecurityException if the caller is not system.
3401 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003402 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003403 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3404 throw new SecurityException("Caller must be system");
3405 }
3406 }
3407
Shuo Qian3b6ee772019-11-13 17:43:31 -08003408 private void enforceActiveEmergencySessionPermission() {
3409 mApp.enforceCallingOrSelfPermission(
3410 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3411 }
3412
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003413 /**
3414 * Make sure the caller has the CALL_PHONE permission.
3415 *
3416 * @throws SecurityException if the caller does not have the required permission
3417 */
3418 private void enforceCallPermission() {
3419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3420 }
3421
paulhu5a773602019-08-23 19:17:33 +08003422 private void enforceSettingsPermission() {
3423 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003424 }
3425
Michele Berionne5e411512020-11-13 02:36:59 +00003426 private void enforceRebootPermission() {
3427 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3428 }
3429
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003430 private String createTelUrl(String number) {
3431 if (TextUtils.isEmpty(number)) {
3432 return null;
3433 }
3434
Jake Hambye994d462014-02-03 13:10:13 -08003435 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003436 }
3437
Ihab Awadf9e92732013-12-05 18:02:52 -08003438 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003439 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3440 }
3441
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003442 private static void logv(String msg) {
3443 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3444 }
3445
Ihab Awadf9e92732013-12-05 18:02:52 -08003446 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003447 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3448 }
3449
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003450 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003451 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003452 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003453 }
3454
Sanket Padawe356d7632015-06-22 14:03:32 -07003455 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003456 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 final Phone phone = PhoneFactory.getPhone(slotIndex);
3460 if (phone == null) {
3461 return PhoneConstants.PHONE_TYPE_NONE;
3462 } else {
3463 return phone.getPhoneType();
3464 }
3465 } finally {
3466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003468 }
3469
3470 /**
3471 * Returns the CDMA ERI icon index to display
3472 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003473 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003474 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3475 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3476 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003477 }
3478
Sanket Padawe356d7632015-06-22 14:03:32 -07003479 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003480 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3481 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003483 mApp, subId, callingPackage, callingFeatureId,
3484 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003485 return -1;
3486 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003487
3488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 final Phone phone = getPhone(subId);
3491 if (phone != null) {
3492 return phone.getCdmaEriIconIndex();
3493 } else {
3494 return -1;
3495 }
3496 } finally {
3497 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003498 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003499 }
3500
3501 /**
3502 * Returns the CDMA ERI icon mode,
3503 * 0 - ON
3504 * 1 - FLASHING
3505 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003506 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003507 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3508 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3509 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003510 }
3511
Sanket Padawe356d7632015-06-22 14:03:32 -07003512 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003513 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3514 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003516 mApp, subId, callingPackage, callingFeatureId,
3517 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003518 return -1;
3519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520
3521 final long identity = Binder.clearCallingIdentity();
3522 try {
3523 final Phone phone = getPhone(subId);
3524 if (phone != null) {
3525 return phone.getCdmaEriIconMode();
3526 } else {
3527 return -1;
3528 }
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003532 }
3533
3534 /**
3535 * Returns the CDMA ERI text,
3536 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003537 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003538 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3539 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3540 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003541 }
3542
Sanket Padawe356d7632015-06-22 14:03:32 -07003543 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003544 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3545 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003547 mApp, subId, callingPackage, callingFeatureId,
3548 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003549 return null;
3550 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 final Phone phone = getPhone(subId);
3555 if (phone != null) {
3556 return phone.getCdmaEriText();
3557 } else {
3558 return null;
3559 }
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003563 }
3564
3565 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003566 * Returns the CDMA MDN.
3567 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003568 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003569 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3571 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572
3573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003576 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577 return phone.getLine1Number();
3578 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003579 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003580 return null;
3581 }
3582 } finally {
3583 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003584 }
3585 }
3586
3587 /**
3588 * Returns the CDMA MIN.
3589 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003590 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003591 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3593 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594
3595 final long identity = Binder.clearCallingIdentity();
3596 try {
3597 final Phone phone = getPhone(subId);
3598 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3599 return phone.getCdmaMin();
3600 } else {
3601 return null;
3602 }
3603 } finally {
3604 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003605 }
3606 }
3607
Hall Liud892bec2018-11-30 14:51:45 -08003608 @Override
3609 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3610 INumberVerificationCallback callback, String callingPackage) {
3611 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3612 != PERMISSION_GRANTED) {
3613 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3614 }
3615 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3616
3617 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3618 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003619 throw new SecurityException("Calling package must be configured in the device config: "
3620 + "calling package: " + callingPackage
3621 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003622 }
3623
3624 if (range == null) {
3625 throw new NullPointerException("Range must be non-null");
3626 }
3627
3628 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003629 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003630
3631 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3632 }
3633
Junda Liuca05d5d2014-08-14 22:36:34 -07003634 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003635 * Returns true if CDMA provisioning needs to run.
3636 */
3637 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638 final long identity = Binder.clearCallingIdentity();
3639 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003640 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003644 }
3645
3646 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003647 * Sets the voice mail number of a given subId.
3648 */
3649 @Override
3650 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003651 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3652 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653
3654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3657 new Pair<String, String>(alphaTag, number), new Integer(subId));
3658 return success;
3659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003662 }
3663
Ta-wei Yen87c49842016-05-13 21:19:52 -07003664 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003665 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003667 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3668 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003669 if (!TextUtils.equals(callingPackage, systemDialer)) {
3670 throw new SecurityException("caller must be system dialer");
3671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3676 if (phoneAccountHandle == null) {
3677 return null;
3678 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003679 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003682 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003683 }
3684
3685 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003686 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3687 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003688 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003690 mApp, subId, callingPackage, callingFeatureId,
3691 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003692 return null;
3693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003695 final long identity = Binder.clearCallingIdentity();
3696 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003697 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003701 }
3702
3703 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003704 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3705 VisualVoicemailSmsFilterSettings settings) {
3706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707
3708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003711 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003715 }
3716
3717 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003718 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003720
3721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003728 }
3729
3730 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003731 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3732 String callingPackage, int subId) {
3733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
3737 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003738 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739 } finally {
3740 Binder.restoreCallingIdentity(identity);
3741 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003742 }
3743
3744 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003745 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003746 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747
3748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003751 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003755 }
3756
3757 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003758 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3759 String callingAttributionTag, int subId, String number, int port, String text,
3760 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003761 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003762 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003763 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003764 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003765 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3766 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003767 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003768
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003769 /**
fionaxu0152e512016-11-14 13:36:14 -08003770 * Sets the voice activation state of a given subId.
3771 */
3772 @Override
3773 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3775 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776
3777 final long identity = Binder.clearCallingIdentity();
3778 try {
3779 final Phone phone = getPhone(subId);
3780 if (phone != null) {
3781 phone.setVoiceActivationState(activationState);
3782 } else {
3783 loge("setVoiceActivationState fails with invalid subId: " + subId);
3784 }
3785 } finally {
3786 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003787 }
3788 }
3789
3790 /**
3791 * Sets the data activation state of a given subId.
3792 */
3793 @Override
3794 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3796 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797
3798 final long identity = Binder.clearCallingIdentity();
3799 try {
3800 final Phone phone = getPhone(subId);
3801 if (phone != null) {
3802 phone.setDataActivationState(activationState);
3803 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003804 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805 }
3806 } finally {
3807 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003808 }
3809 }
3810
3811 /**
3812 * Returns the voice activation state of a given subId.
3813 */
3814 @Override
3815 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003816 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817
fionaxu0152e512016-11-14 13:36:14 -08003818 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819 final long identity = Binder.clearCallingIdentity();
3820 try {
3821 if (phone != null) {
3822 return phone.getVoiceActivationState();
3823 } else {
3824 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3825 }
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003828 }
3829 }
3830
3831 /**
3832 * Returns the data activation state of a given subId.
3833 */
3834 @Override
3835 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837
fionaxu0152e512016-11-14 13:36:14 -08003838 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 if (phone != null) {
3842 return phone.getDataActivationState();
3843 } else {
3844 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3845 }
3846 } finally {
3847 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003848 }
3849 }
3850
3851 /**
Wink Saville36469e72014-06-11 15:17:00 -07003852 * Returns the unread count of voicemails for a subId
3853 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003854 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003855 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3856 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003858 mApp, subId, callingPackage, callingFeatureId,
3859 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003860 return 0;
3861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003862 final long identity = Binder.clearCallingIdentity();
3863 try {
3864 final Phone phone = getPhone(subId);
3865 if (phone != null) {
3866 return phone.getVoiceMessageCount();
3867 } else {
3868 return 0;
3869 }
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003873 }
3874
3875 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003876 * returns true, if the device is in a state where both voice and data
3877 * are supported simultaneously. This can change based on location or network condition.
3878 */
3879 @Override
3880 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003881 final long identity = Binder.clearCallingIdentity();
3882 try {
3883 final Phone phone = getPhone(subId);
3884 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3885 } finally {
3886 Binder.restoreCallingIdentity(identity);
3887 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003888 }
3889
3890 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003891 * Send the dialer code if called from the current default dialer or the caller has
3892 * carrier privilege.
3893 * @param inputCode The dialer code to send
3894 */
3895 @Override
3896 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003897 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003898 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003899 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3900 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003901 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003902 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003903 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905
3906 final long identity = Binder.clearCallingIdentity();
3907 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003908 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 } finally {
3910 Binder.restoreCallingIdentity(identity);
3911 }
fionaxu235cc5e2017-03-06 22:25:57 -08003912 }
3913
Pengquan Menga1bb6272018-09-06 09:59:22 -07003914 @Override
3915 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003916 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003917 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003918 mApp, subId, "getNetworkSelectionMode");
3919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 if (!isActiveSubscription(subId)) {
3922 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3923 }
3924 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3925 } finally {
3926 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003927 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003928 }
3929
Brad Ebinger35c841c2018-10-01 10:40:55 -07003930 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003931 public boolean isInEmergencySmsMode() {
3932 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3933 final long identity = Binder.clearCallingIdentity();
3934 try {
3935 for (Phone phone : PhoneFactory.getPhones()) {
3936 if (phone.isInEmergencySmsMode()) {
3937 return true;
3938 }
3939 }
3940 } finally {
3941 Binder.restoreCallingIdentity(identity);
3942 }
3943 return false;
3944 }
3945
shilu366312e2019-12-17 09:28:10 -08003946 /**
3947 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3948 * @param subId The subscription to use to check the configuration.
3949 * @param c The callback that will be used to send the result.
3950 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003951 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003952 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3953 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003954 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003955 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003956
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003957 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3959 "IMS not available on device.");
3960 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 final long token = Binder.clearCallingIdentity();
3962 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07003963 int slotId = getSlotIndexOrException(subId);
3964 verifyImsMmTelConfiguredOrThrow(slotId);
3965 ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003966 } catch (ImsException e) {
3967 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 } finally {
3969 Binder.restoreCallingIdentity(token);
3970 }
3971 }
3972
shilu366312e2019-12-17 09:28:10 -08003973 /**
3974 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3975 * @param subId The subscription to use to check the configuration.
3976 * @param c The callback that will be used to send the result.
3977 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003979 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003980 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003981 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003982 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3983 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3984 }
Meng Wangafbc5852019-09-19 17:37:13 -07003985 final long token = Binder.clearCallingIdentity();
3986 try {
Meng Wangafbc5852019-09-19 17:37:13 -07003987 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3988 .removeRegistrationCallbackForSubscription(c, subId);
3989 } catch (ImsException e) {
3990 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3991 + "is inactive, ignoring unregister.");
3992 // If the subscription is no longer active, just return, since the callback
3993 // will already have been removed internally.
3994 } finally {
3995 Binder.restoreCallingIdentity(token);
3996 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 }
3998
Brad Ebingera34a6c22019-10-22 17:36:18 -07003999 /**
4000 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
4001 */
4002 @Override
4003 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
4004 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
4005 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4006 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4007 "IMS not available on device.");
4008 }
4009 final long token = Binder.clearCallingIdentity();
4010 try {
4011 Phone phone = getPhone(subId);
4012 if (phone == null) {
4013 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4014 + subId + "'");
4015 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4016 }
4017 phone.getImsRegistrationState(regState -> {
4018 try {
4019 consumer.accept((regState == null)
4020 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
4021 } catch (RemoteException e) {
4022 // Ignore if the remote process is no longer available to call back.
4023 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4024 }
4025 });
4026 } finally {
4027 Binder.restoreCallingIdentity(token);
4028 }
4029 }
4030
4031 /**
4032 * Get the transport type for the IMS service registration state.
4033 */
4034 @Override
4035 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07004036 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004037 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07004038 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4039 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4040 "IMS not available on device.");
4041 }
4042 final long token = Binder.clearCallingIdentity();
4043 try {
4044 Phone phone = getPhone(subId);
4045 if (phone == null) {
4046 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
4047 + subId + "'");
4048 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4049 }
4050 phone.getImsRegistrationTech(regTech -> {
4051 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
4052 int regTechConverted = (regTech == null)
4053 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
4054 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
4055 regTechConverted);
4056 try {
4057 consumer.accept(regTechConverted);
4058 } catch (RemoteException e) {
4059 // Ignore if the remote process is no longer available to call back.
4060 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
4061 }
4062 });
4063 } finally {
4064 Binder.restoreCallingIdentity(token);
4065 }
4066 }
4067
shilu366312e2019-12-17 09:28:10 -08004068 /**
4069 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4070 * @param subId The subscription to use to check the configuration.
4071 * @param c The callback that will be used to send the result.
4072 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004074 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
4075 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07004076 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004077 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004078 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4079 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4080 "IMS not available on device.");
4081 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 final long token = Binder.clearCallingIdentity();
4083 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004084 int slotId = getSlotIndexOrException(subId);
4085 verifyImsMmTelConfiguredOrThrow(slotId);
4086 ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004087 } catch (ImsException e) {
4088 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 } finally {
4090 Binder.restoreCallingIdentity(token);
4091 }
4092 }
4093
shilu366312e2019-12-17 09:28:10 -08004094 /**
4095 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4096 * @param subId The subscription to use to check the configuration.
4097 * @param c The callback that will be used to send the result.
4098 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004100 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07004101 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004102 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004103 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4104 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4105 }
Meng Wangafbc5852019-09-19 17:37:13 -07004106
4107 final long token = Binder.clearCallingIdentity();
4108 try {
Meng Wangafbc5852019-09-19 17:37:13 -07004109 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004110 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07004111 } catch (ImsException e) {
4112 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
4113 + "is inactive, ignoring unregister.");
4114 // If the subscription is no longer active, just return, since the callback
4115 // will already have been removed internally.
4116 } finally {
4117 Binder.restoreCallingIdentity(token);
4118 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 }
4120
4121 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004122 public boolean isCapable(int subId, int capability, int regTech) {
4123 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 final long token = Binder.clearCallingIdentity();
4125 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004126 int slotId = getSlotIndexOrException(subId);
4127 verifyImsMmTelConfiguredOrThrow(slotId);
4128 return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004129 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004130 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4131 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004132 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004133 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4134 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 } finally {
4136 Binder.restoreCallingIdentity(token);
4137 }
4138 }
4139
4140 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004141 public boolean isAvailable(int subId, int capability, int regTech) {
4142 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 final long token = Binder.clearCallingIdentity();
4144 try {
4145 Phone phone = getPhone(subId);
4146 if (phone == null) return false;
4147 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004148 } catch (com.android.ims.ImsException e) {
4149 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4150 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 } finally {
4152 Binder.restoreCallingIdentity(token);
4153 }
4154 }
4155
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004156 /**
4157 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4158 * subscription.
4159 * @param subId The subscription to use to check the configuration.
4160 * @param callback The callback that will be used to send the result.
4161 * @param capability The MmTelFeature capability that will be used to send the result.
4162 * @param transportType The transport type of the MmTelFeature capability.
4163 */
4164 @Override
4165 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4166 int transportType) {
4167 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4168 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4169 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4170 "IMS not available on device.");
4171 }
4172 final long token = Binder.clearCallingIdentity();
4173 try {
4174 int slotId = getSlotIndex(subId);
4175 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4176 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4177 + subId + "'");
4178 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4179 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004180 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004181 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4182 transportType, aBoolean -> {
4183 try {
4184 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4185 } catch (RemoteException e) {
4186 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4187 + "running. Ignore");
4188 }
4189 });
Brad Ebinger919631e2021-06-02 17:46:35 -07004190 } catch (ImsException e) {
4191 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004192 } finally {
4193 Binder.restoreCallingIdentity(token);
4194 }
4195 }
4196
shilu366312e2019-12-17 09:28:10 -08004197 /**
4198 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4199 * @param subId The subscription to use to check the configuration.
4200 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 @Override
4202 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004203 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004204 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004205
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 final long token = Binder.clearCallingIdentity();
4207 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004208 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004209 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004210 return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004211 } catch (ImsException e) {
4212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 } finally {
4214 Binder.restoreCallingIdentity(token);
4215 }
4216 }
4217
4218 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004219 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004221 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 final long identity = Binder.clearCallingIdentity();
4223 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004224 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004225 // This setting doesn't require an active ImsService connection, so do not verify. The
4226 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004227 ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004228 } catch (ImsException e) {
4229 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
4233 }
4234
shilu366312e2019-12-17 09:28:10 -08004235 /**
4236 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4237 * @param subId The subscription to use to check the configuration.
4238 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004240 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004241 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004242 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 final long identity = Binder.clearCallingIdentity();
4244 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004245 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004246 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004247 return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004248 } catch (ImsException e) {
4249 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
4253 }
4254
4255 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004256 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004258 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 final long identity = Binder.clearCallingIdentity();
4260 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004261 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004262 // This setting doesn't require an active ImsService connection, so do not verify. The
4263 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004264 ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004265 } catch (ImsException e) {
4266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
4270 }
4271
shilu366312e2019-12-17 09:28:10 -08004272 /**
4273 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4274 * @param subId The subscription to use to check the configuration.
4275 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 @Override
4277 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004278 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004279 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 final long identity = Binder.clearCallingIdentity();
4281 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004282 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004283 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004284 return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004285 } catch (ImsException e) {
4286 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
4290 }
4291
4292 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004293 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004295 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 final long identity = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004298 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004299 // This setting doesn't require an active ImsService connection, so do not verify. The
4300 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004301 ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004302 } catch (ImsException e) {
4303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307 }
4308
shilu366312e2019-12-17 09:28:10 -08004309 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004310 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4311 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4312 * @param subId The subscription to use to check the configuration.
4313 */
4314 @Override
4315 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004316 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004317 mApp, subId, "isCrossSimCallingEnabledByUser");
4318 final long identity = Binder.clearCallingIdentity();
4319 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004320 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004321 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004322 return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser();
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004323 } catch (ImsException e) {
4324 throw new ServiceSpecificException(e.getCode());
4325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
4328 }
4329
4330 /**
4331 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4332 * Requires MODIFY_PHONE_STATE permission.
4333 * @param subId The subscription to use to check the configuration.
4334 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4335 * false otherwise
4336 */
4337 @Override
4338 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4340 "setCrossSimCallingEnabled");
4341 final long identity = Binder.clearCallingIdentity();
4342 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004343 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004344 // This setting doesn't require an active ImsService connection, so do not verify. The
4345 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004346 ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled);
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004347 } catch (ImsException e) {
4348 throw new ServiceSpecificException(e.getCode());
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
4351 }
4352 }
4353
4354 /**
shilu366312e2019-12-17 09:28:10 -08004355 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4356 * @param subId The subscription to use to check the configuration.
4357 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004359
Brad Ebinger35c841c2018-10-01 10:40:55 -07004360 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004361 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004362 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004363 final long identity = Binder.clearCallingIdentity();
4364 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004365 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004366 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004367 return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004368 } catch (ImsException e) {
4369 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004370 } finally {
4371 Binder.restoreCallingIdentity(identity);
4372 }
4373 }
4374
4375 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004376 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004378 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004379 final long identity = Binder.clearCallingIdentity();
4380 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004381 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004382 // This setting doesn't require an active ImsService connection, so do not verify. The
4383 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004384 ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004385 } catch (ImsException e) {
4386 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004387 } finally {
4388 Binder.restoreCallingIdentity(identity);
4389 }
4390 }
4391
4392 @Override
4393 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4395 "setVoWiFiNonPersistent");
4396 final long identity = Binder.clearCallingIdentity();
4397 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004398 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004399 // This setting will be ignored if the ImsService isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004400 ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004401 } catch (ImsException e) {
4402 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
4406 }
4407
shilu366312e2019-12-17 09:28:10 -08004408 /**
4409 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4410 * @param subId The subscription to use to check the configuration.
4411 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004412 @Override
4413 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004414 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004415 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004416 final long identity = Binder.clearCallingIdentity();
4417 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004418 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004419 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004420 return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004421 } catch (ImsException e) {
4422 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
4426 }
4427
4428 @Override
4429 public void setVoWiFiModeSetting(int subId, int mode) {
4430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4431 "setVoWiFiModeSetting");
4432 final long identity = Binder.clearCallingIdentity();
4433 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004434 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004435 // This setting doesn't require an active ImsService connection, so do not verify. The
4436 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004437 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004438 } catch (ImsException e) {
4439 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004440 } finally {
4441 Binder.restoreCallingIdentity(identity);
4442 }
4443 }
4444
4445 @Override
4446 public int getVoWiFiRoamingModeSetting(int subId) {
4447 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4448 final long identity = Binder.clearCallingIdentity();
4449 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004450 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004451 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004452 return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004453 } catch (ImsException e) {
4454 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
4458 }
4459
4460 @Override
4461 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4463 "setVoWiFiRoamingModeSetting");
4464 final long identity = Binder.clearCallingIdentity();
4465 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004466 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004467 // This setting doesn't require an active ImsService connection, so do not verify. The
4468 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004469 ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004470 } catch (ImsException e) {
4471 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
4475 }
4476
4477 @Override
4478 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4479 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4480 "setRttCapabilityEnabled");
4481 final long identity = Binder.clearCallingIdentity();
4482 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004483 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004484 // This setting doesn't require an active ImsService connection, so do not verify. The
4485 // new setting will be picked up when the ImsService comes up next if it isn't up.
Brad Ebinger919631e2021-06-02 17:46:35 -07004486 ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004487 } catch (ImsException e) {
4488 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004489 } finally {
4490 Binder.restoreCallingIdentity(identity);
4491 }
4492 }
4493
shilu366312e2019-12-17 09:28:10 -08004494 /**
4495 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4496 * @param subId The subscription to use to check the configuration.
4497 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004498 @Override
4499 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004500 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004501 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004502 final long identity = Binder.clearCallingIdentity();
4503 try {
Brad Ebinger919631e2021-06-02 17:46:35 -07004504 int slotId = getSlotIndexOrException(subId);
Brad Ebinger735c5ce2021-07-12 13:58:21 -07004505 // This setting doesn't require an active ImsService connection, so do not verify.
Brad Ebinger919631e2021-06-02 17:46:35 -07004506 return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004507 } catch (ImsException e) {
4508 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004509 } finally {
4510 Binder.restoreCallingIdentity(identity);
4511 }
4512 }
4513
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004514 @Override
4515 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4516 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4517 final long identity = Binder.clearCallingIdentity();
4518 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004519 if (!isImsAvailableOnDevice()) {
4520 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4521 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004522 }
Brad Ebinger919631e2021-06-02 17:46:35 -07004523 int slotId = getSlotIndexOrException(subId);
4524 verifyImsMmTelConfiguredOrThrow(slotId);
4525 ImsManager.getInstance(mApp, slotId)
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004526 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004527 } catch (ImsException e) {
4528 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
4532 }
4533
4534 @Override
4535 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4536 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4537 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004538 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4539 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4540 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004541 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004542 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004543 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004544 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004545 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4546 + "is inactive, ignoring unregister.");
4547 // If the subscription is no longer active, just return, since the callback will already
4548 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
4552 }
4553
allenwtsu99c623b2020-01-03 18:24:23 +08004554
4555 private void checkModifyPhoneStatePermission(int subId, String message) {
4556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4557 message);
4558 }
4559
4560 private boolean isImsProvisioningRequired(int subId, int capability,
4561 boolean isMmtelCapability) {
4562 Phone phone = getPhone(subId);
4563 if (phone == null) {
4564 loge("phone instance null for subid " + subId);
4565 return false;
4566 }
4567 if (isMmtelCapability) {
4568 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4569 return false;
4570 }
4571 } else {
4572 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4573 return false;
4574 }
4575 }
4576 return true;
4577 }
4578
4579 @Override
4580 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4581 boolean isProvisioned) {
4582 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4583
4584 final long identity = Binder.clearCallingIdentity();
4585 try {
4586 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4587 if (!isImsProvisioningRequired(subId, capability, false)) {
4588 return;
4589 }
4590
4591 // this capability requires provisioning, route to the correct API.
4592 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4593 switch (capability) {
4594 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4595 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4596 ims.setEabProvisioned(isProvisioned);
4597 break;
4598 default: {
4599 throw new IllegalArgumentException("Tried to set provisioning for "
4600 + "rcs capability '" + capability + "', which does not require "
4601 + "provisioning.");
4602 }
4603 }
4604 } finally {
4605 Binder.restoreCallingIdentity(identity);
4606 }
4607
4608 }
4609
4610
4611 @Override
4612 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4613 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4614 final long identity = Binder.clearCallingIdentity();
4615 try {
4616 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4617 if (!isImsProvisioningRequired(subId, capability, false)) {
4618 return true;
4619 }
4620
4621 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4622 switch (capability) {
4623 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4624 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4625 return ims.isEabProvisionedOnDevice();
4626
4627 default: {
4628 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4629 + "capability '" + capability + "', which does not require "
4630 + "provisioning.");
4631 }
4632 }
4633
4634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
4637 }
4638
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004639 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004640 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4641 boolean isProvisioned) {
4642 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004643 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4644 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4645 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004646 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4647 }
allenwtsu99c623b2020-01-03 18:24:23 +08004648 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649 final long identity = Binder.clearCallingIdentity();
4650 try {
4651 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004652 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004653 return;
4654 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004655 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4656 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4657 loge("setImsProvisioningStatusForCapability: called for technology that does "
4658 + "not support provisioning - " + tech);
4659 return;
4660 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004661
4662 // this capability requires provisioning, route to the correct API.
4663 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4664 switch (capability) {
4665 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4666 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4667 ims.setVolteProvisioned(isProvisioned);
4668 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4669 ims.setWfcProvisioned(isProvisioned);
4670 }
4671 break;
4672 }
4673 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4674 // There is currently no difference in VT provisioning type.
4675 ims.setVtProvisioned(isProvisioned);
4676 break;
4677 }
4678 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4679 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4680 // change the capability of the feature instead if needed.
4681 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4682 == isProvisioned) {
4683 // No change in provisioning.
4684 return;
4685 }
4686 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4687 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004688 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004689 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4691 + ", Exception" + e.getMessage());
4692 }
4693 break;
4694 }
4695 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004696 throw new IllegalArgumentException("Tried to set provisioning for "
4697 + "MmTel capability '" + capability + "', which does not require "
4698 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004699 }
4700 }
4701
4702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
4705 }
4706
4707 @Override
4708 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4709 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004710 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4711 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4712 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004713 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4714 }
4715 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4716 final long identity = Binder.clearCallingIdentity();
4717 try {
4718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004719 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004720 return true;
4721 }
4722
Brad Ebinger0d79c572021-04-17 15:20:49 -07004723 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4724 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4725 loge("getImsProvisioningStatusForCapability: called for technology that does "
4726 + "not support provisioning - " + tech);
4727 return true;
4728 }
4729
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4731 switch (capability) {
4732 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4733 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4734 return ims.isVolteProvisionedOnDevice();
4735 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4736 return ims.isWfcProvisionedOnDevice();
4737 }
4738 // This should never happen, since we are checking tech above to make sure it
4739 // is either LTE or IWLAN.
4740 throw new IllegalArgumentException("Invalid radio technology for voice "
4741 + "capability.");
4742 }
4743 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4744 // There is currently no difference in VT provisioning type.
4745 return ims.isVtProvisionedOnDevice();
4746 }
4747 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4748 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4749 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4750 }
4751 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004752 throw new IllegalArgumentException(
4753 "Tried to get provisioning for MmTel capability '" + capability
4754 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004755 }
4756 }
4757
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
4760 }
4761 }
4762
4763 @Override
4764 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4765 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4766 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4767 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4768 }
4769 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4770 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4771 return (provisionedBits & capability) > 0;
4772 }
4773
4774 @Override
4775 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4776 boolean isProvisioned) {
4777 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4778 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4779 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4780 }
4781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4782 "setProvisioningStatusForCapability");
4783 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4784 // If the current provisioning status for capability already matches isProvisioned,
4785 // do nothing.
4786 if (((provisionedBits & capability) > 0) == isProvisioned) {
4787 return;
4788 }
4789 if (isProvisioned) {
4790 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4791 } else {
4792 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4793 }
4794 }
4795
4796 /**
4797 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4798 * technology. The bitfield should mirror the bitfield defined by
4799 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4800 */
4801 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4802 String key = getMmTelProvisioningKey(subId, tech);
4803 // Default is no capabilities are provisioned.
4804 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4805 }
4806
4807 /**
4808 * Sets the MmTel capability provisioning bitfield (defined by
4809 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4810 * technology specified.
4811 *
4812 * Note: This is a synchronous command and should not be called on UI thread.
4813 */
4814 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4815 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4816 String key = getMmTelProvisioningKey(subId, tech);
4817 editor.putInt(key, newField);
4818 editor.commit();
4819 }
4820
4821 private static String getMmTelProvisioningKey(int subId, int tech) {
4822 // resulting key is provision_ims_mmtel_{subId}_{tech}
4823 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4824 }
4825
4826 /**
4827 * Query CarrierConfig to see if the specified capability requires provisioning for the
4828 * carrier associated with the subscription id.
4829 */
4830 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4831 int capability) {
4832 CarrierConfigManager configManager = new CarrierConfigManager(context);
4833 PersistableBundle c = configManager.getConfigForSubId(subId);
4834 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004835 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004836 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4837 false);
4838 boolean requireVoiceVtProvisioning = c.getBoolean(
4839 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4840
4841 // First check to make sure that the capability requires provisioning.
4842 switch (capability) {
4843 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4844 // intentional fallthrough
4845 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4846 if (requireVoiceVtProvisioning) {
4847 // Voice and Video requires provisioning
4848 return true;
4849 }
4850 break;
4851 }
4852 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4853 if (requireUtProvisioning) {
4854 // UT requires provisioning
4855 return true;
4856 }
4857 break;
4858 }
4859 }
4860 return false;
4861 }
4862
allenwtsu99c623b2020-01-03 18:24:23 +08004863 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4864 int capability) {
4865 CarrierConfigManager configManager = new CarrierConfigManager(context);
4866 PersistableBundle c = configManager.getConfigForSubId(subId);
4867
4868 boolean requireRcsProvisioning = c.getBoolean(
4869 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4870
4871 // First check to make sure that the capability requires provisioning.
4872 switch (capability) {
4873 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4874 // intentional fallthrough
4875 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4876 if (requireRcsProvisioning) {
4877 // OPTION or PRESENCE requires provisioning
4878 return true;
4879 }
4880 break;
4881 }
4882 }
4883 return false;
4884 }
4885
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004886 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004887 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4889 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4890 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004891 enforceReadPrivilegedPermission("getImsProvisioningInt");
4892 final long identity = Binder.clearCallingIdentity();
4893 try {
4894 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004895 int slotId = getSlotIndex(subId);
4896 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4897 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4898 + subId + "' for key:" + key);
4899 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4900 }
calvinpanb5a34062021-02-08 19:59:36 +08004901 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004902 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004903 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4904 + subId + "' for key:" + key);
4905 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004906 } finally {
4907 Binder.restoreCallingIdentity(identity);
4908 }
4909 }
4910
4911 @Override
4912 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4914 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4915 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004916 enforceReadPrivilegedPermission("getImsProvisioningString");
4917 final long identity = Binder.clearCallingIdentity();
4918 try {
4919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004920 int slotId = getSlotIndex(subId);
4921 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4922 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4923 + subId + "' for key:" + key);
4924 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4925 }
calvinpanb5a34062021-02-08 19:59:36 +08004926 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004927 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004928 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4929 + subId + "' for key:" + key);
4930 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004931 } finally {
4932 Binder.restoreCallingIdentity(identity);
4933 }
4934 }
4935
4936 @Override
4937 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004938 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4939 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4940 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4942 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004943 final long identity = Binder.clearCallingIdentity();
4944 try {
4945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004946 int slotId = getSlotIndex(subId);
4947 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4948 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4949 + subId + "' for key:" + key);
4950 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4951 }
calvinpanb5a34062021-02-08 19:59:36 +08004952 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4953 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004954 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004955 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004956 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
4960 }
4961
4962 @Override
4963 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004964 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4965 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4966 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4968 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004972 int slotId = getSlotIndex(subId);
4973 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4974 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4975 + subId + "' for key:" + key);
4976 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4977 }
calvinpanb5a34062021-02-08 19:59:36 +08004978 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4979 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004980 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004981 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004982 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
4986 }
4987
Brad Ebinger919631e2021-06-02 17:46:35 -07004988 /**
4989 * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL
4990 * for the given slot ID or no ImsResolver instance has been created.
4991 * @param slotId The slot ID that the IMS service is created for.
4992 * @throws ImsException If there is no ImsService configured for this slot.
4993 */
4994 private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException {
4995 if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId,
4996 ImsFeature.FEATURE_MMTEL)) {
4997 throw new ImsException("This subscription does not support MMTEL over IMS",
4998 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
4999 }
5000 }
5001
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005002 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005003 int slotId = SubscriptionManager.getSlotIndex(subId);
5004 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07005005 throw new ImsException("Invalid Subscription Id, subId=" + subId,
5006 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07005007 }
5008 return slotId;
5009 }
5010
Brad Ebinger1c8542e2019-01-14 13:43:14 -08005011 private int getSlotIndex(int subId) {
5012 int slotId = SubscriptionManager.getSlotIndex(subId);
5013 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
5014 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
5015 }
5016 return slotId;
5017 }
5018
Wink Saville36469e72014-06-11 15:17:00 -07005019 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07005020 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07005021 */
5022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005023 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
5024 String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07005025 try {
5026 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5027 } catch (SecurityException se) {
5028 EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid());
5029 throw new SecurityException("Package " + callingPackage + " does not belong to "
5030 + Binder.getCallingUid());
5031 }
Nathan Haroldf096d982020-11-18 17:18:06 -08005032 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005033 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005034 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07005035 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07005036 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005037 mApp, subId, callingPackage, callingFeatureId,
5038 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005039 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5040 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 final long identity = Binder.clearCallingIdentity();
5043 try {
5044 final Phone phone = getPhone(subId);
5045 if (phone != null) {
5046 return phone.getServiceState().getDataNetworkType();
5047 } else {
5048 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5049 }
5050 } finally {
5051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005053 }
5054
5055 /**
5056 * Returns the data network type
5057 */
5058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005059 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08005060 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
5061 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005062 }
5063
5064 /**
5065 * Returns the data network type for a subId
5066 */
5067 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005068 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
5069 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005071 mApp, subId, callingPackage, callingFeatureId,
5072 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005073 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5074 }
5075
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 final Phone phone = getPhone(subId);
5079 if (phone != null) {
5080 return phone.getServiceState().getDataNetworkType();
5081 } else {
5082 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5083 }
5084 } finally {
5085 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005086 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005087 }
5088
5089 /**
Wink Saville36469e72014-06-11 15:17:00 -07005090 * Returns the Voice network type for a subId
5091 */
5092 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005093 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
5094 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005095 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005096 mApp, subId, callingPackage, callingFeatureId,
5097 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07005098 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5099 }
5100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101 final long identity = Binder.clearCallingIdentity();
5102 try {
5103 final Phone phone = getPhone(subId);
5104 if (phone != null) {
5105 return phone.getServiceState().getVoiceNetworkType();
5106 } else {
5107 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
5108 }
5109 } finally {
5110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005112 }
5113
5114 /**
5115 * @return true if a ICC card is present
5116 */
5117 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07005118 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005119 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
5120 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07005121 }
5122
5123 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005124 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07005125 */
Sanket Padawe356d7632015-06-22 14:03:32 -07005126 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005127 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 final long identity = Binder.clearCallingIdentity();
5129 try {
5130 final Phone phone = PhoneFactory.getPhone(slotIndex);
5131 if (phone != null) {
5132 return phone.getIccCard().hasIccCard();
5133 } else {
5134 return false;
5135 }
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08005138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005139 }
5140
5141 /**
5142 * Return if the current radio is LTE on CDMA. This
5143 * is a tri-state return value as for a period of time
5144 * the mode may be unknown.
5145 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005146 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005147 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08005148 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005149 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005150 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005151 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5152 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5153 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005154 }
5155
Sanket Padawe356d7632015-06-22 14:03:32 -07005156 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005157 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5158 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005159 try {
5160 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5161 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005162 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5163 }
5164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 final long identity = Binder.clearCallingIdentity();
5166 try {
5167 final Phone phone = getPhone(subId);
5168 if (phone == null) {
5169 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5170 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005171 return TelephonyProperties.lte_on_cdma_device()
5172 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 }
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005176 }
Wink Saville36469e72014-06-11 15:17:00 -07005177 }
5178
Wink Saville36469e72014-06-11 15:17:00 -07005179 /**
5180 * {@hide}
5181 * Returns Default subId, 0 in the case of single standby.
5182 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005183 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005184 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005185 }
5186
Shishir Agrawala9f32182016-04-12 12:00:16 -07005187 private int getSlotForDefaultSubscription() {
5188 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5189 }
5190
Wink Savilleb564aae2014-10-23 10:18:09 -07005191 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005192 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005193 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005194
Pengquan Menge92a50d2018-09-21 15:54:48 -07005195 private boolean isActiveSubscription(int subId) {
5196 return mSubscriptionController.isActiveSubId(subId);
5197 }
5198
Ihab Awadf2177b72013-11-25 13:33:23 -08005199 /**
5200 * @see android.telephony.TelephonyManager.WifiCallingChoices
5201 */
5202 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203 final long identity = Binder.clearCallingIdentity();
5204 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005205 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5207 getWhenToMakeWifiCallsDefaultPreference());
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005211 }
5212
5213 /**
5214 * @see android.telephony.TelephonyManager.WifiCallingChoices
5215 */
5216 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 final long identity = Binder.clearCallingIdentity();
5218 try {
5219 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005220 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5222 } finally {
5223 Binder.restoreCallingIdentity(identity);
5224 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005225 }
5226
Sailesh Nepald1e68152013-12-12 19:08:02 -08005227 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005228 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005229 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005230 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005231
Jordan Liu4c733742019-02-28 12:03:40 -08005232 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5233 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5234 if (phoneId == -1) {
5235 throw new IllegalArgumentException("Given slot index: " + slotIndex
5236 + " does not correspond to an active phone");
5237 }
5238 return PhoneFactory.getPhone(phoneId);
5239 }
5240
Shishir Agrawal566b7612013-10-28 14:41:00 -07005241 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005242 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5243 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5245 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005247 if (DBG) {
5248 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5249 }
5250 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5251 p2);
5252 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005253
Jordan Liu4c733742019-02-28 12:03:40 -08005254
5255 @Override
5256 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5257 int slotIndex, String callingPackage, String aid, int p2) {
5258 enforceModifyPermission();
5259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5260 if (DBG) {
5261 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5262 }
5263 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5264 callingPackage, aid, p2);
5265 }
5266
5267 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5268 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269 final long identity = Binder.clearCallingIdentity();
5270 try {
5271 if (TextUtils.equals(ISDR_AID, aid)) {
5272 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005273 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5274 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 if (bestComponent == null
5276 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5277 loge("The calling package is not allowed to access ISD-R.");
5278 throw new SecurityException(
5279 "The calling package is not allowed to access ISD-R.");
5280 }
Derek Tan740e1672017-06-27 14:56:27 -07005281 }
Derek Tan740e1672017-06-27 14:56:27 -07005282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005284 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5285 null /* workSource */);
5286 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 return response;
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
5290 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005291 }
5292
5293 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005294 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5296 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005297 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5298 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5299 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005300
Jordan Liu4c733742019-02-28 12:03:40 -08005301 @Override
5302 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5303 enforceModifyPermission();
5304 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5305 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5306 channel);
5307 }
5308
5309 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310 final long identity = Binder.clearCallingIdentity();
5311 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 if (channel < 0) {
5313 return false;
5314 }
Jordan Liu4c733742019-02-28 12:03:40 -08005315 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5316 null /* workSource */);
5317 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318 return success;
5319 } finally {
5320 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005321 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005322 }
5323
5324 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005325 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005326 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5328 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005329 if (DBG) {
5330 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5331 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5332 + p3 + " data=" + data);
5333 }
5334 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5335 command, p1, p2, p3, data);
5336 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005337
Jordan Liu4c733742019-02-28 12:03:40 -08005338 @Override
5339 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5340 int command, int p1, int p2, int p3, String data) {
5341 enforceModifyPermission();
5342 if (DBG) {
5343 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5344 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5345 + p3 + " data=" + data);
5346 }
5347 return iccTransmitApduLogicalChannelWithPermission(
5348 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5349 data);
5350 }
5351
5352 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5353 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 final long identity = Binder.clearCallingIdentity();
5355 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005356 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 return "";
5358 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005361 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5362 null /* workSource */);
5363 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 // Append the returned status code to the end of the response payload.
5366 String s = Integer.toHexString(
5367 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5368 if (response.payload != null) {
5369 s = IccUtils.bytesToHexString(response.payload) + s;
5370 }
5371 return s;
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005374 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005375 }
Jake Hambye994d462014-02-03 13:10:13 -08005376
Evan Charltonc66da362014-05-16 14:06:40 -07005377 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005378 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5379 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5381 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005383 if (DBG) {
5384 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5385 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5386 }
5387 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5388 cla, command, p1, p2, p3, data);
5389 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005390
Jordan Liu4c733742019-02-28 12:03:40 -08005391 @Override
5392 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5393 int command, int p1, int p2, int p3, String data) {
5394 enforceModifyPermission();
5395 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5396 if (DBG) {
5397 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5398 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5399 + " data=" + data);
5400 }
5401
5402 return iccTransmitApduBasicChannelWithPermission(
5403 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5404 p2, p3, data);
5405 }
5406
5407 // open APDU basic channel assuming the caller has sufficient permissions
5408 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5409 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5413 && TextUtils.equals(ISDR_AID, data)) {
5414 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005415 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5416 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005417 if (bestComponent == null
5418 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5419 loge("The calling package is not allowed to select ISD-R.");
5420 throw new SecurityException(
5421 "The calling package is not allowed to select ISD-R.");
5422 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005423 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005426 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5427 null /* workSource */);
5428 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 // Append the returned status code to the end of the response payload.
5431 String s = Integer.toHexString(
5432 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5433 if (response.payload != null) {
5434 s = IccUtils.bytesToHexString(response.payload) + s;
5435 }
5436 return s;
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005439 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005440 }
5441
5442 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005443 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005444 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5446 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
5450 if (DBG) {
5451 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5452 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5453 }
5454
5455 IccIoResult response =
5456 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5457 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5458 subId);
5459
5460 if (DBG) {
5461 log("Exchange SIM_IO [R]" + response);
5462 }
5463
5464 byte[] result = null;
5465 int length = 2;
5466 if (response.payload != null) {
5467 length = 2 + response.payload.length;
5468 result = new byte[length];
5469 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5470 } else {
5471 result = new byte[length];
5472 }
5473
5474 result[length - 1] = (byte) response.sw2;
5475 result[length - 2] = (byte) response.sw1;
5476 return result;
5477 } finally {
5478 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005479 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005480 }
5481
Nathan Haroldb3014052017-01-25 15:57:32 -08005482 /**
5483 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5484 * on a particular subscription
5485 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005486 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5487 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005489 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005490 return null;
5491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005492
5493 final long identity = Binder.clearCallingIdentity();
5494 try {
5495 if (appType != TelephonyManager.APPTYPE_USIM
5496 && appType != TelephonyManager.APPTYPE_SIM) {
5497 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5498 return null;
5499 }
5500 Object response = sendRequest(
5501 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5502 if (response instanceof String[]) {
5503 return (String[]) response;
5504 }
yincheng zhao2737e882019-09-06 17:06:54 -07005505 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005507 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 } finally {
5509 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005510 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005511 }
5512
yincheng zhao2737e882019-09-06 17:06:54 -07005513 /**
5514 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5515 * subscription.
5516 *
5517 * @param subId the id of the subscription.
5518 * @param appType the uicc app type, must be USIM or SIM.
5519 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5520 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005521 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005522 * @return number of fplmns that is successfully written to the SIM.
5523 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005524 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5525 String callingFeatureId) {
5526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5527 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005528 if (DBG) logv("no permissions for setForbiddenplmns");
5529 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5530 }
5531 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5532 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5533 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5534 }
5535 if (fplmns == null) {
5536 throw new IllegalArgumentException("Fplmn List provided is null");
5537 }
5538 for (String fplmn : fplmns) {
5539 if (!CellIdentity.isValidPlmn(fplmn)) {
5540 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5541 }
5542 }
5543 final long identity = Binder.clearCallingIdentity();
5544 try {
5545 Object response = sendRequest(
5546 CMD_SET_FORBIDDEN_PLMNS,
5547 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5548 subId);
5549 return (int) response;
5550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
5553 }
5554
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005555 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005556 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5558 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 final long identity = Binder.clearCallingIdentity();
5561 try {
5562 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5563 if (response.payload == null) {
5564 return "";
5565 }
Evan Charltonc66da362014-05-16 14:06:40 -07005566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 // Append the returned status code to the end of the response payload.
5568 String s = Integer.toHexString(
5569 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5570 s = IccUtils.bytesToHexString(response.payload) + s;
5571 return s;
5572 } finally {
5573 Binder.restoreCallingIdentity(identity);
5574 }
Evan Charltonc66da362014-05-16 14:06:40 -07005575 }
5576
Jake Hambye994d462014-02-03 13:10:13 -08005577 /**
5578 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5579 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5580 *
5581 * @param itemID the ID of the item to read
5582 * @return the NV item as a String, or null on error.
5583 */
5584 @Override
5585 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005586 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5588 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589
5590 final long identity = Binder.clearCallingIdentity();
5591 try {
5592 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005593 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5595 return value;
5596 } finally {
5597 Binder.restoreCallingIdentity(identity);
5598 }
Jake Hambye994d462014-02-03 13:10:13 -08005599 }
5600
5601 /**
5602 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5603 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5604 *
5605 * @param itemID the ID of the item to read
5606 * @param itemValue the value to write, as a String
5607 * @return true on success; false on any failure
5608 */
5609 @Override
5610 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005611 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5613 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614
5615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5618 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005619 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5621 return success;
5622 } finally {
5623 Binder.restoreCallingIdentity(identity);
5624 }
Jake Hambye994d462014-02-03 13:10:13 -08005625 }
5626
5627 /**
5628 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5629 * Used for device configuration by some CDMA operators.
5630 *
5631 * @param preferredRoamingList byte array containing the new PRL
5632 * @return true on success; false on any failure
5633 */
5634 @Override
5635 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5637 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638
5639 final long identity = Binder.clearCallingIdentity();
5640 try {
5641 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5642 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5643 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5644 return success;
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Jake Hambye994d462014-02-03 13:10:13 -08005648 }
5649
5650 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005651 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005652 * Used for device configuration by some CDMA operators.
5653 *
chen xu6dac5ab2018-10-26 17:39:23 -07005654 * @param slotIndex - device slot.
5655 *
Jake Hambye994d462014-02-03 13:10:13 -08005656 * @return true on success; false on any failure
5657 */
5658 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005659 public boolean resetModemConfig(int slotIndex) {
5660 Phone phone = PhoneFactory.getPhone(slotIndex);
5661 if (phone != null) {
5662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5663 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664
chen xu6dac5ab2018-10-26 17:39:23 -07005665 final long identity = Binder.clearCallingIdentity();
5666 try {
5667 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5668 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5669 return success;
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
5672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 }
chen xu6dac5ab2018-10-26 17:39:23 -07005674 return false;
5675 }
5676
5677 /**
5678 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5679 *
5680 * @param slotIndex - device slot.
5681 *
5682 * @return true on success; false on any failure
5683 */
5684 @Override
5685 public boolean rebootModem(int slotIndex) {
5686 Phone phone = PhoneFactory.getPhone(slotIndex);
5687 if (phone != null) {
5688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5689 mApp, phone.getSubId(), "rebootModem");
5690
5691 final long identity = Binder.clearCallingIdentity();
5692 try {
5693 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5694 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5695 return success;
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
5699 }
5700 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005701 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005702
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005703 public String[] getPcscfAddress(String apnType, String callingPackage,
5704 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005705 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5707 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005708 return new String[0];
5709 }
5710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 final long identity = Binder.clearCallingIdentity();
5712 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005713 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 } finally {
5715 Binder.restoreCallingIdentity(identity);
5716 }
Wink Saville36469e72014-06-11 15:17:00 -07005717 }
5718
Brad Ebinger51f743a2017-01-23 13:50:20 -08005719 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005720 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5721 * {@link #disableIms(int)}.
5722 * @param slotIndex device slot.
5723 */
5724 public void resetIms(int slotIndex) {
5725 enforceModifyPermission();
5726
5727 final long identity = Binder.clearCallingIdentity();
5728 try {
5729 if (mImsResolver == null) {
5730 // may happen if the does not support IMS.
5731 return;
5732 }
5733 mImsResolver.disableIms(slotIndex);
5734 mImsResolver.enableIms(slotIndex);
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
5737 }
5738 }
5739
5740 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005741 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5742 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005743 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005744 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005746
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005749 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005750 // may happen if the device does not support IMS.
5751 return;
5752 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005753 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005757 }
5758
5759 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005760 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5761 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005762 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005763 public void disableIms(int slotId) {
5764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765
5766 final long identity = Binder.clearCallingIdentity();
5767 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005768 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005769 // may happen if the device does not support IMS.
5770 return;
5771 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005772 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005776 }
5777
5778 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005779 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5780 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005781 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005782 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005783 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005784 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785
5786 final long identity = Binder.clearCallingIdentity();
5787 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005788 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005789 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5790 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005791 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005792 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005796 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005797 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005798 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5799 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005800 @Override
5801 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005802 enforceModifyPermission();
5803
5804 final long identity = Binder.clearCallingIdentity();
5805 try {
5806 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005807 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
5811 }
5812
5813 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005814 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005815 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005816 */
5817 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819
5820 final long identity = Binder.clearCallingIdentity();
5821 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005822 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005823 // may happen if the device does not support IMS.
5824 return null;
5825 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005826 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005830 }
5831
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005832 /**
5833 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005834 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005835 */
5836 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5837 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838
5839 final long identity = Binder.clearCallingIdentity();
5840 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005841 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005842 // may happen if the device does not support IMS.
5843 return null;
5844 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005845 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005849 }
5850
Brad Ebinger884c07b2018-02-15 16:17:40 -08005851 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005852 * Sets the ImsService Package Name that Telephony will bind to.
5853 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005854 * @param slotIndex the slot ID that the ImsService should bind for.
5855 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005856 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005857 * @param featureTypes An integer array of feature types associated with a packageName.
5858 * @param packageName The name of the package that the current configuration will be replaced
5859 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005860 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005861 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005862 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5863 int[] featureTypes, String packageName) {
5864 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005866 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5867 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005868 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 final long identity = Binder.clearCallingIdentity();
5871 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005872 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005873 // may happen if the device does not support IMS.
5874 return false;
5875 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005876 Map<Integer, String> featureConfig = new HashMap<>();
5877 for (int featureType : featureTypes) {
5878 featureConfig.put(featureType, packageName);
5879 }
5880 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5881 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005885 }
5886
5887 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005888 * Clears any carrier ImsService overrides for the slot index specified that were previously
5889 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5890 *
5891 * This should only be used for testing.
5892 *
5893 * @param slotIndex the slot ID that the ImsService should bind for.
5894 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5895 */
5896 @Override
5897 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5898 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5900 "clearCarrierImsServiceOverride");
5901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5902 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5903 "clearCarrierImsServiceOverride");
5904
5905 final long identity = Binder.clearCallingIdentity();
5906 try {
5907 if (mImsResolver == null) {
5908 // may happen if the device does not support IMS.
5909 return false;
5910 }
5911 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5912 } finally {
5913 Binder.restoreCallingIdentity(identity);
5914 }
5915 }
5916
5917 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005918 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005919 *
5920 * @param slotId The slot that the ImsService is associated with.
5921 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5922 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005923 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005924 * @return the package name of the ImsService configuration.
5925 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005926 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5927 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005928 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005929 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005930 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005931 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5932 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 final long identity = Binder.clearCallingIdentity();
5935 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005936 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005937 // may happen if the device does not support IMS.
5938 return "";
5939 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005940 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005941 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5942 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 } finally {
5944 Binder.restoreCallingIdentity(identity);
5945 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005946 }
5947
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005948 /**
5949 * Get the MmTelFeature state associated with the requested subscription id.
5950 * @param subId The subscription that the MmTelFeature is associated with.
5951 * @param callback A callback with an integer containing the
5952 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5953 */
5954 @Override
5955 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5956 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5957 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5959 "IMS not available on device.");
5960 }
5961 final long token = Binder.clearCallingIdentity();
5962 try {
5963 int slotId = getSlotIndex(subId);
5964 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5965 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5966 + subId + "'");
5967 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5968 }
Brad Ebinger919631e2021-06-02 17:46:35 -07005969 verifyImsMmTelConfiguredOrThrow(slotId);
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005970 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5971 try {
5972 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5973 } catch (RemoteException e) {
5974 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5975 + "Ignore");
5976 }
5977 });
Brad Ebinger919631e2021-06-02 17:46:35 -07005978 } catch (ImsException e) {
5979 throw new ServiceSpecificException(e.getCode());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005980 } finally {
5981 Binder.restoreCallingIdentity(token);
5982 }
5983 }
5984
Daniel Brightbb5840b2021-01-12 15:48:18 -08005985 /**
5986 * Sets the ims registration state on all valid {@link Phone}s.
5987 */
5988 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005989 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990
5991 final long identity = Binder.clearCallingIdentity();
5992 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005993 // NOTE: Before S, this method only set the default phone.
5994 for (final Phone phone : PhoneFactory.getPhones()) {
5995 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5996 phone.setImsRegistrationState(registered);
5997 }
5998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005999 } finally {
6000 Binder.restoreCallingIdentity(identity);
6001 }
Wink Saville36469e72014-06-11 15:17:00 -07006002 }
6003
6004 /**
Stuart Scott54788802015-03-30 13:18:01 -07006005 * Set the network selection mode to automatic.
6006 *
6007 */
6008 @Override
6009 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6011 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012
6013 final long identity = Binder.clearCallingIdentity();
6014 try {
shilufc958392020-01-20 11:36:01 -08006015 if (!isActiveSubscription(subId)) {
6016 return;
6017 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08006019 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
6020 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 } finally {
6022 Binder.restoreCallingIdentity(identity);
6023 }
Stuart Scott54788802015-03-30 13:18:01 -07006024 }
6025
Jack Yud10cdd42020-09-28 20:28:01 -07006026 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07006027 * Ask the radio to connect to the input network and change selection mode to manual.
6028 *
6029 * @param subId the id of the subscription.
6030 * @param operatorInfo the operator information, included the PLMN, long name and short name of
6031 * the operator to attach to.
6032 * @param persistSelection whether the selection will persist until reboot. If true, only allows
6033 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
6034 * normal network selection next time.
6035 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07006036 */
6037 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07006038 public boolean setNetworkSelectionModeManual(
6039 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006040 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6041 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07006042
6043 if (!isActiveSubscription(subId)) {
6044 return false;
6045 }
6046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 final long identity = Binder.clearCallingIdentity();
6048 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07006049 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07006051 if (DBG) {
6052 log("setNetworkSelectionModeManual: subId: " + subId
6053 + " operator: " + operatorInfo);
6054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006059 }
shilu84f6e8b2019-12-19 13:58:01 -08006060 /**
6061 * Get the manual network selection
6062 *
6063 * @param subId the id of the subscription.
6064 *
6065 * @return the previously saved user selected PLMN
6066 */
6067 @Override
6068 public String getManualNetworkSelectionPlmn(int subId) {
6069 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006070 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08006071 mApp, subId, "getManualNetworkSelectionPlmn");
6072
6073 final long identity = Binder.clearCallingIdentity();
6074 try {
6075 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07006076 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006077 }
6078
6079 final Phone phone = getPhone(subId);
6080 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07006081 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08006082 }
6083 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
6084 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
6085 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
6086 } finally {
6087 Binder.restoreCallingIdentity(identity);
6088 }
6089 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006090
6091 /**
6092 * Scans for available networks.
6093 */
6094 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006095 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
6096 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6098 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08006099 LocationAccessPolicy.LocationPermissionResult locationResult =
6100 LocationAccessPolicy.checkLocationPermission(mApp,
6101 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6102 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006103 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006104 .setCallingPid(Binder.getCallingPid())
6105 .setCallingUid(Binder.getCallingUid())
6106 .setMethod("getCellNetworkScanResults")
6107 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006108 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6109 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006110 .build());
6111 switch (locationResult) {
6112 case DENIED_HARD:
6113 throw new SecurityException("Not allowed to access scan results -- location");
6114 case DENIED_SOFT:
6115 return null;
6116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117
Pengquan Menga1bb6272018-09-06 09:59:22 -07006118 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119 try {
6120 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07006121 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 } finally {
6124 Binder.restoreCallingIdentity(identity);
6125 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07006126 }
6127
6128 /**
Shuo Qian4a594052020-01-23 11:59:30 -08006129 * Get the call forwarding info, given the call forwarding reason.
6130 */
6131 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006132 public void getCallForwarding(int subId, int callForwardingReason,
6133 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006134 enforceReadPrivilegedPermission("getCallForwarding");
6135 long identity = Binder.clearCallingIdentity();
6136 try {
6137 if (DBG) {
6138 log("getCallForwarding: subId " + subId
6139 + " callForwardingReason" + callForwardingReason);
6140 }
Hall Liu27d24262020-09-18 19:04:59 -07006141
6142 Phone phone = getPhone(subId);
6143 if (phone == null) {
6144 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006145 callback.onError(
6146 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006147 } catch (RemoteException e) {
6148 // ignore
6149 }
6150 return;
6151 }
6152
6153 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
6154 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6155 @Override
6156 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6157 try {
6158 callback.onCallForwardingInfoAvailable(info);
6159 } catch (RemoteException e) {
6160 // ignore
6161 }
6162 }
6163
6164 @Override
6165 public void onError(int error) {
6166 try {
6167 callback.onError(error);
6168 } catch (RemoteException e) {
6169 // ignore
6170 }
6171 }
6172 });
6173 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006174 } finally {
6175 Binder.restoreCallingIdentity(identity);
6176 }
6177 }
6178
6179 /**
6180 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6181 * reason, the number to forward, and the timeout before the forwarding is attempted.
6182 */
6183 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006184 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6185 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006186 enforceModifyPermission();
6187 long identity = Binder.clearCallingIdentity();
6188 try {
6189 if (DBG) {
6190 log("setCallForwarding: subId " + subId
6191 + " callForwardingInfo" + callForwardingInfo);
6192 }
Hall Liu27d24262020-09-18 19:04:59 -07006193
6194 Phone phone = getPhone(subId);
6195 if (phone == null) {
6196 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006197 callback.accept(
6198 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006199 } catch (RemoteException e) {
6200 // ignore
6201 }
6202 return;
6203 }
6204
6205 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6206 FunctionalUtils.ignoreRemoteException(callback::accept));
6207
6208 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006209 } finally {
6210 Binder.restoreCallingIdentity(identity);
6211 }
6212 }
6213
6214 /**
Hall Liu27d24262020-09-18 19:04:59 -07006215 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006216 */
6217 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006218 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006219 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006220 long identity = Binder.clearCallingIdentity();
6221 try {
Hall Liu27d24262020-09-18 19:04:59 -07006222 Phone phone = getPhone(subId);
6223 if (phone == null) {
6224 try {
6225 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6226 } catch (RemoteException e) {
6227 // ignore
6228 }
6229 return;
6230 }
SongFerngWang0e767992021-03-31 22:08:45 +08006231 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6232 PersistableBundle c = configManager.getConfigForSubId(subId);
6233 boolean requireUssd = c.getBoolean(
6234 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006235
Shuo Qian4a594052020-01-23 11:59:30 -08006236 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006237 if (requireUssd) {
6238 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6239 getSubscriptionCarrierId(subId));
6240 String newUssdCommand = "";
6241 try {
6242 newUssdCommand = carrierXmlParser.getFeature(
6243 CarrierXmlParser.FEATURE_CALL_WAITING)
6244 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6245 } catch (NullPointerException e) {
6246 loge("Failed to generate USSD number" + e);
6247 }
6248 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6249 mMainThreadHandler, callback, carrierXmlParser,
6250 CarrierXmlParser.SsEntry.SSAction.QUERY);
6251 final String ussdCommand = newUssdCommand;
6252 Executors.newSingleThreadExecutor().execute(() -> {
6253 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6254 });
6255 } else {
6256 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6257 callback::accept);
6258 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6259 }
Shuo Qian4a594052020-01-23 11:59:30 -08006260 } finally {
6261 Binder.restoreCallingIdentity(identity);
6262 }
6263 }
6264
6265 /**
Hall Liu27d24262020-09-18 19:04:59 -07006266 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006267 */
6268 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006269 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006270 enforceModifyPermission();
6271 long identity = Binder.clearCallingIdentity();
6272 try {
Hall Liu27d24262020-09-18 19:04:59 -07006273 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6274
6275 Phone phone = getPhone(subId);
6276 if (phone == null) {
6277 try {
6278 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6279 } catch (RemoteException e) {
6280 // ignore
6281 }
6282 return;
6283 }
6284
SongFerngWang0e767992021-03-31 22:08:45 +08006285 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6286 PersistableBundle c = configManager.getConfigForSubId(subId);
6287 boolean requireUssd = c.getBoolean(
6288 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006289
SongFerngWang0e767992021-03-31 22:08:45 +08006290 if (DBG) log("getCallWaitingStatus: subId " + subId);
6291 if (requireUssd) {
6292 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6293 getSubscriptionCarrierId(subId));
6294 CarrierXmlParser.SsEntry.SSAction ssAction =
6295 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6296 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6297 String newUssdCommand = "";
6298 try {
6299 newUssdCommand = carrierXmlParser.getFeature(
6300 CarrierXmlParser.FEATURE_CALL_WAITING)
6301 .makeCommand(ssAction, null);
6302 } catch (NullPointerException e) {
6303 loge("Failed to generate USSD number" + e);
6304 }
6305 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6306 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6307 final String ussdCommand = newUssdCommand;
6308 Executors.newSingleThreadExecutor().execute(() -> {
6309 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6310 });
6311 } else {
6312 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6313 FunctionalUtils.ignoreRemoteException(callback::accept));
6314
6315 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6316 }
Shuo Qian4a594052020-01-23 11:59:30 -08006317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
6320 }
6321
6322 /**
yinxub1bed742017-04-17 11:45:04 -07006323 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006324 *
yinxub1bed742017-04-17 11:45:04 -07006325 * @param subId id of the subscription
6326 * @param request contains the radio access networks with bands/channels to scan
6327 * @param messenger callback messenger for scan results or errors
6328 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006329 * @return the id of the requested scan which can be used to stop the scan.
6330 */
6331 @Override
6332 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006333 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6335 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006336 LocationAccessPolicy.LocationPermissionResult locationResult =
6337 LocationAccessPolicy.checkLocationPermission(mApp,
6338 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6339 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006340 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006341 .setCallingPid(Binder.getCallingPid())
6342 .setCallingUid(Binder.getCallingUid())
6343 .setMethod("requestNetworkScan")
6344 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006345 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6346 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006347 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006348 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006349 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6350 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006351 if (e != null) {
6352 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6353 throw e;
6354 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006355 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006356 return TelephonyScanManager.INVALID_SCAN_ID;
6357 }
6358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 }
Hall Liu912dfd32019-04-25 14:02:26 -07006360 int callingUid = Binder.getCallingUid();
6361 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006362 final long identity = Binder.clearCallingIdentity();
6363 try {
6364 return mNetworkScanRequestTracker.startNetworkScan(
6365 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006366 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
yinxu504e1392017-04-12 16:03:22 -07006370 }
6371
Hall Liub2ac8ef2019-02-28 15:56:23 -08006372 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006373 NetworkScanRequest request, int subId, String callingPackage) {
6374 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006375 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6376 boolean hasNetworkScanPermission =
6377 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6378 == PERMISSION_GRANTED;
6379
6380 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6381 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6382 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006383 }
6384
6385 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6386 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006387 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6388 return new SecurityException("Specific channels must not be"
6389 + " scanned without location access.");
6390 }
6391 }
6392 }
6393
Hall Liub2ac8ef2019-02-28 15:56:23 -08006394 return null;
6395 }
6396
yinxu504e1392017-04-12 16:03:22 -07006397 /**
6398 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006399 *
6400 * @param subId id of the subscription
6401 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006402 */
6403 @Override
6404 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6406 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407
Hall Liu912dfd32019-04-25 14:02:26 -07006408 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409 final long identity = Binder.clearCallingIdentity();
6410 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006411 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
yinxu504e1392017-04-12 16:03:22 -07006415 }
6416
6417 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006418 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006419 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006420 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006421 */
6422 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006423 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006424 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006425 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006426 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427
6428 final long identity = Binder.clearCallingIdentity();
6429 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006430 if (DBG) log("getAllowedNetworkTypesBitmask");
6431 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6432 int networkTypesBitmask = (result != null ? result[0] : -1);
6433 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6434 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006438 }
6439
6440 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006441 * Get the allowed network types for certain reason.
6442 *
6443 * @param subId the id of the subscription.
6444 * @param reason the reason the allowed network type change is taking place
6445 * @return the allowed network types.
6446 */
6447 @Override
6448 public long getAllowedNetworkTypesForReason(int subId,
6449 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006450 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006451 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006452 final long identity = Binder.clearCallingIdentity();
6453 try {
6454 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6455 } finally {
6456 Binder.restoreCallingIdentity(identity);
6457 }
6458 }
6459
6460 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006461 * Enable/Disable E-UTRA-NR Dual Connectivity
6462 * @param subId subscription id of the sim card
6463 * @param nrDualConnectivityState expected NR dual connectivity state
6464 * This can be passed following states
6465 * <ol>
6466 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6467 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6468 * <li>Disable NR dual connectivity and force secondary cell to be released
6469 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6470 * </ol>
6471 * @return operation result.
6472 */
6473 @Override
6474 public int setNrDualConnectivityState(int subId,
6475 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6477 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006478 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006479 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6480 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6481 }
6482
Sooraj Sasindran37444802020-08-11 10:40:43 -07006483 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6484 final long identity = Binder.clearCallingIdentity();
6485 try {
6486 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6487 nrDualConnectivityState, subId,
6488 workSource);
6489 if (DBG) log("enableNRDualConnectivity result: " + result);
6490 return result;
6491 } finally {
6492 Binder.restoreCallingIdentity(identity);
6493 }
6494 }
6495
6496 /**
6497 * Is E-UTRA-NR Dual Connectivity enabled
6498 * @return true if dual connectivity is enabled else false
6499 */
6500 @Override
6501 public boolean isNrDualConnectivityEnabled(int subId) {
6502 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006503 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006504 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006505 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006506 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6507 return false;
6508 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6510 final long identity = Binder.clearCallingIdentity();
6511 try {
6512 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6513 null, subId, workSource);
6514 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6515 return isEnabled;
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
6519 }
6520
6521 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006522 * Set the allowed network types of the device and
6523 * provide the reason triggering the allowed network change.
6524 *
6525 * @param subId the id of the subscription.
6526 * @param reason the reason the allowed network type change is taking place
6527 * @param allowedNetworkTypes the allowed network types.
6528 * @return true on success; false on any failure.
6529 */
6530 @Override
6531 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006532 @TelephonyManager.AllowedNetworkTypesReason int reason,
6533 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6535 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006536 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006537 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6538 return false;
6539 }
6540 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6541 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006542 return false;
6543 }
6544
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006545 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6546 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6547
6548
6549 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6550 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6551 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006552 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006553
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006554 final long identity = Binder.clearCallingIdentity();
6555 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006556 Boolean success = (Boolean) sendRequest(
6557 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6558 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6559
6560 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6561 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
6565 }
6566
6567 /**
Miaoa84611c2019-03-15 09:21:10 +08006568 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006569 *
Miaoa84611c2019-03-15 09:21:10 +08006570 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006571 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006572 * @hide
6573 */
6574 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006575 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006578 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 try {
Miaoa84611c2019-03-15 09:21:10 +08006580 if (phone != null) {
6581 return phone.hasMatchedTetherApnSetting();
6582 } else {
6583 return false;
6584 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006585 } finally {
6586 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006587 }
Junda Liu475951f2014-11-07 16:45:03 -08006588 }
6589
6590 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006591 * Enable or disable always reporting signal strength changes from radio.
6592 *
6593 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6594 */
6595 @Override
6596 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6597 enforceModifyPermission();
6598 enforceSystemCaller();
6599
6600 final long identity = Binder.clearCallingIdentity();
6601 final Phone phone = getPhone(subId);
6602 try {
6603 if (phone != null) {
6604 if (DBG) {
6605 log("setAlwaysReportSignalStrength: subId=" + subId
6606 + " isEnable=" + isEnable);
6607 }
6608 phone.setAlwaysReportSignalStrength(isEnable);
6609 } else {
6610 loge("setAlwaysReportSignalStrength: no phone found for subId="
6611 + subId);
6612 }
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
6616 }
6617
6618 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006619 * Get the user enabled state of Mobile Data.
6620 *
6621 * TODO: remove and use isUserDataEnabled.
6622 * This can't be removed now because some vendor codes
6623 * calls through ITelephony directly while they should
6624 * use TelephonyManager.
6625 *
6626 * @return true on enabled
6627 */
6628 @Override
6629 public boolean getDataEnabled(int subId) {
6630 return isUserDataEnabled(subId);
6631 }
6632
6633 /**
6634 * Get whether mobile data is enabled per user setting.
6635 *
6636 * There are other factors deciding whether mobile data is actually enabled, but they are
6637 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006638 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006639 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006640 *
6641 * @return {@code true} if data is enabled else {@code false}
6642 */
6643 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006644 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006645 try {
6646 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6647 null);
6648 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6650 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652
6653 final long identity = Binder.clearCallingIdentity();
6654 try {
6655 int phoneId = mSubscriptionController.getPhoneId(subId);
6656 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6657 Phone phone = PhoneFactory.getPhone(phoneId);
6658 if (phone != null) {
6659 boolean retVal = phone.isUserDataEnabled();
6660 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6661 return retVal;
6662 } else {
6663 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6664 return false;
6665 }
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006668 }
6669 }
6670
6671 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006672 * Checks if the device is capable of mobile data by considering whether whether the
6673 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6674 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006675 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006676 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006677 */
6678 @Override
6679 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006680 try {
6681 try {
6682 mApp.enforceCallingOrSelfPermission(
6683 android.Manifest.permission.ACCESS_NETWORK_STATE,
6684 null);
6685 } catch (Exception e) {
6686 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6687 "isDataEnabled");
6688 }
6689 } catch (Exception e) {
6690 enforceReadPrivilegedPermission("isDataEnabled");
6691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692
6693 final long identity = Binder.clearCallingIdentity();
6694 try {
6695 int phoneId = mSubscriptionController.getPhoneId(subId);
6696 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6697 Phone phone = PhoneFactory.getPhone(phoneId);
6698 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006699 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6701 return retVal;
6702 } else {
6703 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6704 return false;
6705 }
6706 } finally {
6707 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006708 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006709 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006710
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006711 /**
6712 * Check if data is enabled for a specific reason
6713 * @param subId Subscription index
6714 * @param reason the reason the data enable change is taking place
6715 * @return {@code true} if the overall data is enabled; {@code false} if not.
6716 */
6717 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006718 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006719 @TelephonyManager.DataEnabledReason int reason) {
6720 try {
6721 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6722 null);
6723 } catch (Exception e) {
6724 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006725 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006726 }
6727
6728
6729 final long identity = Binder.clearCallingIdentity();
6730 try {
6731 int phoneId = mSubscriptionController.getPhoneId(subId);
6732 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006733 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006734 + " reason=" + reason);
6735 }
6736 Phone phone = PhoneFactory.getPhone(phoneId);
6737 if (phone != null) {
6738 boolean retVal;
6739 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6740 retVal = phone.isUserDataEnabled();
6741 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006742 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006743 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006744 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006745 return retVal;
6746 } else {
6747 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006748 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006749 + subId + " retVal=false");
6750 }
6751 return false;
6752 }
6753 } finally {
6754 Binder.restoreCallingIdentity(identity);
6755 }
6756 }
6757
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006758 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006759 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006760 if (uid == Process.PHONE_UID) {
6761 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6762 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6764 }
6765
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006766 //load access rules from carrier configs, and check those as well: b/139133814
6767 SubscriptionController subController = SubscriptionController.getInstance();
6768 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6769 || subController == null) return privilegeFromSim;
6770
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006771 PackageManager pkgMgr = phone.getContext().getPackageManager();
6772 String[] packages = pkgMgr.getPackagesForUid(uid);
6773
6774 final long identity = Binder.clearCallingIdentity();
6775 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006776 int subId = phone.getSubId();
6777 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6778 // A test override is in place for the privileges for this subId, so don't try to
6779 // read the subscription privileges.
6780 return privilegeFromSim;
6781 }
6782 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006783 SubscriptionManager subManager = (SubscriptionManager)
6784 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6785 for (String pkg : packages) {
6786 if (subManager.canManageSubscription(subInfo, pkg)) {
6787 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6788 }
6789 }
6790 return privilegeFromSim;
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
6794 }
6795
6796 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6797 String pkgName) {
6798 //load access rules from carrier configs, and check those as well: b/139133814
6799 SubscriptionController subController = SubscriptionController.getInstance();
6800 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6801 || subController == null) return privilegeFromSim;
6802
6803 final long identity = Binder.clearCallingIdentity();
6804 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006805 int subId = phone.getSubId();
6806 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6807 // A test override is in place for the privileges for this subId, so don't try to
6808 // read the subscription privileges.
6809 return privilegeFromSim;
6810 }
6811 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006812 SubscriptionManager subManager = (SubscriptionManager)
6813 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6814 return subManager.canManageSubscription(subInfo, pkgName)
6815 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6816 } finally {
6817 Binder.restoreCallingIdentity(identity);
6818 }
6819 }
6820
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006821 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006822 public int getCarrierPrivilegeStatus(int subId) {
6823 final Phone phone = getPhone(subId);
6824 if (phone == null) {
6825 loge("getCarrierPrivilegeStatus: Invalid subId");
6826 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6827 }
6828 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006829 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006830 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006831 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6832 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006833
6834 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6835 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006836 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006837 }
Junda Liu29340342014-07-10 15:23:27 -07006838
6839 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006840 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006841 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006842 final Phone phone = getPhone(subId);
6843 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006844 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006845 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6846 }
6847 UiccProfile profile =
6848 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6849 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006850 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006851 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6852 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006853 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006854 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006855 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006856 }
6857
6858 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006859 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006860 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006861 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006862 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006863 }
6864
6865 int phoneId = SubscriptionManager.getPhoneId(subId);
6866 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006867 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006868 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006869 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6870 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006871 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6872 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6873 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006874 }
6875
6876 @Override
6877 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Sarah Chinfc3169b2021-04-28 20:21:03 -07006878 // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API
Junda Liu317d70b2016-03-08 09:33:53 -08006879 if (TextUtils.isEmpty(pkgName))
6880 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006881 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6882 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6883 UiccCard card = UiccController.getInstance().getUiccCard(i);
6884 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006885 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006886 continue;
6887 }
6888
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006889 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6890 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6891 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006892 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6893 break;
6894 }
6895 }
6896
6897 return result;
Junda Liu29340342014-07-10 15:23:27 -07006898 }
Derek Tan89e89d42014-07-08 17:00:10 -07006899
6900 @Override
Junda Liue64de782015-04-16 17:19:16 -07006901 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006902 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006903 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6904 loge("phoneId " + phoneId + " is not valid.");
6905 return null;
6906 }
6907 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006908 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006909 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006910 return null ;
6911 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006912 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006913 }
6914
Amith Yamasani6e118872016-02-19 12:53:51 -08006915 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006916 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006917 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006918 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006919 List<String> privilegedPackages = new ArrayList<>();
6920 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006921 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6922 // has UICC in that slot.
6923 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006924 if (card.hasCarrierPrivilegeRules()) {
6925 if (packages == null) {
6926 // Only check packages in user 0 for now
6927 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006928 PackageManager.MATCH_DISABLED_COMPONENTS
6929 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006930 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006931 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006932 }
6933 for (int p = packages.size() - 1; p >= 0; p--) {
6934 PackageInfo pkgInfo = packages.get(p);
6935 if (pkgInfo != null && pkgInfo.packageName != null
6936 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006937 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006938 privilegedPackages.add(pkgInfo.packageName);
6939 }
6940 }
6941 }
6942 }
6943 return privilegedPackages;
6944 }
6945
chen xuf7e9fe82019-05-09 19:31:02 -07006946 @Override
6947 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006948 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6949
6950 final long identity = Binder.clearCallingIdentity();
6951
chen xuf7e9fe82019-05-09 19:31:02 -07006952 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006953 try {
6954 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6955 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6956 }
6957 } finally {
6958 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006959 }
6960 return privilegedPackages;
6961 }
6962
Wink Savilleb564aae2014-10-23 10:18:09 -07006963 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006964 final Phone phone = getPhone(subId);
6965 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006966 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006967 return null;
6968 }
6969 String iccId = card.getIccId();
6970 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006971 return null;
6972 }
6973 return iccId;
6974 }
6975
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006976 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006977 public void setCallComposerStatus(int subId, int status) {
6978 enforceModifyPermission();
6979
6980 final long identity = Binder.clearCallingIdentity();
6981 try {
6982 Phone phone = getPhone(subId);
6983 if (phone != null) {
6984 Phone defaultPhone = phone.getImsPhone();
6985 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6986 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6987 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006988 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6989 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006990 }
6991 }
Shuo Qian284ae752020-12-22 19:10:14 -08006992 } catch (ImsException e) {
6993 throw new ServiceSpecificException(e.getCode());
6994 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006995 Binder.restoreCallingIdentity(identity);
6996 }
6997 }
6998
6999 @Override
7000 public int getCallComposerStatus(int subId) {
7001 enforceReadPrivilegedPermission("getCallComposerStatus");
7002
7003 final long identity = Binder.clearCallingIdentity();
7004 try {
7005 Phone phone = getPhone(subId);
7006 if (phone != null) {
7007 Phone defaultPhone = phone.getImsPhone();
7008 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7009 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7010 return imsPhone.getCallComposerStatus();
7011 }
7012 }
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
7015 }
7016 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
7017 }
7018
7019 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08007020 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
7021 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007022 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007023 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07007024
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 final long identity = Binder.clearCallingIdentity();
7026 try {
7027 final String iccId = getIccId(subId);
7028 final Phone phone = getPhone(subId);
7029 if (phone == null) {
7030 return false;
7031 }
7032 final String subscriberId = phone.getSubscriberId();
7033
7034 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007035 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 + subscriberId + " to " + number);
7037 }
7038
7039 if (TextUtils.isEmpty(iccId)) {
7040 return false;
7041 }
7042
7043 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
7044
7045 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7046 if (alphaTag == null) {
7047 editor.remove(alphaTagPrefKey);
7048 } else {
7049 editor.putString(alphaTagPrefKey, alphaTag);
7050 }
7051
7052 // Record both the line number and IMSI for this ICCID, since we need to
7053 // track all merged IMSIs based on line number
7054 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7055 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7056 if (number == null) {
7057 editor.remove(numberPrefKey);
7058 editor.remove(subscriberPrefKey);
7059 } else {
7060 editor.putString(numberPrefKey, number);
7061 editor.putString(subscriberPrefKey, subscriberId);
7062 }
7063
7064 editor.commit();
7065 return true;
7066 } finally {
7067 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07007068 }
Derek Tan7226c842014-07-02 17:42:23 -07007069 }
7070
7071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007072 public String getLine1NumberForDisplay(int subId, String callingPackage,
7073 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07007074 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007076 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08007077 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07007078 return null;
7079 }
Derek Tan97ebb422014-09-05 16:55:38 -07007080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 final long identity = Binder.clearCallingIdentity();
7082 try {
7083 String iccId = getIccId(subId);
7084 if (iccId != null) {
7085 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7086 if (DBG_MERGE) {
7087 log("getLine1NumberForDisplay returning "
7088 + mTelephonySharedPreferences.getString(numberPrefKey, null));
7089 }
7090 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08007091 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
7093 return null;
7094 } finally {
7095 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007096 }
Derek Tan7226c842014-07-02 17:42:23 -07007097 }
7098
7099 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007100 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
7101 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007103 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07007104 return null;
7105 }
Derek Tan97ebb422014-09-05 16:55:38 -07007106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007107 final long identity = Binder.clearCallingIdentity();
7108 try {
7109 String iccId = getIccId(subId);
7110 if (iccId != null) {
7111 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
7112 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
7113 }
7114 return null;
7115 } finally {
7116 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07007117 }
Derek Tan7226c842014-07-02 17:42:23 -07007118 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007119
7120 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007121 public String[] getMergedSubscriberIds(int subId, String callingPackage,
7122 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007123 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
7124 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08007125 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08007126 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007127 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007128 return null;
7129 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007130
Jordan Liub49b04b2019-05-06 14:45:15 -07007131 // Clear calling identity, when calling TelephonyManager, because callerUid must be
7132 // the process, where TelephonyManager was instantiated.
7133 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007134 final long identity = Binder.clearCallingIdentity();
7135 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007136 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 final TelephonyManager tele = TelephonyManager.from(context);
7138 final SubscriptionManager sub = SubscriptionManager.from(context);
7139
7140 // Figure out what subscribers are currently active
7141 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142
Jordan Liub49b04b2019-05-06 14:45:15 -07007143 // Only consider subs which match the current subId
7144 // This logic can be simplified. See b/131189269 for progress.
7145 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007146 activeSubscriberIds.add(tele.getSubscriberId(subId));
7147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148
7149 // First pass, find a number override for an active subscriber
7150 String mergeNumber = null;
7151 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
7152 for (String key : prefs.keySet()) {
7153 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
7154 final String subscriberId = (String) prefs.get(key);
7155 if (activeSubscriberIds.contains(subscriberId)) {
7156 final String iccId = key.substring(
7157 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7158 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7159 mergeNumber = (String) prefs.get(numberKey);
7160 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007161 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 + " for active subscriber " + subscriberId);
7163 }
7164 if (!TextUtils.isEmpty(mergeNumber)) {
7165 break;
7166 }
7167 }
7168 }
7169 }
7170
7171 // Shortcut when no active merged subscribers
7172 if (TextUtils.isEmpty(mergeNumber)) {
7173 return null;
7174 }
7175
7176 // Second pass, find all subscribers under that line override
7177 final ArraySet<String> result = new ArraySet<>();
7178 for (String key : prefs.keySet()) {
7179 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7180 final String number = (String) prefs.get(key);
7181 if (mergeNumber.equals(number)) {
7182 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7183 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7184 final String subscriberId = (String) prefs.get(subscriberKey);
7185 if (!TextUtils.isEmpty(subscriberId)) {
7186 result.add(subscriberId);
7187 }
7188 }
7189 }
7190 }
7191
7192 final String[] resultArray = result.toArray(new String[result.size()]);
7193 Arrays.sort(resultArray);
7194 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007195 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7197 }
7198 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007199 } finally {
7200 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007201 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007202 }
7203
7204 @Override
zoey chen38003472019-12-13 17:16:31 +08007205 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7206 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007207
7208 final long identity = Binder.clearCallingIdentity();
7209 try {
7210 final TelephonyManager telephonyManager = mApp.getSystemService(
7211 TelephonyManager.class);
7212 String subscriberId = telephonyManager.getSubscriberId(subId);
7213 if (subscriberId == null) {
7214 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007215 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007216 + subId);
7217 }
7218 return null;
7219 }
7220
7221 final SubscriptionInfo info = SubscriptionController.getInstance()
7222 .getSubscriptionInfo(subId);
7223 final ParcelUuid groupUuid = info.getGroupUuid();
7224 // If it doesn't belong to any group, return just subscriberId of itself.
7225 if (groupUuid == null) {
7226 return new String[]{subscriberId};
7227 }
7228
7229 // Get all subscriberIds from the group.
7230 final List<String> mergedSubscriberIds = new ArrayList<>();
7231 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007232 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007233 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007234 for (SubscriptionInfo subInfo : groupInfos) {
7235 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7236 if (subscriberId != null) {
7237 mergedSubscriberIds.add(subscriberId);
7238 }
7239 }
7240
7241 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
7244
7245 }
7246 }
7247
7248 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007249 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007250 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007251 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252
7253 final long identity = Binder.clearCallingIdentity();
7254 try {
7255 final Phone phone = getPhone(subId);
7256 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007260 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007261
7262 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007263 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007264 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7265 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007266 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7267 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268
7269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 final Phone phone = getPhone(subId);
7272 if (phone == null) {
7273 return false;
7274 }
7275 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7276 cdmaNonRoamingList);
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007279 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007280 }
7281
7282 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007283 @Deprecated
7284 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7285 enforceModifyPermission();
7286
7287 int returnValue = 0;
7288 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007289 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007290 if(result.exception == null) {
7291 if (result.result != null) {
7292 byte[] responseData = (byte[])(result.result);
7293 if(responseData.length > oemResp.length) {
7294 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7295 responseData.length + "bytes. Buffer Size is " +
7296 oemResp.length + "bytes.");
7297 }
7298 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7299 returnValue = responseData.length;
7300 }
7301 } else {
7302 CommandException ex = (CommandException) result.exception;
7303 returnValue = ex.getCommandError().ordinal();
7304 if(returnValue > 0) returnValue *= -1;
7305 }
7306 } catch (RuntimeException e) {
7307 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7308 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7309 if(returnValue > 0) returnValue *= -1;
7310 }
7311
7312 return returnValue;
7313 }
7314
7315 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007316 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007317 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007318 try {
7319 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007320 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007321 mApp, phone.getSubId(), "getRadioAccessFamily");
7322 } catch (SecurityException e) {
7323 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7324 throw e;
7325 }
chen xub97461a2018-10-26 14:17:57 -07007326 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007327 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007328 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007330 final long identity = Binder.clearCallingIdentity();
7331 try {
chen xub97461a2018-10-26 14:17:57 -07007332 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007333 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007334 mApp, phone.getSubId(), "getRadioAccessFamily");
7335 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
chen xub97461a2018-10-26 14:17:57 -07007339 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007340 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007341
7342 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007343 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007344 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007345 try {
7346 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7347 Binder.getCallingUid())) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007348 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007349 }
7350 } catch (PackageManager.NameNotFoundException e) {
Tyler Gunnb87925a2021-06-10 14:54:27 -07007351 throw new SecurityException("Invalid package:" + callingPackage);
Hall Liu82694d52020-12-11 18:22:04 -08007352 }
7353 RoleManager rm = mApp.getSystemService(RoleManager.class);
7354 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7355 if (!dialerRoleHolders.contains(callingPackage)) {
7356 throw new SecurityException("App must be the dialer role holder to"
7357 + " upload a call composer pic");
7358 }
7359
7360 Executors.newSingleThreadExecutor().execute(() -> {
7361 ByteArrayOutputStream output = new ByteArrayOutputStream(
7362 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7363 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7364 boolean readUntilEnd = false;
7365 int totalBytesRead = 0;
7366 byte[] buffer = new byte[16 * 1024];
7367 while (true) {
7368 int numRead;
7369 try {
7370 numRead = input.read(buffer);
7371 } catch (IOException e) {
7372 try {
7373 fd.checkError();
7374 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7375 null);
7376 } catch (IOException e1) {
7377 // This means that the other side closed explicitly with an error. If this
7378 // happens, log and ignore.
7379 loge("Remote end of call composer picture pipe closed: " + e1);
7380 }
7381 break;
7382 }
7383 if (numRead == -1) {
7384 readUntilEnd = true;
7385 break;
7386 }
7387 totalBytesRead += numRead;
7388 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7389 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7390 try {
7391 input.close();
7392 } catch (IOException e) {
7393 // ignore
7394 }
7395 break;
7396 }
7397 output.write(buffer, 0, numRead);
7398 }
7399 // Generally, the remote end will close the file descriptors. The only case where we
7400 // close is above, where the picture size is too big.
7401
7402 try {
7403 fd.checkError();
7404 } catch (IOException e) {
7405 loge("Remote end for call composer closed with an error: " + e);
7406 return;
7407 }
7408
Hall Liuaa4211e2021-01-20 15:43:39 -08007409 if (!readUntilEnd) {
7410 loge("Did not finish reading entire image; aborting");
7411 return;
7412 }
Hall Liu82694d52020-12-11 18:22:04 -08007413
Hall Liuaa4211e2021-01-20 15:43:39 -08007414 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7415 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7416 new CallComposerPictureTransfer.Factory() {},
7417 imageData,
7418 (result) -> {
7419 if (result.first != null) {
7420 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7421 Bundle outputResult = new Bundle();
7422 outputResult.putParcelable(
7423 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7424 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7425 outputResult);
7426 } else {
7427 callback.send(result.second, null);
7428 }
7429 }
7430 );
Hall Liu82694d52020-12-11 18:22:04 -08007431 });
7432 }
7433
7434 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007435 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007436 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438
7439 final long identity = Binder.clearCallingIdentity();
7440 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007441 ImsManager.getInstance(defaultPhone.getContext(),
7442 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 } finally {
7444 Binder.restoreCallingIdentity(identity);
7445 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007446 }
7447
7448 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007449 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007450 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007451 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7452 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007453 return false;
7454 }
Svet Ganovb320e182015-04-16 12:30:10 -07007455
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 final long identity = Binder.clearCallingIdentity();
7457 try {
7458 // Check the user preference and the system-level IMS setting. Even if the user has
7459 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7460 // In the long run, we may instead need to check if there exists a connection service
7461 // which can support video calling.
7462 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007463 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 return imsManager.isVtEnabledByPlatform()
7465 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7466 && imsManager.isVtEnabledByUser();
7467 } finally {
7468 Binder.restoreCallingIdentity(identity);
7469 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007470 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007471
Andrew Leea1239f22015-03-02 17:44:07 -08007472 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007473 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7474 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007476 mApp, subId, callingPackage, callingFeatureId,
7477 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007478 return false;
7479 }
7480
7481 final long identity = Binder.clearCallingIdentity();
7482 try {
7483 CarrierConfigManager configManager =
7484 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007485 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
Andrew Leea1239f22015-03-02 17:44:07 -08007490 }
7491
7492 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007493 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007494 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007495 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 return false;
7497 }
7498
7499 final long identity = Binder.clearCallingIdentity();
7500 try {
7501 CarrierConfigManager configManager =
7502 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007503 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007504 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7505 } finally {
7506 Binder.restoreCallingIdentity(identity);
7507 }
Andrew Leea1239f22015-03-02 17:44:07 -08007508 }
7509
Andrew Lee9431b832015-03-09 18:46:45 -07007510 @Override
7511 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007512 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007513 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007514 }
7515
7516 @Override
7517 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 final long identity = Binder.clearCallingIdentity();
7519 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007520 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 } finally {
7522 Binder.restoreCallingIdentity(identity);
7523 }
Andrew Lee9431b832015-03-09 18:46:45 -07007524 }
7525
Hall Liuf6668912018-10-31 17:05:23 -07007526 /**
7527 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7528 * support for the feature and device firmware support.
7529 *
7530 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7531 */
7532 @Override
7533 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007535 final Phone phone = getPhone(subscriptionId);
7536 if (phone == null) {
7537 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7538 return false;
7539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007540 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007541 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7543 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007544 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 return isCarrierSupported && isDeviceSupported;
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
Hall Liu98187582018-01-22 19:15:32 -08007549 }
7550
Hall Liuf6668912018-10-31 17:05:23 -07007551 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007552 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7553 * RTT setting, will return true if the device and carrier both support RTT.
7554 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007555 */
7556 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 final long identity = Binder.clearCallingIdentity();
7558 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007559 boolean isRttSupported = isRttSupported(subscriptionId);
7560 boolean isUserRttSettingOn = Settings.Secure.getInt(
7561 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7562 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7563 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7564 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 } finally {
7566 Binder.restoreCallingIdentity(identity);
7567 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007568 }
7569
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007570 @Deprecated
7571 @Override
7572 public String getDeviceId(String callingPackage) {
7573 return getDeviceIdWithFeature(callingPackage, null);
7574 }
7575
Sanket Padawe7310cc72015-01-14 09:53:20 -08007576 /**
7577 * Returns the unique device ID of phone, for example, the IMEI for
7578 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7579 *
7580 * <p>Requires Permission:
7581 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7582 */
7583 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007584 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Shuo Qian13d89152021-05-10 23:58:11 -07007585 try {
7586 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
7587 } catch (SecurityException se) {
7588 EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid());
7589 throw new SecurityException("Package " + callingPackage + " does not belong to "
7590 + Binder.getCallingUid());
7591 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007592 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007593 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007594 return null;
7595 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007596 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007597 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007598 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007599 return null;
7600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007601
7602 final long identity = Binder.clearCallingIdentity();
7603 try {
7604 return phone.getDeviceId();
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
7607 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007608 }
7609
Ping Sunc67b7c22016-03-02 19:16:45 +08007610 /**
7611 * {@hide}
7612 * Returns the IMS Registration Status on a particular subid
7613 *
7614 * @param subId
7615 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007616 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007617 Phone phone = getPhone(subId);
7618 if (phone != null) {
7619 return phone.isImsRegistered();
7620 } else {
7621 return false;
7622 }
7623 }
7624
Santos Cordon7a1885b2015-02-03 11:15:19 -08007625 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007626 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007627 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007629 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007630 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7631 }
7632 final long identity = Binder.clearCallingIdentity();
7633 try {
7634 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
7638 }
7639
7640 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007641 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007642 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007643 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007644 mApp,
7645 subscriptionId,
7646 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007647 final long identity = Binder.clearCallingIdentity();
7648 try {
7649 Phone phone = getPhone(subscriptionId);
7650 if (phone == null) {
7651 return null;
7652 }
7653 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7654 } finally {
7655 Binder.restoreCallingIdentity(identity);
7656 }
7657 }
7658
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007659 /**
7660 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007661 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007662 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 Phone phone = getPhone(subId);
7666 if (phone != null) {
7667 return phone.isWifiCallingEnabled();
7668 } else {
7669 return false;
7670 }
7671 } finally {
7672 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007673 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007674 }
7675
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007676 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007677 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007678 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007679 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 Phone phone = getPhone(subId);
7683 if (phone != null) {
7684 return phone.isVideoEnabled();
7685 } else {
7686 return false;
7687 }
7688 } finally {
7689 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007690 }
7691 }
7692
7693 /**
7694 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7695 * defined in {@link ImsRegistrationImplBase}.
7696 */
7697 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 final long identity = Binder.clearCallingIdentity();
7699 try {
7700 Phone phone = getPhone(subId);
7701 if (phone != null) {
7702 return phone.getImsRegistrationTech();
7703 } else {
7704 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7705 }
7706 } finally {
7707 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007708 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007709 }
7710
Stuart Scott8eef64f2015-04-08 15:13:54 -07007711 @Override
7712 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007713 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007714 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7715 return;
7716 }
Kai Shif70f46f2021-03-03 13:59:46 -08007717 Phone defaultPhone = getDefaultPhone();
7718 if (defaultPhone != null) {
7719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7720 mApp, getDefaultPhone().getSubId(), "factoryReset");
7721 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007722 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007723
Svet Ganovcc087f82015-05-12 20:35:54 -07007724 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007725 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7726 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007727 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007728 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007729 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007730 Phone phone = getPhone(subId);
SongFerngWangfd89b102021-05-27 22:44:54 +08007731 cleanUpAllowedNetworkTypes(phone, subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007732 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007733 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007734 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007735 // There has been issues when Sms raw table somehow stores orphan
7736 // fragments. They lead to garbled message when new fragments come
7737 // in and combined with those stale ones. In case this happens again,
7738 // user can reset all network settings which will clean up this table.
7739 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007740 // Clean up IMS settings as well here.
7741 int slotId = getSlotIndex(subId);
7742 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7743 ImsManager.getInstance(mApp, slotId).factoryReset();
7744 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007745
Kai Shif70f46f2021-03-03 13:59:46 -08007746 if (defaultPhone == null) {
7747 return;
7748 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007749 // Erase modem config if erase modem on network setting is enabled.
7750 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7751 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7752 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007753 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007754 }
Kai Shif70f46f2021-03-03 13:59:46 -08007755
7756 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007757 } finally {
7758 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007759 }
7760 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007761
SongFerngWangfd89b102021-05-27 22:44:54 +08007762 @VisibleForTesting
7763 void cleanUpAllowedNetworkTypes(Phone phone, int subId) {
7764 if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) {
7765 return;
7766 }
7767 long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType(
7768 RILConstants.PREFERRED_NETWORK_MODE);
7769 SubscriptionManager.setSubscriptionProperty(subId,
7770 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7771 "user=" + defaultNetworkType);
7772 phone.loadAllowedNetworksFromSubscriptionDatabase();
7773 phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7774 defaultNetworkType, null);
7775 }
7776
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007777 private void cleanUpSmsRawTable(Context context) {
7778 ContentResolver resolver = context.getContentResolver();
7779 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7780 resolver.delete(uri, null, null);
7781 }
7782
Narayan Kamath1c496c22015-04-16 14:40:19 +01007783 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007784 public String getSimLocaleForSubscriber(int subId) {
7785 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7786 final Phone phone = getPhone(subId);
7787 if (phone == null) {
7788 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007789 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007790 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 final long identity = Binder.clearCallingIdentity();
7792 try {
chen xu5d3637b2019-01-21 23:31:38 -08007793 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007794 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007795 if (info == null) {
7796 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7797 return null;
7798 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007799 // Try and fetch the locale from the carrier properties or from the SIM language
7800 // preferences (EF-PL and EF-LI)...
7801 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007803 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7804 if (localeFromDefaultSim != null) {
7805 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7806 if (DBG) log("Using locale from subId: " + subId + " locale: "
7807 + localeFromDefaultSim);
7808 return localeFromDefaultSim.toLanguageTag();
7809 } else {
7810 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007811 }
7812 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 // The SIM language preferences only store a language (e.g. fr = French), not an
7815 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7816 // the SIM and carrier preferences does not include a country we add the country
7817 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007818 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007819 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007820 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007821 return mccLocale.toLanguageTag();
7822 }
7823
7824 if (DBG) log("No locale found - returning null");
7825 return null;
7826 } finally {
7827 Binder.restoreCallingIdentity(identity);
7828 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007829 }
7830
7831 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007832 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007833 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007834 }
7835
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007836 /**
7837 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7838 */
7839 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007840 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007841 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007842 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007843
Chenjie Yu1ba97252018-01-11 18:16:20 -08007844 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007845 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007846
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007847 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007848 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7849 * representing the state of the modem.
7850 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007851 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7852 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007853 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007854 */
7855 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007856 public void requestModemActivityInfo(ResultReceiver result) {
7857 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007858 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007859
7860 final long identity = Binder.clearCallingIdentity();
7861 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007862 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007863 } finally {
7864 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007865 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007866 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007867
Siddharth Rayb8114062018-06-17 15:02:38 -07007868 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7869 // less than total activity duration.
7870 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7871 if (info == null) {
7872 return false;
7873 }
7874 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007875 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7876 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7877
Siddharth Rayb8114062018-06-17 15:02:38 -07007878 return (info.isValid()
7879 && (info.getSleepTimeMillis() <= activityDurationMs)
7880 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007881 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007882 && (totalTxTimeMs <= activityDurationMs));
7883 }
7884
Jack Yu85bd38a2015-11-09 11:34:32 -08007885 /**
7886 * {@hide}
7887 * Returns the service state information on specified subscription.
7888 */
7889 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007890 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7891 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007893 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007894 return null;
7895 }
7896
Hall Liuf19c44f2018-11-27 14:38:17 -08007897 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7898 LocationAccessPolicy.checkLocationPermission(mApp,
7899 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7900 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007901 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007902 .setCallingPid(Binder.getCallingPid())
7903 .setCallingUid(Binder.getCallingUid())
7904 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007905 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007906 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007907 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7908 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007909 .build());
7910
7911 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7912 LocationAccessPolicy.checkLocationPermission(mApp,
7913 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7914 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007915 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007916 .setCallingPid(Binder.getCallingPid())
7917 .setCallingUid(Binder.getCallingUid())
7918 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007919 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007920 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007921 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7922 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007923 .build());
7924 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7925 boolean hasFinePermission =
7926 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7927 boolean hasCoarsePermission =
7928 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7929
Jack Yu479f40e2020-10-27 21:29:25 -07007930 final Phone phone = getPhone(subId);
7931 if (phone == null) {
7932 return null;
7933 }
7934
Jordan Liu0f2bc442020-11-18 16:47:37 -08007935 final long identity = Binder.clearCallingIdentity();
7936
Jack Yu479f40e2020-10-27 21:29:25 -07007937 boolean isCallingPackageDataService = phone.getDataServicePackages()
7938 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007940 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7941 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7942 Rlog.d(LOG_TAG,
7943 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7944 return null;
7945 }
7946
Hall Liuf19c44f2018-11-27 14:38:17 -08007947 ServiceState ss = phone.getServiceState();
7948
7949 // Scrub out the location info in ServiceState depending on what level of access
7950 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007951 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007952 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7953 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007954 } finally {
7955 Binder.restoreCallingIdentity(identity);
7956 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007957 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007958
7959 /**
7960 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7961 *
7962 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7963 * voicemail ringtone.
7964 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7965 * PhoneAccount.
7966 */
7967 @Override
7968 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 final long identity = Binder.clearCallingIdentity();
7970 try {
7971 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7972 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007973 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007974 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007976 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7977 } finally {
7978 Binder.restoreCallingIdentity(identity);
7979 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007980 }
7981
7982 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007983 * Sets the per-account voicemail ringtone.
7984 *
7985 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7986 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7987 *
7988 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7989 * voicemail ringtone.
7990 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7991 * PhoneAccount.
7992 */
7993 @Override
7994 public void setVoicemailRingtoneUri(String callingPackage,
7995 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007996 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007997 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007998 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7999 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8001 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8002 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008003 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004
8005 final long identity = Binder.clearCallingIdentity();
8006 try {
8007 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8008 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008009 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008010 }
8011 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
8012 } finally {
8013 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008014 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008015 }
8016
8017 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08008018 * Returns whether vibration is set for voicemail notification in Phone settings.
8019 *
8020 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
8021 * voicemail vibration setting.
8022 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
8023 */
8024 @Override
8025 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026 final long identity = Binder.clearCallingIdentity();
8027 try {
8028 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
8029 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008030 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008031 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008033 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
8034 } finally {
8035 Binder.restoreCallingIdentity(identity);
8036 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08008037 }
8038
Youhan Wange64578a2016-05-02 15:32:42 -07008039 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008040 * Sets the per-account voicemail vibration.
8041 *
8042 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
8043 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8044 *
8045 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
8046 * voicemail vibration setting.
8047 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
8048 * specific PhoneAccount.
8049 */
8050 @Override
8051 public void setVoicemailVibrationEnabled(String callingPackage,
8052 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008053 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008054 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07008055 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
8056 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8058 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
8059 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008060 }
8061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008062 final long identity = Binder.clearCallingIdentity();
8063 try {
8064 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
8065 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008066 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008067 }
8068 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
8069 } finally {
8070 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008071 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08008072 }
8073
8074 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008075 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
8076 *
8077 * @throws SecurityException if the caller does not have the required permission
8078 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07008079 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07008080 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07008081 message);
Youhan Wange64578a2016-05-02 15:32:42 -07008082 }
8083
8084 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008085 * Make sure either called from same process as self (phone) or IPC caller has send SMS
8086 * permission.
8087 *
8088 * @throws SecurityException if the caller does not have the required permission
8089 */
8090 private void enforceSendSmsPermission() {
8091 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
8092 }
8093
8094 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008095 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008096 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008097 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008098 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08008099 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008100 final long identity = Binder.clearCallingIdentity();
8101 try {
8102 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008103 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 if (componentName == null) {
8105 throw new SecurityException(
8106 "Caller not current active visual voicemail package[null]");
8107 }
8108 String vvmPackage = componentName.getPackageName();
8109 if (!callingPackage.equals(vvmPackage)) {
8110 throw new SecurityException("Caller not current active visual voicemail package["
8111 + vvmPackage + "]");
8112 }
8113 } finally {
8114 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08008115 }
8116 }
8117
8118 /**
Youhan Wange64578a2016-05-02 15:32:42 -07008119 * Return the application ID for the app type.
8120 *
8121 * @param subId the subscription ID that this request applies to.
8122 * @param appType the uicc app type.
8123 * @return Application ID for specificied app type, or null if no uicc.
8124 */
8125 @Override
8126 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008127 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07008128 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129
8130 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07008131 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008132 if (phone == null) {
8133 return null;
8134 }
8135 String aid = null;
8136 try {
8137 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
8138 .getApplicationByType(appType).getAid();
8139 } catch (Exception e) {
8140 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
8141 }
8142 return aid;
8143 } finally {
8144 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07008145 }
Youhan Wange64578a2016-05-02 15:32:42 -07008146 }
8147
Youhan Wang4001d252016-05-11 10:29:41 -07008148 /**
8149 * Return the Electronic Serial Number.
8150 *
8151 * @param subId the subscription ID that this request applies to.
8152 * @return ESN or null if error.
8153 */
8154 @Override
8155 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008156 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07008157 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008158
8159 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008160 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 if (phone == null) {
8162 return null;
8163 }
8164 String esn = null;
8165 try {
8166 esn = phone.getEsn();
8167 } catch (Exception e) {
8168 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8169 }
8170 return esn;
8171 } finally {
8172 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008173 }
Youhan Wang4001d252016-05-11 10:29:41 -07008174 }
8175
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008176 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008177 * Return the Preferred Roaming List Version.
8178 *
8179 * @param subId the subscription ID that this request applies to.
8180 * @return PRLVersion or null if error.
8181 */
8182 @Override
8183 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008184 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008185 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008186
8187 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008188 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 if (phone == null) {
8190 return null;
8191 }
8192 String cdmaPrlVersion = null;
8193 try {
8194 cdmaPrlVersion = phone.getCdmaPrlVersion();
8195 } catch (Exception e) {
8196 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8197 }
8198 return cdmaPrlVersion;
8199 } finally {
8200 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008201 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008202 }
8203
8204 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008205 * Get snapshot of Telephony histograms
8206 * @return List of Telephony histograms
8207 * @hide
8208 */
8209 @Override
8210 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8212 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008213
8214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 return RIL.getTelephonyRILTimingHistograms();
8217 } finally {
8218 Binder.restoreCallingIdentity(identity);
8219 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008220 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008221
8222 /**
8223 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008224 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8225 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008226 * Require system privileges. In the future we may add this to carrier APIs.
8227 *
Michele Berionne482f8202018-11-27 18:57:59 -08008228 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008229 */
8230 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008231 @TelephonyManager.SetCarrierRestrictionResult
8232 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008233 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008234 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008235
Michele Berionne482f8202018-11-27 18:57:59 -08008236 if (carrierRestrictionRules == null) {
8237 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008238 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240 final long identity = Binder.clearCallingIdentity();
8241 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008242 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008243 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 } finally {
8245 Binder.restoreCallingIdentity(identity);
8246 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008247 }
8248
8249 /**
8250 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008251 * Get the allowed carrier list and the excluded carrier list, including the priority between
8252 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008253 * Require system privileges. In the future we may add this to carrier APIs.
8254 *
Michele Berionne482f8202018-11-27 18:57:59 -08008255 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008256 */
8257 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008258 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008259 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008260 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008261
8262 final long identity = Binder.clearCallingIdentity();
8263 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008264 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8265 if (response instanceof CarrierRestrictionRules) {
8266 return (CarrierRestrictionRules) response;
8267 }
8268 // Response is an Exception of some kind,
8269 // which is signalled to the user as a NULL retval
8270 return null;
8271 } catch (Exception e) {
8272 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8273 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008274 } finally {
8275 Binder.restoreCallingIdentity(identity);
8276 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008277 }
8278
fionaxu59545b42016-05-25 15:53:37 -07008279 /**
fionaxu59545b42016-05-25 15:53:37 -07008280 * Action set from carrier signalling broadcast receivers to enable/disable radio
8281 * @param subId the subscription ID that this action applies to.
8282 * @param enabled control enable or disable radio.
8283 * {@hide}
8284 */
8285 @Override
8286 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8287 enforceModifyPermission();
8288 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008289
8290 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008291 if (phone == null) {
8292 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8293 return;
8294 }
8295 try {
8296 phone.carrierActionSetRadioEnabled(enabled);
8297 } catch (Exception e) {
8298 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 } finally {
8300 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008301 }
8302 }
8303
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008304 /**
Sooraj Sasindrandaf060f2021-06-15 14:52:55 -07008305 * Enable or disable Voice over NR (VoNR)
8306 * @param subId the subscription ID that this action applies to.
8307 * @param enabled enable or disable VoNR.
8308 * @return operation result.
8309 */
8310 @Override
8311 public int setVoNrEnabled(int subId, boolean enabled) {
8312 enforceModifyPermission();
8313 final Phone phone = getPhone(subId);
8314
8315 final long identity = Binder.clearCallingIdentity();
8316 if (phone == null) {
8317 loge("setVoNrEnabled fails with no phone object for subId: " + subId);
8318 return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE;
8319 }
8320
8321 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8322 try {
8323 int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId,
8324 workSource);
8325 if (DBG) log("setVoNrEnabled result: " + result);
8326 return result;
8327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
8330 }
8331
8332 /**
8333 * Is voice over NR enabled
8334 * @return true if VoNR is enabled else false
8335 */
8336 @Override
8337 public boolean isVoNrEnabled(int subId) {
8338 enforceReadPrivilegedPermission("isVoNrEnabled");
8339 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8340 final long identity = Binder.clearCallingIdentity();
8341 try {
8342 boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED,
8343 null, subId, workSource);
8344 if (DBG) log("isVoNrEnabled: " + isEnabled);
8345 return isEnabled;
8346 } finally {
8347 Binder.restoreCallingIdentity(identity);
8348 }
8349 }
8350
8351 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008352 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8353 * network status based on which carrier apps could apply actions accordingly,
8354 * enable/disable default url handler for example.
8355 *
8356 * @param subId the subscription ID that this action applies to.
8357 * @param report control start/stop reporting the default network status.
8358 * {@hide}
8359 */
8360 @Override
8361 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8362 enforceModifyPermission();
8363 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008364
8365 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008366 if (phone == null) {
8367 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8368 return;
8369 }
8370 try {
8371 phone.carrierActionReportDefaultNetworkStatus(report);
8372 } catch (Exception e) {
8373 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008374 } finally {
8375 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008376 }
8377 }
8378
8379 /**
fionaxud9622282017-07-17 17:51:30 -07008380 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8381 * @param subId the subscription ID that this action applies to.
8382 * {@hide}
8383 */
8384 @Override
8385 public void carrierActionResetAll(int subId) {
8386 enforceModifyPermission();
8387 final Phone phone = getPhone(subId);
8388 if (phone == null) {
8389 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8390 return;
8391 }
8392 try {
8393 phone.carrierActionResetAll();
8394 } catch (Exception e) {
8395 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8396 }
8397 }
8398
8399 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008400 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8401 * bug report is being generated.
8402 */
8403 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008404 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008405 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8406 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008407 writer.println("Permission Denial: can't dump Phone from pid="
8408 + Binder.getCallingPid()
8409 + ", uid=" + Binder.getCallingUid()
8410 + "without permission "
8411 + android.Manifest.permission.DUMP);
8412 return;
8413 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008414 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008415 }
Jack Yueb89b242016-06-22 13:27:47 -07008416
Brad Ebingerdac2f002018-04-03 15:17:52 -07008417 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008418 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8419 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8420 @NonNull String[] args) {
8421 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8422 this, in.getFileDescriptor(), out.getFileDescriptor(),
8423 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008424 }
8425
Jack Yueb89b242016-06-22 13:27:47 -07008426 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008427 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008428 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008429 * @param reason the reason the data enable change is taking place
8430 * @param enabled True if enabling the data, otherwise disabling.
8431 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008432 */
8433 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008434 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008435 boolean enabled) {
8436 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8437 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8438 try {
8439 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008440 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008441 } catch (SecurityException se) {
8442 enforceModifyPermission();
8443 }
8444 } else {
8445 enforceModifyPermission();
8446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447
8448 final long identity = Binder.clearCallingIdentity();
8449 try {
8450 Phone phone = getPhone(subId);
8451 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008452 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8453 phone.carrierActionSetMeteredApnsEnabled(enabled);
8454 } else {
8455 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008457 }
8458 } finally {
8459 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008460 }
8461 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008462
8463 /**
8464 * Get Client request stats
8465 * @return List of Client Request Stats
8466 * @hide
8467 */
8468 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008469 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8470 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008472 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008473 return null;
8474 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008475 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008477 final long identity = Binder.clearCallingIdentity();
8478 try {
8479 if (phone != null) {
8480 return phone.getClientRequestStats();
8481 }
8482
8483 return null;
8484 } finally {
8485 Binder.restoreCallingIdentity(identity);
8486 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008487 }
8488
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008489 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008490 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008491 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008492 }
Jack Yueb4124c2017-02-16 15:32:43 -08008493
8494 /**
Grace Chen70990072017-03-24 17:21:30 -07008495 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008496 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008497 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008498 * @param state State of SIM (power down, power up, pass through)
8499 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8500 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8501 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008502 *
8503 **/
8504 @Override
Grace Chen70990072017-03-24 17:21:30 -07008505 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008506 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008507 Phone phone = PhoneFactory.getPhone(slotIndex);
8508
vagdeviaf9a5b92018-08-15 16:01:53 -07008509 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008511 final long identity = Binder.clearCallingIdentity();
8512 try {
8513 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008514 phone.setSimPowerState(state, null, workSource);
8515 }
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 }
8520
8521 /**
8522 * Set SIM card power state.
8523 *
8524 * @param slotIndex SIM slot id.
8525 * @param state State of SIM (power down, power up, pass through)
8526 * @param callback callback to trigger after success or failure
8527 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8528 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8529 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8530 *
8531 **/
8532 @Override
8533 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8534 IIntegerConsumer callback) {
8535 enforceModifyPermission();
8536 Phone phone = PhoneFactory.getPhone(slotIndex);
8537
8538 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8539
8540 final long identity = Binder.clearCallingIdentity();
8541 try {
8542 if (phone != null) {
8543 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8544 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545 }
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008548 }
8549 }
Shuo Qiandd210312017-04-12 22:11:33 +00008550
Tyler Gunn65d45c22017-06-05 11:22:26 -07008551 private boolean isUssdApiAllowed(int subId) {
8552 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008553 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008554 if (configManager == null) {
8555 return false;
8556 }
8557 PersistableBundle pb = configManager.getConfigForSubId(subId);
8558 if (pb == null) {
8559 return false;
8560 }
8561 return pb.getBoolean(
8562 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8563 }
8564
Shuo Qiandd210312017-04-12 22:11:33 +00008565 /**
8566 * Check if phone is in emergency callback mode
8567 * @return true if phone is in emergency callback mode
8568 * @param subId sub id
8569 */
goneil9c5f4872017-12-05 14:07:56 -08008570 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008571 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008572 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008573 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008574
8575 final long identity = Binder.clearCallingIdentity();
8576 try {
8577 if (phone != null) {
8578 return phone.isInEcm();
8579 } else {
8580 return false;
8581 }
8582 } finally {
8583 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008584 }
8585 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008586
8587 /**
8588 * Get the current signal strength information for the given subscription.
8589 * Because this information is not updated when the device is in a low power state
8590 * it should not be relied-upon to be current.
8591 * @param subId Subscription index
8592 * @return the most recent cached signal strength info from the modem
8593 */
8594 @Override
8595 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008596 final long identity = Binder.clearCallingIdentity();
8597 try {
8598 Phone p = getPhone(subId);
8599 if (p == null) {
8600 return null;
8601 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008602
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008603 return p.getSignalStrength();
8604 } finally {
8605 Binder.restoreCallingIdentity(identity);
8606 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008607 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008608
Pengquan Meng77b7f132018-08-22 14:49:57 -07008609 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008610 * Get the current modem radio state for the given slot.
8611 * @param slotIndex slot index.
8612 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008613 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008614 * @return the current radio power state from the modem
8615 */
8616 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008617 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008618 Phone phone = PhoneFactory.getPhone(slotIndex);
8619 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008620 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8621 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008622 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8623 }
8624
8625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 return phone.getRadioPowerState();
8628 } finally {
8629 Binder.restoreCallingIdentity(identity);
8630 }
8631 }
8632 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8633 }
8634
8635 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008636 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8637 *
8638 * <p>Requires one of the following permissions:
8639 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8640 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8641 * privileges.
8642 *
8643 * @param subId subscription id
8644 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8645 * {@code false}.
8646 */
8647 @Override
8648 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008649 try {
8650 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8651 null);
8652 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008653 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008654 mApp, subId, "isDataRoamingEnabled");
8655 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008656
Pengquan Menga1bb6272018-09-06 09:59:22 -07008657 boolean isEnabled = false;
8658 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008659 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008660 Phone phone = getPhone(subId);
8661 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008662 } finally {
8663 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008664 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008665 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008666 }
8667
8668
8669 /**
8670 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8671 *
8672 * <p> Requires permission:
8673 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8674 * privileges.
8675 *
8676 * @param subId subscription id
8677 * @param isEnabled {@code true} means enable, {@code false} means disable.
8678 */
8679 @Override
8680 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8682 mApp, subId, "setDataRoamingEnabled");
8683
Pengquan Menga1bb6272018-09-06 09:59:22 -07008684 final long identity = Binder.clearCallingIdentity();
8685 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008686 Phone phone = getPhone(subId);
8687 if (phone != null) {
8688 phone.setDataRoamingEnabled(isEnabled);
8689 }
8690 } finally {
8691 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008692 }
8693 }
8694
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008695 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008696 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008697 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008698 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008699 mApp, subId, "isManualNetworkSelectionAllowed");
8700
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008701 boolean isAllowed = true;
8702 final long identity = Binder.clearCallingIdentity();
8703 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008704 Phone phone = getPhone(subId);
8705 if (phone != null) {
8706 isAllowed = phone.isCspPlmnEnabled();
8707 }
8708 } finally {
8709 Binder.restoreCallingIdentity(identity);
8710 }
8711 return isAllowed;
8712 }
8713
8714 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008715 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008716 // Verify that tha callingPackage belongs to the calling UID
8717 mApp.getSystemService(AppOpsManager.class)
8718 .checkPackage(Binder.getCallingUid(), callingPackage);
8719
Jordan Liu1e142fc2019-04-22 15:10:43 -07008720 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008721 try {
8722 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008723 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008724 } catch (SecurityException e) {
8725 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8726 // has carrier privileges on an active UICC
8727 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8728 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008729 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008730 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008731 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008732
8733 final long identity = Binder.clearCallingIdentity();
8734 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008735 UiccController uiccController = UiccController.getInstance();
8736 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008737 if (hasReadPermission) {
8738 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008739 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008740
8741 // Remove private info if the caller doesn't have access
8742 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8743 for (UiccCardInfo cardInfo : cardInfos) {
8744 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8745 // is available
8746 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8747 if (card == null || card.getUiccProfile() == null) {
8748 // assume no access if the card or profile is unavailable
8749 filteredInfos.add(cardInfo.getUnprivileged());
8750 continue;
8751 }
8752 UiccProfile profile = card.getUiccProfile();
8753 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8754 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8755 filteredInfos.add(cardInfo);
8756 } else {
8757 filteredInfos.add(cardInfo.getUnprivileged());
8758 }
8759 }
8760 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008761 } finally {
8762 Binder.restoreCallingIdentity(identity);
8763 }
8764 }
8765
8766 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008767 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008768 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008770 final long identity = Binder.clearCallingIdentity();
8771 try {
8772 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8773 if (slots == null) {
8774 Rlog.i(LOG_TAG, "slots is null.");
8775 return null;
8776 }
8777
8778 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8779 for (int i = 0; i < slots.length; i++) {
8780 UiccSlot slot = slots[i];
8781 if (slot == null) {
8782 continue;
8783 }
8784
Jordan Liu7be7e652019-05-06 18:55:02 +00008785 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008786 UiccCard card = slot.getUiccCard();
8787 if (card != null) {
8788 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008789 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008790 cardId = slot.getEid();
8791 if (TextUtils.isEmpty(cardId)) {
8792 cardId = slot.getIccId();
8793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008794 }
8795
Jordan Liu857451f2019-05-09 16:35:35 -07008796 if (cardId != null) {
8797 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8798 // if cardId is an EID, it's all digits so this is fine
8799 cardId = IccUtils.stripTrailingFs(cardId);
8800 }
8801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008802 int cardState = 0;
8803 switch (slot.getCardState()) {
8804 case CARDSTATE_ABSENT:
8805 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8806 break;
8807 case CARDSTATE_PRESENT:
8808 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8809 break;
8810 case CARDSTATE_ERROR:
8811 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8812 break;
8813 case CARDSTATE_RESTRICTED:
8814 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8815 break;
8816 default:
8817 break;
8818
8819 }
8820
8821 infos[i] = new UiccSlotInfo(
8822 slot.isActive(),
8823 slot.isEuicc(),
8824 cardId,
8825 cardState,
8826 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008827 slot.isExtendedApduSupported(),
8828 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008829 }
8830 return infos;
8831 } finally {
8832 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008833 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008834 }
8835
8836 @Override
8837 public boolean switchSlots(int[] physicalSlots) {
8838 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008839
8840 final long identity = Binder.clearCallingIdentity();
8841 try {
8842 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8843 } finally {
8844 Binder.restoreCallingIdentity(identity);
8845 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008846 }
Jack Yu4c988042018-02-27 15:30:01 -08008847
8848 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008849 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008850 final long identity = Binder.clearCallingIdentity();
8851 try {
8852 return UiccController.getInstance().getCardIdForDefaultEuicc();
8853 } finally {
8854 Binder.restoreCallingIdentity(identity);
8855 }
8856 }
8857
Pengquan Meng85728fb2018-03-12 16:31:21 -07008858 /**
goneil47ffb6e2018-04-06 15:40:58 -07008859 * A test API to reload the UICC profile.
8860 *
8861 * <p>Requires that the calling app has permission
8862 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8863 * @hide
8864 */
8865 @Override
8866 public void refreshUiccProfile(int subId) {
8867 enforceModifyPermission();
8868
8869 final long identity = Binder.clearCallingIdentity();
8870 try {
8871 Phone phone = getPhone(subId);
8872 if (phone == null) {
8873 return;
8874 }
8875 UiccCard uiccCard = phone.getUiccCard();
8876 if (uiccCard == null) {
8877 return;
8878 }
8879 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8880 if (uiccProfile == null) {
8881 return;
8882 }
8883 uiccProfile.refresh();
8884 } finally {
8885 Binder.restoreCallingIdentity(identity);
8886 }
8887 }
8888
8889 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008890 * Returns false if the mobile data is disabled by default, otherwise return true.
8891 */
8892 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008893 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008894 }
8895
8896 /**
8897 * Returns true if the data roaming is enabled by default, i.e the system property
8898 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8899 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8900 */
8901 private boolean getDefaultDataRoamingEnabled(int subId) {
8902 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008903 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008904 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008905 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8906 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8907 return isDataRoamingEnabled;
8908 }
8909
8910 /**
8911 * Returns the default network type for the given {@code subId}, if the default network type is
8912 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8913 */
8914 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008915 List<Integer> list = TelephonyProperties.default_network();
8916 int phoneId = mSubscriptionController.getPhoneId(subId);
8917 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8918 return list.get(phoneId);
8919 }
8920 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008921 }
fionaxua13278b2018-03-21 00:08:13 -07008922
8923 @Override
8924 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008925 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008926 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008927
8928 final long identity = Binder.clearCallingIdentity();
8929 try {
8930 final Phone phone = getPhone(subId);
8931 if (phone == null) {
8932 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8933 return;
8934 }
chen xueaba88a2019-03-15 13:15:10 -07008935 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8936 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008937 if (carrierPrivilegeRules == null) {
8938 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8939 } else {
8940 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8941 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008942 } finally {
8943 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008944 }
fionaxua13278b2018-03-21 00:08:13 -07008945 }
8946
8947 @Override
8948 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008949 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008950
8951 final long identity = Binder.clearCallingIdentity();
8952 try {
8953 final Phone phone = getPhone(subId);
8954 if (phone == null) {
8955 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8956 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8957 }
8958 return phone.getCarrierIdListVersion();
8959 } finally {
8960 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008961 }
fionaxua13278b2018-03-21 00:08:13 -07008962 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008963
8964 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008965 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8966 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008968 mApp, subId, callingPackage, callingFeatureId,
8969 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008970 return -1;
8971 }
8972
8973 final long identity = Binder.clearCallingIdentity();
8974 try {
8975 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
8978 }
8979 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008980
8981 @Override
8982 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008983 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008984 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008985 mApp, subId, "getCdmaRoamingMode");
8986
8987 final long identity = Binder.clearCallingIdentity();
8988 try {
8989 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8990 } finally {
8991 Binder.restoreCallingIdentity(identity);
8992 }
8993 }
8994
8995 @Override
8996 public boolean setCdmaRoamingMode(int subId, int mode) {
8997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8998 mApp, subId, "setCdmaRoamingMode");
8999
9000 final long identity = Binder.clearCallingIdentity();
9001 try {
9002 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
9003 } finally {
9004 Binder.restoreCallingIdentity(identity);
9005 }
9006 }
9007
9008 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07009009 public int getCdmaSubscriptionMode(int subId) {
9010 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009011 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07009012 mApp, subId, "getCdmaSubscriptionMode");
9013
9014 final long identity = Binder.clearCallingIdentity();
9015 try {
9016 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
9017 } finally {
9018 Binder.restoreCallingIdentity(identity);
9019 }
9020 }
9021
9022 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07009023 public boolean setCdmaSubscriptionMode(int subId, int mode) {
9024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9025 mApp, subId, "setCdmaSubscriptionMode");
9026
9027 final long identity = Binder.clearCallingIdentity();
9028 try {
9029 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
9030 } finally {
9031 Binder.restoreCallingIdentity(identity);
9032 }
9033 }
Makoto Onukida3bf792018-09-18 16:06:29 -07009034
sqianc5eccab2018-10-19 18:46:41 -07009035 @Override
sqian8c685422019-02-22 15:55:18 -08009036 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009037 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08009038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009039 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
9040 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08009041 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9042 }
9043 final long identity = Binder.clearCallingIdentity();
9044 try {
sqian854d44b2018-12-12 16:48:18 -08009045 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
9046 for (Phone phone: PhoneFactory.getPhones()) {
9047 if (phone.getEmergencyNumberTracker() != null
9048 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
9049 emergencyNumberListInternal.put(
9050 phone.getSubId(),
9051 phone.getEmergencyNumberTracker().getEmergencyNumberList());
9052 }
sqian11b7a0e2018-12-05 18:48:28 -08009053 }
sqian854d44b2018-12-12 16:48:18 -08009054 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08009055 } finally {
9056 Binder.restoreCallingIdentity(identity);
9057 }
sqianc5eccab2018-10-19 18:46:41 -07009058 }
9059
9060 @Override
sqian8c685422019-02-22 15:55:18 -08009061 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08009062 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08009063 if (!exactMatch) {
9064 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009065 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08009066 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08009067 }
9068 final long identity = Binder.clearCallingIdentity();
9069 try {
sqian854d44b2018-12-12 16:48:18 -08009070 for (Phone phone: PhoneFactory.getPhones()) {
9071 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09009072 && phone.getEmergencyNumberTracker()
9073 .isEmergencyNumber(number, exactMatch)) {
9074 return true;
sqian11b7a0e2018-12-05 18:48:28 -08009075 }
sqian11b7a0e2018-12-05 18:48:28 -08009076 }
9077 return false;
9078 } finally {
9079 Binder.restoreCallingIdentity(identity);
9080 }
9081 }
9082
sqianf4ca7ed2019-01-15 18:32:07 -08009083 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08009084 * Start emergency callback mode for GsmCdmaPhone for testing.
9085 */
9086 @Override
9087 public void startEmergencyCallbackMode() {
9088 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9089 "startEmergencyCallbackMode");
9090 enforceModifyPermission();
9091 final long identity = Binder.clearCallingIdentity();
9092 try {
9093 for (Phone phone : PhoneFactory.getPhones()) {
9094 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
9095 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
9096 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
9097 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
9098 gsmCdmaPhone.obtainMessage(
9099 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
9100 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
9101 }
9102 }
9103 } finally {
9104 Binder.restoreCallingIdentity(identity);
9105 }
9106 }
9107
9108 /**
sqianf4ca7ed2019-01-15 18:32:07 -08009109 * Update emergency number list for test mode.
9110 */
9111 @Override
9112 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
9113 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9114 "updateEmergencyNumberListTestMode");
9115
9116 final long identity = Binder.clearCallingIdentity();
9117 try {
9118 for (Phone phone: PhoneFactory.getPhones()) {
9119 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9120 if (tracker != null) {
9121 tracker.executeEmergencyNumberTestModeCommand(action, num);
9122 }
9123 }
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 }
9128
9129 /**
9130 * Get the full emergency number list for test mode.
9131 */
9132 @Override
9133 public List<String> getEmergencyNumberListTestMode() {
9134 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9135 "getEmergencyNumberListTestMode");
9136
9137 final long identity = Binder.clearCallingIdentity();
9138 try {
9139 Set<String> emergencyNumbers = new HashSet<>();
9140 for (Phone phone: PhoneFactory.getPhones()) {
9141 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9142 if (tracker != null) {
9143 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
9144 emergencyNumbers.add(num.getNumber());
9145 }
9146 }
9147 }
9148 return new ArrayList<>(emergencyNumbers);
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
9151 }
9152 }
9153
chen xud6b45bd2018-10-30 22:27:10 -07009154 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08009155 public int getEmergencyNumberDbVersion(int subId) {
9156 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
9157
9158 final long identity = Binder.clearCallingIdentity();
9159 try {
9160 final Phone phone = getPhone(subId);
9161 if (phone == null) {
9162 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
9163 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
9164 }
9165 return phone.getEmergencyNumberDbVersion();
9166 } finally {
9167 Binder.restoreCallingIdentity(identity);
9168 }
9169 }
9170
9171 @Override
9172 public void notifyOtaEmergencyNumberDbInstalled() {
9173 enforceModifyPermission();
9174
9175 final long identity = Binder.clearCallingIdentity();
9176 try {
9177 for (Phone phone: PhoneFactory.getPhones()) {
9178 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9179 if (tracker != null) {
9180 tracker.updateOtaEmergencyNumberDatabase();
9181 }
9182 }
9183 } finally {
9184 Binder.restoreCallingIdentity(identity);
9185 }
9186 }
9187
9188 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08009189 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08009190 enforceActiveEmergencySessionPermission();
9191
9192 final long identity = Binder.clearCallingIdentity();
9193 try {
9194 for (Phone phone: PhoneFactory.getPhones()) {
9195 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9196 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08009197 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
9198 }
9199 }
9200 } finally {
9201 Binder.restoreCallingIdentity(identity);
9202 }
9203 }
9204
9205 @Override
9206 public void resetOtaEmergencyNumberDbFilePath() {
9207 enforceActiveEmergencySessionPermission();
9208
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 for (Phone phone: PhoneFactory.getPhones()) {
9212 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9213 if (tracker != null) {
9214 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009215 }
9216 }
9217 } finally {
9218 Binder.restoreCallingIdentity(identity);
9219 }
9220 }
9221
9222 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009223 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9224 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9225 Phone phone = getPhone(subId);
9226 if (phone == null) {
9227 return null;
9228 }
9229 final long identity = Binder.clearCallingIdentity();
9230 try {
9231 UiccProfile profile = UiccController.getInstance()
9232 .getUiccProfileForPhone(phone.getPhoneId());
9233 if (profile != null) {
9234 return profile.getCertsFromCarrierPrivilegeAccessRules();
9235 }
9236 } finally {
9237 Binder.restoreCallingIdentity(identity);
9238 }
9239 return null;
9240 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009241
9242 /**
9243 * Enable or disable a modem stack.
9244 */
9245 @Override
9246 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9247 enforceModifyPermission();
9248
9249 final long identity = Binder.clearCallingIdentity();
9250 try {
9251 Phone phone = PhoneFactory.getPhone(slotIndex);
9252 if (phone == null) {
9253 return false;
9254 } else {
9255 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9256 }
9257 } finally {
9258 Binder.restoreCallingIdentity(identity);
9259 }
9260 }
Michelecea4cf22018-12-21 15:00:11 -08009261
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009262 /**
9263 * Whether a modem stack is enabled or not.
9264 */
9265 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009266 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9267 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009268 Phone phone = PhoneFactory.getPhone(slotIndex);
9269 if (phone == null) return false;
9270
9271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009272 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9273 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009274 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9275 }
9276
9277 final long identity = Binder.clearCallingIdentity();
9278 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009279 try {
9280 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9281 } catch (NoSuchElementException ex) {
9282 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9283 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
9288
Michelecea4cf22018-12-21 15:00:11 -08009289 @Override
Michele0ea7d782019-03-19 14:58:42 -07009290 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009291 enforceModifyPermission();
9292
9293 final long identity = Binder.clearCallingIdentity();
9294 try {
9295 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009296 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009297 .commit();
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
9302
9303 @Override
Michele0ea7d782019-03-19 14:58:42 -07009304 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009305 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009307 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9308 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009309 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009310 }
Michelecea4cf22018-12-21 15:00:11 -08009311
9312 final long identity = Binder.clearCallingIdentity();
9313 try {
Michele0ea7d782019-03-19 14:58:42 -07009314 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009315 } finally {
9316 Binder.restoreCallingIdentity(identity);
9317 }
9318 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009319
Michele0ea7d782019-03-19 14:58:42 -07009320 @TelephonyManager.IsMultiSimSupportedResult
9321 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009322 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9323 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9324 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009325 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9326 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009327 }
9328 // Check if the hardware supports multisim functionality. If usage of multisim is not
9329 // supported by the modem, indicate that it is restricted.
9330 PhoneCapability staticCapability =
9331 mPhoneConfigurationManager.getStaticPhoneCapability();
9332 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009333 loge("isMultiSimSupportedInternal: no static configuration available");
9334 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009335 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009336 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009337 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9338 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009339 }
9340 // Check if support of multiple SIMs is restricted by carrier
9341 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009342 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009343 }
9344
Michele0ea7d782019-03-19 14:58:42 -07009345 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009346 }
9347
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009348 /**
9349 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009350 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9351 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9352 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009353 * @param numOfSims number of active sims we want to switch to
9354 */
9355 @Override
9356 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009357 if (numOfSims == 1) {
9358 enforceModifyPermission();
9359 } else {
9360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9361 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9362 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009363 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009364
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009365 try {
Michele30b57b22019-03-01 12:01:14 -08009366 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009367 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009368 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9369 return;
9370 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009371 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9372 } finally {
9373 Binder.restoreCallingIdentity(identity);
9374 }
9375 }
9376
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009377 @Override
9378 public boolean isApplicationOnUicc(int subId, int appType) {
9379 enforceReadPrivilegedPermission("isApplicationOnUicc");
9380 Phone phone = getPhone(subId);
9381 if (phone == null) {
9382 return false;
9383 }
9384 final long identity = Binder.clearCallingIdentity();
9385 try {
9386 UiccCard uiccCard = phone.getUiccCard();
9387 if (uiccCard == null) {
9388 return false;
9389 }
9390 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9391 if (uiccProfile == null) {
9392 return false;
9393 }
9394 if (TelephonyManager.APPTYPE_SIM <= appType
9395 && appType <= TelephonyManager.APPTYPE_ISIM) {
9396 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9397 }
9398 return false;
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 }
9403
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009404 /**
chen xub4baa772019-04-03 10:23:41 -07009405 * Get whether making changes to modem configurations will trigger reboot.
9406 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009407 */
9408 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009409 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9410 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009412 mApp, subId, callingPackage, callingFeatureId,
9413 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009414 return false;
9415 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009416 final long identity = Binder.clearCallingIdentity();
9417 try {
9418 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9419 } finally {
9420 Binder.restoreCallingIdentity(identity);
9421 }
9422 }
9423
Nathan Harold29f5f052019-02-15 13:41:57 -08009424 private void updateModemStateMetrics() {
9425 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9426 // TODO: check the state for each modem if the api is ready.
9427 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9428 }
9429
Pengquan Meng3889a572019-01-23 11:16:29 -08009430 @Override
9431 public int[] getSlotsMapping() {
9432 enforceReadPrivilegedPermission("getSlotsMapping");
9433
9434 final long identity = Binder.clearCallingIdentity();
9435 try {
9436 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9437 // All logical slots should have a mapping to a physical slot.
9438 int[] logicalSlotsMapping = new int[phoneCount];
9439 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9440 for (int i = 0; i < slotInfos.length; i++) {
9441 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9442 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9443 }
9444 }
9445 return logicalSlotsMapping;
9446 } finally {
9447 Binder.restoreCallingIdentity(identity);
9448 }
9449 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009450
9451 /**
9452 * Get the IRadio HAL Version
9453 */
9454 @Override
9455 public int getRadioHalVersion() {
9456 Phone phone = getDefaultPhone();
9457 if (phone == null) return -1;
9458 HalVersion hv = phone.getHalVersion();
9459 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9460 return hv.major * 100 + hv.minor;
9461 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009462
9463 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009464 * Get the current calling package name.
9465 * @return the current calling package name
9466 */
9467 @Override
9468 public String getCurrentPackageName() {
9469 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9470 }
9471
9472 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009473 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9474 * corresponding network requests on a subId.
9475 *
9476 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009477 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009478 * 2) APN is un-metered for this subscription, or
9479 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009480 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009481 *
9482 * @return whether data is allowed for a apn type.
9483 *
9484 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009485 */
9486 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009487 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009488 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9489 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009490
9491 // Now that all security checks passes, perform the operation as ourselves.
9492 final long identity = Binder.clearCallingIdentity();
9493 try {
9494 Phone phone = getPhone(subId);
9495 if (phone == null) return false;
9496
Jack Yu41407ee2019-05-13 16:54:09 -07009497 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009498 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9499 } finally {
9500 Binder.restoreCallingIdentity(identity);
9501 }
9502 }
9503
9504 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009505 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009506 enforceReadPrivilegedPermission("isApnMetered");
9507
9508 // Now that all security checks passes, perform the operation as ourselves.
9509 final long identity = Binder.clearCallingIdentity();
9510 try {
9511 Phone phone = getPhone(subId);
9512 if (phone == null) return true; // By default return true.
9513
Jack Yu41407ee2019-05-13 16:54:09 -07009514 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009515 } finally {
9516 Binder.restoreCallingIdentity(identity);
9517 }
9518 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009519
9520 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009521 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9522 int subscriptionId, IBooleanConsumer resultCallback) {
9523 enforceModifyPermission();
9524 long token = Binder.clearCallingIdentity();
9525 try {
9526 Phone phone = getPhone(subscriptionId);
9527 if (phone == null) {
9528 try {
9529 if (resultCallback != null) {
9530 resultCallback.accept(false);
9531 }
9532 } catch (RemoteException e) {
9533 // ignore
9534 }
9535 return;
9536 }
9537 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9538 Pair.create(specifiers, (x) -> {
9539 try {
9540 if (resultCallback != null) {
9541 resultCallback.accept(x);
9542 }
9543 } catch (RemoteException e) {
9544 // ignore
9545 }
9546 });
9547 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9548 } finally {
9549 Binder.restoreCallingIdentity(token);
9550 }
9551 }
9552
9553 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009554 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9555 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009556 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009557 mApp, subId, "getSystemSelectionChannels");
9558 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9559 final long identity = Binder.clearCallingIdentity();
9560 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009561 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9562 if (result instanceof IllegalStateException) {
9563 throw (IllegalStateException) result;
9564 }
9565 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009566 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9567 return specifiers;
9568 } finally {
9569 Binder.restoreCallingIdentity(identity);
9570 }
9571 }
9572
9573 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009574 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009575 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009576 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9577 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9578 if (iccRecords == null) {
9579 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9580 return false;
9581 }
9582 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9583 }
9584
9585 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009586 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9587 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009588 if (callingPackage == null) {
9589 callingPackage = getCurrentPackageName();
9590 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009591 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9592 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009593 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9594 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009595 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9596 }
9597 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9598 Intent intent = new Intent();
9599 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9600 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9601 // Bring up choose default SMS subscription dialog right now
9602 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9603 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9604 mApp.startActivity(intent);
9605 }
chen xud5ca2d52019-05-28 15:20:57 -07009606
9607 @Override
9608 public String getMmsUAProfUrl(int subId) {
9609 //TODO investigate if this API should require proper permission check in R b/133791609
9610 final long identity = Binder.clearCallingIdentity();
9611 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009612 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9613 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9614 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9615 return carrierUAProfUrl;
9616 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009617 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9618 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009619 } finally {
9620 Binder.restoreCallingIdentity(identity);
9621 }
9622 }
9623
9624 @Override
9625 public String getMmsUserAgent(int subId) {
9626 //TODO investigate if this API should require proper permission check in R b/133791609
9627 final long identity = Binder.clearCallingIdentity();
9628 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009629 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9630 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9631 if (!TextUtils.isEmpty(carrierUserAgent)) {
9632 return carrierUserAgent;
9633 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009634 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9635 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009636 } finally {
9637 Binder.restoreCallingIdentity(identity);
9638 }
9639 }
Jack Yub07d4972019-05-28 16:12:25 -07009640
9641 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009642 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9643 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009644
Jack Yub07d4972019-05-28 16:12:25 -07009645 final long identity = Binder.clearCallingIdentity();
9646 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009647 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009648 if (phone == null) return false;
9649
Hall Liua62f5da2020-09-25 10:42:19 -07009650 switch (policy) {
9651 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9652 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9653 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9654 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9655 default:
9656 throw new IllegalArgumentException(policy + " is not a valid policy");
9657 }
Jack Yub07d4972019-05-28 16:12:25 -07009658 } finally {
9659 Binder.restoreCallingIdentity(identity);
9660 }
9661 }
9662
9663 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009664 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009665 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009666 enforceModifyPermission();
9667
changbettyd5c246e2019-12-24 15:40:37 +08009668 final long identity = Binder.clearCallingIdentity();
9669 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009670 Phone phone = getPhone(subscriptionId);
9671 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009672
Hall Liua62f5da2020-09-25 10:42:19 -07009673 switch (policy) {
9674 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9675 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9676 break;
9677 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9678 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9679 break;
9680 default:
9681 throw new IllegalArgumentException(policy + " is not a valid policy");
9682 }
changbettyd5c246e2019-12-24 15:40:37 +08009683 } finally {
9684 Binder.restoreCallingIdentity(identity);
9685 }
9686 }
9687
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009688 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009689 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009690 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9691 * otherwise.
9692 */
9693 @Override
9694 public void setCepEnabled(boolean isCepEnabled) {
9695 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9696
9697 final long identity = Binder.clearCallingIdentity();
9698 try {
9699 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9700 for (Phone phone : PhoneFactory.getPhones()) {
9701 Phone defaultPhone = phone.getImsPhone();
9702 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9703 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9704 ImsPhoneCallTracker imsPhoneCallTracker =
9705 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9706 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9707 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9708 + imsPhone.getMsisdn());
9709 }
9710 }
9711 } finally {
9712 Binder.restoreCallingIdentity(identity);
9713 }
9714 }
allenwtsu46dcc572020-01-08 18:24:03 +08009715
9716 /**
9717 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9718 *
9719 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9720 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9721 * before being read.
9722 */
9723 @Override
9724 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9725 isCompressed) {
9726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9727 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009728 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9729 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9730 }
9731 if (!isImsAvailableOnDevice()) {
9732 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9733 "IMS not available on device.");
9734 }
9735
9736 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009737 try {
Hui Wang761a6682020-10-31 05:12:53 +00009738 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9739 } finally {
9740 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009741 }
9742 }
zoey chene02881a2019-12-30 16:11:23 +08009743
9744 @Override
9745 public boolean isIccLockEnabled(int subId) {
9746 enforceReadPrivilegedPermission("isIccLockEnabled");
9747
9748 // Now that all security checks passes, perform the operation as ourselves.
9749 final long identity = Binder.clearCallingIdentity();
9750 try {
9751 Phone phone = getPhone(subId);
9752 if (phone != null && phone.getIccCard() != null) {
9753 return phone.getIccCard().getIccLockEnabled();
9754 } else {
9755 return false;
9756 }
9757 } finally {
9758 Binder.restoreCallingIdentity(identity);
9759 }
9760 }
9761
9762 /**
9763 * Set the ICC pin lock enabled or disabled.
9764 *
9765 * @return an integer representing the status of IccLock enabled or disabled in the following
9766 * three cases:
9767 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9768 * successfully.
9769 * - Positive number and zero for remaining password attempts.
9770 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9771 *
9772 */
9773 @Override
9774 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9775 enforceModifyPermission();
9776
9777 Phone phone = getPhone(subId);
9778 if (phone == null) {
9779 return 0;
9780 }
9781 // Now that all security checks passes, perform the operation as ourselves.
9782 final long identity = Binder.clearCallingIdentity();
9783 try {
9784 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9785 new Pair<Boolean, String>(enabled, password), phone, null);
9786 return attemptsRemaining;
9787
9788 } catch (Exception e) {
9789 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9790 } finally {
9791 Binder.restoreCallingIdentity(identity);
9792 }
9793 return 0;
9794 }
9795
9796 /**
9797 * Change the ICC password used in ICC pin lock.
9798 *
9799 * @return an integer representing the status of IccLock changed in the following three cases:
9800 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9801 * - Positive number and zero for remaining password attempts.
9802 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9803 *
9804 */
9805 @Override
9806 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9807 enforceModifyPermission();
9808
9809 Phone phone = getPhone(subId);
9810 if (phone == null) {
9811 return 0;
9812 }
9813 // Now that all security checks passes, perform the operation as ourselves.
9814 final long identity = Binder.clearCallingIdentity();
9815 try {
9816 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9817 new Pair<String, String>(oldPassword, newPassword), phone, null);
9818 return attemptsRemaining;
9819
9820 } catch (Exception e) {
9821 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9822 } finally {
9823 Binder.restoreCallingIdentity(identity);
9824 }
9825 return 0;
9826 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009827
9828 /**
9829 * Request for receiving user activity notification
9830 */
9831 @Override
9832 public void requestUserActivityNotification() {
9833 if (!mNotifyUserActivity.get()
9834 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9835 mNotifyUserActivity.set(true);
9836 }
9837 }
9838
9839 /**
9840 * Called when userActivity is signalled in the power manager.
9841 * This is safe to call from any thread, with any window manager locks held or not.
9842 */
9843 @Override
9844 public void userActivity() {
9845 // ***************************************
9846 // * Inherited from PhoneWindowManager *
9847 // ***************************************
9848 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9849 // WITH ITS LOCKS HELD.
9850 //
9851 // This code must be VERY careful about the locks
9852 // it acquires.
9853 // In fact, the current code acquires way too many,
9854 // and probably has lurking deadlocks.
9855
9856 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9857 throw new SecurityException("Only the OS may call notifyUserActivity()");
9858 }
9859
9860 if (mNotifyUserActivity.getAndSet(false)) {
9861 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9862 USER_ACTIVITY_NOTIFICATION_DELAY);
9863 }
9864 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009865
9866 @Override
9867 public boolean canConnectTo5GInDsdsMode() {
9868 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9869 }
Jack Yud10cdd42020-09-28 20:28:01 -07009870
9871 @Override
9872 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9873 String callingFeatureId) {
9874 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9875 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9876 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9877 }
9878
9879 Phone phone = getPhone(subId);
9880 if (phone == null) {
9881 throw new RuntimeException("phone is not available");
9882 }
9883 // Now that all security checks passes, perform the operation as ourselves.
9884 final long identity = Binder.clearCallingIdentity();
9885 try {
9886 return phone.getEquivalentHomePlmns();
9887 } finally {
9888 Binder.restoreCallingIdentity(identity);
9889 }
9890 }
Daniel Bright59e67312020-11-13 11:49:37 -08009891
9892 @Override
9893 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009894 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9895 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009896 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009897 if (radioInterfaceCapabilities == null) {
9898 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009899 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009900 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009901 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009902
Hui Wang641e81c2020-10-12 12:14:23 -07009903 @Override
9904 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9905 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009906 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9907 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9908 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9909 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9910 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009911 if (DBG) {
9912 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9913 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9914 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9915 }
9916
9917 if (!SubscriptionManager.isValidSubscriptionId(subId)
9918 || appType < TelephonyManager.APPTYPE_UNKNOWN
9919 || appType > TelephonyManager.APPTYPE_ISIM
9920 || nafUrl == null || securityProtocol == null || callback == null) {
9921 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9922 if (callback != null) {
9923 try {
9924 callback.onAuthenticationFailure(
9925 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9926 } catch (RemoteException exception) {
9927 log("Fail to notify onAuthenticationFailure due to " + exception);
9928 }
9929 return;
9930 }
9931 }
9932
9933 final long token = Binder.clearCallingIdentity();
9934 try {
9935 getGbaManager(subId).bootstrapAuthenticationRequest(
9936 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9937 forceBootStrapping, callback));
9938 } finally {
9939 Binder.restoreCallingIdentity(token);
9940 }
9941 }
9942
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009943 /**
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009944 * Attempts to set the radio power state for all phones for thermal reason.
9945 * This does not guarantee that the
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009946 * requested radio power state will actually be set. See {@link
9947 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9948 *
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009949 * @param enable {@code true} if trying to turn radio on.
9950 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9951 * false}.
9952 */
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009953 private boolean setRadioPowerForThermal(boolean enable) {
9954 boolean isPhoneAvailable = false;
9955 for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) {
9956 Phone phone = PhoneFactory.getPhone(i);
9957 if (phone != null) {
9958 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9959 isPhoneAvailable = true;
9960 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009961 }
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009962
9963 // return true if successfully informed the phone object about the thermal radio power
9964 // request.
9965 return isPhoneAvailable;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009966 }
9967
9968 private int handleDataThrottlingRequest(int subId,
9969 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009970 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9971 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9972 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9973 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9974 throw new IllegalArgumentException("modem does not support data throttling");
9975 }
9976
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009977 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9978 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -07009979 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009980 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9981 }
9982
9983 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9984
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009985 if (isDataThrottlingSupported) {
9986 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009987 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009988 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9989 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9990 } else if (thermalMitigationResult
9991 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
Jack Nudelman760d0962021-05-20 13:57:30 -07009992 log("Modem likely does not support data throttling on secondary carrier. Data " +
9993 "throttling action = " + dataThrottlingRequest.getDataThrottlingAction());
9994 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009995 }
9996 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009997 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009998
9999 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010000 }
10001
Jack Nudelman644b91a2021-03-12 14:09:48 -080010002 private static List<String> getThermalMitigationAllowlist(Context context) {
10003 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
10004 for (String pckg : context.getResources()
10005 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
10006 sThermalMitigationAllowlistedPackages.add(pckg);
10007 }
10008 }
10009
10010 return sThermalMitigationAllowlistedPackages;
10011 }
10012
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010013 private boolean isAnyPhoneInEmergencyState() {
10014 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
10015 if (tm.isInEmergencyCall()) {
10016 Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call");
10017 return true;
10018 }
10019 for (Phone phone : PhoneFactory.getPhones()) {
10020 if (phone.isInEmergencySmsMode() || phone.isInEcm()) {
10021 Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = "
10022 + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = "
10023 + phone.isInEcm());
10024 return true;
10025 }
10026 }
10027
10028 return false;
10029 }
10030
Jack Nudelman644b91a2021-03-12 14:09:48 -080010031 /**
10032 * Used by shell commands to add an authorized package name for thermal mitigation.
10033 * @param packageName name of package to be allowlisted
10034 * @param context
10035 */
10036 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
10037 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10038 sThermalMitigationAllowlistedPackages.add(packageName);
10039 }
10040
10041 /**
10042 * Used by shell commands to remove an authorized package name for thermal mitigation.
10043 * @param packageName name of package to remove from allowlist
10044 * @param context
10045 */
10046 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
10047 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
10048 sThermalMitigationAllowlistedPackages.remove(packageName);
10049 }
10050
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010051 /**
10052 * Thermal mitigation request to control functionalities at modem.
10053 *
10054 * @param subId the id of the subscription.
10055 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -080010056 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010057 *
10058 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
10059 */
10060 @Override
10061 @ThermalMitigationResult
10062 public int sendThermalMitigationRequest(
10063 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -080010064 ThermalMitigationRequest thermalMitigationRequest,
10065 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010066 enforceModifyPermission();
10067
Jack Nudelman644b91a2021-03-12 14:09:48 -080010068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
10069 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
10070 .contains(callingPackage)) {
10071 throw new SecurityException("Calling package must be configured in the device config. "
10072 + "calling package: " + callingPackage);
10073 }
10074
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010075 WorkSource workSource = getWorkSource(Binder.getCallingUid());
10076 final long identity = Binder.clearCallingIdentity();
10077
10078 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
10079 try {
10080 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
10081 switch (thermalMitigationAction) {
10082 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
10083 thermalMitigationResult =
10084 handleDataThrottlingRequest(subId,
10085 thermalMitigationRequest.getDataThrottlingRequest());
10086 break;
10087 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
10088 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10089 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
10090 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
10091 }
10092
10093 // Ensure that radio is on. If not able to power on due to phone being
10094 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010095 if (!setRadioPowerForThermal(true)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010096 thermalMitigationResult =
10097 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10098 break;
10099 }
10100
10101 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
10102 false);
10103 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10104 break;
10105 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
10106 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
10107 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
10108 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
10109 }
10110
10111 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
10112 if (registry != null) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010113 Phone phone = getPhone(subId);
10114 if (phone == null) {
10115 thermalMitigationResult =
10116 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10117 break;
10118 }
10119
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010120 TelephonyConnectionService service =
10121 registry.getTelephonyConnectionService();
Jack Nudelmanb30ac302021-06-17 15:39:58 -070010122 if (service != null && service.isEmergencyCallPending()) {
Jack Nudelmane69bbc82021-05-13 10:00:15 -070010123 Log.e(LOG_TAG, "An emergency call is pending");
10124 thermalMitigationResult =
10125 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10126 break;
10127 } else if (isAnyPhoneInEmergencyState()) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010128 thermalMitigationResult =
10129 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
10130 break;
10131 }
10132 } else {
10133 thermalMitigationResult =
10134 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10135 break;
10136 }
10137
10138 // Turn radio off. If not able to power off due to phone being unavailable,
10139 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
Sooraj Sasindran72cff492021-07-29 09:42:42 -070010140 if (!setRadioPowerForThermal(false)) {
Jack Nudelmanb0b87642020-11-12 15:04:39 -080010141 thermalMitigationResult =
10142 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
10143 break;
10144 }
10145 thermalMitigationResult =
10146 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
10147 break;
10148 default:
10149 throw new IllegalArgumentException("the requested thermalMitigationAction does "
10150 + "not exist. Requested action: " + thermalMitigationAction);
10151 }
10152 } catch (IllegalArgumentException e) {
10153 throw e;
10154 } catch (Exception e) {
10155 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
10156 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
10157 } finally {
10158 Binder.restoreCallingIdentity(identity);
10159 }
10160
10161 if (DBG) {
10162 log("thermalMitigationRequest returning with thermalMitigationResult: "
10163 + thermalMitigationResult);
10164 }
10165
10166 return thermalMitigationResult;
10167 }
Hui Wang641e81c2020-10-12 12:14:23 -070010168
10169 /**
10170 * Set the GbaService Package Name that Telephony will bind to.
10171 *
10172 * @param subId The sim that the GbaService is associated with.
10173 * @param packageName The name of the package to be replaced with.
10174 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10175 */
10176 @Override
10177 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
10178 enforceModifyPermission();
10179
10180 final long identity = Binder.clearCallingIdentity();
10181 try {
10182 return getGbaManager(subId).overrideServicePackage(packageName);
10183 } finally {
10184 Binder.restoreCallingIdentity(identity);
10185 }
10186 }
10187
10188 /**
10189 * Return the package name of the currently bound GbaService.
10190 *
10191 * @param subId The sim that the GbaService is associated with.
10192 * @return the package name of the GbaService configuration, null if GBA is not supported.
10193 */
10194 @Override
10195 public String getBoundGbaService(int subId) {
10196 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
10197
10198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 return getGbaManager(subId).getServicePackage();
10201 } finally {
10202 Binder.restoreCallingIdentity(identity);
10203 }
10204 }
10205
10206 /**
10207 * Set the release time for telephony to unbind GbaService.
10208 *
10209 * @param subId The sim that the GbaService is associated with.
10210 * @param interval The release time to unbind GbaService by millisecond.
10211 * @return true if setting the GbaService to bind to succeeded, false if it did not.
10212 */
10213 @Override
10214 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
10215 enforceModifyPermission();
10216
10217 final long identity = Binder.clearCallingIdentity();
10218 try {
10219 return getGbaManager(subId).overrideReleaseTime(interval);
10220 } finally {
10221 Binder.restoreCallingIdentity(identity);
10222 }
10223 }
10224
10225 /**
10226 * Return the release time for telephony to unbind GbaService.
10227 *
10228 * @param subId The sim that the GbaService is associated with.
10229 * @return The release time to unbind GbaService by millisecond.
10230 */
10231 @Override
10232 public int getGbaReleaseTime(int subId) {
10233 enforceReadPrivilegedPermission("getGbaReleaseTime");
10234
10235 final long identity = Binder.clearCallingIdentity();
10236 try {
10237 return getGbaManager(subId).getReleaseTime();
10238 } finally {
10239 Binder.restoreCallingIdentity(identity);
10240 }
10241 }
10242
10243 private GbaManager getGbaManager(int subId) {
10244 GbaManager instance = GbaManager.getInstance(subId);
10245 if (instance == null) {
10246 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10247 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10248 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10249 }
10250 return instance;
10251 }
Hui Wang761a6682020-10-31 05:12:53 +000010252
10253 /**
10254 * indicate whether the device and the carrier can support
10255 * RCS VoLTE single registration.
10256 */
10257 @Override
10258 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010259 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10260 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10261 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10262 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010263
10264 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10265 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10266 }
10267
10268 final long identity = Binder.clearCallingIdentity();
10269 try {
10270 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10271 if (rpm != null) {
Hui Wang67af90e2021-06-04 16:57:15 -070010272 Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId);
10273 if (isCapable != null) {
10274 return isCapable;
10275 }
Hui Wang761a6682020-10-31 05:12:53 +000010276 }
Hui Wang67af90e2021-06-04 16:57:15 -070010277 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10278 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010279 } finally {
10280 Binder.restoreCallingIdentity(identity);
10281 }
10282 }
10283
10284 /**
10285 * Register RCS provisioning callback.
10286 */
10287 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010288 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010289 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010290 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010291 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010292 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10293 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010294
10295 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10296 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10297 }
10298 if (!isImsAvailableOnDevice()) {
10299 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10300 "IMS not available on device.");
10301 }
10302
10303 final long identity = Binder.clearCallingIdentity();
10304 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010305 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010306 .registerRcsProvisioningCallback(subId, callback)) {
Brad Ebinger919631e2021-06-02 17:46:35 -070010307 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10308 "Active subscription not found.");
Hui Wang68cd3722021-01-11 20:04:53 -080010309 }
Hui Wang761a6682020-10-31 05:12:53 +000010310 } finally {
10311 Binder.restoreCallingIdentity(identity);
10312 }
10313 }
10314
10315 /**
10316 * Unregister RCS provisioning callback.
10317 */
10318 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010319 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010320 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010321 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010322 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010323 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10324 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010325
10326 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10327 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10328 }
10329 if (!isImsAvailableOnDevice()) {
10330 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10331 "IMS not available on device.");
10332 }
10333
10334 final long identity = Binder.clearCallingIdentity();
10335 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010336 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010337 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010338 } finally {
10339 Binder.restoreCallingIdentity(identity);
10340 }
10341 }
10342
10343 /**
10344 * trigger RCS reconfiguration.
10345 */
10346 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010347 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10348 "triggerRcsReconfiguration",
10349 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010350
10351 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10352 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10353 }
10354 if (!isImsAvailableOnDevice()) {
10355 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10356 "IMS not available on device.");
10357 }
10358
10359 final long identity = Binder.clearCallingIdentity();
10360 try {
10361 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10362 } finally {
10363 Binder.restoreCallingIdentity(identity);
10364 }
10365 }
10366
10367 /**
10368 * Provide the client configuration parameters of the RCS application.
10369 */
10370 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010371 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10372 "setRcsClientConfiguration",
10373 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010374
10375 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10376 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10377 }
10378 if (!isImsAvailableOnDevice()) {
10379 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10380 "IMS not available on device.");
10381 }
10382
10383 final long identity = Binder.clearCallingIdentity();
10384
10385 try {
10386 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10387 if (configBinder == null) {
10388 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
Brad Ebinger919631e2021-06-02 17:46:35 -070010389 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION,
10390 "could not find the requested subscription");
Hui Wang761a6682020-10-31 05:12:53 +000010391 } else {
10392 configBinder.setRcsClientConfiguration(rcc);
10393 }
10394 } catch (RemoteException e) {
10395 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
Brad Ebinger919631e2021-06-02 17:46:35 -070010396 throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE,
10397 "service is temporarily unavailable.");
Hui Wang761a6682020-10-31 05:12:53 +000010398 } finally {
10399 Binder.restoreCallingIdentity(identity);
10400 }
10401 }
10402
10403 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010404 * Enables or disables the test mode for RCS VoLTE single registration.
10405 */
10406 @Override
10407 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10408 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10409 "setRcsSingleRegistrationTestModeEnabled");
10410
10411 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10412 }
10413
10414 /**
10415 * Gets the test mode for RCS VoLTE single registration.
10416 */
10417 @Override
10418 public boolean getRcsSingleRegistrationTestModeEnabled() {
10419 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10420 "getRcsSingleRegistrationTestModeEnabled");
10421
10422 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10423 }
10424
10425 /**
Hui Wang761a6682020-10-31 05:12:53 +000010426 * Overrides the config of RCS VoLTE single registration enabled for the device.
10427 */
10428 @Override
10429 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10430 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10431 "setDeviceSingleRegistrationEnabledOverride");
10432 enforceModifyPermission();
10433
10434 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10435 : Boolean.parseBoolean(enabledStr);
10436 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010437 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010438 }
10439
10440 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010441 * Sends a device to device communication message. Only usable via shell.
10442 * @param message message to send.
10443 * @param value message value.
10444 */
10445 @Override
10446 public void sendDeviceToDeviceMessage(int message, int value) {
10447 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010448 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010449 enforceModifyPermission();
10450
10451 final long identity = Binder.clearCallingIdentity();
10452 try {
10453 TelephonyConnectionService service =
10454 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10455 if (service == null) {
10456 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10457 return;
10458 }
10459 service.sendTestDeviceToDeviceMessage(message, value);
10460 } finally {
10461 Binder.restoreCallingIdentity(identity);
10462 }
10463 }
10464
Tyler Gunnbabbda02021-02-10 11:05:02 -080010465 /**
10466 * Sets the specified device to device transport active.
10467 * @param transport The transport to set active.
10468 */
10469 @Override
10470 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10471 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10472 "setActiveDeviceToDeviceTransport");
10473 enforceModifyPermission();
10474
10475 final long identity = Binder.clearCallingIdentity();
10476 try {
10477 TelephonyConnectionService service =
10478 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10479 if (service == null) {
10480 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10481 return;
10482 }
10483 service.setActiveDeviceToDeviceTransport(transport);
10484 } finally {
10485 Binder.restoreCallingIdentity(identity);
10486 }
10487 }
Tyler Gunn92479152021-01-20 16:30:10 -080010488
Tyler Gunnd4339262021-05-03 14:46:49 -070010489 @Override
10490 public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) {
10491 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10492 "setDeviceToDeviceForceEnabled");
10493
10494 final long identity = Binder.clearCallingIdentity();
10495 try {
10496 Arrays.stream(PhoneFactory.getPhones()).forEach(
10497 p -> {
10498 Phone thePhone = p.getImsPhone();
10499 if (thePhone != null && thePhone instanceof ImsPhone) {
10500 ImsPhone imsPhone = (ImsPhone) thePhone;
10501 CallTracker tracker = imsPhone.getCallTracker();
10502 if (tracker != null && tracker instanceof ImsPhoneCallTracker) {
10503 ImsPhoneCallTracker imsPhoneCallTracker =
10504 (ImsPhoneCallTracker) tracker;
10505 imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled);
10506 }
10507 }
10508 }
10509 );
10510 } finally {
10511 Binder.restoreCallingIdentity(identity);
10512 }
10513 }
10514
Tyler Gunn92479152021-01-20 16:30:10 -080010515 /**
Hui Wang761a6682020-10-31 05:12:53 +000010516 * Gets the config of RCS VoLTE single registration enabled for the device.
10517 */
10518 @Override
10519 public boolean getDeviceSingleRegistrationEnabled() {
10520 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10521 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10522 }
10523
10524 /**
10525 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10526 */
10527 @Override
10528 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10529 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10530 "setCarrierSingleRegistrationEnabledOverride");
10531 enforceModifyPermission();
10532
10533 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10534 : Boolean.parseBoolean(enabledStr);
10535 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10536 subId, enabled);
10537 }
10538
10539 /**
10540 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10541 */
10542 @Override
10543 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10544 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10545 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10546 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010547
10548 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010549 * Overrides the ims feature validation result
10550 */
10551 @Override
10552 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10554 "setImsFeatureValidationOverride");
10555
10556 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10557 : Boolean.parseBoolean(enabledStr);
10558 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10559 subId, enabled);
10560 }
10561
10562 /**
10563 * Gets the ims feature validation override value
10564 */
10565 @Override
10566 public boolean getImsFeatureValidationOverride(int subId) {
10567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10568 "getImsFeatureValidationOverride");
10569 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10570 }
10571
10572 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010573 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10574 * their mobile plan.
10575 */
10576 @Override
10577 public String getMobileProvisioningUrl() {
10578 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10579 final long identity = Binder.clearCallingIdentity();
10580 try {
10581 return getDefaultPhone().getMobileProvisioningUrl();
10582 } finally {
10583 Binder.restoreCallingIdentity(identity);
10584 }
10585 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010586
James.cf Linbcdf8b32021-01-14 16:44:13 +080010587 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010588 * Get the EAB contact from the EAB database.
10589 */
10590 @Override
10591 public String getContactFromEab(String contact) {
10592 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10593 enforceModifyPermission();
10594 final long identity = Binder.clearCallingIdentity();
10595 try {
10596 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10597 } finally {
10598 Binder.restoreCallingIdentity(identity);
10599 }
10600 }
10601
10602 /**
Calvin Pana1434322021-07-01 19:27:01 +080010603 * Get the EAB capability from the EAB database.
10604 */
10605 @Override
10606 public String getCapabilityFromEab(String contact) {
10607 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab");
10608 enforceModifyPermission();
10609 final long identity = Binder.clearCallingIdentity();
10610 try {
10611 return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact);
10612 } finally {
10613 Binder.restoreCallingIdentity(identity);
10614 }
10615 }
10616
10617 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010618 * Remove the EAB contacts from the EAB database.
10619 */
10620 @Override
10621 public int removeContactFromEab(int subId, String contacts) {
10622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10623 enforceModifyPermission();
10624 final long identity = Binder.clearCallingIdentity();
10625 try {
10626 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10627 } finally {
10628 Binder.restoreCallingIdentity(identity);
10629 }
10630 }
10631
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010632 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010633 public boolean getDeviceUceEnabled() {
10634 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10635 final long identity = Binder.clearCallingIdentity();
10636 try {
10637 return mApp.getDeviceUceEnabled();
10638 } finally {
10639 Binder.restoreCallingIdentity(identity);
10640 }
10641 }
10642
10643 @Override
10644 public void setDeviceUceEnabled(boolean isEnabled) {
10645 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10646 final long identity = Binder.clearCallingIdentity();
10647 try {
10648 mApp.setDeviceUceEnabled(isEnabled);
10649 } finally {
10650 Binder.restoreCallingIdentity(identity);
10651 }
10652 }
10653
Brad Ebinger14d467f2021-02-12 06:18:28 +000010654 /**
10655 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10656 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10657 */
10658 // Used for SHELL command only right now.
10659 @Override
10660 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10661 List<String> featureTags) {
10662 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10663 "addUceRegistrationOverrideShell");
10664 final long identity = Binder.clearCallingIdentity();
10665 try {
10666 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10667 new ArraySet<>(featureTags));
10668 } catch (ImsException e) {
10669 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10670 } finally {
10671 Binder.restoreCallingIdentity(identity);
10672 }
10673 }
10674
10675 /**
10676 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10677 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10678 */
10679 // Used for SHELL command only right now.
10680 @Override
10681 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10682 List<String> featureTags) {
10683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10684 "removeUceRegistrationOverrideShell");
10685 final long identity = Binder.clearCallingIdentity();
10686 try {
10687 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10688 new ArraySet<>(featureTags));
10689 } catch (ImsException e) {
10690 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10691 } finally {
10692 Binder.restoreCallingIdentity(identity);
10693 }
10694 }
10695
10696 /**
10697 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10698 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10699 */
10700 // Used for SHELL command only right now.
10701 @Override
10702 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10704 "clearUceRegistrationOverrideShell");
10705 final long identity = Binder.clearCallingIdentity();
10706 try {
10707 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10708 } catch (ImsException e) {
10709 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10710 } finally {
10711 Binder.restoreCallingIdentity(identity);
10712 }
10713 }
10714
10715 /**
10716 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10717 */
10718 // Used for SHELL command only right now.
10719 @Override
10720 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10721 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10722 "getLatestRcsContactUceCapabilityShell");
10723 final long identity = Binder.clearCallingIdentity();
10724 try {
10725 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10726 } catch (ImsException e) {
10727 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10728 } finally {
10729 Binder.restoreCallingIdentity(identity);
10730 }
10731 }
10732
10733 /**
10734 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10735 * device does not have an active PUBLISH.
10736 */
10737 // Used for SHELL command only right now.
10738 @Override
10739 public String getLastUcePidfXmlShell(int subId) {
10740 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10741 final long identity = Binder.clearCallingIdentity();
10742 try {
10743 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10744 } catch (ImsException e) {
10745 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10746 } finally {
10747 Binder.restoreCallingIdentity(identity);
10748 }
10749 }
10750
James.cf Line8713a42021-04-29 16:04:26 +080010751 /**
10752 * Remove UCE requests cannot be sent to the network status.
10753 */
10754 // Used for SHELL command only right now.
10755 @Override
10756 public boolean removeUceRequestDisallowedStatus(int subId) {
10757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus");
10758 final long identity = Binder.clearCallingIdentity();
10759 try {
10760 return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId);
10761 } catch (ImsException e) {
10762 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10763 } finally {
10764 Binder.restoreCallingIdentity(identity);
10765 }
10766 }
10767
James.cf Lin18bb9002021-05-25 01:37:38 +080010768 /**
10769 * Remove UCE requests cannot be sent to the network status.
10770 */
10771 // Used for SHELL command only.
10772 @Override
10773 public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) {
10774 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout");
10775 final long identity = Binder.clearCallingIdentity();
10776 try {
10777 return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs);
10778 } catch (ImsException e) {
10779 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10780 } finally {
10781 Binder.restoreCallingIdentity(identity);
10782 }
10783 }
Brad Ebinger14d467f2021-02-12 06:18:28 +000010784
James.cf Lin4b784aa2021-01-31 03:25:15 +080010785 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010786 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10787 String callingPackage) {
10788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10789 mApp, subId, "setSignalStrengthUpdateRequest");
10790
10791 final int callingUid = Binder.getCallingUid();
10792 // Verify that tha callingPackage belongs to the calling UID
10793 mApp.getSystemService(AppOpsManager.class)
10794 .checkPackage(callingUid, callingPackage);
10795
10796 validateSignalStrengthUpdateRequest(request, callingUid);
10797
10798 final long identity = Binder.clearCallingIdentity();
10799 try {
10800 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10801 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10802
10803 if (result instanceof IllegalStateException) {
10804 throw (IllegalStateException) result;
10805 }
10806 } finally {
10807 Binder.restoreCallingIdentity(identity);
10808 }
10809 }
10810
10811 @Override
10812 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10813 String callingPackage) {
10814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10815 mApp, subId, "clearSignalStrengthUpdateRequest");
10816
10817 final int callingUid = Binder.getCallingUid();
10818 // Verify that tha callingPackage belongs to the calling UID
10819 mApp.getSystemService(AppOpsManager.class)
10820 .checkPackage(callingUid, callingPackage);
10821
10822 final long identity = Binder.clearCallingIdentity();
10823 try {
10824 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10825 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10826
10827 if (result instanceof IllegalStateException) {
10828 throw (IllegalStateException) result;
10829 }
10830 } finally {
10831 Binder.restoreCallingIdentity(identity);
10832 }
10833 }
10834
10835 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10836 int callingUid) {
10837 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10838 // phone/system process do not have further restriction on request
10839 return;
10840 }
10841
10842 // Applications has restrictions on how to use the request:
10843 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10844 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10845 // This is not system caller which has been checked above
10846 throw new IllegalArgumentException(
10847 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10848 }
10849
10850 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10851 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10852 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10853 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10854 || info.isEnabled()) {
10855 throw new IllegalArgumentException(
10856 "Only system can set hide fields in SignalThresholdInfo");
10857 }
10858
10859 // Thresholds length for each RAN need in range. This has been validated in
10860 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10861 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10862 final int[] thresholds = info.getThresholds();
10863 Objects.requireNonNull(thresholds);
10864 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10865 || thresholds.length
10866 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10867 throw new IllegalArgumentException(
10868 "thresholds length is out of range: " + thresholds.length);
10869 }
10870 }
10871 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010872
10873 /**
10874 * Gets the current phone capability.
10875 *
10876 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10877 * @return the PhoneCapability which describes the data connection capability of modem.
10878 * It's used to evaluate possible phone config change, for example from single
10879 * SIM device to multi-SIM device.
10880 */
10881 @Override
10882 public PhoneCapability getPhoneCapability() {
10883 enforceReadPrivilegedPermission("getPhoneCapability");
10884 final long identity = Binder.clearCallingIdentity();
10885 try {
10886 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10887 } finally {
10888 Binder.restoreCallingIdentity(identity);
10889 }
10890 }
Michele Berionne5e411512020-11-13 02:36:59 +000010891
10892 /**
10893 * Prepare TelephonyManager for an unattended reboot. The reboot is
10894 * required to be done shortly after the API is invoked.
10895 */
10896 @Override
10897 @TelephonyManager.PrepareUnattendedRebootResult
10898 public int prepareForUnattendedReboot() {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010899 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Michele Berionne5e411512020-11-13 02:36:59 +000010900 enforceRebootPermission();
10901
10902 final long identity = Binder.clearCallingIdentity();
10903 try {
Rafael Higuera Silvad9630642021-09-20 15:32:01 +000010904 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource);
Michele Berionne5e411512020-11-13 02:36:59 +000010905 } finally {
10906 Binder.restoreCallingIdentity(identity);
10907 }
10908 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010909
10910 /**
10911 * Request to get the current slicing configuration including URSP rules and
10912 * NSSAIs (configured, allowed and rejected).
10913 *
10914 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10915 */
10916 @Override
10917 public void getSlicingConfig(ResultReceiver callback) {
10918 enforceReadPrivilegedPermission("getSlicingConfig");
10919
10920 final long identity = Binder.clearCallingIdentity();
10921 try {
10922 Phone phone = getDefaultPhone();
10923 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10924 } finally {
10925 Binder.restoreCallingIdentity(identity);
10926 }
10927 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010928}