blob: 63def4e31ddda582c991eacfa4bcb51621e53458 [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;
Shuo Qian4a594052020-01-23 11:59:30 -0800140import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700142import com.android.internal.telephony.CallStateException;
chen xu651eec72018-11-11 19:03:44 -0800143import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700144import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800146import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700148import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800149import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800150import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800151import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700152import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800154import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800156import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700157import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700158import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700159import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700161import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800162import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700163import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700164import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700165import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700166import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800167import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800168import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700170import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800172import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800173import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800174import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700175import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700177import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800178import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700179import com.android.internal.telephony.imsphone.ImsPhone;
180import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800181import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700182import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800184import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700187import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800190import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000191import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800192import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700193import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700194import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800195import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800196import com.android.phone.callcomposer.CallComposerPictureManager;
197import com.android.phone.callcomposer.CallComposerPictureTransfer;
198import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700200import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800201import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700203import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800204import com.android.services.telephony.TelecomAccountRegistry;
205import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800206import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800207
Hall Liu82694d52020-12-11 18:22:04 -0800208import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700209import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.IOException;
211import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700212import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800214import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800215import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800216import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800217import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100218import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800219import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700220import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800222import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800224import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800225import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226
227/**
228 * Implementation of the ITelephony interface.
229 */
Santos Cordon117fee72014-05-16 17:56:12 -0700230public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 private static final String LOG_TAG = "PhoneInterfaceManager";
232 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
233 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235
236 // Message codes used with mMainThreadHandler
237 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700238 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
239 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700240 private static final int CMD_OPEN_CHANNEL = 9;
241 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
242 private static final int CMD_CLOSE_CHANNEL = 11;
243 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800244 private static final int CMD_NV_READ_ITEM = 13;
245 private static final int EVENT_NV_READ_ITEM_DONE = 14;
246 private static final int CMD_NV_WRITE_ITEM = 15;
247 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
248 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
249 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700250 private static final int CMD_RESET_MODEM_CONFIG = 19;
251 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800252 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
253 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800254 private static final int CMD_SEND_ENVELOPE = 25;
255 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000256 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
257 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700258 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
259 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
260 private static final int CMD_EXCHANGE_SIM_IO = 31;
261 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800262 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
263 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700264 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
265 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700266 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
267 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700268 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
269 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
270 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
271 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700272 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
273 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
274 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
275 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700276 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800277 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
278 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000279 private static final int CMD_SWITCH_SLOTS = 50;
280 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700281 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
282 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
283 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
284 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
285 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
286 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
287 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
288 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700289 private static final int CMD_GET_ALL_CELL_INFO = 60;
290 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
291 private static final int CMD_GET_CELL_LOCATION = 62;
292 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700293 private static final int CMD_MODEM_REBOOT = 64;
294 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700295 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
296 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800297 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
298 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700299 private static final int CMD_GET_MODEM_STATUS = 70;
300 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700301 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
302 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700303 private static final int CMD_ERASE_MODEM_CONFIG = 74;
304 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800305 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
306 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
307 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
308 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800309 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
310 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800311 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800312 private static final int CMD_GET_CALL_FORWARDING = 83;
313 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
314 private static final int CMD_SET_CALL_FORWARDING = 85;
315 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
316 private static final int CMD_GET_CALL_WAITING = 87;
317 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
318 private static final int CMD_SET_CALL_WAITING = 89;
319 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700320 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
321 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
322 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
323 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700324 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
325 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800326 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
327 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800328 private static final int CMD_SET_DATA_THROTTLING = 99;
329 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800330 private static final int CMD_SET_SIM_POWER = 101;
331 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800332 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
333 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
334 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
335 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800336 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
337 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000338 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800339 private static final int CMD_GET_SLICING_CONFIG = 110;
340 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Kai Shif70f46f2021-03-03 13:59:46 -0800341 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800343 // Parameters of select command.
344 private static final int SELECT_COMMAND = 0xA4;
345 private static final int SELECT_P1 = 0x04;
346 private static final int SELECT_P2 = 0;
347 private static final int SELECT_P3 = 0x10;
348
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 /** The singleton instance. */
350 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800351 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352
Wink Saville3ab207e2014-11-20 13:07:20 -0800353 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800354 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800355 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700356 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800357 private AppOpsManager mAppOps;
Grace Jia0ddb3612021-04-22 13:35:26 -0700358 private PackageManager mPm;
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800360 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800361 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700362 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800363 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364
Peter Wangdafb9ac2020-01-15 14:13:38 -0800365 /** User Activity */
366 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800367 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
368
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700369 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
370
Derek Tan97ebb422014-09-05 16:55:38 -0700371 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
372 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800373 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800374 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700375
Michelecea4cf22018-12-21 15:00:11 -0800376 // String to store multi SIM allowed
377 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
378
Derek Tan740e1672017-06-27 14:56:27 -0700379 // The AID of ISD-R.
380 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
381
yinxub1bed742017-04-17 11:45:04 -0700382 private NetworkScanRequestTracker mNetworkScanRequestTracker;
383
David Kelly5e06a7f2018-03-12 14:10:59 +0000384 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
385 private static final int MANUFACTURER_CODE_LENGTH = 8;
386
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800387 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800388 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800389
Derek Tan89e89d42014-07-08 17:00:10 -0700390 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700391 * Experiment flag to enable erase modem config on reset network, default value is false
392 */
393 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
394 "reset_network_erase_modem_config_enabled";
395
Rambo Wang0f050d82021-02-12 11:43:36 -0800396 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
397
Naina Nallurid63128d2019-09-17 14:10:30 -0700398 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700399 * A request object to use for transmitting data to an ICC.
400 */
401 private static final class IccAPDUArgument {
402 public int channel, cla, command, p1, p2, p3;
403 public String data;
404
405 public IccAPDUArgument(int channel, int cla, int command,
406 int p1, int p2, int p3, String data) {
407 this.channel = channel;
408 this.cla = cla;
409 this.command = command;
410 this.p1 = p1;
411 this.p2 = p2;
412 this.p3 = p3;
413 this.data = data;
414 }
415 }
416
417 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700418 * A request object to use for transmitting data to an ICC.
419 */
420 private static final class ManualNetworkSelectionArgument {
421 public OperatorInfo operatorInfo;
422 public boolean persistSelection;
423
424 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
425 this.operatorInfo = operatorInfo;
426 this.persistSelection = persistSelection;
427 }
428 }
429
430 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
432 * request after sending. The main thread will notify the request when it is complete.
433 */
434 private static final class MainThreadRequest {
435 /** The argument to use for the request */
436 public Object argument;
437 /** The result of the request that is run on the main thread */
438 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800439 // The subscriber id that this request applies to. Defaults to
440 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
441 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442
Nathan Harold92bed182018-10-12 18:16:49 -0700443 // In cases where subId is unavailable, the caller needs to specify the phone.
444 public Phone phone;
445
vagdeviaf9a5b92018-08-15 16:01:53 -0700446 public WorkSource workSource;
447
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 public MainThreadRequest(Object argument) {
449 this.argument = argument;
450 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800451
Nathan Harold92bed182018-10-12 18:16:49 -0700452 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
453 this.argument = argument;
454 if (phone != null) {
455 this.phone = phone;
456 }
457 this.workSource = workSource;
458 }
459
vagdeviaf9a5b92018-08-15 16:01:53 -0700460 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800461 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800462 if (subId != null) {
463 this.subId = subId;
464 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700465 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700467 }
468
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800469 private static final class IncomingThirdPartyCallArgs {
470 public final ComponentName component;
471 public final String callId;
472 public final String callerDisplayName;
473
474 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
475 String callerDisplayName) {
476 this.component = component;
477 this.callId = callId;
478 this.callerDisplayName = callerDisplayName;
479 }
480 }
481
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 /**
483 * A handler that processes messages on the main thread in the phone process. Since many
484 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
485 * inbound binder threads to the main thread in the phone process. The Binder thread
486 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
487 * on, which will be notified when the operation completes and will contain the result of the
488 * request.
489 *
490 * <p>If a MainThreadRequest object is provided in the msg.obj field,
491 * note that request.result must be set to something non-null for the calling thread to
492 * unblock.
493 */
494 private final class MainThreadHandler extends Handler {
495 @Override
496 public void handleMessage(Message msg) {
497 MainThreadRequest request;
498 Message onCompleted;
499 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800500 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800502 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700503
504 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 case CMD_HANDLE_USSD_REQUEST: {
506 request = (MainThreadRequest) msg.obj;
507 final Phone phone = getPhoneFromRequest(request);
508 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
509 String ussdRequest = ussdObject.first;
510 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700511
Pengquan Menga1bb6272018-09-06 09:59:22 -0700512 if (!isUssdApiAllowed(request.subId)) {
513 // Carrier does not support use of this API, return failure.
514 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
515 UssdResponse response = new UssdResponse(ussdRequest, null);
516 Bundle returnData = new Bundle();
517 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
518 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700519
Pengquan Menga1bb6272018-09-06 09:59:22 -0700520 request.result = true;
521 notifyRequester(request);
522 return;
523 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700524
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 try {
526 request.result = phone != null
527 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
528 } catch (CallStateException cse) {
529 request.result = false;
530 }
531 // Wake up the requesting thread
532 notifyRequester(request);
533 break;
pkanwar32d516d2016-10-14 19:37:38 -0700534 }
535
Yorke Lee716f67e2015-06-17 15:39:16 -0700536 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700537 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700538 final Phone phone = getPhoneFromRequest(request);
539 request.result = phone != null ?
540 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
541 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700543 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700546
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800550 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 if (uiccCard == null) {
552 loge("iccTransmitApduLogicalChannel: No UICC");
553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700554 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
557 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 iccArgument.channel, iccArgument.cla, iccArgument.command,
560 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 break;
564
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700565 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
568 if (ar.exception == null && ar.result != null) {
569 request.result = ar.result;
570 } else {
571 request.result = new IccIoResult(0x6F, 0, (byte[])null);
572 if (ar.result == null) {
573 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800574 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800576 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 } else {
578 loge("iccTransmitApduLogicalChannel: Unknown exception");
579 }
580 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 break;
583
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
585 request = (MainThreadRequest) msg.obj;
586 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800587 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 if (uiccCard == null) {
589 loge("iccTransmitApduBasicChannel: No UICC");
590 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700591 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 } else {
593 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
594 request);
595 uiccCard.iccTransmitApduBasicChannel(
596 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
597 iccArgument.p3, iccArgument.data, onCompleted);
598 }
599 break;
600
601 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
606 } else {
607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 if (ar.result == null) {
609 loge("iccTransmitApduBasicChannel: Empty response");
610 } else if (ar.exception instanceof CommandException) {
611 loge("iccTransmitApduBasicChannel: CommandException: " +
612 ar.exception);
613 } else {
614 loge("iccTransmitApduBasicChannel: Unknown exception");
615 }
616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 break;
619
620 case CMD_EXCHANGE_SIM_IO:
621 request = (MainThreadRequest) msg.obj;
622 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800623 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 if (uiccCard == null) {
625 loge("iccExchangeSimIO: No UICC");
626 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700627 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 } else {
629 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
630 request);
631 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
632 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
633 iccArgument.data, onCompleted);
634 }
635 break;
636
637 case EVENT_EXCHANGE_SIM_IO_DONE:
638 ar = (AsyncResult) msg.obj;
639 request = (MainThreadRequest) ar.userObj;
640 if (ar.exception == null && ar.result != null) {
641 request.result = ar.result;
642 } else {
643 request.result = new IccIoResult(0x6f, 0, (byte[])null);
644 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700646 break;
647
Derek Tan4d5e5c12014-02-04 11:54:58 -0800648 case CMD_SEND_ENVELOPE:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("sendEnvelopeWithStatus: No UICC");
653 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
657 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
658 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 break;
660
661 case EVENT_SEND_ENVELOPE_DONE:
662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800666 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700667 request.result = new IccIoResult(0x6F, 0, (byte[])null);
668 if (ar.result == null) {
669 loge("sendEnvelopeWithStatus: Empty response");
670 } else if (ar.exception instanceof CommandException) {
671 loge("sendEnvelopeWithStatus: CommandException: " +
672 ar.exception);
673 } else {
674 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
675 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800678 break;
679
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 case CMD_OPEN_CHANNEL:
681 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800682 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800683 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 if (uiccCard == null) {
685 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800686 request.result = new IccOpenLogicalChannelResponse(-1,
687 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700689 } else {
690 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800691 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
692 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700693 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 break;
695
696 case EVENT_OPEN_CHANNEL_DONE:
697 ar = (AsyncResult) msg.obj;
698 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700701 int[] result = (int[]) ar.result;
702 int channelId = result[0];
703 byte[] selectResponse = null;
704 if (result.length > 1) {
705 selectResponse = new byte[result.length - 1];
706 for (int i = 1; i < result.length; ++i) {
707 selectResponse[i - 1] = (byte) result[i];
708 }
709 }
710 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700711 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 if (ar.result == null) {
714 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700716 if (ar.exception != null) {
717 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
718 }
719
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700720 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700721 if (ar.exception instanceof CommandException) {
722 CommandException.Error error =
723 ((CommandException) (ar.exception)).getCommandError();
724 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700725 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700726 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700727 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700728 }
729 }
730 openChannelResp = new IccOpenLogicalChannelResponse(
731 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700732 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700733 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700735 break;
736
737 case CMD_CLOSE_CHANNEL:
738 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800739 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700740 if (uiccCard == null) {
741 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900742 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700743 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700744 } else {
745 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
746 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
747 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700748 break;
749
750 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800751 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
752 break;
753
754 case CMD_NV_READ_ITEM:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800757 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
758 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800759 break;
760
761 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 ar = (AsyncResult) msg.obj;
763 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800764 if (ar.exception == null && ar.result != null) {
765 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800767 request.result = "";
768 if (ar.result == null) {
769 loge("nvReadItem: Empty response");
770 } else if (ar.exception instanceof CommandException) {
771 loge("nvReadItem: CommandException: " +
772 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800774 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 }
776 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700777 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700778 break;
779
Jake Hambye994d462014-02-03 13:10:13 -0800780 case CMD_NV_WRITE_ITEM:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
783 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700785 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800786 break;
787
788 case EVENT_NV_WRITE_ITEM_DONE:
789 handleNullReturnEvent(msg, "nvWriteItem");
790 break;
791
792 case CMD_NV_WRITE_CDMA_PRL:
793 request = (MainThreadRequest) msg.obj;
794 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800795 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800796 break;
797
798 case EVENT_NV_WRITE_CDMA_PRL_DONE:
799 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
800 break;
801
chen xu6dac5ab2018-10-26 17:39:23 -0700802 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800803 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700804 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800805 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800806 break;
807
chen xu6dac5ab2018-10-26 17:39:23 -0700808 case EVENT_RESET_MODEM_CONFIG_DONE:
809 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800810 break;
811
Sooraj Sasindran37444802020-08-11 10:40:43 -0700812 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
815 request);
816 Phone phone = getPhoneFromRequest(request);
817 if (phone != null) {
818 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
819 } else {
820 loge("isNRDualConnectivityEnabled: No phone object");
821 request.result = false;
822 notifyRequester(request);
823 }
824 break;
825 }
826
827 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
828 ar = (AsyncResult) msg.obj;
829 request = (MainThreadRequest) ar.userObj;
830 if (ar.exception == null && ar.result != null) {
831 request.result = ar.result;
832 } else {
833 // request.result must be set to something non-null
834 // for the calling thread to unblock
835 if (request.result != null) {
836 request.result = ar.result;
837 } else {
838 request.result = false;
839 }
840 if (ar.result == null) {
841 loge("isNRDualConnectivityEnabled: Empty response");
842 } else if (ar.exception instanceof CommandException) {
843 loge("isNRDualConnectivityEnabled: CommandException: "
844 + ar.exception);
845 } else {
846 loge("isNRDualConnectivityEnabled: Unknown exception");
847 }
848 }
849 notifyRequester(request);
850 break;
851
852 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
853 request = (MainThreadRequest) msg.obj;
854 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
855 Phone phone = getPhoneFromRequest(request);
856 if (phone != null) {
857 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
858 request.workSource);
859 } else {
860 loge("enableNrDualConnectivity: No phone object");
861 request.result =
862 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
863 notifyRequester(request);
864 }
865 break;
866 }
867
868 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null) {
872 request.result =
873 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
874 } else {
875 request.result =
876 TelephonyManager
877 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
878 if (ar.exception instanceof CommandException) {
879 CommandException.Error error =
880 ((CommandException) (ar.exception)).getCommandError();
881 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
882 request.result =
883 TelephonyManager
884 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000885 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
886 request.result =
887 TelephonyManager
888 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700889 }
890 loge("enableNrDualConnectivity" + ": CommandException: "
891 + ar.exception);
892 } else {
893 loge("enableNrDualConnectivity" + ": Unknown exception");
894 }
895 }
896 notifyRequester(request);
897 break;
898 }
899
SongFerngWang3ef3e072020-12-21 16:41:52 +0800900 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800902 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
903 request);
904 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 break;
906
SongFerngWang3ef3e072020-12-21 16:41:52 +0800907 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
910 if (ar.exception == null && ar.result != null) {
911 request.result = ar.result; // Integer
912 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530913 // request.result must be set to something non-null
914 // for the calling thread to unblock
915 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800916 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800917 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800919 loge("getAllowedNetworkTypesBitmask: CommandException: "
920 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800922 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 }
924 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700925 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800926 break;
927
SongFerngWang3ef3e072020-12-21 16:41:52 +0800928 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800929 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800930 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
931 request);
932 Pair<Integer, Long> reasonWithNetworkTypes =
933 (Pair<Integer, Long>) request.argument;
934 getPhoneFromRequest(request).setAllowedNetworkTypes(
935 reasonWithNetworkTypes.first,
936 reasonWithNetworkTypes.second,
937 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800938 break;
939
SongFerngWang3ef3e072020-12-21 16:41:52 +0800940 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
941 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800942 break;
943
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000944 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
945 request = (MainThreadRequest)msg.obj;
946 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800947 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000948 break;
949
950 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
951 ar = (AsyncResult)msg.obj;
952 request = (MainThreadRequest)ar.userObj;
953 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700954 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000955 break;
956
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800957 case CMD_SET_VOICEMAIL_NUMBER:
958 request = (MainThreadRequest) msg.obj;
959 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
960 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800961 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
962 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800963 break;
964
965 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
966 handleNullReturnEvent(msg, "setVoicemailNumber");
967 break;
968
Stuart Scott54788802015-03-30 13:18:01 -0700969 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
970 request = (MainThreadRequest) msg.obj;
971 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
972 request);
973 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
974 break;
975
976 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
977 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
978 break;
979
Shishir Agrawal302c8692015-06-19 13:49:39 -0700980 case CMD_PERFORM_NETWORK_SCAN:
981 request = (MainThreadRequest) msg.obj;
982 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
983 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
984 break;
985
Hall Liu27d24262020-09-18 19:04:59 -0700986 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700989 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
990 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
991 request.argument;
992 int callForwardingReason = args.first;
993 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800994 break;
Hall Liu27d24262020-09-18 19:04:59 -0700995 }
996 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700999 TelephonyManager.CallForwardingInfoCallback callback =
1000 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1001 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001002 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001003 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001004 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1005 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1006 // Service Class is a bit mask per 3gpp 27.007. Search for
1007 // any service for voice call.
1008 if ((callForwardInfo.serviceClass
1009 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001010 callForwardingInfo = new CallForwardingInfo(true,
1011 callForwardInfo.reason,
1012 callForwardInfo.number,
1013 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001014 break;
1015 }
1016 }
1017 // Didn't find a call forward info for voice call.
1018 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001019 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1020 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001021 }
Hall Liu27d24262020-09-18 19:04:59 -07001022 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001023 } else {
1024 if (ar.result == null) {
1025 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1026 }
1027 if (ar.exception != null) {
1028 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1029 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001030 int errorCode = TelephonyManager
1031 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001032 if (ar.exception instanceof CommandException) {
1033 CommandException.Error error =
1034 ((CommandException) (ar.exception)).getCommandError();
1035 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001036 errorCode = TelephonyManager
1037 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001038 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001039 errorCode = TelephonyManager
1040 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001041 }
1042 }
Hall Liu27d24262020-09-18 19:04:59 -07001043 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001044 }
Shuo Qian4a594052020-01-23 11:59:30 -08001045 break;
Hall Liu27d24262020-09-18 19:04:59 -07001046 }
Shuo Qian4a594052020-01-23 11:59:30 -08001047
Hall Liu27d24262020-09-18 19:04:59 -07001048 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001049 request = (MainThreadRequest) msg.obj;
1050 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001051 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001052 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001053 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1054 request.argument).first;
1055 request.phone.setCallForwardingOption(
1056 callForwardingInfoToSet.isEnabled()
1057 ? CommandsInterface.CF_ACTION_ENABLE
1058 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001059 callForwardingInfoToSet.getReason(),
1060 callForwardingInfoToSet.getNumber(),
1061 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1062 break;
Hall Liu27d24262020-09-18 19:04:59 -07001063 }
Shuo Qian4a594052020-01-23 11:59:30 -08001064
Hall Liu27d24262020-09-18 19:04:59 -07001065 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001066 ar = (AsyncResult) msg.obj;
1067 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001068 Consumer<Integer> callback =
1069 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1070 request.argument).second;
1071 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001072 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001073 int errorCode = TelephonyManager.CallForwardingInfoCallback
1074 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001075 if (ar.exception instanceof CommandException) {
1076 CommandException.Error error =
1077 ((CommandException) (ar.exception)).getCommandError();
1078 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001079 errorCode = TelephonyManager.CallForwardingInfoCallback
1080 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001081 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001082 errorCode = TelephonyManager.CallForwardingInfoCallback
1083 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
1085 }
1086 callback.accept(errorCode);
1087 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001088 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001089 }
Shuo Qian4a594052020-01-23 11:59:30 -08001090 break;
Hall Liu27d24262020-09-18 19:04:59 -07001091 }
Shuo Qian4a594052020-01-23 11:59:30 -08001092
Hall Liu27d24262020-09-18 19:04:59 -07001093 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001094 request = (MainThreadRequest) msg.obj;
1095 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1096 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1097 break;
Hall Liu27d24262020-09-18 19:04:59 -07001098 }
Shuo Qian4a594052020-01-23 11:59:30 -08001099
Hall Liu27d24262020-09-18 19:04:59 -07001100 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001103 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001104 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1105 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001106 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001107 // Service Class is a bit mask per 3gpp 27.007.
1108 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001109 if (callForwardResults.length > 1
1110 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001111 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001112 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001113 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1114 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001115 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001116 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001117 }
1118 } else {
1119 if (ar.result == null) {
1120 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1121 }
1122 if (ar.exception != null) {
1123 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1124 }
1125 if (ar.exception instanceof CommandException) {
1126 CommandException.Error error =
1127 ((CommandException) (ar.exception)).getCommandError();
1128 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1129 callForwardingStatus =
1130 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1131 }
1132 }
1133 }
Hall Liu27d24262020-09-18 19:04:59 -07001134 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001135 break;
Hall Liu27d24262020-09-18 19:04:59 -07001136 }
Shuo Qian4a594052020-01-23 11:59:30 -08001137
Hall Liu27d24262020-09-18 19:04:59 -07001138 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001141 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1142 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001143 break;
Hall Liu27d24262020-09-18 19:04:59 -07001144 }
Shuo Qian4a594052020-01-23 11:59:30 -08001145
Hall Liu27d24262020-09-18 19:04:59 -07001146 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001147 ar = (AsyncResult) msg.obj;
1148 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001149 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1150 Consumer<Integer> callback =
1151 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1152 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001153 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001154 if (ar.exception instanceof CommandException) {
1155 CommandException.Error error =
1156 ((CommandException) (ar.exception)).getCommandError();
1157 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1158 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1159 } else {
1160 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1161 }
1162 } else {
1163 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1164 }
1165 } else {
1166 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1167 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001168 }
Shuo Qian4a594052020-01-23 11:59:30 -08001169 break;
Hall Liu27d24262020-09-18 19:04:59 -07001170 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07001171 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1172 ar = (AsyncResult) msg.obj;
1173 request = (MainThreadRequest) ar.userObj;
1174 CellNetworkScanResult cellScanResult;
1175 if (ar.exception == null && ar.result != null) {
1176 cellScanResult = new CellNetworkScanResult(
1177 CellNetworkScanResult.STATUS_SUCCESS,
1178 (List<OperatorInfo>) ar.result);
1179 } else {
1180 if (ar.result == null) {
1181 loge("getCellNetworkScanResults: Empty response");
1182 }
1183 if (ar.exception != null) {
1184 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1185 }
1186 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1187 if (ar.exception instanceof CommandException) {
1188 CommandException.Error error =
1189 ((CommandException) (ar.exception)).getCommandError();
1190 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1191 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1192 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1193 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1194 }
1195 }
1196 cellScanResult = new CellNetworkScanResult(errorCode, null);
1197 }
1198 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001199 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001200 break;
1201
1202 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1203 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001204 ManualNetworkSelectionArgument selArg =
1205 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001206 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1207 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001208 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1209 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001210 break;
1211
1212 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001213 ar = (AsyncResult) msg.obj;
1214 request = (MainThreadRequest) ar.userObj;
1215 if (ar.exception == null) {
1216 request.result = true;
1217 } else {
1218 request.result = false;
1219 loge("setNetworkSelectionModeManual " + ar.exception);
1220 }
1221 notifyRequester(request);
1222 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001223 break;
1224
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001225 case CMD_GET_MODEM_ACTIVITY_INFO:
1226 request = (MainThreadRequest) msg.obj;
1227 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001228 if (defaultPhone != null) {
1229 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001230 } else {
1231 ResultReceiver result = (ResultReceiver) request.argument;
1232 Bundle bundle = new Bundle();
1233 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001234 new ModemActivityInfo(0, 0, 0,
1235 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001236 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001237 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001238 break;
1239
Hall Liud0f208c2020-10-14 16:54:44 -07001240 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001241 ar = (AsyncResult) msg.obj;
1242 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001243 ResultReceiver result = (ResultReceiver) request.argument;
1244
Hall Liud0f208c2020-10-14 16:54:44 -07001245 ModemActivityInfo ret = null;
1246 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001247 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001248 // Update the last modem activity info and the result of the request.
1249 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1250 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001251 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001252 int[] txTimeMs = info.getTransmitTimeMillis();
1253 int[] lastModemTxTimeMs = mLastModemActivityInfo
1254 .getTransmitTimeMillis();
1255 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1256 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1257 }
Hall Liu49656c02020-10-09 19:00:11 -07001258 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001259 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1260 + mLastModemActivityInfo.getSleepTimeMillis());
1261 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1262 + mLastModemActivityInfo.getIdleTimeMillis());
1263 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1264 mLastModemActivityInfo.setReceiveTimeMillis(
1265 info.getReceiveTimeMillis()
1266 + mLastModemActivityInfo.getReceiveTimeMillis());
1267 }
Hall Liu49656c02020-10-09 19:00:11 -07001268 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001269 mLastModemActivityInfo.getSleepTimeMillis(),
1270 mLastModemActivityInfo.getIdleTimeMillis(),
1271 mLastModemActivityInfo.getTransmitTimeMillis(),
1272 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001273 } else {
1274 if (ar.result == null) {
1275 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001276 error = TelephonyManager.ModemActivityInfoException
1277 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001278 } else if (ar.exception instanceof CommandException) {
1279 loge("queryModemActivityInfo: CommandException: " +
1280 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001281 error = TelephonyManager.ModemActivityInfoException
1282 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001283 } else {
1284 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001285 error = TelephonyManager.ModemActivityInfoException
1286 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001287 }
1288 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001289 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001290 if (ret != null) {
1291 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1292 } else {
1293 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1294 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001295 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001296 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001297 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001298 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001299
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 case CMD_SET_ALLOWED_CARRIERS:
1301 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001302 CarrierRestrictionRules argument =
1303 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001305 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 break;
1307
1308 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1309 ar = (AsyncResult) msg.obj;
1310 request = (MainThreadRequest) ar.userObj;
1311 if (ar.exception == null && ar.result != null) {
1312 request.result = ar.result;
1313 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001314 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1315 if (ar.exception instanceof CommandException) {
1316 loge("setAllowedCarriers: CommandException: " + ar.exception);
1317 CommandException.Error error =
1318 ((CommandException) (ar.exception)).getCommandError();
1319 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1320 request.result =
1321 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1322 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001323 } else {
1324 loge("setAllowedCarriers: Unknown exception");
1325 }
1326 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001327 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001328 break;
1329
1330 case CMD_GET_ALLOWED_CARRIERS:
1331 request = (MainThreadRequest) msg.obj;
1332 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001333 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001334 break;
1335
1336 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
1339 if (ar.exception == null && ar.result != null) {
1340 request.result = ar.result;
1341 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001342 request.result = new IllegalStateException(
1343 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001344 if (ar.result == null) {
1345 loge("getAllowedCarriers: Empty response");
1346 } else if (ar.exception instanceof CommandException) {
1347 loge("getAllowedCarriers: CommandException: " +
1348 ar.exception);
1349 } else {
1350 loge("getAllowedCarriers: Unknown exception");
1351 }
1352 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001353 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001354 break;
1355
Nathan Haroldb3014052017-01-25 15:57:32 -08001356 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1357 ar = (AsyncResult) msg.obj;
1358 request = (MainThreadRequest) ar.userObj;
1359 if (ar.exception == null && ar.result != null) {
1360 request.result = ar.result;
1361 } else {
1362 request.result = new IllegalArgumentException(
1363 "Failed to retrieve Forbidden Plmns");
1364 if (ar.result == null) {
1365 loge("getForbiddenPlmns: Empty response");
1366 } else {
1367 loge("getForbiddenPlmns: Unknown exception");
1368 }
1369 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001370 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001371 break;
1372
1373 case CMD_GET_FORBIDDEN_PLMNS:
1374 request = (MainThreadRequest) msg.obj;
1375 uiccCard = getUiccCardFromRequest(request);
1376 if (uiccCard == null) {
1377 loge("getForbiddenPlmns() UiccCard is null");
1378 request.result = new IllegalArgumentException(
1379 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001380 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001381 break;
1382 }
1383 Integer appType = (Integer) request.argument;
1384 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1385 if (uiccApp == null) {
1386 loge("getForbiddenPlmns() no app with specified type -- "
1387 + appType);
1388 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001389 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001390 break;
1391 } else {
1392 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1393 + " specified type -- " + appType);
1394 }
1395 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1396 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1397 onCompleted);
1398 break;
1399
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001400 case CMD_SWITCH_SLOTS:
1401 request = (MainThreadRequest) msg.obj;
1402 int[] physicalSlots = (int[]) request.argument;
1403 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1404 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1405 break;
1406
1407 case EVENT_SWITCH_SLOTS_DONE:
1408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
1410 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001411 notifyRequester(request);
1412 break;
1413 case CMD_GET_NETWORK_SELECTION_MODE:
1414 request = (MainThreadRequest) msg.obj;
1415 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1416 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1417 break;
1418
1419 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception != null) {
1423 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1424 } else {
1425 int mode = ((int[]) ar.result)[0];
1426 if (mode == 0) {
1427 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1428 } else {
1429 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1430 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001431 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001432 notifyRequester(request);
1433 break;
1434 case CMD_GET_CDMA_ROAMING_MODE:
1435 request = (MainThreadRequest) msg.obj;
1436 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1437 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1438 break;
1439 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1440 ar = (AsyncResult) msg.obj;
1441 request = (MainThreadRequest) ar.userObj;
1442 if (ar.exception != null) {
1443 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1444 } else {
1445 request.result = ((int[]) ar.result)[0];
1446 }
1447 notifyRequester(request);
1448 break;
1449 case CMD_SET_CDMA_ROAMING_MODE:
1450 request = (MainThreadRequest) msg.obj;
1451 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1452 int mode = (int) request.argument;
1453 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1454 break;
1455 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
1458 request.result = ar.exception == null;
1459 notifyRequester(request);
1460 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001461 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1462 request = (MainThreadRequest) msg.obj;
1463 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1464 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1465 break;
1466 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 if (ar.exception != null) {
1470 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1471 } else {
1472 request.result = ((int[]) ar.result)[0];
1473 }
1474 notifyRequester(request);
1475 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001476 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1477 request = (MainThreadRequest) msg.obj;
1478 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1479 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001480 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1481 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001482 break;
1483 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1484 ar = (AsyncResult) msg.obj;
1485 request = (MainThreadRequest) ar.userObj;
1486 request.result = ar.exception == null;
1487 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001488 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 case CMD_GET_ALL_CELL_INFO:
1490 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001492 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 case EVENT_GET_ALL_CELL_INFO_DONE:
1495 ar = (AsyncResult) msg.obj;
1496 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001497 // If a timeout occurs, the response will be null
1498 request.result = (ar.exception == null && ar.result != null)
1499 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001500 synchronized (request) {
1501 request.notifyAll();
1502 }
1503 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001504 case CMD_REQUEST_CELL_INFO_UPDATE:
1505 request = (MainThreadRequest) msg.obj;
1506 request.phone.requestCellInfoUpdate(request.workSource,
1507 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1508 break;
1509 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1510 ar = (AsyncResult) msg.obj;
1511 request = (MainThreadRequest) ar.userObj;
1512 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1513 try {
1514 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001515 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001516 cb.onError(
1517 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1518 ar.exception.getClass().getName(),
1519 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001520 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001521 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001522 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001523 } else {
1524 // use the result as returned
1525 cb.onCellInfo((List<CellInfo>) ar.result);
1526 }
1527 } catch (RemoteException re) {
1528 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1529 }
1530 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001531 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001532 request = (MainThreadRequest) msg.obj;
1533 WorkSource ws = (WorkSource) request.argument;
1534 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001535 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001536 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001537 }
1538 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001539 ar = (AsyncResult) msg.obj;
1540 request = (MainThreadRequest) ar.userObj;
1541 if (ar.exception == null) {
1542 request.result = ar.result;
1543 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001544 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001545 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001546 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001547 }
1548
1549 synchronized (request) {
1550 request.notifyAll();
1551 }
1552 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001553 }
chen xu6dac5ab2018-10-26 17:39:23 -07001554 case CMD_MODEM_REBOOT:
1555 request = (MainThreadRequest) msg.obj;
1556 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001557 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001558 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001559 case EVENT_CMD_MODEM_REBOOT_DONE:
1560 handleNullReturnEvent(msg, "rebootModem");
1561 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001562 case CMD_REQUEST_ENABLE_MODEM:
1563 request = (MainThreadRequest) msg.obj;
1564 boolean enable = (boolean) request.argument;
1565 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001566 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001567 PhoneConfigurationManager.getInstance()
1568 .enablePhone(request.phone, enable, onCompleted);
1569 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001570 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001574 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001575 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001576 if ((boolean) request.result) {
1577 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1578 updateModemStateMetrics();
1579 } else {
1580 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1581 + ar.exception);
1582 }
1583 notifyRequester(request);
1584 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001585 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001586 case CMD_GET_MODEM_STATUS:
1587 request = (MainThreadRequest) msg.obj;
1588 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1589 PhoneConfigurationManager.getInstance()
1590 .getPhoneStatusFromModem(request.phone, onCompleted);
1591 break;
1592 case EVENT_GET_MODEM_STATUS_DONE:
1593 ar = (AsyncResult) msg.obj;
1594 request = (MainThreadRequest) ar.userObj;
1595 int id = request.phone.getPhoneId();
1596 if (ar.exception == null && ar.result != null) {
1597 request.result = ar.result;
1598 //update the cache as modem status has changed
1599 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1600 (boolean) request.result);
1601 } else {
1602 // Return true if modem status cannot be retrieved. For most cases,
1603 // modem status is on. And for older version modems, GET_MODEM_STATUS
1604 // and disable modem are not supported. Modem is always on.
1605 // TODO: this should be fixed in R to support a third
1606 // status UNKNOWN b/131631629
1607 request.result = true;
1608 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1609 + ar.exception);
1610 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001611 notifyRequester(request);
1612 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001613 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1614 request = (MainThreadRequest) msg.obj;
1615 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1616 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1617 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1618 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1619 break;
1620 }
1621 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1625 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1626 args.second.accept(ar.exception == null);
1627 notifyRequester(request);
1628 break;
1629 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001630 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1631 request = (MainThreadRequest) msg.obj;
1632 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1633 Phone phone = getPhoneFromRequest(request);
1634 if (phone != null) {
1635 phone.getSystemSelectionChannels(onCompleted);
1636 } else {
1637 loge("getSystemSelectionChannels: No phone object");
1638 request.result = new ArrayList<RadioAccessSpecifier>();
1639 notifyRequester(request);
1640 }
1641 break;
1642 }
1643 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1644 ar = (AsyncResult) msg.obj;
1645 request = (MainThreadRequest) ar.userObj;
1646 if (ar.exception == null && ar.result != null) {
1647 request.result = ar.result;
1648 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001649 request.result = new IllegalStateException(
1650 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001651 if (ar.result == null) {
1652 loge("getSystemSelectionChannels: Empty response");
1653 } else {
1654 loge("getSystemSelectionChannels: Unknown exception");
1655 }
1656 }
1657 notifyRequester(request);
1658 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001659 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
1662 if (ar.exception == null && ar.result != null) {
1663 request.result = ar.result;
1664 } else {
1665 request.result = -1;
1666 loge("Failed to set Forbidden Plmns");
1667 if (ar.result == null) {
1668 loge("setForbidenPlmns: Empty response");
1669 } else if (ar.exception != null) {
1670 loge("setForbiddenPlmns: Exception: " + ar.exception);
1671 request.result = -1;
1672 } else {
1673 loge("setForbiddenPlmns: Unknown exception");
1674 }
1675 }
1676 notifyRequester(request);
1677 break;
1678 case CMD_SET_FORBIDDEN_PLMNS:
1679 request = (MainThreadRequest) msg.obj;
1680 uiccCard = getUiccCardFromRequest(request);
1681 if (uiccCard == null) {
1682 loge("setForbiddenPlmns: UiccCard is null");
1683 request.result = -1;
1684 notifyRequester(request);
1685 break;
1686 }
1687 Pair<Integer, List<String>> setFplmnsArgs =
1688 (Pair<Integer, List<String>>) request.argument;
1689 appType = setFplmnsArgs.first;
1690 List<String> fplmns = setFplmnsArgs.second;
1691 uiccApp = uiccCard.getApplicationByType(appType);
1692 if (uiccApp == null) {
1693 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1694 request.result = -1;
1695 loge("Failed to get UICC App");
1696 notifyRequester(request);
1697 } else {
1698 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1699 ((SIMRecords) uiccApp.getIccRecords())
1700 .setForbiddenPlmns(onCompleted, fplmns);
1701 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001702 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001703 case CMD_ERASE_MODEM_CONFIG:
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1706 defaultPhone.eraseModemConfig(onCompleted);
1707 break;
1708 case EVENT_ERASE_MODEM_CONFIG_DONE:
1709 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001710 break;
zoey chene02881a2019-12-30 16:11:23 +08001711
Kai Shif70f46f2021-03-03 13:59:46 -08001712 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1713 request = (MainThreadRequest) msg.obj;
1714 request.result = defaultPhone.eraseDataInSharedPreferences();
1715 notifyRequester(request);
1716 break;
1717
zoey chene02881a2019-12-30 16:11:23 +08001718 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1719 request = (MainThreadRequest) msg.obj;
1720 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1721 Pair<String, String> changed = (Pair<String, String>) request.argument;
1722 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1723 changed.first, changed.second, onCompleted);
1724 break;
1725 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1726 ar = (AsyncResult) msg.obj;
1727 request = (MainThreadRequest) ar.userObj;
1728 if (ar.exception == null) {
1729 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001730 // If the operation is successful, update the PIN storage
1731 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1732 int phoneId = getPhoneFromRequest(request).getPhoneId();
1733 UiccController.getInstance().getPinStorage()
1734 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001735 } else {
1736 request.result = msg.arg1;
1737 }
1738 notifyRequester(request);
1739 break;
1740
Michele Berionne5e411512020-11-13 02:36:59 +00001741 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001742 request = (MainThreadRequest) msg.obj;
1743 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1744 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1745 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1746 enabled.first, enabled.second, onCompleted);
1747 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001748 }
zoey chene02881a2019-12-30 16:11:23 +08001749 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 if (ar.exception == null) {
1753 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001754 // If the operation is successful, update the PIN storage
1755 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1756 int phoneId = getPhoneFromRequest(request).getPhoneId();
1757 if (enabled.first) {
1758 UiccController.getInstance().getPinStorage()
1759 .storePin(enabled.second, phoneId);
1760 } else {
1761 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1762 }
zoey chene02881a2019-12-30 16:11:23 +08001763 } else {
1764 request.result = msg.arg1;
1765 }
Michele Berionne5e411512020-11-13 02:36:59 +00001766
1767
zoey chene02881a2019-12-30 16:11:23 +08001768 notifyRequester(request);
1769 break;
1770
Peter Wangdafb9ac2020-01-15 14:13:38 -08001771 case MSG_NOTIFY_USER_ACTIVITY:
1772 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001773 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001774 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1775 getDefaultPhone().getContext().sendBroadcastAsUser(
1776 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1777 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001778
1779 case CMD_SET_DATA_THROTTLING: {
1780 request = (MainThreadRequest) msg.obj;
1781 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1782 DataThrottlingRequest dataThrottlingRequest =
1783 (DataThrottlingRequest) request.argument;
1784 Phone phone = getPhoneFromRequest(request);
1785 if (phone != null) {
1786 phone.setDataThrottling(onCompleted,
1787 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1788 dataThrottlingRequest.getCompletionDurationMillis());
1789 } else {
1790 loge("setDataThrottling: No phone object");
1791 request.result =
1792 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1793 notifyRequester(request);
1794 }
1795
1796 break;
1797 }
1798 case EVENT_SET_DATA_THROTTLING_DONE:
1799 ar = (AsyncResult) msg.obj;
1800 request = (MainThreadRequest) ar.userObj;
1801
1802 if (ar.exception == null) {
1803 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1804 } else if (ar.exception instanceof CommandException) {
1805 loge("setDataThrottling: CommandException: " + ar.exception);
1806 CommandException.Error error =
1807 ((CommandException) (ar.exception)).getCommandError();
1808
1809 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1810 request.result = TelephonyManager
1811 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1812 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1813 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001814 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1815 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001816 } else {
1817 request.result =
1818 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1819 }
1820 } else {
1821 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1822 }
1823 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1824 notifyRequester(request);
1825 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001826
1827 case CMD_SET_SIM_POWER: {
1828 request = (MainThreadRequest) msg.obj;
1829 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1830 request = (MainThreadRequest) msg.obj;
1831 int stateToSet =
1832 ((Pair<Integer, IIntegerConsumer>)
1833 request.argument).first;
1834 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1835 break;
1836 }
1837 case EVENT_SET_SIM_POWER_DONE: {
1838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 IIntegerConsumer callback =
1841 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1842 if (ar.exception != null) {
1843 loge("setSimPower exception: " + ar.exception);
1844 int errorCode = TelephonyManager.CallForwardingInfoCallback
1845 .RESULT_ERROR_UNKNOWN;
1846 if (ar.exception instanceof CommandException) {
1847 CommandException.Error error =
1848 ((CommandException) (ar.exception)).getCommandError();
1849 if (error == CommandException.Error.SIM_ERR) {
1850 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1851 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1852 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1853 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1854 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1855 } else {
1856 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1857 }
1858 }
1859 try {
1860 callback.accept(errorCode);
1861 } catch (RemoteException e) {
1862 // Ignore if the remote process is no longer available to call back.
1863 Log.w(LOG_TAG, "setSimPower: callback not available.");
1864 }
1865 } else {
1866 try {
1867 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1868 } catch (RemoteException e) {
1869 // Ignore if the remote process is no longer available to call back.
1870 Log.w(LOG_TAG, "setSimPower: callback not available.");
1871 }
1872 }
1873 break;
1874 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001875 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1876 request = (MainThreadRequest) msg.obj;
1877
1878 final Phone phone = getPhoneFromRequest(request);
1879 if (phone == null || phone.getServiceStateTracker() == null) {
1880 request.result = new IllegalStateException("Phone or SST is null");
1881 notifyRequester(request);
1882 break;
1883 }
1884
1885 Pair<Integer, SignalStrengthUpdateRequest> pair =
1886 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1887 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1888 request);
1889 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1890 request.subId, pair.first /*callingUid*/,
1891 pair.second /*request*/, onCompleted);
1892 break;
1893 }
1894 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1895 ar = (AsyncResult) msg.obj;
1896 request = (MainThreadRequest) ar.userObj;
1897 // request.result will be the exception of ar if present, true otherwise.
1898 // Be cautious not to leave result null which will wait() forever
1899 request.result = ar.exception != null ? ar.exception : true;
1900 notifyRequester(request);
1901 break;
1902 }
1903 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1904 request = (MainThreadRequest) msg.obj;
1905
1906 Phone phone = getPhoneFromRequest(request);
1907 if (phone == null || phone.getServiceStateTracker() == null) {
1908 request.result = new IllegalStateException("Phone or SST is null");
1909 notifyRequester(request);
1910 break;
1911 }
1912
1913 Pair<Integer, SignalStrengthUpdateRequest> pair =
1914 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1915 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1916 request);
1917 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1918 request.subId, pair.first /*callingUid*/,
1919 pair.second /*request*/, onCompleted);
1920 break;
1921 }
1922 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1923 ar = (AsyncResult) msg.obj;
1924 request = (MainThreadRequest) ar.userObj;
1925 request.result = ar.exception != null ? ar.exception : true;
1926 notifyRequester(request);
1927 break;
1928 }
Jordan Liu109698e2020-11-24 14:50:34 -08001929
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001930 case CMD_GET_SLICING_CONFIG: {
1931 request = (MainThreadRequest) msg.obj;
1932 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1933 request.phone.getSlicingConfig(onCompleted);
1934 break;
1935 }
1936 case EVENT_GET_SLICING_CONFIG_DONE: {
1937 ar = (AsyncResult) msg.obj;
1938 request = (MainThreadRequest) ar.userObj;
1939 ResultReceiver result = (ResultReceiver) request.argument;
1940
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001941 NetworkSlicingConfig slicingConfig = null;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001942 Bundle bundle = new Bundle();
1943 int resultCode = 0;
1944 if (ar.exception != null) {
1945 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1946 + ar.exception);
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001947 resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001948 } else if (ar.result == null) {
1949 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001950 resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001951 } else {
1952 // use the result as returned
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001953 resultCode = TelephonyManager.NetworkSlicingException.SUCCESS;
1954 slicingConfig = (NetworkSlicingConfig) ar.result;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001955 }
1956
1957 if (slicingConfig == null) {
Hongbo Zeng0e18b162021-04-07 16:52:18 +08001958 slicingConfig = new NetworkSlicingConfig();
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001959 }
1960 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1961 result.send(resultCode, bundle);
1962 notifyRequester(request);
1963 break;
1964 }
1965
Michele Berionne5e411512020-11-13 02:36:59 +00001966 case CMD_PREPARE_UNATTENDED_REBOOT:
1967 request = (MainThreadRequest) msg.obj;
1968 request.result =
1969 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1970 notifyRequester(request);
1971 break;
1972
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 default:
1974 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1975 break;
1976 }
1977 }
Jake Hambye994d462014-02-03 13:10:13 -08001978
Pengquan Menga1bb6272018-09-06 09:59:22 -07001979 private void notifyRequester(MainThreadRequest request) {
1980 synchronized (request) {
1981 request.notifyAll();
1982 }
1983 }
1984
Jake Hambye994d462014-02-03 13:10:13 -08001985 private void handleNullReturnEvent(Message msg, String command) {
1986 AsyncResult ar = (AsyncResult) msg.obj;
1987 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1988 if (ar.exception == null) {
1989 request.result = true;
1990 } else {
1991 request.result = false;
1992 if (ar.exception instanceof CommandException) {
1993 loge(command + ": CommandException: " + ar.exception);
1994 } else {
1995 loge(command + ": Unknown exception");
1996 }
1997 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001998 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
2001
2002 /**
2003 * Posts the specified command to be executed on the main thread,
2004 * waits for the request to complete, and returns the result.
2005 * @see #sendRequestAsync
2006 */
2007 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002008 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2009 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002010 }
2011
2012 /**
2013 * Posts the specified command to be executed on the main thread,
2014 * waits for the request to complete, and returns the result.
2015 * @see #sendRequestAsync
2016 */
2017 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2018 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002019 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002020 }
2021
2022 /**
2023 * Posts the specified command to be executed on the main thread,
2024 * waits for the request to complete, and returns the result.
2025 * @see #sendRequestAsync
2026 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002027 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002028 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2029 }
2030
2031 /**
2032 * Posts the specified command to be executed on the main thread,
2033 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2034 * if not timeout or null otherwise.
2035 * @see #sendRequestAsync
2036 */
2037 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2038 long timeoutInMs) {
2039 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002040 }
2041
2042 /**
2043 * Posts the specified command to be executed on the main thread,
2044 * waits for the request to complete, and returns the result.
2045 * @see #sendRequestAsync
2046 */
Nathan Harold92bed182018-10-12 18:16:49 -07002047 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002048 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002049 }
2050
2051 /**
2052 * Posts the specified command to be executed on the main thread,
2053 * waits for the request to complete, and returns the result.
2054 * @see #sendRequestAsync
2055 */
2056 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002057 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2058 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002059 }
2060
2061 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002062 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2063 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2064 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002065 * @see #sendRequestAsync
2066 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002067 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2068 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2070 throw new RuntimeException("This method will deadlock if called from the main thread.");
2071 }
2072
Nathan Harold92bed182018-10-12 18:16:49 -07002073 MainThreadRequest request = null;
2074 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2075 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2076 } else if (phone != null) {
2077 request = new MainThreadRequest(argument, phone, workSource);
2078 } else {
2079 request = new MainThreadRequest(argument, subId, workSource);
2080 }
2081
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 Message msg = mMainThreadHandler.obtainMessage(command, request);
2083 msg.sendToTarget();
2084
Rambo Wang0f050d82021-02-12 11:43:36 -08002085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002087 if (timeoutInMs >= 0) {
2088 // Wait for at least timeoutInMs before returning null request result
2089 long now = SystemClock.elapsedRealtime();
2090 long deadline = now + timeoutInMs;
2091 while (request == null && now < deadline) {
2092 try {
2093 request.wait(deadline - now);
2094 } catch (InterruptedException e) {
2095 // Do nothing, go back and check if request is completed or timeout
2096 } finally {
2097 now = SystemClock.elapsedRealtime();
2098 }
2099 }
2100 } else {
2101 // Wait for the request to complete
2102 while (request.result == null) {
2103 try {
2104 request.wait();
2105 } catch (InterruptedException e) {
2106 // Do nothing, go back and wait until the request is complete
2107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109 }
2110 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002111 if (request.result == null) {
2112 Log.wtf(LOG_TAG,
2113 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 return request.result;
2116 }
2117
2118 /**
2119 * Asynchronous ("fire and forget") version of sendRequest():
2120 * Posts the specified command to be executed on the main thread, and
2121 * returns immediately.
2122 * @see #sendRequest
2123 */
2124 private void sendRequestAsync(int command) {
2125 mMainThreadHandler.sendEmptyMessage(command);
2126 }
2127
2128 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002129 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002130 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002131 */
2132 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002133 sendRequestAsync(command, argument, null, null);
2134 }
2135
2136 /**
2137 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2138 * @see {@link #sendRequest(int,Object)}
2139 */
2140 private void sendRequestAsync(
2141 int command, Object argument, Phone phone, WorkSource workSource) {
2142 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002143 Message msg = mMainThreadHandler.obtainMessage(command, request);
2144 msg.sendToTarget();
2145 }
2146
2147 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 * Initialize the singleton PhoneInterfaceManager instance.
2149 * This is only done once, at startup, from PhoneApp.onCreate().
2150 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002151 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 synchronized (PhoneInterfaceManager.class) {
2153 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002154 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 } else {
2156 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2157 }
2158 return sInstance;
2159 }
2160 }
2161
2162 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002163 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002166 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002167 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
Grace Jia0ddb3612021-04-22 13:35:26 -07002169 mPm = app.getSystemService(PackageManager.class);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002171 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002172 mTelephonySharedPreferences =
2173 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002174 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002175 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002176 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002177 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 publish();
2180 }
2181
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002182 private Phone getDefaultPhone() {
2183 Phone thePhone = getPhone(getDefaultSubscription());
2184 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2185 }
2186
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 private void publish() {
2188 if (DBG) log("publish: " + this);
2189
Peter Wangc035ce42020-01-08 21:00:22 -08002190 TelephonyFrameworkInitializer
2191 .getTelephonyServiceManager()
2192 .getTelephonyServiceRegisterer()
2193 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 }
2195
Stuart Scott584921c2015-01-15 17:10:34 -08002196 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002197 if (request.phone != null) {
2198 return request.phone;
2199 } else {
2200 return getPhoneFromSubId(request.subId);
2201 }
2202 }
2203
2204 private Phone getPhoneFromSubId(int subId) {
2205 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2206 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002207 }
2208
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002209 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2210 Phone phone = getPhoneFromRequest(request);
2211 return phone == null ? null :
2212 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2213 }
2214
Wink Saville36469e72014-06-11 15:17:00 -07002215 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002216 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002217 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002218 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219
Kai Shif70f46f2021-03-03 13:59:46 -08002220 private void sendEraseModemConfig(@NonNull Phone phone) {
2221 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2222 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2223 }
2224
2225 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2226 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2227 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002228 }
2229
Peter Wang44b186e2020-01-13 23:33:09 -08002230 private boolean isImsAvailableOnDevice() {
2231 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2232 if (pm == null) {
2233 // For some reason package manger is not available.. This will fail internally anyway,
2234 // so do not throw error and allow.
2235 return true;
2236 }
2237 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2238 }
2239
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002241 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002242 }
2243
Wink Savilleb564aae2014-10-23 10:18:09 -07002244 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 if (DBG) log("dial: " + number);
2246 // No permission check needed here: This is just a wrapper around the
2247 // ACTION_DIAL intent, which is available to any app since it puts up
2248 // the UI before it does anything.
2249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250 final long identity = Binder.clearCallingIdentity();
2251 try {
2252 String url = createTelUrl(number);
2253 if (url == null) {
2254 return;
2255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002257 // PENDING: should we just silently fail if phone is offhook or ringing?
2258 PhoneConstants.State state = mCM.getState(subId);
2259 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2260 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2261 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2262 mApp.startActivity(intent);
2263 }
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267 }
2268
2269 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002270 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002271 }
2272
Wink Savilleb564aae2014-10-23 10:18:09 -07002273 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 if (DBG) log("call: " + number);
2275
2276 // This is just a wrapper around the ACTION_CALL intent, but we still
2277 // need to do a permission check since we're calling startActivity()
2278 // from the context of the phone app.
2279 enforceCallPermission();
2280
Jordan Liu1617b712019-07-10 15:06:26 -07002281 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 != AppOpsManager.MODE_ALLOWED) {
2283 return;
2284 }
2285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286 final long identity = Binder.clearCallingIdentity();
2287 try {
2288 String url = createTelUrl(number);
2289 if (url == null) {
2290 return;
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293 boolean isValid = false;
2294 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2295 if (slist != null) {
2296 for (SubscriptionInfo subInfoRecord : slist) {
2297 if (subInfoRecord.getSubscriptionId() == subId) {
2298 isValid = true;
2299 break;
2300 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002301 }
Wink Saville08874612014-08-31 19:19:58 -07002302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 if (!isValid) {
2304 return;
2305 }
Wink Saville08874612014-08-31 19:19:58 -07002306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002307 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2308 intent.putExtra(SUBSCRIPTION_KEY, subId);
2309 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2310 mApp.startActivity(intent);
2311 } finally {
2312 Binder.restoreCallingIdentity(identity);
2313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 }
2315
Wink Savilleb564aae2014-10-23 10:18:09 -07002316 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002317 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002318 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2319 }
2320
Wink Savilleb564aae2014-10-23 10:18:09 -07002321 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002322 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002323 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2324 }
2325
Wink Savilleb564aae2014-10-23 10:18:09 -07002326 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328
2329 final long identity = Binder.clearCallingIdentity();
2330 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002331 Phone phone = getPhone(subId);
2332 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002333 checkSimPin.start();
2334 return checkSimPin.unlockSim(null, pin);
2335 } finally {
2336 Binder.restoreCallingIdentity(identity);
2337 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 }
2339
Wink Savilleb564aae2014-10-23 10:18:09 -07002340 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002345 Phone phone = getPhone(subId);
2346 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347 checkSimPuk.start();
2348 return checkSimPuk.unlockSim(puk, pin);
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
2351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
2353
2354 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002355 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002356 * a synchronous one.
2357 */
2358 private static class UnlockSim extends Thread {
2359
2360 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002361 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362
2363 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002364 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2365 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366
2367 // For replies from SimCard interface
2368 private Handler mHandler;
2369
2370 // For async handler to identify request type
2371 private static final int SUPPLY_PIN_COMPLETE = 100;
2372
Michele Berionne5e411512020-11-13 02:36:59 +00002373 UnlockSim(int phoneId, IccCard simCard) {
2374 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 mSimCard = simCard;
2376 }
2377
2378 @Override
2379 public void run() {
2380 Looper.prepare();
2381 synchronized (UnlockSim.this) {
2382 mHandler = new Handler() {
2383 @Override
2384 public void handleMessage(Message msg) {
2385 AsyncResult ar = (AsyncResult) msg.obj;
2386 switch (msg.what) {
2387 case SUPPLY_PIN_COMPLETE:
2388 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2389 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002390 mRetryCount = msg.arg1;
2391 if (ar.exception != null) {
2392 if (ar.exception instanceof CommandException &&
2393 ((CommandException)(ar.exception)).getCommandError()
2394 == CommandException.Error.PASSWORD_INCORRECT) {
2395 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002396 } //When UiccCardApp dispose,handle message and return exception
2397 else if (ar.exception instanceof CommandException &&
2398 ((CommandException) (ar.exception)).getCommandError()
2399 == CommandException.Error.ABORTED) {
2400 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002401 } else {
2402 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2403 }
2404 } else {
2405 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 mDone = true;
2408 UnlockSim.this.notifyAll();
2409 }
2410 break;
2411 }
2412 }
2413 };
2414 UnlockSim.this.notifyAll();
2415 }
2416 Looper.loop();
2417 }
2418
2419 /*
2420 * Use PIN or PUK to unlock SIM card
2421 *
2422 * If PUK is null, unlock SIM card with PIN
2423 *
2424 * If PUK is not null, unlock SIM card with PUK and set PIN code
2425 */
Wink Saville9de0f752013-10-22 19:04:03 -07002426 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427
2428 while (mHandler == null) {
2429 try {
2430 wait();
2431 } catch (InterruptedException e) {
2432 Thread.currentThread().interrupt();
2433 }
2434 }
2435 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2436
2437 if (puk == null) {
2438 mSimCard.supplyPin(pin, callback);
2439 } else {
2440 mSimCard.supplyPuk(puk, pin, callback);
2441 }
2442
2443 while (!mDone) {
2444 try {
2445 Log.d(LOG_TAG, "wait for done");
2446 wait();
2447 } catch (InterruptedException e) {
2448 // Restore the interrupted status
2449 Thread.currentThread().interrupt();
2450 }
2451 }
2452 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002453 int[] resultArray = new int[2];
2454 resultArray[0] = mResult;
2455 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002456
2457 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2458 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2459 }
2460
Wink Saville9de0f752013-10-22 19:04:03 -07002461 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463 }
2464
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002465 /**
2466 * This method has been removed due to privacy and stability concerns.
2467 */
2468 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002469 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002470 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2471 return;
Wink Saville36469e72014-06-11 15:17:00 -07002472 }
2473
Nathan Harold1f889d82020-06-04 17:05:26 -07002474 @Override
2475 public void updateServiceLocationWithPackageName(String callingPackage) {
2476 mApp.getSystemService(AppOpsManager.class)
2477 .checkPackage(Binder.getCallingUid(), callingPackage);
2478
Nathan Haroldf096d982020-11-18 17:18:06 -08002479 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002480 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2481 // Callers targeting S have no business invoking this method.
2482 return;
2483 }
2484
2485 LocationAccessPolicy.LocationPermissionResult locationResult =
2486 LocationAccessPolicy.checkLocationPermission(mApp,
2487 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2488 .setCallingPackage(callingPackage)
2489 .setCallingFeatureId(null)
2490 .setCallingPid(Binder.getCallingPid())
2491 .setCallingUid(Binder.getCallingUid())
2492 .setMethod("updateServiceLocation")
2493 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2494 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2495 .build());
2496 // Apps that lack location permission have no business calling this method;
2497 // however, because no permission was declared in the public API, denials must
2498 // all be "soft".
2499 switch (locationResult) {
2500 case DENIED_HARD: /* fall through */
2501 case DENIED_SOFT:
2502 return;
2503 }
2504
2505 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002508 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002510 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511 }
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002517 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002518 @Override
2519 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002520 return isRadioOnWithFeature(callingPackage, null);
2521 }
2522
2523
2524 @Override
2525 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2526 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2527 callingFeatureId);
2528 }
2529
2530 @Deprecated
2531 @Override
2532 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2533 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002534 }
2535
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002536 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002537 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2538 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002540 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002541 return false;
2542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 return isRadioOnForSubscriber(subId);
2547 } finally {
2548 Binder.restoreCallingIdentity(identity);
2549 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002550 }
2551
2552 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
2556 if (phone != null) {
2557 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2558 } else {
2559 return false;
2560 }
2561 } finally {
2562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
2565
2566 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002567 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
Wink Saville36469e72014-06-11 15:17:00 -07002569
Wink Savilleb564aae2014-10-23 10:18:09 -07002570 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002571 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572
2573 final long identity = Binder.clearCallingIdentity();
2574 try {
2575 final Phone phone = getPhone(subId);
2576 if (phone != null) {
2577 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002581 }
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
2584 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002585 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002586 }
2587
Wink Savilleb564aae2014-10-23 10:18:09 -07002588 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590
2591 final long identity = Binder.clearCallingIdentity();
2592 try {
2593 final Phone phone = getPhone(subId);
2594 if (phone == null) {
2595 return false;
2596 }
2597 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2598 toggleRadioOnOffForSubscriber(subId);
2599 }
2600 return true;
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 }
Wink Saville36469e72014-06-11 15:17:00 -07002605
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002606 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002607 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002608 /*
2609 * If any of the Radios are available, it will need to be
2610 * shutdown. So return true if any Radio is available.
2611 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2615 Phone phone = PhoneFactory.getPhone(i);
2616 if (phone != null && phone.isRadioAvailable()) return true;
2617 }
2618 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2619 return false;
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002622 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002623 }
2624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002626 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 enforceModifyPermission();
2628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2632 logv("Shutting down Phone " + i);
2633 shutdownRadioUsingPhoneId(i);
2634 }
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002637 }
2638 }
2639
2640 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002641 Phone phone = PhoneFactory.getPhone(phoneId);
2642 if (phone != null && phone.isRadioAvailable()) {
2643 phone.shutdownRadio();
2644 }
2645 }
2646
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002649
2650 final long identity = Binder.clearCallingIdentity();
2651 try {
2652 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2653 if (defaultPhone != null) {
2654 defaultPhone.setRadioPower(turnOn);
2655 return true;
2656 } else {
2657 loge("There's no default phone.");
2658 return false;
2659 }
2660 } finally {
2661 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002662 }
Wink Saville36469e72014-06-11 15:17:00 -07002663 }
2664
Wink Savilleb564aae2014-10-23 10:18:09 -07002665 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667
2668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 if (phone != null) {
2672 phone.setRadioPower(turnOn);
2673 return true;
2674 } else {
2675 return false;
2676 }
2677 } finally {
2678 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002679 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 }
2681
Wink Saville36469e72014-06-11 15:17:00 -07002682 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002683 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 public boolean enableDataConnectivity() {
2685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 int subId = mSubscriptionController.getDefaultDataSubId();
2690 final Phone phone = getPhone(subId);
2691 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002692 phone.getDataEnabledSettings().setDataEnabled(
2693 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694 return true;
2695 } else {
2696 return false;
2697 }
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 }
2702
Wink Saville36469e72014-06-11 15:17:00 -07002703 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 public boolean disableDataConnectivity() {
2706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707
2708 final long identity = Binder.clearCallingIdentity();
2709 try {
2710 int subId = mSubscriptionController.getDefaultDataSubId();
2711 final Phone phone = getPhone(subId);
2712 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002713 phone.getDataEnabledSettings().setDataEnabled(
2714 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 return true;
2716 } else {
2717 return false;
2718 }
2719 } finally {
2720 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 }
2723
Sanket Padawe356d7632015-06-22 14:03:32 -07002724 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002725 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 final Phone phone = getPhone(subId);
2729 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002730 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 } else {
2732 return false;
2733 }
2734 } finally {
2735 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002736 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002737 }
2738
2739 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002740 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002741 }
2742
pkanwarae03a6b2016-11-06 20:37:09 -08002743 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744 enforceCallPermission();
2745
2746 final long identity = Binder.clearCallingIdentity();
2747 try {
2748 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2749 return;
2750 }
2751 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2752 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
2755 }
pkanwar32d516d2016-10-14 19:37:38 -07002756 };
2757
Wink Savilleb564aae2014-10-23 10:18:09 -07002758 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
2763 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2764 return false;
2765 }
2766 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2767 } finally {
2768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002772 /**
2773 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2774 * tag on getCallState Binder call.
2775 */
2776 @Deprecated
2777 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002779 if (CompatChanges.isChangeEnabled(
2780 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2781 Binder.getCallingUid())) {
2782 // Do not allow this API to be called on API version 31+, it should only be
2783 // called on old apps using this Binder call directly.
2784 throw new SecurityException("This method can only be used for applications "
2785 + "targeting API version 30 or less.");
2786 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 final long identity = Binder.clearCallingIdentity();
2788 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002789 Phone phone = getPhone(getDefaultSubscription());
2790 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2791 PhoneConstantConversions.convertCallState(phone.getState());
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
2794 }
2795 }
2796
2797 @Override
2798 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2799 if (CompatChanges.isChangeEnabled(
2800 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2801 Binder.getCallingUid())) {
2802 // Check READ_PHONE_STATE for API version 31+
2803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2804 featureId, "getCallStateForSubscription")) {
2805 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2806 + "targeting API level 31+.");
2807 }
2808 }
2809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2813 PhoneConstantConversions.convertCallState(phone.getState());
2814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 }
2818
Sanket Padawe356d7632015-06-22 14:03:32 -07002819 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002820 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002821 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2822 }
2823
2824 @Override
2825 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 final long identity = Binder.clearCallingIdentity();
2827 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002828 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829 if (phone != null) {
2830 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2831 } else {
2832 return PhoneConstantConversions.convertDataState(
2833 PhoneConstants.DataState.DISCONNECTED);
2834 }
2835 } finally {
2836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002838 }
2839
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002841 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002842 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2843 }
2844
2845 @Override
2846 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847 final long identity = Binder.clearCallingIdentity();
2848 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002849 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 if (phone != null) {
2851 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2852 } else {
2853 return TelephonyManager.DATA_ACTIVITY_NONE;
2854 }
2855 } finally {
2856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 }
2859
2860 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002861 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002862 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002863 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002864
2865 LocationAccessPolicy.LocationPermissionResult locationResult =
2866 LocationAccessPolicy.checkLocationPermission(mApp,
2867 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2868 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002869 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002870 .setCallingPid(Binder.getCallingPid())
2871 .setCallingUid(Binder.getCallingUid())
2872 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002873 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002874 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2875 .build());
2876 switch (locationResult) {
2877 case DENIED_HARD:
2878 throw new SecurityException("Not allowed to access cell location");
2879 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002880 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2881 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002882 }
2883
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002884 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002888 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002889 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 } finally {
2891 Binder.restoreCallingIdentity(identity);
2892 }
Svetoslav64fad262015-04-14 14:35:21 -07002893 }
2894
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002896 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002897 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2898 // registered cell info, so return a NULL country instead.
2899 final long identity = Binder.clearCallingIdentity();
2900 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002901 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2902 // Get default phone in this case.
2903 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2904 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002905 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002907 if (phone == null) return "";
2908 ServiceStateTracker sst = phone.getServiceStateTracker();
2909 if (sst == null) return "";
2910 LocaleTracker lt = sst.getLocaleTracker();
2911 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002912 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002913 } finally {
2914 Binder.restoreCallingIdentity(identity);
2915 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002916 }
2917
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002918 /**
2919 * This method was removed due to potential issues caused by performing partial
2920 * updates of service state, and lack of a credible use case.
2921 *
2922 * This has the ability to break the telephony implementation by disabling notification of
2923 * changes in device connectivity. DO NOT USE THIS!
2924 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002925 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 public void enableLocationUpdates() {
2927 mApp.enforceCallingOrSelfPermission(
2928 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929 }
2930
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002931 /**
2932 * This method was removed due to potential issues caused by performing partial
2933 * updates of service state, and lack of a credible use case.
2934 *
2935 * This has the ability to break the telephony implementation by disabling notification of
2936 * changes in device connectivity. DO NOT USE THIS!
2937 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002938 @Override
2939 public void disableLocationUpdates() {
2940 mApp.enforceCallingOrSelfPermission(
2941 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 }
2943
2944 @Override
2945 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002946 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2947 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002948 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002949 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2950 throw new SecurityException(
2951 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2952 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002953
Jordan Liu1617b712019-07-10 15:06:26 -07002954 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2956 return null;
2957 }
Svetoslav64fad262015-04-14 14:35:21 -07002958
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002959 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002961 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002962 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002963
Nathan Haroldf180aac2018-06-01 18:43:55 -07002964 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2965 for (CellInfo ci : info) {
2966 if (ci instanceof CellInfoGsm) {
2967 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2968 } else if (ci instanceof CellInfoWcdma) {
2969 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002972 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002973 }
2974
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002975 private List<CellInfo> getCachedCellInfo() {
2976 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2977 for (Phone phone : PhoneFactory.getPhones()) {
2978 List<CellInfo> info = phone.getAllCellInfo();
2979 if (info != null) cellInfos.addAll(info);
2980 }
2981 return cellInfos;
2982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983
2984 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002985 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002986 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002987 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002988
2989 LocationAccessPolicy.LocationPermissionResult locationResult =
2990 LocationAccessPolicy.checkLocationPermission(mApp,
2991 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2992 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002993 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002994 .setCallingPid(Binder.getCallingPid())
2995 .setCallingUid(Binder.getCallingUid())
2996 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002997 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002998 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2999 .build());
3000 switch (locationResult) {
3001 case DENIED_HARD:
3002 throw new SecurityException("Not allowed to access cell info");
3003 case DENIED_SOFT:
3004 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 }
3006
Nathan Haroldf096d982020-11-18 17:18:06 -08003007 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003008 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3009 return getCachedCellInfo();
3010 }
3011
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003012 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003013 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3017 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003018 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003019 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020 if (info != null) cellInfos.addAll(info);
3021 }
3022 return cellInfos;
3023 } finally {
3024 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003025 }
3026 }
3027
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003028 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003029 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3030 String callingFeatureId) {
3031 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3032 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003033 }
3034
3035 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003036 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3037 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003038 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003039 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003040 }
3041
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003042 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3043 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003044 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003045 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003046
3047 LocationAccessPolicy.LocationPermissionResult locationResult =
3048 LocationAccessPolicy.checkLocationPermission(mApp,
3049 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3050 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003051 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003052 .setCallingPid(Binder.getCallingPid())
3053 .setCallingUid(Binder.getCallingUid())
3054 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003055 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3056 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003057 .build());
3058 switch (locationResult) {
3059 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003060 if (TelephonyPermissions
3061 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003062 // Safetynet logging for b/154934934
3063 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3064 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003065 throw new SecurityException("Not allowed to access cell info");
3066 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003067 if (TelephonyPermissions
3068 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003069 // Safetynet logging for b/154934934
3070 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3071 }
Nathan Harold5320c422019-05-09 10:26:08 -07003072 try {
3073 cb.onCellInfo(new ArrayList<CellInfo>());
3074 } catch (RemoteException re) {
3075 // Drop without consequences
3076 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003077 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003078 }
3079
Nathan Harolda939a962019-05-09 10:13:47 -07003080
3081 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003082 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3083
3084 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3085 }
3086
3087 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003088 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003089 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003091
3092 final long identity = Binder.clearCallingIdentity();
3093 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003094 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003095 } finally {
3096 Binder.restoreCallingIdentity(identity);
3097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 }
3099
Shishir Agrawala9f32182016-04-12 12:00:16 -07003100 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003101 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003102 Phone phone = PhoneFactory.getPhone(slotIndex);
3103 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003104 return null;
3105 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003106 int subId = phone.getSubId();
Grace Jia0ddb3612021-04-22 13:35:26 -07003107 enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot");
Michael Groover70af6dc2018-10-01 16:23:15 -07003108 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003109 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003110 return null;
3111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112
3113 final long identity = Binder.clearCallingIdentity();
3114 try {
3115 return phone.getImei();
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003119 }
3120
3121 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003122 public String getTypeAllocationCodeForSlot(int slotIndex) {
3123 Phone phone = PhoneFactory.getPhone(slotIndex);
3124 String tac = null;
3125 if (phone != null) {
3126 String imei = phone.getImei();
3127 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3128 }
3129 return tac;
3130 }
3131
3132 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003133 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003134 Phone phone = PhoneFactory.getPhone(slotIndex);
3135 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003136 return null;
3137 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003138
Jeff Davidson913390f2018-02-23 17:11:49 -08003139 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003140 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003141 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003142 return null;
3143 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144
3145 final long identity = Binder.clearCallingIdentity();
3146 try {
3147 return phone.getMeid();
3148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
Jack Yu2af8d712017-03-15 17:14:14 -07003151 }
3152
3153 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003154 public String getManufacturerCodeForSlot(int slotIndex) {
3155 Phone phone = PhoneFactory.getPhone(slotIndex);
3156 String manufacturerCode = null;
3157 if (phone != null) {
3158 String meid = phone.getMeid();
3159 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3160 }
3161 return manufacturerCode;
3162 }
3163
3164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003165 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3166 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003167 Phone phone = PhoneFactory.getPhone(slotIndex);
3168 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003169 return null;
3170 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003171 int subId = phone.getSubId();
3172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003173 mApp, subId, callingPackage, callingFeatureId,
3174 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003175 return null;
3176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177
3178 final long identity = Binder.clearCallingIdentity();
3179 try {
3180 return phone.getDeviceSvn();
3181 } finally {
3182 Binder.restoreCallingIdentity(identity);
3183 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003184 }
3185
fionaxu43304da2017-11-27 22:51:16 -08003186 @Override
3187 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 final Phone phone = getPhone(subId);
3191 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
fionaxu43304da2017-11-27 22:51:16 -08003195 }
3196
3197 @Override
3198 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 final Phone phone = getPhone(subId);
3202 return phone == null ? null : phone.getCarrierName();
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
fionaxu43304da2017-11-27 22:51:16 -08003206 }
3207
calvinpanffe225e2018-11-01 19:43:06 +08003208 @Override
chen xu0026ca62019-03-06 15:28:50 -08003209 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 final Phone phone = getPhone(subId);
3213 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003214 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003215 } finally {
3216 Binder.restoreCallingIdentity(identity);
3217 }
3218 }
3219
3220 @Override
chen xu0026ca62019-03-06 15:28:50 -08003221 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003225 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
3229 }
3230
chen xu651eec72018-11-11 19:03:44 -08003231 @Override
chen xu864e11c2018-12-06 22:10:03 -08003232 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3233 if (!isSubscriptionMccMnc) {
3234 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3235 }
chen xu651eec72018-11-11 19:03:44 -08003236 final Phone phone = PhoneFactory.getPhone(slotIndex);
3237 if (phone == null) {
3238 return TelephonyManager.UNKNOWN_CARRIER_ID;
3239 }
3240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003248 //
3249 // Internal helper methods.
3250 //
3251
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003252 /**
Grace Jia0ddb3612021-04-22 13:35:26 -07003253 * Make sure the caller is the calling package itself
3254 *
3255 * @throws SecurityException if the caller is not the calling package
3256 */
3257 private void enforceCallingPackage(String callingPackage, int callingUid, String message) {
3258 int packageUid = -1;
3259 try {
3260 packageUid = mPm.getPackageUid(callingPackage, 0);
3261 } catch (PackageManager.NameNotFoundException e) {
3262 // packageUid is -1
3263 }
3264 if (packageUid != callingUid) {
3265 throw new SecurityException(message + ": Package " + callingPackage
3266 + " does not belong to " + callingUid);
3267 }
3268 }
3269
3270 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003271 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3272 *
3273 * @throws SecurityException if the caller does not have the required permission
3274 */
3275 private void enforceModifyPermission() {
3276 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3277 }
3278
Shuo Qiancd19c462020-01-16 20:51:11 -08003279 /**
3280 * Make sure the caller is system.
3281 *
3282 * @throws SecurityException if the caller is not system.
3283 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003284 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003285 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3286 throw new SecurityException("Caller must be system");
3287 }
3288 }
3289
Shuo Qian3b6ee772019-11-13 17:43:31 -08003290 private void enforceActiveEmergencySessionPermission() {
3291 mApp.enforceCallingOrSelfPermission(
3292 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3293 }
3294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003295 /**
3296 * Make sure the caller has the CALL_PHONE permission.
3297 *
3298 * @throws SecurityException if the caller does not have the required permission
3299 */
3300 private void enforceCallPermission() {
3301 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3302 }
3303
paulhu5a773602019-08-23 19:17:33 +08003304 private void enforceSettingsPermission() {
3305 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003306 }
3307
Michele Berionne5e411512020-11-13 02:36:59 +00003308 private void enforceRebootPermission() {
3309 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3310 }
3311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003312 private String createTelUrl(String number) {
3313 if (TextUtils.isEmpty(number)) {
3314 return null;
3315 }
3316
Jake Hambye994d462014-02-03 13:10:13 -08003317 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003318 }
3319
Ihab Awadf9e92732013-12-05 18:02:52 -08003320 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3322 }
3323
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003324 private static void logv(String msg) {
3325 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3326 }
3327
Ihab Awadf9e92732013-12-05 18:02:52 -08003328 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003329 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3330 }
3331
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003332 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003333 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003334 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003335 }
3336
Sanket Padawe356d7632015-06-22 14:03:32 -07003337 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003338 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 final Phone phone = PhoneFactory.getPhone(slotIndex);
3342 if (phone == null) {
3343 return PhoneConstants.PHONE_TYPE_NONE;
3344 } else {
3345 return phone.getPhoneType();
3346 }
3347 } finally {
3348 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003350 }
3351
3352 /**
3353 * Returns the CDMA ERI icon index to display
3354 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003355 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003356 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3357 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3358 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003359 }
3360
Sanket Padawe356d7632015-06-22 14:03:32 -07003361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003362 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3363 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003365 mApp, subId, callingPackage, callingFeatureId,
3366 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003367 return -1;
3368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003369
3370 final long identity = Binder.clearCallingIdentity();
3371 try {
3372 final Phone phone = getPhone(subId);
3373 if (phone != null) {
3374 return phone.getCdmaEriIconIndex();
3375 } else {
3376 return -1;
3377 }
3378 } finally {
3379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003381 }
3382
3383 /**
3384 * Returns the CDMA ERI icon mode,
3385 * 0 - ON
3386 * 1 - FLASHING
3387 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003388 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003389 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3390 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3391 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003392 }
3393
Sanket Padawe356d7632015-06-22 14:03:32 -07003394 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003395 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3396 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003398 mApp, subId, callingPackage, callingFeatureId,
3399 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003400 return -1;
3401 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003402
3403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 final Phone phone = getPhone(subId);
3406 if (phone != null) {
3407 return phone.getCdmaEriIconMode();
3408 } else {
3409 return -1;
3410 }
3411 } finally {
3412 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003413 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003414 }
3415
3416 /**
3417 * Returns the CDMA ERI text,
3418 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003419 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003420 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3421 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3422 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003423 }
3424
Sanket Padawe356d7632015-06-22 14:03:32 -07003425 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003426 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3427 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003428 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003429 mApp, subId, callingPackage, callingFeatureId,
3430 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003431 return null;
3432 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433
3434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 final Phone phone = getPhone(subId);
3437 if (phone != null) {
3438 return phone.getCdmaEriText();
3439 } else {
3440 return null;
3441 }
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003445 }
3446
3447 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003448 * Returns the CDMA MDN.
3449 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003450 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003451 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3453 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003454
3455 final long identity = Binder.clearCallingIdentity();
3456 try {
3457 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003458 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003459 return phone.getLine1Number();
3460 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003461 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462 return null;
3463 }
3464 } finally {
3465 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003466 }
3467 }
3468
3469 /**
3470 * Returns the CDMA MIN.
3471 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003472 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003473 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3475 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 final Phone phone = getPhone(subId);
3480 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3481 return phone.getCdmaMin();
3482 } else {
3483 return null;
3484 }
3485 } finally {
3486 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003487 }
3488 }
3489
Hall Liud892bec2018-11-30 14:51:45 -08003490 @Override
3491 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3492 INumberVerificationCallback callback, String callingPackage) {
3493 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3494 != PERMISSION_GRANTED) {
3495 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3496 }
3497 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3498
3499 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3500 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003501 throw new SecurityException("Calling package must be configured in the device config: "
3502 + "calling package: " + callingPackage
3503 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003504 }
3505
3506 if (range == null) {
3507 throw new NullPointerException("Range must be non-null");
3508 }
3509
3510 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003511 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003512
3513 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3514 }
3515
Junda Liuca05d5d2014-08-14 22:36:34 -07003516 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003517 * Returns true if CDMA provisioning needs to run.
3518 */
3519 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520 final long identity = Binder.clearCallingIdentity();
3521 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003522 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003526 }
3527
3528 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003529 * Sets the voice mail number of a given subId.
3530 */
3531 @Override
3532 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003533 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3534 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3539 new Pair<String, String>(alphaTag, number), new Integer(subId));
3540 return success;
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003544 }
3545
Ta-wei Yen87c49842016-05-13 21:19:52 -07003546 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003547 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3548 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003549 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3550 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003551 if (!TextUtils.equals(callingPackage, systemDialer)) {
3552 throw new SecurityException("caller must be system dialer");
3553 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554
3555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3558 if (phoneAccountHandle == null) {
3559 return null;
3560 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003561 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562 } finally {
3563 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003564 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003565 }
3566
3567 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003568 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3569 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003570 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003572 mApp, subId, callingPackage, callingFeatureId,
3573 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003574 return null;
3575 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003577 final long identity = Binder.clearCallingIdentity();
3578 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003579 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003580 } finally {
3581 Binder.restoreCallingIdentity(identity);
3582 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003583 }
3584
3585 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003586 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3587 VisualVoicemailSmsFilterSettings settings) {
3588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589
3590 final long identity = Binder.clearCallingIdentity();
3591 try {
3592 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003593 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003597 }
3598
3599 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003600 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3601 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602
3603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003606 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003607 } finally {
3608 Binder.restoreCallingIdentity(identity);
3609 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003610 }
3611
3612 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003613 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3614 String callingPackage, int subId) {
3615 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003616
3617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003620 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621 } finally {
3622 Binder.restoreCallingIdentity(identity);
3623 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003624 }
3625
3626 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003627 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003628 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003629
3630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003633 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003637 }
3638
3639 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003640 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3641 String callingAttributionTag, int subId, String number, int port, String text,
3642 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003644 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003645 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003646 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003647 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3648 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003649 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003650
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003651 /**
fionaxu0152e512016-11-14 13:36:14 -08003652 * Sets the voice activation state of a given subId.
3653 */
3654 @Override
3655 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3657 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
3661 final Phone phone = getPhone(subId);
3662 if (phone != null) {
3663 phone.setVoiceActivationState(activationState);
3664 } else {
3665 loge("setVoiceActivationState fails with invalid subId: " + subId);
3666 }
3667 } finally {
3668 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003669 }
3670 }
3671
3672 /**
3673 * Sets the data activation state of a given subId.
3674 */
3675 @Override
3676 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3678 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003679
3680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 final Phone phone = getPhone(subId);
3683 if (phone != null) {
3684 phone.setDataActivationState(activationState);
3685 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003686 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003687 }
3688 } finally {
3689 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003690 }
3691 }
3692
3693 /**
3694 * Returns the voice activation state of a given subId.
3695 */
3696 @Override
3697 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699
fionaxu0152e512016-11-14 13:36:14 -08003700 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 if (phone != null) {
3704 return phone.getVoiceActivationState();
3705 } else {
3706 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3707 }
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003710 }
3711 }
3712
3713 /**
3714 * Returns the data activation state of a given subId.
3715 */
3716 @Override
3717 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003719
fionaxu0152e512016-11-14 13:36:14 -08003720 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003721 final long identity = Binder.clearCallingIdentity();
3722 try {
3723 if (phone != null) {
3724 return phone.getDataActivationState();
3725 } else {
3726 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3727 }
3728 } finally {
3729 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003730 }
3731 }
3732
3733 /**
Wink Saville36469e72014-06-11 15:17:00 -07003734 * Returns the unread count of voicemails for a subId
3735 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003736 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003737 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3738 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003740 mApp, subId, callingPackage, callingFeatureId,
3741 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003742 return 0;
3743 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744 final long identity = Binder.clearCallingIdentity();
3745 try {
3746 final Phone phone = getPhone(subId);
3747 if (phone != null) {
3748 return phone.getVoiceMessageCount();
3749 } else {
3750 return 0;
3751 }
3752 } finally {
3753 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003754 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003755 }
3756
3757 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003758 * returns true, if the device is in a state where both voice and data
3759 * are supported simultaneously. This can change based on location or network condition.
3760 */
3761 @Override
3762 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003763 final long identity = Binder.clearCallingIdentity();
3764 try {
3765 final Phone phone = getPhone(subId);
3766 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003770 }
3771
3772 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003773 * Send the dialer code if called from the current default dialer or the caller has
3774 * carrier privilege.
3775 * @param inputCode The dialer code to send
3776 */
3777 @Override
3778 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003779 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003781 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3782 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003783 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003784 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003785 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003786 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003787
3788 final long identity = Binder.clearCallingIdentity();
3789 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003790 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 } finally {
3792 Binder.restoreCallingIdentity(identity);
3793 }
fionaxu235cc5e2017-03-06 22:25:57 -08003794 }
3795
Pengquan Menga1bb6272018-09-06 09:59:22 -07003796 @Override
3797 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003798 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003799 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003800 mApp, subId, "getNetworkSelectionMode");
3801 final long identity = Binder.clearCallingIdentity();
3802 try {
3803 if (!isActiveSubscription(subId)) {
3804 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3805 }
3806 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3807 } finally {
3808 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003809 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003810 }
3811
Brad Ebinger35c841c2018-10-01 10:40:55 -07003812 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003813 public boolean isInEmergencySmsMode() {
3814 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3815 final long identity = Binder.clearCallingIdentity();
3816 try {
3817 for (Phone phone : PhoneFactory.getPhones()) {
3818 if (phone.isInEmergencySmsMode()) {
3819 return true;
3820 }
3821 }
3822 } finally {
3823 Binder.restoreCallingIdentity(identity);
3824 }
3825 return false;
3826 }
3827
shilu366312e2019-12-17 09:28:10 -08003828 /**
3829 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3830 * @param subId The subscription to use to check the configuration.
3831 * @param c The callback that will be used to send the result.
3832 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003833 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003834 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3835 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003836 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003837 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003838
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003839 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3840 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3841 "IMS not available on device.");
3842 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 final long token = Binder.clearCallingIdentity();
3844 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003845 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003846 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003848 } catch (ImsException e) {
3849 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003850 } finally {
3851 Binder.restoreCallingIdentity(token);
3852 }
3853 }
3854
shilu366312e2019-12-17 09:28:10 -08003855 /**
3856 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3857 * @param subId The subscription to use to check the configuration.
3858 * @param c The callback that will be used to send the result.
3859 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003861 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003862 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003863 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003864 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3865 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3866 }
Meng Wangafbc5852019-09-19 17:37:13 -07003867 final long token = Binder.clearCallingIdentity();
3868 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003869 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003870 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3871 .removeRegistrationCallbackForSubscription(c, subId);
3872 } catch (ImsException e) {
3873 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3874 + "is inactive, ignoring unregister.");
3875 // If the subscription is no longer active, just return, since the callback
3876 // will already have been removed internally.
3877 } finally {
3878 Binder.restoreCallingIdentity(token);
3879 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 }
3881
Brad Ebingera34a6c22019-10-22 17:36:18 -07003882 /**
3883 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3884 */
3885 @Override
3886 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3887 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3888 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3889 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3890 "IMS not available on device.");
3891 }
3892 final long token = Binder.clearCallingIdentity();
3893 try {
3894 Phone phone = getPhone(subId);
3895 if (phone == null) {
3896 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3897 + subId + "'");
3898 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3899 }
3900 phone.getImsRegistrationState(regState -> {
3901 try {
3902 consumer.accept((regState == null)
3903 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3904 } catch (RemoteException e) {
3905 // Ignore if the remote process is no longer available to call back.
3906 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3907 }
3908 });
3909 } finally {
3910 Binder.restoreCallingIdentity(token);
3911 }
3912 }
3913
3914 /**
3915 * Get the transport type for the IMS service registration state.
3916 */
3917 @Override
3918 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003919 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003920 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003921 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3922 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3923 "IMS not available on device.");
3924 }
3925 final long token = Binder.clearCallingIdentity();
3926 try {
3927 Phone phone = getPhone(subId);
3928 if (phone == null) {
3929 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3930 + subId + "'");
3931 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3932 }
3933 phone.getImsRegistrationTech(regTech -> {
3934 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3935 int regTechConverted = (regTech == null)
3936 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3937 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3938 regTechConverted);
3939 try {
3940 consumer.accept(regTechConverted);
3941 } catch (RemoteException e) {
3942 // Ignore if the remote process is no longer available to call back.
3943 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3944 }
3945 });
3946 } finally {
3947 Binder.restoreCallingIdentity(token);
3948 }
3949 }
3950
shilu366312e2019-12-17 09:28:10 -08003951 /**
3952 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3953 * @param subId The subscription to use to check the configuration.
3954 * @param c The callback that will be used to send the result.
3955 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003957 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3958 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003959 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003960 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003961 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3962 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3963 "IMS not available on device.");
3964 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3966 final long token = Binder.clearCallingIdentity();
3967 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003968 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003969 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003970 } catch (ImsException e) {
3971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 } finally {
3973 Binder.restoreCallingIdentity(token);
3974 }
3975 }
3976
shilu366312e2019-12-17 09:28:10 -08003977 /**
3978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3979 * @param subId The subscription to use to check the configuration.
3980 * @param c The callback that will be used to send the result.
3981 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003983 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003984 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003985 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003986 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3987 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3988 }
Meng Wangafbc5852019-09-19 17:37:13 -07003989
3990 final long token = Binder.clearCallingIdentity();
3991 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003992 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003993 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003994 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003995 } catch (ImsException e) {
3996 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3997 + "is inactive, ignoring unregister.");
3998 // If the subscription is no longer active, just return, since the callback
3999 // will already have been removed internally.
4000 } finally {
4001 Binder.restoreCallingIdentity(token);
4002 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07004003 }
4004
4005 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004006 public boolean isCapable(int subId, int capability, int regTech) {
4007 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4009 final long token = Binder.clearCallingIdentity();
4010 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004011 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004013 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
4015 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004016 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08004017 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
4018 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004019 } finally {
4020 Binder.restoreCallingIdentity(token);
4021 }
4022 }
4023
4024 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004025 public boolean isAvailable(int subId, int capability, int regTech) {
4026 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004027 final long token = Binder.clearCallingIdentity();
4028 try {
4029 Phone phone = getPhone(subId);
4030 if (phone == null) return false;
4031 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004032 } catch (com.android.ims.ImsException e) {
4033 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4034 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 } finally {
4036 Binder.restoreCallingIdentity(token);
4037 }
4038 }
4039
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004040 /**
4041 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4042 * subscription.
4043 * @param subId The subscription to use to check the configuration.
4044 * @param callback The callback that will be used to send the result.
4045 * @param capability The MmTelFeature capability that will be used to send the result.
4046 * @param transportType The transport type of the MmTelFeature capability.
4047 */
4048 @Override
4049 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4050 int transportType) {
4051 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4052 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4053 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4054 "IMS not available on device.");
4055 }
4056 final long token = Binder.clearCallingIdentity();
4057 try {
4058 int slotId = getSlotIndex(subId);
4059 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4060 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4061 + subId + "'");
4062 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4063 }
4064 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4065 transportType, aBoolean -> {
4066 try {
4067 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4068 } catch (RemoteException e) {
4069 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4070 + "running. Ignore");
4071 }
4072 });
4073 } finally {
4074 Binder.restoreCallingIdentity(token);
4075 }
4076 }
4077
shilu366312e2019-12-17 09:28:10 -08004078 /**
4079 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4080 * @param subId The subscription to use to check the configuration.
4081 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 @Override
4083 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004084 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004085 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004086
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4088 final long token = Binder.clearCallingIdentity();
4089 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004090 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004092 } catch (ImsException e) {
4093 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 } finally {
4095 Binder.restoreCallingIdentity(token);
4096 }
4097 }
4098
4099 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004100 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004102 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004106 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004108 } catch (ImsException e) {
4109 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
4113 }
4114
shilu366312e2019-12-17 09:28:10 -08004115 /**
4116 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4117 * @param subId The subscription to use to check the configuration.
4118 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004120 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004121 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004122 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004126 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4127 } catch (ImsException e) {
4128 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
4132 }
4133
4134 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004135 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004137 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004142 } catch (ImsException e) {
4143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
shilu366312e2019-12-17 09:28:10 -08004149 /**
4150 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4151 * @param subId The subscription to use to check the configuration.
4152 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 @Override
4154 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004155 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004156 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004160 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004161 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004162 } catch (ImsException e) {
4163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
4169 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004170 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004172 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004176 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004177 } catch (ImsException e) {
4178 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
4182 }
4183
shilu366312e2019-12-17 09:28:10 -08004184 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004185 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4186 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4187 * @param subId The subscription to use to check the configuration.
4188 */
4189 @Override
4190 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004191 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004192 mApp, subId, "isCrossSimCallingEnabledByUser");
4193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4196 return ImsManager.getInstance(mApp,
4197 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4198 } catch (ImsException e) {
4199 throw new ServiceSpecificException(e.getCode());
4200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
4203 }
4204
4205 /**
4206 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4207 * Requires MODIFY_PHONE_STATE permission.
4208 * @param subId The subscription to use to check the configuration.
4209 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4210 * false otherwise
4211 */
4212 @Override
4213 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4215 "setCrossSimCallingEnabled");
4216 final long identity = Binder.clearCallingIdentity();
4217 try {
4218 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4219 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4220 .setCrossSimCallingEnabled(isEnabled);
4221 } catch (ImsException e) {
4222 throw new ServiceSpecificException(e.getCode());
4223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
4226 }
4227
4228 /**
shilu366312e2019-12-17 09:28:10 -08004229 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4230 * @param subId The subscription to use to check the configuration.
4231 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004233
Brad Ebinger35c841c2018-10-01 10:40:55 -07004234 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004235 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004236 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 final long identity = Binder.clearCallingIdentity();
4238 try {
4239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004240 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
4249 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004250 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004252 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 final long identity = Binder.clearCallingIdentity();
4254 try {
4255 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004256 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004257 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004258 } catch (ImsException e) {
4259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
4263 }
4264
4265 @Override
4266 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4268 "setVoWiFiNonPersistent");
4269 final long identity = Binder.clearCallingIdentity();
4270 try {
4271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004273 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004274 } catch (ImsException e) {
4275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
4279 }
4280
shilu366312e2019-12-17 09:28:10 -08004281 /**
4282 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4283 * @param subId The subscription to use to check the configuration.
4284 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004285 @Override
4286 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004287 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004288 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 final long identity = Binder.clearCallingIdentity();
4290 try {
4291 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004292 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004293 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004294 } catch (ImsException e) {
4295 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
4299 }
4300
4301 @Override
4302 public void setVoWiFiModeSetting(int subId, int mode) {
4303 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4304 "setVoWiFiModeSetting");
4305 final long identity = Binder.clearCallingIdentity();
4306 try {
4307 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004308 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004309 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004310 } catch (ImsException e) {
4311 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
4315 }
4316
4317 @Override
4318 public int getVoWiFiRoamingModeSetting(int subId) {
4319 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4320 final long identity = Binder.clearCallingIdentity();
4321 try {
4322 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004323 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004325 } catch (ImsException e) {
4326 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004327 } finally {
4328 Binder.restoreCallingIdentity(identity);
4329 }
4330 }
4331
4332 @Override
4333 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4335 "setVoWiFiRoamingModeSetting");
4336 final long identity = Binder.clearCallingIdentity();
4337 try {
4338 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004339 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004340 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004341 } catch (ImsException e) {
4342 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
4346 }
4347
4348 @Override
4349 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4351 "setRttCapabilityEnabled");
4352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004355 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4356 } catch (ImsException e) {
4357 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
shilu366312e2019-12-17 09:28:10 -08004363 /**
4364 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4365 * @param subId The subscription to use to check the configuration.
4366 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004367 @Override
4368 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004369 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004370 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004371 final long identity = Binder.clearCallingIdentity();
4372 try {
4373 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004374 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004375 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004376 } catch (ImsException e) {
4377 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
4381 }
4382
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004383 @Override
4384 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4385 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4386 final long identity = Binder.clearCallingIdentity();
4387 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004388 if (!isImsAvailableOnDevice()) {
4389 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4390 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004391 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004392 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004393 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004394 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004395 } catch (ImsException e) {
4396 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401
4402 @Override
4403 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4404 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4405 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004406 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4407 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4408 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004409 try {
4410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004411 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004412 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004413 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004414 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4415 + "is inactive, ignoring unregister.");
4416 // If the subscription is no longer active, just return, since the callback will already
4417 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004418 } finally {
4419 Binder.restoreCallingIdentity(identity);
4420 }
4421 }
4422
allenwtsu99c623b2020-01-03 18:24:23 +08004423
4424 private void checkModifyPhoneStatePermission(int subId, String message) {
4425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4426 message);
4427 }
4428
4429 private boolean isImsProvisioningRequired(int subId, int capability,
4430 boolean isMmtelCapability) {
4431 Phone phone = getPhone(subId);
4432 if (phone == null) {
4433 loge("phone instance null for subid " + subId);
4434 return false;
4435 }
4436 if (isMmtelCapability) {
4437 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4438 return false;
4439 }
4440 } else {
4441 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4442 return false;
4443 }
4444 }
4445 return true;
4446 }
4447
4448 @Override
4449 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4450 boolean isProvisioned) {
4451 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4452
4453 final long identity = Binder.clearCallingIdentity();
4454 try {
4455 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4456 if (!isImsProvisioningRequired(subId, capability, false)) {
4457 return;
4458 }
4459
4460 // this capability requires provisioning, route to the correct API.
4461 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4462 switch (capability) {
4463 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4464 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4465 ims.setEabProvisioned(isProvisioned);
4466 break;
4467 default: {
4468 throw new IllegalArgumentException("Tried to set provisioning for "
4469 + "rcs capability '" + capability + "', which does not require "
4470 + "provisioning.");
4471 }
4472 }
4473 } finally {
4474 Binder.restoreCallingIdentity(identity);
4475 }
4476
4477 }
4478
4479
4480 @Override
4481 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4482 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4483 final long identity = Binder.clearCallingIdentity();
4484 try {
4485 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4486 if (!isImsProvisioningRequired(subId, capability, false)) {
4487 return true;
4488 }
4489
4490 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4491 switch (capability) {
4492 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4493 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4494 return ims.isEabProvisionedOnDevice();
4495
4496 default: {
4497 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4498 + "capability '" + capability + "', which does not require "
4499 + "provisioning.");
4500 }
4501 }
4502
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004508 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004509 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4510 boolean isProvisioned) {
4511 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004512 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4513 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4514 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004515 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4516 }
allenwtsu99c623b2020-01-03 18:24:23 +08004517 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004518 final long identity = Binder.clearCallingIdentity();
4519 try {
4520 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004521 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004522 return;
4523 }
Brad Ebinger0d79c572021-04-17 15:20:49 -07004524 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4525 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4526 loge("setImsProvisioningStatusForCapability: called for technology that does "
4527 + "not support provisioning - " + tech);
4528 return;
4529 }
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004530
4531 // this capability requires provisioning, route to the correct API.
4532 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4533 switch (capability) {
4534 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4535 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4536 ims.setVolteProvisioned(isProvisioned);
4537 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4538 ims.setWfcProvisioned(isProvisioned);
4539 }
4540 break;
4541 }
4542 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4543 // There is currently no difference in VT provisioning type.
4544 ims.setVtProvisioned(isProvisioned);
4545 break;
4546 }
4547 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4548 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4549 // change the capability of the feature instead if needed.
4550 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4551 == isProvisioned) {
4552 // No change in provisioning.
4553 return;
4554 }
4555 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4556 try {
Brad Ebinger0d79c572021-04-17 15:20:49 -07004557 ims.changeMmTelCapability(isProvisioned, capability, tech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004558 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004559 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4560 + ", Exception" + e.getMessage());
4561 }
4562 break;
4563 }
4564 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004565 throw new IllegalArgumentException("Tried to set provisioning for "
4566 + "MmTel capability '" + capability + "', which does not require "
4567 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004568 }
4569 }
4570
4571 } finally {
4572 Binder.restoreCallingIdentity(identity);
4573 }
4574 }
4575
4576 @Override
4577 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4578 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
Brad Ebinger0d79c572021-04-17 15:20:49 -07004579 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE
4580 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR
4581 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004582 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4583 }
4584 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4585 final long identity = Binder.clearCallingIdentity();
4586 try {
4587 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004588 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004589 return true;
4590 }
4591
Brad Ebinger0d79c572021-04-17 15:20:49 -07004592 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR
4593 || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) {
4594 loge("getImsProvisioningStatusForCapability: called for technology that does "
4595 + "not support provisioning - " + tech);
4596 return true;
4597 }
4598
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004599 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4600 switch (capability) {
4601 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4602 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4603 return ims.isVolteProvisionedOnDevice();
4604 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4605 return ims.isWfcProvisionedOnDevice();
4606 }
4607 // This should never happen, since we are checking tech above to make sure it
4608 // is either LTE or IWLAN.
4609 throw new IllegalArgumentException("Invalid radio technology for voice "
4610 + "capability.");
4611 }
4612 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4613 // There is currently no difference in VT provisioning type.
4614 return ims.isVtProvisionedOnDevice();
4615 }
4616 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4617 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4618 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4619 }
4620 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004621 throw new IllegalArgumentException(
4622 "Tried to get provisioning for MmTel capability '" + capability
4623 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004624 }
4625 }
4626
4627 } finally {
4628 Binder.restoreCallingIdentity(identity);
4629 }
4630 }
4631
4632 @Override
4633 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4634 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4635 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4636 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4637 }
4638 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4639 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4640 return (provisionedBits & capability) > 0;
4641 }
4642
4643 @Override
4644 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4645 boolean isProvisioned) {
4646 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4647 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4648 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4649 }
4650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4651 "setProvisioningStatusForCapability");
4652 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4653 // If the current provisioning status for capability already matches isProvisioned,
4654 // do nothing.
4655 if (((provisionedBits & capability) > 0) == isProvisioned) {
4656 return;
4657 }
4658 if (isProvisioned) {
4659 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4660 } else {
4661 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4662 }
4663 }
4664
4665 /**
4666 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4667 * technology. The bitfield should mirror the bitfield defined by
4668 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4669 */
4670 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4671 String key = getMmTelProvisioningKey(subId, tech);
4672 // Default is no capabilities are provisioned.
4673 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4674 }
4675
4676 /**
4677 * Sets the MmTel capability provisioning bitfield (defined by
4678 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4679 * technology specified.
4680 *
4681 * Note: This is a synchronous command and should not be called on UI thread.
4682 */
4683 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4684 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4685 String key = getMmTelProvisioningKey(subId, tech);
4686 editor.putInt(key, newField);
4687 editor.commit();
4688 }
4689
4690 private static String getMmTelProvisioningKey(int subId, int tech) {
4691 // resulting key is provision_ims_mmtel_{subId}_{tech}
4692 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4693 }
4694
4695 /**
4696 * Query CarrierConfig to see if the specified capability requires provisioning for the
4697 * carrier associated with the subscription id.
4698 */
4699 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4700 int capability) {
4701 CarrierConfigManager configManager = new CarrierConfigManager(context);
4702 PersistableBundle c = configManager.getConfigForSubId(subId);
4703 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004704 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4706 false);
4707 boolean requireVoiceVtProvisioning = c.getBoolean(
4708 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4709
4710 // First check to make sure that the capability requires provisioning.
4711 switch (capability) {
4712 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4713 // intentional fallthrough
4714 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4715 if (requireVoiceVtProvisioning) {
4716 // Voice and Video requires provisioning
4717 return true;
4718 }
4719 break;
4720 }
4721 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4722 if (requireUtProvisioning) {
4723 // UT requires provisioning
4724 return true;
4725 }
4726 break;
4727 }
4728 }
4729 return false;
4730 }
4731
allenwtsu99c623b2020-01-03 18:24:23 +08004732 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4733 int capability) {
4734 CarrierConfigManager configManager = new CarrierConfigManager(context);
4735 PersistableBundle c = configManager.getConfigForSubId(subId);
4736
4737 boolean requireRcsProvisioning = c.getBoolean(
4738 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4739
4740 // First check to make sure that the capability requires provisioning.
4741 switch (capability) {
4742 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4743 // intentional fallthrough
4744 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4745 if (requireRcsProvisioning) {
4746 // OPTION or PRESENCE requires provisioning
4747 return true;
4748 }
4749 break;
4750 }
4751 }
4752 return false;
4753 }
4754
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004755 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004756 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004757 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4758 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4759 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004760 enforceReadPrivilegedPermission("getImsProvisioningInt");
4761 final long identity = Binder.clearCallingIdentity();
4762 try {
4763 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004764 int slotId = getSlotIndex(subId);
4765 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4766 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4767 + subId + "' for key:" + key);
4768 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4769 }
calvinpanb5a34062021-02-08 19:59:36 +08004770 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004771 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004772 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4773 + subId + "' for key:" + key);
4774 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004775 } finally {
4776 Binder.restoreCallingIdentity(identity);
4777 }
4778 }
4779
4780 @Override
4781 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004782 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4783 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4784 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004785 enforceReadPrivilegedPermission("getImsProvisioningString");
4786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004789 int slotId = getSlotIndex(subId);
4790 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4791 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4792 + subId + "' for key:" + key);
4793 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4794 }
calvinpanb5a34062021-02-08 19:59:36 +08004795 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004796 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004797 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4798 + subId + "' for key:" + key);
4799 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004800 } finally {
4801 Binder.restoreCallingIdentity(identity);
4802 }
4803 }
4804
4805 @Override
4806 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4808 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4809 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4811 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004812 final long identity = Binder.clearCallingIdentity();
4813 try {
4814 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004815 int slotId = getSlotIndex(subId);
4816 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4817 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4818 + subId + "' for key:" + key);
4819 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4820 }
calvinpanb5a34062021-02-08 19:59:36 +08004821 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4822 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004823 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004824 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004825 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004826 } finally {
4827 Binder.restoreCallingIdentity(identity);
4828 }
4829 }
4830
4831 @Override
4832 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004833 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4834 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4835 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4837 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004838 final long identity = Binder.clearCallingIdentity();
4839 try {
4840 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004841 int slotId = getSlotIndex(subId);
4842 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4843 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4844 + subId + "' for key:" + key);
4845 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4846 }
calvinpanb5a34062021-02-08 19:59:36 +08004847 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4848 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004849 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004850 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004851 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004852 } finally {
4853 Binder.restoreCallingIdentity(identity);
4854 }
4855 }
4856
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004857 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004858 int slotId = SubscriptionManager.getSlotIndex(subId);
4859 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004860 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4861 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004862 }
4863 return slotId;
4864 }
4865
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004866 private int getSlotIndex(int subId) {
4867 int slotId = SubscriptionManager.getSlotIndex(subId);
4868 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4869 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4870 }
4871 return slotId;
4872 }
4873
Wink Saville36469e72014-06-11 15:17:00 -07004874 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004875 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004876 */
4877 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004878 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4879 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004880 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004881 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004882 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004883 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004884 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004885 mApp, subId, callingPackage, callingFeatureId,
4886 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004887 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4888 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 final Phone phone = getPhone(subId);
4893 if (phone != null) {
4894 return phone.getServiceState().getDataNetworkType();
4895 } else {
4896 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4897 }
4898 } finally {
4899 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004901 }
4902
4903 /**
4904 * Returns the data network type
4905 */
4906 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004907 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
Zoey Chenfd61f7f2021-04-21 13:42:10 +08004908 return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(),
4909 callingPackage, callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004910 }
4911
4912 /**
4913 * Returns the data network type for a subId
4914 */
4915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004916 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4917 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004919 mApp, subId, callingPackage, callingFeatureId,
4920 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004921 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4922 }
4923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 final Phone phone = getPhone(subId);
4927 if (phone != null) {
4928 return phone.getServiceState().getDataNetworkType();
4929 } else {
4930 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4931 }
4932 } finally {
4933 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004934 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004935 }
4936
4937 /**
Wink Saville36469e72014-06-11 15:17:00 -07004938 * Returns the Voice network type for a subId
4939 */
4940 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004941 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4942 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004944 mApp, subId, callingPackage, callingFeatureId,
4945 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004946 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4947 }
4948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 final long identity = Binder.clearCallingIdentity();
4950 try {
4951 final Phone phone = getPhone(subId);
4952 if (phone != null) {
4953 return phone.getServiceState().getVoiceNetworkType();
4954 } else {
4955 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4956 }
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004960 }
4961
4962 /**
4963 * @return true if a ICC card is present
4964 */
4965 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004966 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004967 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4968 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004969 }
4970
4971 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004972 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004973 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004974 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004975 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 final long identity = Binder.clearCallingIdentity();
4977 try {
4978 final Phone phone = PhoneFactory.getPhone(slotIndex);
4979 if (phone != null) {
4980 return phone.getIccCard().hasIccCard();
4981 } else {
4982 return false;
4983 }
4984 } finally {
4985 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004987 }
4988
4989 /**
4990 * Return if the current radio is LTE on CDMA. This
4991 * is a tri-state return value as for a period of time
4992 * the mode may be unknown.
4993 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004994 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004995 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004996 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004997 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004998 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004999 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
5000 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
5001 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07005002 }
5003
Sanket Padawe356d7632015-06-22 14:03:32 -07005004 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005005 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
5006 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08005007 try {
5008 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
5009 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005010 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5011 }
5012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 final long identity = Binder.clearCallingIdentity();
5014 try {
5015 final Phone phone = getPhone(subId);
5016 if (phone == null) {
5017 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
5018 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07005019 return TelephonyProperties.lte_on_cdma_device()
5020 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 }
5022 } finally {
5023 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005024 }
Wink Saville36469e72014-06-11 15:17:00 -07005025 }
5026
Wink Saville36469e72014-06-11 15:17:00 -07005027 /**
5028 * {@hide}
5029 * Returns Default subId, 0 in the case of single standby.
5030 */
Wink Savilleb564aae2014-10-23 10:18:09 -07005031 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005032 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07005033 }
5034
Shishir Agrawala9f32182016-04-12 12:00:16 -07005035 private int getSlotForDefaultSubscription() {
5036 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5037 }
5038
Wink Savilleb564aae2014-10-23 10:18:09 -07005039 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005040 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005041 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005042
Pengquan Menge92a50d2018-09-21 15:54:48 -07005043 private boolean isActiveSubscription(int subId) {
5044 return mSubscriptionController.isActiveSubId(subId);
5045 }
5046
Ihab Awadf2177b72013-11-25 13:33:23 -08005047 /**
5048 * @see android.telephony.TelephonyManager.WifiCallingChoices
5049 */
5050 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005051 final long identity = Binder.clearCallingIdentity();
5052 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005053 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5055 getWhenToMakeWifiCallsDefaultPreference());
5056 } finally {
5057 Binder.restoreCallingIdentity(identity);
5058 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005059 }
5060
5061 /**
5062 * @see android.telephony.TelephonyManager.WifiCallingChoices
5063 */
5064 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005068 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005073 }
5074
Sailesh Nepald1e68152013-12-12 19:08:02 -08005075 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005076 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005077 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005078 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005079
Jordan Liu4c733742019-02-28 12:03:40 -08005080 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5081 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5082 if (phoneId == -1) {
5083 throw new IllegalArgumentException("Given slot index: " + slotIndex
5084 + " does not correspond to an active phone");
5085 }
5086 return PhoneFactory.getPhone(phoneId);
5087 }
5088
Shishir Agrawal566b7612013-10-28 14:41:00 -07005089 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005090 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5091 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5093 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005095 if (DBG) {
5096 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5097 }
5098 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5099 p2);
5100 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005101
Jordan Liu4c733742019-02-28 12:03:40 -08005102
5103 @Override
5104 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5105 int slotIndex, String callingPackage, String aid, int p2) {
5106 enforceModifyPermission();
5107 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5108 if (DBG) {
5109 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5110 }
5111 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5112 callingPackage, aid, p2);
5113 }
5114
5115 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5116 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117 final long identity = Binder.clearCallingIdentity();
5118 try {
5119 if (TextUtils.equals(ISDR_AID, aid)) {
5120 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005121 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5122 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 if (bestComponent == null
5124 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5125 loge("The calling package is not allowed to access ISD-R.");
5126 throw new SecurityException(
5127 "The calling package is not allowed to access ISD-R.");
5128 }
Derek Tan740e1672017-06-27 14:56:27 -07005129 }
Derek Tan740e1672017-06-27 14:56:27 -07005130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005132 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5133 null /* workSource */);
5134 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 return response;
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005139 }
5140
5141 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005142 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5144 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005145 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5146 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5147 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005148
Jordan Liu4c733742019-02-28 12:03:40 -08005149 @Override
5150 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5151 enforceModifyPermission();
5152 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5153 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5154 channel);
5155 }
5156
5157 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 final long identity = Binder.clearCallingIdentity();
5159 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005160 if (channel < 0) {
5161 return false;
5162 }
Jordan Liu4c733742019-02-28 12:03:40 -08005163 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5164 null /* workSource */);
5165 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 return success;
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005169 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005170 }
5171
5172 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005173 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005174 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5176 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005177 if (DBG) {
5178 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5179 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5180 + p3 + " data=" + data);
5181 }
5182 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5183 command, p1, p2, p3, data);
5184 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005185
Jordan Liu4c733742019-02-28 12:03:40 -08005186 @Override
5187 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5188 int command, int p1, int p2, int p3, String data) {
5189 enforceModifyPermission();
5190 if (DBG) {
5191 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5192 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5193 + p3 + " data=" + data);
5194 }
5195 return iccTransmitApduLogicalChannelWithPermission(
5196 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5197 data);
5198 }
5199
5200 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5201 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202 final long identity = Binder.clearCallingIdentity();
5203 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005204 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 return "";
5206 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005209 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5210 null /* workSource */);
5211 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213 // Append the returned status code to the end of the response payload.
5214 String s = Integer.toHexString(
5215 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5216 if (response.payload != null) {
5217 s = IccUtils.bytesToHexString(response.payload) + s;
5218 }
5219 return s;
5220 } finally {
5221 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005222 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005223 }
Jake Hambye994d462014-02-03 13:10:13 -08005224
Evan Charltonc66da362014-05-16 14:06:40 -07005225 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005226 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5227 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5229 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005231 if (DBG) {
5232 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5233 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5234 }
5235 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5236 cla, command, p1, p2, p3, data);
5237 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005238
Jordan Liu4c733742019-02-28 12:03:40 -08005239 @Override
5240 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5241 int command, int p1, int p2, int p3, String data) {
5242 enforceModifyPermission();
5243 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5244 if (DBG) {
5245 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5246 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5247 + " data=" + data);
5248 }
5249
5250 return iccTransmitApduBasicChannelWithPermission(
5251 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5252 p2, p3, data);
5253 }
5254
5255 // open APDU basic channel assuming the caller has sufficient permissions
5256 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5257 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005258 final long identity = Binder.clearCallingIdentity();
5259 try {
5260 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5261 && TextUtils.equals(ISDR_AID, data)) {
5262 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005263 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5264 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005265 if (bestComponent == null
5266 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5267 loge("The calling package is not allowed to select ISD-R.");
5268 throw new SecurityException(
5269 "The calling package is not allowed to select ISD-R.");
5270 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005271 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005274 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5275 null /* workSource */);
5276 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 // Append the returned status code to the end of the response payload.
5279 String s = Integer.toHexString(
5280 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5281 if (response.payload != null) {
5282 s = IccUtils.bytesToHexString(response.payload) + s;
5283 }
5284 return s;
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005287 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005288 }
5289
5290 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005291 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005292 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5294 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005295
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 final long identity = Binder.clearCallingIdentity();
5297 try {
5298 if (DBG) {
5299 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5300 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5301 }
5302
5303 IccIoResult response =
5304 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5305 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5306 subId);
5307
5308 if (DBG) {
5309 log("Exchange SIM_IO [R]" + response);
5310 }
5311
5312 byte[] result = null;
5313 int length = 2;
5314 if (response.payload != null) {
5315 length = 2 + response.payload.length;
5316 result = new byte[length];
5317 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5318 } else {
5319 result = new byte[length];
5320 }
5321
5322 result[length - 1] = (byte) response.sw2;
5323 result[length - 2] = (byte) response.sw1;
5324 return result;
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005327 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005328 }
5329
Nathan Haroldb3014052017-01-25 15:57:32 -08005330 /**
5331 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5332 * on a particular subscription
5333 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005334 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5335 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005337 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005338 return null;
5339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340
5341 final long identity = Binder.clearCallingIdentity();
5342 try {
5343 if (appType != TelephonyManager.APPTYPE_USIM
5344 && appType != TelephonyManager.APPTYPE_SIM) {
5345 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5346 return null;
5347 }
5348 Object response = sendRequest(
5349 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5350 if (response instanceof String[]) {
5351 return (String[]) response;
5352 }
yincheng zhao2737e882019-09-06 17:06:54 -07005353 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005355 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 } finally {
5357 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005358 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005359 }
5360
yincheng zhao2737e882019-09-06 17:06:54 -07005361 /**
5362 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5363 * subscription.
5364 *
5365 * @param subId the id of the subscription.
5366 * @param appType the uicc app type, must be USIM or SIM.
5367 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5368 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005369 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005370 * @return number of fplmns that is successfully written to the SIM.
5371 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005372 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5373 String callingFeatureId) {
5374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5375 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005376 if (DBG) logv("no permissions for setForbiddenplmns");
5377 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5378 }
5379 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5380 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5381 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5382 }
5383 if (fplmns == null) {
5384 throw new IllegalArgumentException("Fplmn List provided is null");
5385 }
5386 for (String fplmn : fplmns) {
5387 if (!CellIdentity.isValidPlmn(fplmn)) {
5388 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5389 }
5390 }
5391 final long identity = Binder.clearCallingIdentity();
5392 try {
5393 Object response = sendRequest(
5394 CMD_SET_FORBIDDEN_PLMNS,
5395 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5396 subId);
5397 return (int) response;
5398 } finally {
5399 Binder.restoreCallingIdentity(identity);
5400 }
5401 }
5402
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005403 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005404 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5406 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 final long identity = Binder.clearCallingIdentity();
5409 try {
5410 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5411 if (response.payload == null) {
5412 return "";
5413 }
Evan Charltonc66da362014-05-16 14:06:40 -07005414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 // Append the returned status code to the end of the response payload.
5416 String s = Integer.toHexString(
5417 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5418 s = IccUtils.bytesToHexString(response.payload) + s;
5419 return s;
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
Evan Charltonc66da362014-05-16 14:06:40 -07005423 }
5424
Jake Hambye994d462014-02-03 13:10:13 -08005425 /**
5426 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5427 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5428 *
5429 * @param itemID the ID of the item to read
5430 * @return the NV item as a String, or null on error.
5431 */
5432 @Override
5433 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005434 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5436 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005437
5438 final long identity = Binder.clearCallingIdentity();
5439 try {
5440 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005441 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5443 return value;
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
5446 }
Jake Hambye994d462014-02-03 13:10:13 -08005447 }
5448
5449 /**
5450 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5451 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5452 *
5453 * @param itemID the ID of the item to read
5454 * @param itemValue the value to write, as a String
5455 * @return true on success; false on any failure
5456 */
5457 @Override
5458 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005459 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5461 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462
5463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5466 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005467 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5469 return success;
5470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
Jake Hambye994d462014-02-03 13:10:13 -08005473 }
5474
5475 /**
5476 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5477 * Used for device configuration by some CDMA operators.
5478 *
5479 * @param preferredRoamingList byte array containing the new PRL
5480 * @return true on success; false on any failure
5481 */
5482 @Override
5483 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5485 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486
5487 final long identity = Binder.clearCallingIdentity();
5488 try {
5489 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5490 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5491 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5492 return success;
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
Jake Hambye994d462014-02-03 13:10:13 -08005496 }
5497
5498 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005499 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005500 * Used for device configuration by some CDMA operators.
5501 *
chen xu6dac5ab2018-10-26 17:39:23 -07005502 * @param slotIndex - device slot.
5503 *
Jake Hambye994d462014-02-03 13:10:13 -08005504 * @return true on success; false on any failure
5505 */
5506 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005507 public boolean resetModemConfig(int slotIndex) {
5508 Phone phone = PhoneFactory.getPhone(slotIndex);
5509 if (phone != null) {
5510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5511 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512
chen xu6dac5ab2018-10-26 17:39:23 -07005513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5516 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5517 return success;
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 }
chen xu6dac5ab2018-10-26 17:39:23 -07005522 return false;
5523 }
5524
5525 /**
5526 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5527 *
5528 * @param slotIndex - device slot.
5529 *
5530 * @return true on success; false on any failure
5531 */
5532 @Override
5533 public boolean rebootModem(int slotIndex) {
5534 Phone phone = PhoneFactory.getPhone(slotIndex);
5535 if (phone != null) {
5536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5537 mApp, phone.getSubId(), "rebootModem");
5538
5539 final long identity = Binder.clearCallingIdentity();
5540 try {
5541 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5542 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5543 return success;
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
5547 }
5548 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005549 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005550
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005551 public String[] getPcscfAddress(String apnType, String callingPackage,
5552 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005553 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5555 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005556 return new String[0];
5557 }
5558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 final long identity = Binder.clearCallingIdentity();
5560 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005561 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562 } finally {
5563 Binder.restoreCallingIdentity(identity);
5564 }
Wink Saville36469e72014-06-11 15:17:00 -07005565 }
5566
Brad Ebinger51f743a2017-01-23 13:50:20 -08005567 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005568 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5569 * {@link #disableIms(int)}.
5570 * @param slotIndex device slot.
5571 */
5572 public void resetIms(int slotIndex) {
5573 enforceModifyPermission();
5574
5575 final long identity = Binder.clearCallingIdentity();
5576 try {
5577 if (mImsResolver == null) {
5578 // may happen if the does not support IMS.
5579 return;
5580 }
5581 mImsResolver.disableIms(slotIndex);
5582 mImsResolver.enableIms(slotIndex);
5583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
5586 }
5587
5588 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005589 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5590 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005591 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005592 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005593 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594
5595 final long identity = Binder.clearCallingIdentity();
5596 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005597 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005598 // may happen if the device does not support IMS.
5599 return;
5600 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005601 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 } finally {
5603 Binder.restoreCallingIdentity(identity);
5604 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005605 }
5606
5607 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005608 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5609 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005610 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005611 public void disableIms(int slotId) {
5612 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613
5614 final long identity = Binder.clearCallingIdentity();
5615 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005616 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005617 // may happen if the device does not support IMS.
5618 return;
5619 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005620 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005624 }
5625
5626 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005627 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5628 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005629 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005630 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005631 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005632 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005636 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005637 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5638 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005639 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005640 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005644 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005645 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005646 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5647 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005648 @Override
5649 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005650 enforceModifyPermission();
5651
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005655 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005656 } finally {
5657 Binder.restoreCallingIdentity(identity);
5658 }
5659 }
5660
5661 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005662 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005663 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005664 */
5665 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5666 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667
5668 final long identity = Binder.clearCallingIdentity();
5669 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005670 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005671 // may happen if the device does not support IMS.
5672 return null;
5673 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005674 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005678 }
5679
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005680 /**
5681 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005682 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005683 */
5684 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005689 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005690 // may happen if the device does not support IMS.
5691 return null;
5692 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005693 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005697 }
5698
Brad Ebinger884c07b2018-02-15 16:17:40 -08005699 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005700 * Sets the ImsService Package Name that Telephony will bind to.
5701 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005702 * @param slotIndex the slot ID that the ImsService should bind for.
5703 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005704 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005705 * @param featureTypes An integer array of feature types associated with a packageName.
5706 * @param packageName The name of the package that the current configuration will be replaced
5707 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005708 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005709 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005710 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5711 int[] featureTypes, String packageName) {
5712 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5713 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5715 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 final long identity = Binder.clearCallingIdentity();
5719 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005720 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005721 // may happen if the device does not support IMS.
5722 return false;
5723 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005724 Map<Integer, String> featureConfig = new HashMap<>();
5725 for (int featureType : featureTypes) {
5726 featureConfig.put(featureType, packageName);
5727 }
5728 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5729 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 } finally {
5731 Binder.restoreCallingIdentity(identity);
5732 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005733 }
5734
5735 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005736 * Clears any carrier ImsService overrides for the slot index specified that were previously
5737 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5738 *
5739 * This should only be used for testing.
5740 *
5741 * @param slotIndex the slot ID that the ImsService should bind for.
5742 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5743 */
5744 @Override
5745 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5746 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5747 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5748 "clearCarrierImsServiceOverride");
5749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5750 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5751 "clearCarrierImsServiceOverride");
5752
5753 final long identity = Binder.clearCallingIdentity();
5754 try {
5755 if (mImsResolver == null) {
5756 // may happen if the device does not support IMS.
5757 return false;
5758 }
5759 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5760 } finally {
5761 Binder.restoreCallingIdentity(identity);
5762 }
5763 }
5764
5765 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005766 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005767 *
5768 * @param slotId The slot that the ImsService is associated with.
5769 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5770 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005771 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005772 * @return the package name of the ImsService configuration.
5773 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005774 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5775 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005776 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005777 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005778 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005779 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5780 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005782 final long identity = Binder.clearCallingIdentity();
5783 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005784 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005785 // may happen if the device does not support IMS.
5786 return "";
5787 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005788 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005789 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5790 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 } finally {
5792 Binder.restoreCallingIdentity(identity);
5793 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005794 }
5795
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005796 /**
5797 * Get the MmTelFeature state associated with the requested subscription id.
5798 * @param subId The subscription that the MmTelFeature is associated with.
5799 * @param callback A callback with an integer containing the
5800 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5801 */
5802 @Override
5803 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5804 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5805 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5806 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5807 "IMS not available on device.");
5808 }
5809 final long token = Binder.clearCallingIdentity();
5810 try {
5811 int slotId = getSlotIndex(subId);
5812 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5813 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5814 + subId + "'");
5815 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5816 }
5817 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5818 try {
5819 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5820 } catch (RemoteException e) {
5821 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5822 + "Ignore");
5823 }
5824 });
5825 } finally {
5826 Binder.restoreCallingIdentity(token);
5827 }
5828 }
5829
Daniel Brightbb5840b2021-01-12 15:48:18 -08005830 /**
5831 * Sets the ims registration state on all valid {@link Phone}s.
5832 */
5833 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835
5836 final long identity = Binder.clearCallingIdentity();
5837 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005838 // NOTE: Before S, this method only set the default phone.
5839 for (final Phone phone : PhoneFactory.getPhones()) {
5840 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5841 phone.setImsRegistrationState(registered);
5842 }
5843 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Wink Saville36469e72014-06-11 15:17:00 -07005847 }
5848
5849 /**
Stuart Scott54788802015-03-30 13:18:01 -07005850 * Set the network selection mode to automatic.
5851 *
5852 */
5853 @Override
5854 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5856 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
shilufc958392020-01-20 11:36:01 -08005860 if (!isActiveSubscription(subId)) {
5861 return;
5862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005864 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5865 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 } finally {
5867 Binder.restoreCallingIdentity(identity);
5868 }
Stuart Scott54788802015-03-30 13:18:01 -07005869 }
5870
Jack Yud10cdd42020-09-28 20:28:01 -07005871 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005872 * Ask the radio to connect to the input network and change selection mode to manual.
5873 *
5874 * @param subId the id of the subscription.
5875 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5876 * the operator to attach to.
5877 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5878 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5879 * normal network selection next time.
5880 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005881 */
5882 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005883 public boolean setNetworkSelectionModeManual(
5884 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5886 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005887
5888 if (!isActiveSubscription(subId)) {
5889 return false;
5890 }
5891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 final long identity = Binder.clearCallingIdentity();
5893 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005894 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005896 if (DBG) {
5897 log("setNetworkSelectionModeManual: subId: " + subId
5898 + " operator: " + operatorInfo);
5899 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005904 }
shilu84f6e8b2019-12-19 13:58:01 -08005905 /**
5906 * Get the manual network selection
5907 *
5908 * @param subId the id of the subscription.
5909 *
5910 * @return the previously saved user selected PLMN
5911 */
5912 @Override
5913 public String getManualNetworkSelectionPlmn(int subId) {
5914 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005915 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005916 mApp, subId, "getManualNetworkSelectionPlmn");
5917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005921 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005922 }
5923
5924 final Phone phone = getPhone(subId);
5925 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005926 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005927 }
5928 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5929 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5930 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
5934 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005935
5936 /**
5937 * Scans for available networks.
5938 */
5939 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005940 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5941 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5943 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005944 LocationAccessPolicy.LocationPermissionResult locationResult =
5945 LocationAccessPolicy.checkLocationPermission(mApp,
5946 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5947 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005948 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005949 .setCallingPid(Binder.getCallingPid())
5950 .setCallingUid(Binder.getCallingUid())
5951 .setMethod("getCellNetworkScanResults")
5952 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005953 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5954 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005955 .build());
5956 switch (locationResult) {
5957 case DENIED_HARD:
5958 throw new SecurityException("Not allowed to access scan results -- location");
5959 case DENIED_SOFT:
5960 return null;
5961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962
Pengquan Menga1bb6272018-09-06 09:59:22 -07005963 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 try {
5965 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005966 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 } finally {
5969 Binder.restoreCallingIdentity(identity);
5970 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005971 }
5972
5973 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005974 * Get the call forwarding info, given the call forwarding reason.
5975 */
5976 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005977 public void getCallForwarding(int subId, int callForwardingReason,
5978 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005979 enforceReadPrivilegedPermission("getCallForwarding");
5980 long identity = Binder.clearCallingIdentity();
5981 try {
5982 if (DBG) {
5983 log("getCallForwarding: subId " + subId
5984 + " callForwardingReason" + callForwardingReason);
5985 }
Hall Liu27d24262020-09-18 19:04:59 -07005986
5987 Phone phone = getPhone(subId);
5988 if (phone == null) {
5989 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005990 callback.onError(
5991 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005992 } catch (RemoteException e) {
5993 // ignore
5994 }
5995 return;
5996 }
5997
5998 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5999 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
6000 @Override
6001 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
6002 try {
6003 callback.onCallForwardingInfoAvailable(info);
6004 } catch (RemoteException e) {
6005 // ignore
6006 }
6007 }
6008
6009 @Override
6010 public void onError(int error) {
6011 try {
6012 callback.onError(error);
6013 } catch (RemoteException e) {
6014 // ignore
6015 }
6016 }
6017 });
6018 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
6022 }
6023
6024 /**
6025 * Sets the voice call forwarding info including status (enable/disable), call forwarding
6026 * reason, the number to forward, and the timeout before the forwarding is attempted.
6027 */
6028 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006029 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
6030 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006031 enforceModifyPermission();
6032 long identity = Binder.clearCallingIdentity();
6033 try {
6034 if (DBG) {
6035 log("setCallForwarding: subId " + subId
6036 + " callForwardingInfo" + callForwardingInfo);
6037 }
Hall Liu27d24262020-09-18 19:04:59 -07006038
6039 Phone phone = getPhone(subId);
6040 if (phone == null) {
6041 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006042 callback.accept(
6043 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006044 } catch (RemoteException e) {
6045 // ignore
6046 }
6047 return;
6048 }
6049
6050 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6051 FunctionalUtils.ignoreRemoteException(callback::accept));
6052
6053 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
6057 }
6058
6059 /**
Hall Liu27d24262020-09-18 19:04:59 -07006060 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006061 */
6062 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006063 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
SongFerngWang0e767992021-03-31 22:08:45 +08006064 enforceReadPrivilegedPermission("getCallWaitingStatus");
Shuo Qian4a594052020-01-23 11:59:30 -08006065 long identity = Binder.clearCallingIdentity();
6066 try {
Hall Liu27d24262020-09-18 19:04:59 -07006067 Phone phone = getPhone(subId);
6068 if (phone == null) {
6069 try {
6070 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6071 } catch (RemoteException e) {
6072 // ignore
6073 }
6074 return;
6075 }
SongFerngWang0e767992021-03-31 22:08:45 +08006076 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6077 PersistableBundle c = configManager.getConfigForSubId(subId);
6078 boolean requireUssd = c.getBoolean(
6079 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006080
Shuo Qian4a594052020-01-23 11:59:30 -08006081 if (DBG) log("getCallWaitingStatus: subId " + subId);
SongFerngWang0e767992021-03-31 22:08:45 +08006082 if (requireUssd) {
6083 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6084 getSubscriptionCarrierId(subId));
6085 String newUssdCommand = "";
6086 try {
6087 newUssdCommand = carrierXmlParser.getFeature(
6088 CarrierXmlParser.FEATURE_CALL_WAITING)
6089 .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null);
6090 } catch (NullPointerException e) {
6091 loge("Failed to generate USSD number" + e);
6092 }
6093 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6094 mMainThreadHandler, callback, carrierXmlParser,
6095 CarrierXmlParser.SsEntry.SSAction.QUERY);
6096 final String ussdCommand = newUssdCommand;
6097 Executors.newSingleThreadExecutor().execute(() -> {
6098 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6099 });
6100 } else {
6101 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(
6102 callback::accept);
6103 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
6104 }
Shuo Qian4a594052020-01-23 11:59:30 -08006105 } finally {
6106 Binder.restoreCallingIdentity(identity);
6107 }
6108 }
6109
6110 /**
Hall Liu27d24262020-09-18 19:04:59 -07006111 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006112 */
6113 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006114 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006115 enforceModifyPermission();
6116 long identity = Binder.clearCallingIdentity();
6117 try {
Hall Liu27d24262020-09-18 19:04:59 -07006118 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6119
6120 Phone phone = getPhone(subId);
6121 if (phone == null) {
6122 try {
6123 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6124 } catch (RemoteException e) {
6125 // ignore
6126 }
6127 return;
6128 }
6129
SongFerngWang0e767992021-03-31 22:08:45 +08006130 CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext());
6131 PersistableBundle c = configManager.getConfigForSubId(subId);
6132 boolean requireUssd = c.getBoolean(
6133 CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false);
Hall Liu27d24262020-09-18 19:04:59 -07006134
SongFerngWang0e767992021-03-31 22:08:45 +08006135 if (DBG) log("getCallWaitingStatus: subId " + subId);
6136 if (requireUssd) {
6137 CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(),
6138 getSubscriptionCarrierId(subId));
6139 CarrierXmlParser.SsEntry.SSAction ssAction =
6140 enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE
6141 : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE;
6142 String newUssdCommand = "";
6143 try {
6144 newUssdCommand = carrierXmlParser.getFeature(
6145 CarrierXmlParser.FEATURE_CALL_WAITING)
6146 .makeCommand(ssAction, null);
6147 } catch (NullPointerException e) {
6148 loge("Failed to generate USSD number" + e);
6149 }
6150 ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver(
6151 mMainThreadHandler, callback, carrierXmlParser, ssAction);
6152 final String ussdCommand = newUssdCommand;
6153 Executors.newSingleThreadExecutor().execute(() -> {
6154 handleUssdRequest(subId, ussdCommand, wrappedCallback);
6155 });
6156 } else {
6157 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6158 FunctionalUtils.ignoreRemoteException(callback::accept));
6159
6160 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
6161 }
Shuo Qian4a594052020-01-23 11:59:30 -08006162 } finally {
6163 Binder.restoreCallingIdentity(identity);
6164 }
6165 }
6166
6167 /**
yinxub1bed742017-04-17 11:45:04 -07006168 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006169 *
yinxub1bed742017-04-17 11:45:04 -07006170 * @param subId id of the subscription
6171 * @param request contains the radio access networks with bands/channels to scan
6172 * @param messenger callback messenger for scan results or errors
6173 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006174 * @return the id of the requested scan which can be used to stop the scan.
6175 */
6176 @Override
6177 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006178 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6180 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006181 LocationAccessPolicy.LocationPermissionResult locationResult =
6182 LocationAccessPolicy.checkLocationPermission(mApp,
6183 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6184 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006185 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006186 .setCallingPid(Binder.getCallingPid())
6187 .setCallingUid(Binder.getCallingUid())
6188 .setMethod("requestNetworkScan")
6189 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006190 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6191 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006192 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006193 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006194 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6195 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006196 if (e != null) {
6197 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6198 throw e;
6199 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006200 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006201 return TelephonyScanManager.INVALID_SCAN_ID;
6202 }
6203 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 }
Hall Liu912dfd32019-04-25 14:02:26 -07006205 int callingUid = Binder.getCallingUid();
6206 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006207 final long identity = Binder.clearCallingIdentity();
6208 try {
6209 return mNetworkScanRequestTracker.startNetworkScan(
6210 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006211 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006212 } finally {
6213 Binder.restoreCallingIdentity(identity);
6214 }
yinxu504e1392017-04-12 16:03:22 -07006215 }
6216
Hall Liub2ac8ef2019-02-28 15:56:23 -08006217 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006218 NetworkScanRequest request, int subId, String callingPackage) {
6219 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006220 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6221 boolean hasNetworkScanPermission =
6222 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6223 == PERMISSION_GRANTED;
6224
6225 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6226 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6227 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006228 }
6229
6230 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6231 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006232 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6233 return new SecurityException("Specific channels must not be"
6234 + " scanned without location access.");
6235 }
6236 }
6237 }
6238
Hall Liub2ac8ef2019-02-28 15:56:23 -08006239 return null;
6240 }
6241
yinxu504e1392017-04-12 16:03:22 -07006242 /**
6243 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006244 *
6245 * @param subId id of the subscription
6246 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006247 */
6248 @Override
6249 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6251 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252
Hall Liu912dfd32019-04-25 14:02:26 -07006253 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 final long identity = Binder.clearCallingIdentity();
6255 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006256 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 } finally {
6258 Binder.restoreCallingIdentity(identity);
6259 }
yinxu504e1392017-04-12 16:03:22 -07006260 }
6261
6262 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006263 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006264 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006265 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006266 */
6267 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006268 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006269 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006270 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006271 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272
6273 final long identity = Binder.clearCallingIdentity();
6274 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006275 if (DBG) log("getAllowedNetworkTypesBitmask");
6276 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6277 int networkTypesBitmask = (result != null ? result[0] : -1);
6278 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6279 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 } finally {
6281 Binder.restoreCallingIdentity(identity);
6282 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006283 }
6284
6285 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006286 * Get the allowed network types for certain reason.
6287 *
6288 * @param subId the id of the subscription.
6289 * @param reason the reason the allowed network type change is taking place
6290 * @return the allowed network types.
6291 */
6292 @Override
6293 public long getAllowedNetworkTypesForReason(int subId,
6294 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006295 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006296 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006297 final long identity = Binder.clearCallingIdentity();
6298 try {
6299 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6300 } finally {
6301 Binder.restoreCallingIdentity(identity);
6302 }
6303 }
6304
6305 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006306 * Enable/Disable E-UTRA-NR Dual Connectivity
6307 * @param subId subscription id of the sim card
6308 * @param nrDualConnectivityState expected NR dual connectivity state
6309 * This can be passed following states
6310 * <ol>
6311 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6312 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6313 * <li>Disable NR dual connectivity and force secondary cell to be released
6314 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6315 * </ol>
6316 * @return operation result.
6317 */
6318 @Override
6319 public int setNrDualConnectivityState(int subId,
6320 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6322 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006323 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006324 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6325 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6326 }
6327
Sooraj Sasindran37444802020-08-11 10:40:43 -07006328 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
6331 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6332 nrDualConnectivityState, subId,
6333 workSource);
6334 if (DBG) log("enableNRDualConnectivity result: " + result);
6335 return result;
6336 } finally {
6337 Binder.restoreCallingIdentity(identity);
6338 }
6339 }
6340
6341 /**
6342 * Is E-UTRA-NR Dual Connectivity enabled
6343 * @return true if dual connectivity is enabled else false
6344 */
6345 @Override
6346 public boolean isNrDualConnectivityEnabled(int subId) {
6347 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006348 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006349 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006350 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006351 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6352 return false;
6353 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006354 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6358 null, subId, workSource);
6359 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6360 return isEnabled;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
6364 }
6365
6366 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006367 * Set the allowed network types of the device and
6368 * provide the reason triggering the allowed network change.
6369 *
6370 * @param subId the id of the subscription.
6371 * @param reason the reason the allowed network type change is taking place
6372 * @param allowedNetworkTypes the allowed network types.
6373 * @return true on success; false on any failure.
6374 */
6375 @Override
6376 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006377 @TelephonyManager.AllowedNetworkTypesReason int reason,
6378 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6380 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006381 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
SongFerngWang7ffc2732021-04-15 19:46:33 +08006382 loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason);
6383 return false;
6384 }
6385 if (!SubscriptionManager.isUsableSubscriptionId(subId)) {
6386 loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId);
SongFerngWang3ef3e072020-12-21 16:41:52 +08006387 return false;
6388 }
6389
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006390 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6391 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6392
6393
6394 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6395 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6396 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006397 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006398
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006399 final long identity = Binder.clearCallingIdentity();
6400 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006401 Boolean success = (Boolean) sendRequest(
6402 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6403 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6404
6405 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6406 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006407 } finally {
6408 Binder.restoreCallingIdentity(identity);
6409 }
6410 }
6411
6412 /**
Miaoa84611c2019-03-15 09:21:10 +08006413 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006414 *
Miaoa84611c2019-03-15 09:21:10 +08006415 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006416 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006417 * @hide
6418 */
6419 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006420 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006421 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006422 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006423 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 try {
Miaoa84611c2019-03-15 09:21:10 +08006425 if (phone != null) {
6426 return phone.hasMatchedTetherApnSetting();
6427 } else {
6428 return false;
6429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006430 } finally {
6431 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006432 }
Junda Liu475951f2014-11-07 16:45:03 -08006433 }
6434
6435 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006436 * Enable or disable always reporting signal strength changes from radio.
6437 *
6438 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6439 */
6440 @Override
6441 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6442 enforceModifyPermission();
6443 enforceSystemCaller();
6444
6445 final long identity = Binder.clearCallingIdentity();
6446 final Phone phone = getPhone(subId);
6447 try {
6448 if (phone != null) {
6449 if (DBG) {
6450 log("setAlwaysReportSignalStrength: subId=" + subId
6451 + " isEnable=" + isEnable);
6452 }
6453 phone.setAlwaysReportSignalStrength(isEnable);
6454 } else {
6455 loge("setAlwaysReportSignalStrength: no phone found for subId="
6456 + subId);
6457 }
6458 } finally {
6459 Binder.restoreCallingIdentity(identity);
6460 }
6461 }
6462
6463 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006464 * Get the user enabled state of Mobile Data.
6465 *
6466 * TODO: remove and use isUserDataEnabled.
6467 * This can't be removed now because some vendor codes
6468 * calls through ITelephony directly while they should
6469 * use TelephonyManager.
6470 *
6471 * @return true on enabled
6472 */
6473 @Override
6474 public boolean getDataEnabled(int subId) {
6475 return isUserDataEnabled(subId);
6476 }
6477
6478 /**
6479 * Get whether mobile data is enabled per user setting.
6480 *
6481 * There are other factors deciding whether mobile data is actually enabled, but they are
6482 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006483 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006484 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006485 *
6486 * @return {@code true} if data is enabled else {@code false}
6487 */
6488 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006489 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006490 try {
6491 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6492 null);
6493 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6495 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497
6498 final long identity = Binder.clearCallingIdentity();
6499 try {
6500 int phoneId = mSubscriptionController.getPhoneId(subId);
6501 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6502 Phone phone = PhoneFactory.getPhone(phoneId);
6503 if (phone != null) {
6504 boolean retVal = phone.isUserDataEnabled();
6505 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6506 return retVal;
6507 } else {
6508 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6509 return false;
6510 }
6511 } finally {
6512 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006513 }
6514 }
6515
6516 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006517 * Checks if the device is capable of mobile data by considering whether whether the
6518 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6519 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006520 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006521 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006522 */
6523 @Override
6524 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006525 try {
6526 try {
6527 mApp.enforceCallingOrSelfPermission(
6528 android.Manifest.permission.ACCESS_NETWORK_STATE,
6529 null);
6530 } catch (Exception e) {
6531 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6532 "isDataEnabled");
6533 }
6534 } catch (Exception e) {
6535 enforceReadPrivilegedPermission("isDataEnabled");
6536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006537
6538 final long identity = Binder.clearCallingIdentity();
6539 try {
6540 int phoneId = mSubscriptionController.getPhoneId(subId);
6541 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6542 Phone phone = PhoneFactory.getPhone(phoneId);
6543 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006544 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6546 return retVal;
6547 } else {
6548 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6549 return false;
6550 }
6551 } finally {
6552 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006553 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006554 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006555
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006556 /**
6557 * Check if data is enabled for a specific reason
6558 * @param subId Subscription index
6559 * @param reason the reason the data enable change is taking place
6560 * @return {@code true} if the overall data is enabled; {@code false} if not.
6561 */
6562 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006563 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006564 @TelephonyManager.DataEnabledReason int reason) {
6565 try {
6566 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6567 null);
6568 } catch (Exception e) {
6569 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006570 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006571 }
6572
6573
6574 final long identity = Binder.clearCallingIdentity();
6575 try {
6576 int phoneId = mSubscriptionController.getPhoneId(subId);
6577 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006578 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006579 + " reason=" + reason);
6580 }
6581 Phone phone = PhoneFactory.getPhone(phoneId);
6582 if (phone != null) {
6583 boolean retVal;
6584 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6585 retVal = phone.isUserDataEnabled();
6586 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006587 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006588 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006589 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006590 return retVal;
6591 } else {
6592 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006593 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006594 + subId + " retVal=false");
6595 }
6596 return false;
6597 }
6598 } finally {
6599 Binder.restoreCallingIdentity(identity);
6600 }
6601 }
6602
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006603 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006604 Phone phone) {
Sarah Chin3394efe2021-04-09 10:37:15 -07006605 if (uid == Process.PHONE_UID) {
6606 // Skip the check if it's the phone UID (system UID removed in b/184713596)
6607 // TODO (b/184954344): Check for system/phone UID at call site instead of here
Hall Liu54a2a0c2020-07-13 12:13:03 -07006608 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6609 }
6610
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006611 //load access rules from carrier configs, and check those as well: b/139133814
6612 SubscriptionController subController = SubscriptionController.getInstance();
6613 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6614 || subController == null) return privilegeFromSim;
6615
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006616 PackageManager pkgMgr = phone.getContext().getPackageManager();
6617 String[] packages = pkgMgr.getPackagesForUid(uid);
6618
6619 final long identity = Binder.clearCallingIdentity();
6620 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006621 int subId = phone.getSubId();
6622 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6623 // A test override is in place for the privileges for this subId, so don't try to
6624 // read the subscription privileges.
6625 return privilegeFromSim;
6626 }
6627 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006628 SubscriptionManager subManager = (SubscriptionManager)
6629 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6630 for (String pkg : packages) {
6631 if (subManager.canManageSubscription(subInfo, pkg)) {
6632 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6633 }
6634 }
6635 return privilegeFromSim;
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
6638 }
6639 }
6640
6641 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6642 String pkgName) {
6643 //load access rules from carrier configs, and check those as well: b/139133814
6644 SubscriptionController subController = SubscriptionController.getInstance();
6645 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6646 || subController == null) return privilegeFromSim;
6647
6648 final long identity = Binder.clearCallingIdentity();
6649 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006650 int subId = phone.getSubId();
6651 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6652 // A test override is in place for the privileges for this subId, so don't try to
6653 // read the subscription privileges.
6654 return privilegeFromSim;
6655 }
6656 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006657 SubscriptionManager subManager = (SubscriptionManager)
6658 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6659 return subManager.canManageSubscription(subInfo, pkgName)
6660 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6661 } finally {
6662 Binder.restoreCallingIdentity(identity);
6663 }
6664 }
6665
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006666 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006667 public int getCarrierPrivilegeStatus(int subId) {
6668 final Phone phone = getPhone(subId);
6669 if (phone == null) {
6670 loge("getCarrierPrivilegeStatus: Invalid subId");
6671 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6672 }
6673 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006674 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006675 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006676 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6677 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006678
6679 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6680 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006681 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006682 }
Junda Liu29340342014-07-10 15:23:27 -07006683
6684 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006685 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006686 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006687 final Phone phone = getPhone(subId);
6688 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006689 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006690 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6691 }
6692 UiccProfile profile =
6693 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6694 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006695 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006696 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6697 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006698 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006699 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006700 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006701 }
6702
6703 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006704 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006705 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage");
chen xuf7e9fe82019-05-09 19:31:02 -07006706 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006707 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006708 }
6709
6710 int phoneId = SubscriptionManager.getPhoneId(subId);
6711 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006712 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006713 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006714 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6715 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006716 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6717 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6718 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006719 }
6720
6721 @Override
6722 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Nazanin1adf4562021-03-29 15:35:30 -07006723 enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone");
Junda Liu317d70b2016-03-08 09:33:53 -08006724 if (TextUtils.isEmpty(pkgName))
6725 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006726 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6727 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6728 UiccCard card = UiccController.getInstance().getUiccCard(i);
6729 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006730 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006731 continue;
6732 }
6733
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006734 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6735 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6736 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006737 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6738 break;
6739 }
6740 }
6741
6742 return result;
Junda Liu29340342014-07-10 15:23:27 -07006743 }
Derek Tan89e89d42014-07-08 17:00:10 -07006744
6745 @Override
Junda Liue64de782015-04-16 17:19:16 -07006746 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006747 enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone");
Junda Liue64de782015-04-16 17:19:16 -07006748 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6749 loge("phoneId " + phoneId + " is not valid.");
6750 return null;
6751 }
6752 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006753 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006754 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006755 return null ;
6756 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006757 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006758 }
6759
Amith Yamasani6e118872016-02-19 12:53:51 -08006760 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006761 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin1adf4562021-03-29 15:35:30 -07006762 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges");
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006763 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006764 List<String> privilegedPackages = new ArrayList<>();
6765 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006766 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6767 // has UICC in that slot.
6768 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006769 if (card.hasCarrierPrivilegeRules()) {
6770 if (packages == null) {
6771 // Only check packages in user 0 for now
6772 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006773 PackageManager.MATCH_DISABLED_COMPONENTS
6774 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006775 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006776 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006777 }
6778 for (int p = packages.size() - 1; p >= 0; p--) {
6779 PackageInfo pkgInfo = packages.get(p);
6780 if (pkgInfo != null && pkgInfo.packageName != null
6781 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006782 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006783 privilegedPackages.add(pkgInfo.packageName);
6784 }
6785 }
6786 }
6787 }
6788 return privilegedPackages;
6789 }
6790
chen xuf7e9fe82019-05-09 19:31:02 -07006791 @Override
6792 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006793 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6794
6795 final long identity = Binder.clearCallingIdentity();
6796
chen xuf7e9fe82019-05-09 19:31:02 -07006797 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006798 try {
6799 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6800 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6801 }
6802 } finally {
6803 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006804 }
6805 return privilegedPackages;
6806 }
6807
Wink Savilleb564aae2014-10-23 10:18:09 -07006808 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006809 final Phone phone = getPhone(subId);
6810 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006811 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006812 return null;
6813 }
6814 String iccId = card.getIccId();
6815 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006816 return null;
6817 }
6818 return iccId;
6819 }
6820
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006821 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006822 public void setCallComposerStatus(int subId, int status) {
6823 enforceModifyPermission();
6824
6825 final long identity = Binder.clearCallingIdentity();
6826 try {
6827 Phone phone = getPhone(subId);
6828 if (phone != null) {
6829 Phone defaultPhone = phone.getImsPhone();
6830 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6831 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6832 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006833 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6834 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006835 }
6836 }
Shuo Qian284ae752020-12-22 19:10:14 -08006837 } catch (ImsException e) {
6838 throw new ServiceSpecificException(e.getCode());
6839 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006840 Binder.restoreCallingIdentity(identity);
6841 }
6842 }
6843
6844 @Override
6845 public int getCallComposerStatus(int subId) {
6846 enforceReadPrivilegedPermission("getCallComposerStatus");
6847
6848 final long identity = Binder.clearCallingIdentity();
6849 try {
6850 Phone phone = getPhone(subId);
6851 if (phone != null) {
6852 Phone defaultPhone = phone.getImsPhone();
6853 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6854 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6855 return imsPhone.getCallComposerStatus();
6856 }
6857 }
6858 } finally {
6859 Binder.restoreCallingIdentity(identity);
6860 }
6861 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6862 }
6863
6864 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006865 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6866 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006867 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006868 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870 final long identity = Binder.clearCallingIdentity();
6871 try {
6872 final String iccId = getIccId(subId);
6873 final Phone phone = getPhone(subId);
6874 if (phone == null) {
6875 return false;
6876 }
6877 final String subscriberId = phone.getSubscriberId();
6878
6879 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006880 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 + subscriberId + " to " + number);
6882 }
6883
6884 if (TextUtils.isEmpty(iccId)) {
6885 return false;
6886 }
6887
6888 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6889
6890 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6891 if (alphaTag == null) {
6892 editor.remove(alphaTagPrefKey);
6893 } else {
6894 editor.putString(alphaTagPrefKey, alphaTag);
6895 }
6896
6897 // Record both the line number and IMSI for this ICCID, since we need to
6898 // track all merged IMSIs based on line number
6899 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6900 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6901 if (number == null) {
6902 editor.remove(numberPrefKey);
6903 editor.remove(subscriberPrefKey);
6904 } else {
6905 editor.putString(numberPrefKey, number);
6906 editor.putString(subscriberPrefKey, subscriberId);
6907 }
6908
6909 editor.commit();
6910 return true;
6911 } finally {
6912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006913 }
Derek Tan7226c842014-07-02 17:42:23 -07006914 }
6915
6916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006917 public String getLine1NumberForDisplay(int subId, String callingPackage,
6918 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006919 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006921 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006922 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006923 return null;
6924 }
Derek Tan97ebb422014-09-05 16:55:38 -07006925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 String iccId = getIccId(subId);
6929 if (iccId != null) {
6930 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6931 if (DBG_MERGE) {
6932 log("getLine1NumberForDisplay returning "
6933 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6934 }
6935 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006936 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6938 return null;
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006941 }
Derek Tan7226c842014-07-02 17:42:23 -07006942 }
6943
6944 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006945 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6946 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006948 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006949 return null;
6950 }
Derek Tan97ebb422014-09-05 16:55:38 -07006951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 final long identity = Binder.clearCallingIdentity();
6953 try {
6954 String iccId = getIccId(subId);
6955 if (iccId != null) {
6956 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6957 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6958 }
6959 return null;
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006962 }
Derek Tan7226c842014-07-02 17:42:23 -07006963 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006964
6965 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006966 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6967 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006968 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6969 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006970 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006971 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006972 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006973 return null;
6974 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006975
Jordan Liub49b04b2019-05-06 14:45:15 -07006976 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6977 // the process, where TelephonyManager was instantiated.
6978 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006979 final long identity = Binder.clearCallingIdentity();
6980 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006981 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 final TelephonyManager tele = TelephonyManager.from(context);
6983 final SubscriptionManager sub = SubscriptionManager.from(context);
6984
6985 // Figure out what subscribers are currently active
6986 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987
Jordan Liub49b04b2019-05-06 14:45:15 -07006988 // Only consider subs which match the current subId
6989 // This logic can be simplified. See b/131189269 for progress.
6990 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006991 activeSubscriberIds.add(tele.getSubscriberId(subId));
6992 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993
6994 // First pass, find a number override for an active subscriber
6995 String mergeNumber = null;
6996 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6997 for (String key : prefs.keySet()) {
6998 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6999 final String subscriberId = (String) prefs.get(key);
7000 if (activeSubscriberIds.contains(subscriberId)) {
7001 final String iccId = key.substring(
7002 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
7003 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
7004 mergeNumber = (String) prefs.get(numberKey);
7005 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007006 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007 + " for active subscriber " + subscriberId);
7008 }
7009 if (!TextUtils.isEmpty(mergeNumber)) {
7010 break;
7011 }
7012 }
7013 }
7014 }
7015
7016 // Shortcut when no active merged subscribers
7017 if (TextUtils.isEmpty(mergeNumber)) {
7018 return null;
7019 }
7020
7021 // Second pass, find all subscribers under that line override
7022 final ArraySet<String> result = new ArraySet<>();
7023 for (String key : prefs.keySet()) {
7024 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
7025 final String number = (String) prefs.get(key);
7026 if (mergeNumber.equals(number)) {
7027 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
7028 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
7029 final String subscriberId = (String) prefs.get(subscriberKey);
7030 if (!TextUtils.isEmpty(subscriberId)) {
7031 result.add(subscriberId);
7032 }
7033 }
7034 }
7035 }
7036
7037 final String[] resultArray = result.toArray(new String[result.size()]);
7038 Arrays.sort(resultArray);
7039 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08007040 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
7042 }
7043 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07007044 } finally {
7045 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08007046 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08007047 }
7048
7049 @Override
zoey chen38003472019-12-13 17:16:31 +08007050 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
7051 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07007052
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 final TelephonyManager telephonyManager = mApp.getSystemService(
7056 TelephonyManager.class);
7057 String subscriberId = telephonyManager.getSubscriberId(subId);
7058 if (subscriberId == null) {
7059 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08007060 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07007061 + subId);
7062 }
7063 return null;
7064 }
7065
7066 final SubscriptionInfo info = SubscriptionController.getInstance()
7067 .getSubscriptionInfo(subId);
7068 final ParcelUuid groupUuid = info.getGroupUuid();
7069 // If it doesn't belong to any group, return just subscriberId of itself.
7070 if (groupUuid == null) {
7071 return new String[]{subscriberId};
7072 }
7073
7074 // Get all subscriberIds from the group.
7075 final List<String> mergedSubscriberIds = new ArrayList<>();
7076 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007077 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007078 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07007079 for (SubscriptionInfo subInfo : groupInfos) {
7080 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
7081 if (subscriberId != null) {
7082 mergedSubscriberIds.add(subscriberId);
7083 }
7084 }
7085
7086 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
7087 } finally {
7088 Binder.restoreCallingIdentity(identity);
7089
7090 }
7091 }
7092
7093 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007094 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007095 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08007096 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097
7098 final long identity = Binder.clearCallingIdentity();
7099 try {
7100 final Phone phone = getPhone(subId);
7101 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007105 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007106
7107 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007108 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007109 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7110 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007111 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7112 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
7116 final Phone phone = getPhone(subId);
7117 if (phone == null) {
7118 return false;
7119 }
7120 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7121 cdmaNonRoamingList);
7122 } finally {
7123 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007124 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007125 }
7126
7127 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007128 @Deprecated
7129 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7130 enforceModifyPermission();
7131
7132 int returnValue = 0;
7133 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007134 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007135 if(result.exception == null) {
7136 if (result.result != null) {
7137 byte[] responseData = (byte[])(result.result);
7138 if(responseData.length > oemResp.length) {
7139 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7140 responseData.length + "bytes. Buffer Size is " +
7141 oemResp.length + "bytes.");
7142 }
7143 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7144 returnValue = responseData.length;
7145 }
7146 } else {
7147 CommandException ex = (CommandException) result.exception;
7148 returnValue = ex.getCommandError().ordinal();
7149 if(returnValue > 0) returnValue *= -1;
7150 }
7151 } catch (RuntimeException e) {
7152 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7153 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7154 if(returnValue > 0) returnValue *= -1;
7155 }
7156
7157 return returnValue;
7158 }
7159
7160 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007161 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007162 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007163 try {
7164 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007165 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007166 mApp, phone.getSubId(), "getRadioAccessFamily");
7167 } catch (SecurityException e) {
7168 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7169 throw e;
7170 }
chen xub97461a2018-10-26 14:17:57 -07007171 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007172 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007173 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175 final long identity = Binder.clearCallingIdentity();
7176 try {
chen xub97461a2018-10-26 14:17:57 -07007177 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007178 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007179 mApp, phone.getSubId(), "getRadioAccessFamily");
7180 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 } finally {
7182 Binder.restoreCallingIdentity(identity);
7183 }
chen xub97461a2018-10-26 14:17:57 -07007184 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007185 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007186
7187 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007188 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007189 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007190 try {
7191 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7192 Binder.getCallingUid())) {
7193 throw new SecurityException("Package uid and package name do not match: "
7194 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7195 }
7196 } catch (PackageManager.NameNotFoundException e) {
7197 throw new SecurityException("Package name invalid:" + callingPackage);
7198 }
7199 RoleManager rm = mApp.getSystemService(RoleManager.class);
7200 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7201 if (!dialerRoleHolders.contains(callingPackage)) {
7202 throw new SecurityException("App must be the dialer role holder to"
7203 + " upload a call composer pic");
7204 }
7205
7206 Executors.newSingleThreadExecutor().execute(() -> {
7207 ByteArrayOutputStream output = new ByteArrayOutputStream(
7208 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7209 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7210 boolean readUntilEnd = false;
7211 int totalBytesRead = 0;
7212 byte[] buffer = new byte[16 * 1024];
7213 while (true) {
7214 int numRead;
7215 try {
7216 numRead = input.read(buffer);
7217 } catch (IOException e) {
7218 try {
7219 fd.checkError();
7220 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7221 null);
7222 } catch (IOException e1) {
7223 // This means that the other side closed explicitly with an error. If this
7224 // happens, log and ignore.
7225 loge("Remote end of call composer picture pipe closed: " + e1);
7226 }
7227 break;
7228 }
7229 if (numRead == -1) {
7230 readUntilEnd = true;
7231 break;
7232 }
7233 totalBytesRead += numRead;
7234 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7235 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7236 try {
7237 input.close();
7238 } catch (IOException e) {
7239 // ignore
7240 }
7241 break;
7242 }
7243 output.write(buffer, 0, numRead);
7244 }
7245 // Generally, the remote end will close the file descriptors. The only case where we
7246 // close is above, where the picture size is too big.
7247
7248 try {
7249 fd.checkError();
7250 } catch (IOException e) {
7251 loge("Remote end for call composer closed with an error: " + e);
7252 return;
7253 }
7254
Hall Liuaa4211e2021-01-20 15:43:39 -08007255 if (!readUntilEnd) {
7256 loge("Did not finish reading entire image; aborting");
7257 return;
7258 }
Hall Liu82694d52020-12-11 18:22:04 -08007259
Hall Liuaa4211e2021-01-20 15:43:39 -08007260 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7261 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7262 new CallComposerPictureTransfer.Factory() {},
7263 imageData,
7264 (result) -> {
7265 if (result.first != null) {
7266 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7267 Bundle outputResult = new Bundle();
7268 outputResult.putParcelable(
7269 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7270 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7271 outputResult);
7272 } else {
7273 callback.send(result.second, null);
7274 }
7275 }
7276 );
Hall Liu82694d52020-12-11 18:22:04 -08007277 });
7278 }
7279
7280 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007281 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007282 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007283 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007284
7285 final long identity = Binder.clearCallingIdentity();
7286 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007287 ImsManager.getInstance(defaultPhone.getContext(),
7288 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007292 }
7293
7294 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007295 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007296 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7298 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007299 return false;
7300 }
Svet Ganovb320e182015-04-16 12:30:10 -07007301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 final long identity = Binder.clearCallingIdentity();
7303 try {
7304 // Check the user preference and the system-level IMS setting. Even if the user has
7305 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7306 // In the long run, we may instead need to check if there exists a connection service
7307 // which can support video calling.
7308 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007309 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 return imsManager.isVtEnabledByPlatform()
7311 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7312 && imsManager.isVtEnabledByUser();
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
7315 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007316 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007317
Andrew Leea1239f22015-03-02 17:44:07 -08007318 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007319 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7320 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007322 mApp, subId, callingPackage, callingFeatureId,
7323 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 return false;
7325 }
7326
7327 final long identity = Binder.clearCallingIdentity();
7328 try {
7329 CarrierConfigManager configManager =
7330 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007331 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7333 } finally {
7334 Binder.restoreCallingIdentity(identity);
7335 }
Andrew Leea1239f22015-03-02 17:44:07 -08007336 }
7337
7338 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007339 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007341 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007342 return false;
7343 }
7344
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 CarrierConfigManager configManager =
7348 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007349 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
7353 }
Andrew Leea1239f22015-03-02 17:44:07 -08007354 }
7355
Andrew Lee9431b832015-03-09 18:46:45 -07007356 @Override
7357 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007358 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007359 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007360 }
7361
7362 @Override
7363 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364 final long identity = Binder.clearCallingIdentity();
7365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007366 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007367 } finally {
7368 Binder.restoreCallingIdentity(identity);
7369 }
Andrew Lee9431b832015-03-09 18:46:45 -07007370 }
7371
Hall Liuf6668912018-10-31 17:05:23 -07007372 /**
7373 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7374 * support for the feature and device firmware support.
7375 *
7376 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7377 */
7378 @Override
7379 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007380 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007381 final Phone phone = getPhone(subscriptionId);
7382 if (phone == null) {
7383 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7384 return false;
7385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007387 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7389 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007390 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007391 return isCarrierSupported && isDeviceSupported;
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
7394 }
Hall Liu98187582018-01-22 19:15:32 -08007395 }
7396
Hall Liuf6668912018-10-31 17:05:23 -07007397 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007398 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7399 * RTT setting, will return true if the device and carrier both support RTT.
7400 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007401 */
7402 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403 final long identity = Binder.clearCallingIdentity();
7404 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007405 boolean isRttSupported = isRttSupported(subscriptionId);
7406 boolean isUserRttSettingOn = Settings.Secure.getInt(
7407 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7408 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7409 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7410 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007414 }
7415
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007416 @Deprecated
7417 @Override
7418 public String getDeviceId(String callingPackage) {
7419 return getDeviceIdWithFeature(callingPackage, null);
7420 }
7421
Sanket Padawe7310cc72015-01-14 09:53:20 -08007422 /**
7423 * Returns the unique device ID of phone, for example, the IMEI for
7424 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7425 *
7426 * <p>Requires Permission:
7427 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7428 */
7429 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007430 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007431 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007432 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007433 return null;
7434 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007435 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007436 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007437 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007438 return null;
7439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440
7441 final long identity = Binder.clearCallingIdentity();
7442 try {
7443 return phone.getDeviceId();
7444 } finally {
7445 Binder.restoreCallingIdentity(identity);
7446 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007447 }
7448
Ping Sunc67b7c22016-03-02 19:16:45 +08007449 /**
7450 * {@hide}
7451 * Returns the IMS Registration Status on a particular subid
7452 *
7453 * @param subId
7454 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007455 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007456 Phone phone = getPhone(subId);
7457 if (phone != null) {
7458 return phone.isImsRegistered();
7459 } else {
7460 return false;
7461 }
7462 }
7463
Santos Cordon7a1885b2015-02-03 11:15:19 -08007464 @Override
7465 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 final long identity = Binder.clearCallingIdentity();
7467 try {
7468 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007472 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007473
Tyler Gunnf70ed162019-04-03 15:28:53 -07007474 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007475 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007476 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007479 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7480 }
7481 final long identity = Binder.clearCallingIdentity();
7482 try {
7483 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7484 } finally {
7485 Binder.restoreCallingIdentity(identity);
7486 }
7487 }
7488
7489 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007490 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007491 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007492 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007493 mApp,
7494 subscriptionId,
7495 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007496 final long identity = Binder.clearCallingIdentity();
7497 try {
7498 Phone phone = getPhone(subscriptionId);
7499 if (phone == null) {
7500 return null;
7501 }
7502 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
7505 }
7506 }
7507
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007508 /**
7509 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007510 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007511 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 final long identity = Binder.clearCallingIdentity();
7513 try {
7514 Phone phone = getPhone(subId);
7515 if (phone != null) {
7516 return phone.isWifiCallingEnabled();
7517 } else {
7518 return false;
7519 }
7520 } finally {
7521 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007522 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007523 }
7524
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007525 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007526 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007527 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007528 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 Phone phone = getPhone(subId);
7532 if (phone != null) {
7533 return phone.isVideoEnabled();
7534 } else {
7535 return false;
7536 }
7537 } finally {
7538 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007539 }
7540 }
7541
7542 /**
7543 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7544 * defined in {@link ImsRegistrationImplBase}.
7545 */
7546 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 final long identity = Binder.clearCallingIdentity();
7548 try {
7549 Phone phone = getPhone(subId);
7550 if (phone != null) {
7551 return phone.getImsRegistrationTech();
7552 } else {
7553 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7554 }
7555 } finally {
7556 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007557 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007558 }
7559
Stuart Scott8eef64f2015-04-08 15:13:54 -07007560 @Override
7561 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007562 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007563 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7564 return;
7565 }
Kai Shif70f46f2021-03-03 13:59:46 -08007566 Phone defaultPhone = getDefaultPhone();
7567 if (defaultPhone != null) {
7568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7569 mApp, getDefaultPhone().getSubId(), "factoryReset");
7570 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007571 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007572
Svet Ganovcc087f82015-05-12 20:35:54 -07007573 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007574 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7575 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007576 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007577 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007578 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007579 Phone phone = getPhone(subId);
7580 if (phone != null) {
7581 SubscriptionManager.setSubscriptionProperty(subId,
7582 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7583 "user=" + RadioAccessFamily.getRafFromNetworkType(
7584 RILConstants.PREFERRED_NETWORK_MODE));
7585 phone.loadAllowedNetworksFromSubscriptionDatabase();
7586 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007587 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007588 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007589 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007590 // There has been issues when Sms raw table somehow stores orphan
7591 // fragments. They lead to garbled message when new fragments come
7592 // in and combined with those stale ones. In case this happens again,
7593 // user can reset all network settings which will clean up this table.
7594 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007595 // Clean up IMS settings as well here.
7596 int slotId = getSlotIndex(subId);
7597 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7598 ImsManager.getInstance(mApp, slotId).factoryReset();
7599 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007600
Kai Shif70f46f2021-03-03 13:59:46 -08007601 if (defaultPhone == null) {
7602 return;
7603 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007604 // Erase modem config if erase modem on network setting is enabled.
7605 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7606 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7607 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007608 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007609 }
Kai Shif70f46f2021-03-03 13:59:46 -08007610
7611 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007612 } finally {
7613 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007614 }
7615 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007616
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007617 private void cleanUpSmsRawTable(Context context) {
7618 ContentResolver resolver = context.getContentResolver();
7619 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7620 resolver.delete(uri, null, null);
7621 }
7622
Narayan Kamath1c496c22015-04-16 14:40:19 +01007623 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007624 public String getSimLocaleForSubscriber(int subId) {
7625 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7626 final Phone phone = getPhone(subId);
7627 if (phone == null) {
7628 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007629 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007630 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007631 final long identity = Binder.clearCallingIdentity();
7632 try {
chen xu5d3637b2019-01-21 23:31:38 -08007633 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007634 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007635 if (info == null) {
7636 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7637 return null;
7638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639 // Try and fetch the locale from the carrier properties or from the SIM language
7640 // preferences (EF-PL and EF-LI)...
7641 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007642 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007643 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7644 if (localeFromDefaultSim != null) {
7645 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7646 if (DBG) log("Using locale from subId: " + subId + " locale: "
7647 + localeFromDefaultSim);
7648 return localeFromDefaultSim.toLanguageTag();
7649 } else {
7650 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 }
7652 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 // The SIM language preferences only store a language (e.g. fr = French), not an
7655 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7656 // the SIM and carrier preferences does not include a country we add the country
7657 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007658 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007660 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007661 return mccLocale.toLanguageTag();
7662 }
7663
7664 if (DBG) log("No locale found - returning null");
7665 return null;
7666 } finally {
7667 Binder.restoreCallingIdentity(identity);
7668 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007669 }
7670
7671 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007672 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007673 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007674 }
7675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 /**
7677 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7678 */
7679 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007680 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007681 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007682 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007683
Chenjie Yu1ba97252018-01-11 18:16:20 -08007684 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007685 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007686
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007687 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007688 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7689 * representing the state of the modem.
7690 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007691 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7692 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007693 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007694 */
7695 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007696 public void requestModemActivityInfo(ResultReceiver result) {
7697 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007698 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007699
7700 final long identity = Binder.clearCallingIdentity();
7701 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007702 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007705 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007706 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007707
Siddharth Rayb8114062018-06-17 15:02:38 -07007708 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7709 // less than total activity duration.
7710 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7711 if (info == null) {
7712 return false;
7713 }
7714 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007715 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7716 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7717
Siddharth Rayb8114062018-06-17 15:02:38 -07007718 return (info.isValid()
7719 && (info.getSleepTimeMillis() <= activityDurationMs)
7720 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007721 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007722 && (totalTxTimeMs <= activityDurationMs));
7723 }
7724
Jack Yu85bd38a2015-11-09 11:34:32 -08007725 /**
7726 * {@hide}
7727 * Returns the service state information on specified subscription.
7728 */
7729 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007730 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7731 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007732 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007733 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007734 return null;
7735 }
7736
Hall Liuf19c44f2018-11-27 14:38:17 -08007737 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7738 LocationAccessPolicy.checkLocationPermission(mApp,
7739 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7740 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007741 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007742 .setCallingPid(Binder.getCallingPid())
7743 .setCallingUid(Binder.getCallingUid())
7744 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007745 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007746 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007747 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7748 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007749 .build());
7750
7751 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7752 LocationAccessPolicy.checkLocationPermission(mApp,
7753 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7754 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007755 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007756 .setCallingPid(Binder.getCallingPid())
7757 .setCallingUid(Binder.getCallingUid())
7758 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007759 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007760 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007761 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7762 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007763 .build());
7764 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7765 boolean hasFinePermission =
7766 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7767 boolean hasCoarsePermission =
7768 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7769
Jack Yu479f40e2020-10-27 21:29:25 -07007770 final Phone phone = getPhone(subId);
7771 if (phone == null) {
7772 return null;
7773 }
7774
Jordan Liu0f2bc442020-11-18 16:47:37 -08007775 final long identity = Binder.clearCallingIdentity();
7776
Jack Yu479f40e2020-10-27 21:29:25 -07007777 boolean isCallingPackageDataService = phone.getDataServicePackages()
7778 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007780 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7781 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7782 Rlog.d(LOG_TAG,
7783 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7784 return null;
7785 }
7786
Hall Liuf19c44f2018-11-27 14:38:17 -08007787 ServiceState ss = phone.getServiceState();
7788
7789 // Scrub out the location info in ServiceState depending on what level of access
7790 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007791 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007792 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7793 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 } finally {
7795 Binder.restoreCallingIdentity(identity);
7796 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007797 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007798
7799 /**
7800 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7801 *
7802 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7803 * voicemail ringtone.
7804 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7805 * PhoneAccount.
7806 */
7807 @Override
7808 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 final long identity = Binder.clearCallingIdentity();
7810 try {
7811 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7812 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007813 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007816 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7817 } finally {
7818 Binder.restoreCallingIdentity(identity);
7819 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007820 }
7821
7822 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007823 * Sets the per-account voicemail ringtone.
7824 *
7825 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7826 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7827 *
7828 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7829 * voicemail ringtone.
7830 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7831 * PhoneAccount.
7832 */
7833 @Override
7834 public void setVoicemailRingtoneUri(String callingPackage,
7835 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007836 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007837 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007838 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7839 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7841 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7842 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007843 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844
7845 final long identity = Binder.clearCallingIdentity();
7846 try {
7847 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7848 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007849 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007850 }
7851 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007854 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007855 }
7856
7857 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007858 * Returns whether vibration is set for voicemail notification in Phone settings.
7859 *
7860 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7861 * voicemail vibration setting.
7862 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7863 */
7864 @Override
7865 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7869 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007870 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007871 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007872
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007873 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7874 } finally {
7875 Binder.restoreCallingIdentity(identity);
7876 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007877 }
7878
Youhan Wange64578a2016-05-02 15:32:42 -07007879 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007880 * Sets the per-account voicemail vibration.
7881 *
7882 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7883 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7884 *
7885 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7886 * voicemail vibration setting.
7887 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7888 * specific PhoneAccount.
7889 */
7890 @Override
7891 public void setVoicemailVibrationEnabled(String callingPackage,
7892 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007893 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007894 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007895 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7896 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7898 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7899 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007900 }
7901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007902 final long identity = Binder.clearCallingIdentity();
7903 try {
7904 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7905 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007906 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007907 }
7908 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007911 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007912 }
7913
7914 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007915 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7916 *
7917 * @throws SecurityException if the caller does not have the required permission
7918 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007919 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007920 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007921 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007922 }
7923
7924 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007925 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7926 * permission.
7927 *
7928 * @throws SecurityException if the caller does not have the required permission
7929 */
7930 private void enforceSendSmsPermission() {
7931 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7932 }
7933
7934 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007935 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007936 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007937 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007938 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007939 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007943 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007944 if (componentName == null) {
7945 throw new SecurityException(
7946 "Caller not current active visual voicemail package[null]");
7947 }
7948 String vvmPackage = componentName.getPackageName();
7949 if (!callingPackage.equals(vvmPackage)) {
7950 throw new SecurityException("Caller not current active visual voicemail package["
7951 + vvmPackage + "]");
7952 }
7953 } finally {
7954 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007955 }
7956 }
7957
7958 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007959 * Return the application ID for the app type.
7960 *
7961 * @param subId the subscription ID that this request applies to.
7962 * @param appType the uicc app type.
7963 * @return Application ID for specificied app type, or null if no uicc.
7964 */
7965 @Override
7966 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007967 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007968 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969
7970 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007971 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007972 if (phone == null) {
7973 return null;
7974 }
7975 String aid = null;
7976 try {
7977 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7978 .getApplicationByType(appType).getAid();
7979 } catch (Exception e) {
7980 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7981 }
7982 return aid;
7983 } finally {
7984 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007985 }
Youhan Wange64578a2016-05-02 15:32:42 -07007986 }
7987
Youhan Wang4001d252016-05-11 10:29:41 -07007988 /**
7989 * Return the Electronic Serial Number.
7990 *
7991 * @param subId the subscription ID that this request applies to.
7992 * @return ESN or null if error.
7993 */
7994 @Override
7995 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007996 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007997 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998
7999 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07008000 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008001 if (phone == null) {
8002 return null;
8003 }
8004 String esn = null;
8005 try {
8006 esn = phone.getEsn();
8007 } catch (Exception e) {
8008 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
8009 }
8010 return esn;
8011 } finally {
8012 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07008013 }
Youhan Wang4001d252016-05-11 10:29:41 -07008014 }
8015
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008016 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07008017 * Return the Preferred Roaming List Version.
8018 *
8019 * @param subId the subscription ID that this request applies to.
8020 * @return PRLVersion or null if error.
8021 */
8022 @Override
8023 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008024 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07008025 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026
8027 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07008028 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008029 if (phone == null) {
8030 return null;
8031 }
8032 String cdmaPrlVersion = null;
8033 try {
8034 cdmaPrlVersion = phone.getCdmaPrlVersion();
8035 } catch (Exception e) {
8036 Log.e(LOG_TAG, "Not getting PRLVersion", e);
8037 }
8038 return cdmaPrlVersion;
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07008041 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07008042 }
8043
8044 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008045 * Get snapshot of Telephony histograms
8046 * @return List of Telephony histograms
8047 * @hide
8048 */
8049 @Override
8050 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8052 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008053
8054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 return RIL.getTelephonyRILTimingHistograms();
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07008060 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008061
8062 /**
8063 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008064 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
8065 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008066 * Require system privileges. In the future we may add this to carrier APIs.
8067 *
Michele Berionne482f8202018-11-27 18:57:59 -08008068 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008069 */
8070 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008071 @TelephonyManager.SetCarrierRestrictionResult
8072 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07008073 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07008074 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008075
Michele Berionne482f8202018-11-27 18:57:59 -08008076 if (carrierRestrictionRules == null) {
8077 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08008078 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008079
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008080 final long identity = Binder.clearCallingIdentity();
8081 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008082 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07008083 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008084 } finally {
8085 Binder.restoreCallingIdentity(identity);
8086 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008087 }
8088
8089 /**
8090 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08008091 * Get the allowed carrier list and the excluded carrier list, including the priority between
8092 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07008093 * Require system privileges. In the future we may add this to carrier APIs.
8094 *
Michele Berionne482f8202018-11-27 18:57:59 -08008095 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07008096 */
8097 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008098 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008099 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008100 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101
8102 final long identity = Binder.clearCallingIdentity();
8103 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008104 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8105 if (response instanceof CarrierRestrictionRules) {
8106 return (CarrierRestrictionRules) response;
8107 }
8108 // Response is an Exception of some kind,
8109 // which is signalled to the user as a NULL retval
8110 return null;
8111 } catch (Exception e) {
8112 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8113 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008114 } finally {
8115 Binder.restoreCallingIdentity(identity);
8116 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008117 }
8118
fionaxu59545b42016-05-25 15:53:37 -07008119 /**
fionaxu59545b42016-05-25 15:53:37 -07008120 * Action set from carrier signalling broadcast receivers to enable/disable radio
8121 * @param subId the subscription ID that this action applies to.
8122 * @param enabled control enable or disable radio.
8123 * {@hide}
8124 */
8125 @Override
8126 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8127 enforceModifyPermission();
8128 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129
8130 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008131 if (phone == null) {
8132 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8133 return;
8134 }
8135 try {
8136 phone.carrierActionSetRadioEnabled(enabled);
8137 } catch (Exception e) {
8138 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 } finally {
8140 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008141 }
8142 }
8143
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008144 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008145 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8146 * network status based on which carrier apps could apply actions accordingly,
8147 * enable/disable default url handler for example.
8148 *
8149 * @param subId the subscription ID that this action applies to.
8150 * @param report control start/stop reporting the default network status.
8151 * {@hide}
8152 */
8153 @Override
8154 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8155 enforceModifyPermission();
8156 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008157
8158 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008159 if (phone == null) {
8160 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8161 return;
8162 }
8163 try {
8164 phone.carrierActionReportDefaultNetworkStatus(report);
8165 } catch (Exception e) {
8166 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008167 } finally {
8168 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008169 }
8170 }
8171
8172 /**
fionaxud9622282017-07-17 17:51:30 -07008173 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8174 * @param subId the subscription ID that this action applies to.
8175 * {@hide}
8176 */
8177 @Override
8178 public void carrierActionResetAll(int subId) {
8179 enforceModifyPermission();
8180 final Phone phone = getPhone(subId);
8181 if (phone == null) {
8182 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8183 return;
8184 }
8185 try {
8186 phone.carrierActionResetAll();
8187 } catch (Exception e) {
8188 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8189 }
8190 }
8191
8192 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008193 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8194 * bug report is being generated.
8195 */
8196 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008197 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008198 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8199 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008200 writer.println("Permission Denial: can't dump Phone from pid="
8201 + Binder.getCallingPid()
8202 + ", uid=" + Binder.getCallingUid()
8203 + "without permission "
8204 + android.Manifest.permission.DUMP);
8205 return;
8206 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008207 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008208 }
Jack Yueb89b242016-06-22 13:27:47 -07008209
Brad Ebingerdac2f002018-04-03 15:17:52 -07008210 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008211 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8212 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8213 @NonNull String[] args) {
8214 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8215 this, in.getFileDescriptor(), out.getFileDescriptor(),
8216 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008217 }
8218
Jack Yueb89b242016-06-22 13:27:47 -07008219 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008220 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008221 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008222 * @param reason the reason the data enable change is taking place
8223 * @param enabled True if enabling the data, otherwise disabling.
8224 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008225 */
8226 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008227 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008228 boolean enabled) {
8229 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8230 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8231 try {
8232 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008233 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008234 } catch (SecurityException se) {
8235 enforceModifyPermission();
8236 }
8237 } else {
8238 enforceModifyPermission();
8239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240
8241 final long identity = Binder.clearCallingIdentity();
8242 try {
8243 Phone phone = getPhone(subId);
8244 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008245 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8246 phone.carrierActionSetMeteredApnsEnabled(enabled);
8247 } else {
8248 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250 }
8251 } finally {
8252 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008253 }
8254 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008255
8256 /**
8257 * Get Client request stats
8258 * @return List of Client Request Stats
8259 * @hide
8260 */
8261 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008262 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8263 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008265 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008266 return null;
8267 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008268 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270 final long identity = Binder.clearCallingIdentity();
8271 try {
8272 if (phone != null) {
8273 return phone.getClientRequestStats();
8274 }
8275
8276 return null;
8277 } finally {
8278 Binder.restoreCallingIdentity(identity);
8279 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008280 }
8281
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008282 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008283 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008284 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008285 }
Jack Yueb4124c2017-02-16 15:32:43 -08008286
8287 /**
Grace Chen70990072017-03-24 17:21:30 -07008288 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008289 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008290 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008291 * @param state State of SIM (power down, power up, pass through)
8292 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8293 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8294 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008295 *
8296 **/
8297 @Override
Grace Chen70990072017-03-24 17:21:30 -07008298 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008299 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008300 Phone phone = PhoneFactory.getPhone(slotIndex);
8301
vagdeviaf9a5b92018-08-15 16:01:53 -07008302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008304 final long identity = Binder.clearCallingIdentity();
8305 try {
8306 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008307 phone.setSimPowerState(state, null, workSource);
8308 }
8309 } finally {
8310 Binder.restoreCallingIdentity(identity);
8311 }
8312 }
8313
8314 /**
8315 * Set SIM card power state.
8316 *
8317 * @param slotIndex SIM slot id.
8318 * @param state State of SIM (power down, power up, pass through)
8319 * @param callback callback to trigger after success or failure
8320 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8321 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8322 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8323 *
8324 **/
8325 @Override
8326 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8327 IIntegerConsumer callback) {
8328 enforceModifyPermission();
8329 Phone phone = PhoneFactory.getPhone(slotIndex);
8330
8331 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8332
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 if (phone != null) {
8336 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8337 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008338 }
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008341 }
8342 }
Shuo Qiandd210312017-04-12 22:11:33 +00008343
Tyler Gunn65d45c22017-06-05 11:22:26 -07008344 private boolean isUssdApiAllowed(int subId) {
8345 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008346 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008347 if (configManager == null) {
8348 return false;
8349 }
8350 PersistableBundle pb = configManager.getConfigForSubId(subId);
8351 if (pb == null) {
8352 return false;
8353 }
8354 return pb.getBoolean(
8355 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8356 }
8357
Shuo Qiandd210312017-04-12 22:11:33 +00008358 /**
8359 * Check if phone is in emergency callback mode
8360 * @return true if phone is in emergency callback mode
8361 * @param subId sub id
8362 */
goneil9c5f4872017-12-05 14:07:56 -08008363 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008364 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008365 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008366 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367
8368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 if (phone != null) {
8371 return phone.isInEcm();
8372 } else {
8373 return false;
8374 }
8375 } finally {
8376 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008377 }
8378 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008379
8380 /**
8381 * Get the current signal strength information for the given subscription.
8382 * Because this information is not updated when the device is in a low power state
8383 * it should not be relied-upon to be current.
8384 * @param subId Subscription index
8385 * @return the most recent cached signal strength info from the modem
8386 */
8387 @Override
8388 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008389 final long identity = Binder.clearCallingIdentity();
8390 try {
8391 Phone p = getPhone(subId);
8392 if (p == null) {
8393 return null;
8394 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008396 return p.getSignalStrength();
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
8399 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008400 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008401
Pengquan Meng77b7f132018-08-22 14:49:57 -07008402 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008403 * Get the current modem radio state for the given slot.
8404 * @param slotIndex slot index.
8405 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008406 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008407 * @return the current radio power state from the modem
8408 */
8409 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008410 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008411 Phone phone = PhoneFactory.getPhone(slotIndex);
8412 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008413 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8414 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008415 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8416 }
8417
8418 final long identity = Binder.clearCallingIdentity();
8419 try {
8420 return phone.getRadioPowerState();
8421 } finally {
8422 Binder.restoreCallingIdentity(identity);
8423 }
8424 }
8425 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8426 }
8427
8428 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008429 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8430 *
8431 * <p>Requires one of the following permissions:
8432 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8433 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8434 * privileges.
8435 *
8436 * @param subId subscription id
8437 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8438 * {@code false}.
8439 */
8440 @Override
8441 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008442 try {
8443 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8444 null);
8445 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008446 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008447 mApp, subId, "isDataRoamingEnabled");
8448 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008449
Pengquan Menga1bb6272018-09-06 09:59:22 -07008450 boolean isEnabled = false;
8451 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008452 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008453 Phone phone = getPhone(subId);
8454 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008455 } finally {
8456 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008457 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008458 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008459 }
8460
8461
8462 /**
8463 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8464 *
8465 * <p> Requires permission:
8466 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8467 * privileges.
8468 *
8469 * @param subId subscription id
8470 * @param isEnabled {@code true} means enable, {@code false} means disable.
8471 */
8472 @Override
8473 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8475 mApp, subId, "setDataRoamingEnabled");
8476
Pengquan Menga1bb6272018-09-06 09:59:22 -07008477 final long identity = Binder.clearCallingIdentity();
8478 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008479 Phone phone = getPhone(subId);
8480 if (phone != null) {
8481 phone.setDataRoamingEnabled(isEnabled);
8482 }
8483 } finally {
8484 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008485 }
8486 }
8487
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008488 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008489 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008490 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008491 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008492 mApp, subId, "isManualNetworkSelectionAllowed");
8493
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008494 boolean isAllowed = true;
8495 final long identity = Binder.clearCallingIdentity();
8496 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008497 Phone phone = getPhone(subId);
8498 if (phone != null) {
8499 isAllowed = phone.isCspPlmnEnabled();
8500 }
8501 } finally {
8502 Binder.restoreCallingIdentity(identity);
8503 }
8504 return isAllowed;
8505 }
8506
8507 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008508 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008509 // Verify that tha callingPackage belongs to the calling UID
8510 mApp.getSystemService(AppOpsManager.class)
8511 .checkPackage(Binder.getCallingUid(), callingPackage);
8512
Jordan Liu1e142fc2019-04-22 15:10:43 -07008513 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008514 try {
8515 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008516 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008517 } catch (SecurityException e) {
8518 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8519 // has carrier privileges on an active UICC
8520 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8521 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008522 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008523 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008524 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008525
8526 final long identity = Binder.clearCallingIdentity();
8527 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008528 UiccController uiccController = UiccController.getInstance();
8529 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008530 if (hasReadPermission) {
8531 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008532 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008533
8534 // Remove private info if the caller doesn't have access
8535 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8536 for (UiccCardInfo cardInfo : cardInfos) {
8537 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8538 // is available
8539 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8540 if (card == null || card.getUiccProfile() == null) {
8541 // assume no access if the card or profile is unavailable
8542 filteredInfos.add(cardInfo.getUnprivileged());
8543 continue;
8544 }
8545 UiccProfile profile = card.getUiccProfile();
8546 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8547 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8548 filteredInfos.add(cardInfo);
8549 } else {
8550 filteredInfos.add(cardInfo.getUnprivileged());
8551 }
8552 }
8553 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008554 } finally {
8555 Binder.restoreCallingIdentity(identity);
8556 }
8557 }
8558
8559 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008560 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008561 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008562
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008563 final long identity = Binder.clearCallingIdentity();
8564 try {
8565 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8566 if (slots == null) {
8567 Rlog.i(LOG_TAG, "slots is null.");
8568 return null;
8569 }
8570
8571 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8572 for (int i = 0; i < slots.length; i++) {
8573 UiccSlot slot = slots[i];
8574 if (slot == null) {
8575 continue;
8576 }
8577
Jordan Liu7be7e652019-05-06 18:55:02 +00008578 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008579 UiccCard card = slot.getUiccCard();
8580 if (card != null) {
8581 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008582 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008583 cardId = slot.getEid();
8584 if (TextUtils.isEmpty(cardId)) {
8585 cardId = slot.getIccId();
8586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008587 }
8588
Jordan Liu857451f2019-05-09 16:35:35 -07008589 if (cardId != null) {
8590 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8591 // if cardId is an EID, it's all digits so this is fine
8592 cardId = IccUtils.stripTrailingFs(cardId);
8593 }
8594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008595 int cardState = 0;
8596 switch (slot.getCardState()) {
8597 case CARDSTATE_ABSENT:
8598 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8599 break;
8600 case CARDSTATE_PRESENT:
8601 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8602 break;
8603 case CARDSTATE_ERROR:
8604 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8605 break;
8606 case CARDSTATE_RESTRICTED:
8607 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8608 break;
8609 default:
8610 break;
8611
8612 }
8613
8614 infos[i] = new UiccSlotInfo(
8615 slot.isActive(),
8616 slot.isEuicc(),
8617 cardId,
8618 cardState,
8619 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008620 slot.isExtendedApduSupported(),
8621 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008622 }
8623 return infos;
8624 } finally {
8625 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008626 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008627 }
8628
8629 @Override
8630 public boolean switchSlots(int[] physicalSlots) {
8631 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008632
8633 final long identity = Binder.clearCallingIdentity();
8634 try {
8635 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
8638 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008639 }
Jack Yu4c988042018-02-27 15:30:01 -08008640
8641 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008642 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008643 final long identity = Binder.clearCallingIdentity();
8644 try {
8645 return UiccController.getInstance().getCardIdForDefaultEuicc();
8646 } finally {
8647 Binder.restoreCallingIdentity(identity);
8648 }
8649 }
8650
Pengquan Meng85728fb2018-03-12 16:31:21 -07008651 /**
goneil47ffb6e2018-04-06 15:40:58 -07008652 * A test API to reload the UICC profile.
8653 *
8654 * <p>Requires that the calling app has permission
8655 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8656 * @hide
8657 */
8658 @Override
8659 public void refreshUiccProfile(int subId) {
8660 enforceModifyPermission();
8661
8662 final long identity = Binder.clearCallingIdentity();
8663 try {
8664 Phone phone = getPhone(subId);
8665 if (phone == null) {
8666 return;
8667 }
8668 UiccCard uiccCard = phone.getUiccCard();
8669 if (uiccCard == null) {
8670 return;
8671 }
8672 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8673 if (uiccProfile == null) {
8674 return;
8675 }
8676 uiccProfile.refresh();
8677 } finally {
8678 Binder.restoreCallingIdentity(identity);
8679 }
8680 }
8681
8682 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008683 * Returns false if the mobile data is disabled by default, otherwise return true.
8684 */
8685 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008686 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008687 }
8688
8689 /**
8690 * Returns true if the data roaming is enabled by default, i.e the system property
8691 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8692 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8693 */
8694 private boolean getDefaultDataRoamingEnabled(int subId) {
8695 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008696 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008697 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008698 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8699 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8700 return isDataRoamingEnabled;
8701 }
8702
8703 /**
8704 * Returns the default network type for the given {@code subId}, if the default network type is
8705 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8706 */
8707 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008708 List<Integer> list = TelephonyProperties.default_network();
8709 int phoneId = mSubscriptionController.getPhoneId(subId);
8710 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8711 return list.get(phoneId);
8712 }
8713 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008714 }
fionaxua13278b2018-03-21 00:08:13 -07008715
8716 @Override
8717 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008718 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008719 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008720
8721 final long identity = Binder.clearCallingIdentity();
8722 try {
8723 final Phone phone = getPhone(subId);
8724 if (phone == null) {
8725 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8726 return;
8727 }
chen xueaba88a2019-03-15 13:15:10 -07008728 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8729 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008730 if (carrierPrivilegeRules == null) {
8731 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8732 } else {
8733 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008735 } finally {
8736 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008737 }
fionaxua13278b2018-03-21 00:08:13 -07008738 }
8739
8740 @Override
8741 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008742 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008743
8744 final long identity = Binder.clearCallingIdentity();
8745 try {
8746 final Phone phone = getPhone(subId);
8747 if (phone == null) {
8748 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8749 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8750 }
8751 return phone.getCarrierIdListVersion();
8752 } finally {
8753 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008754 }
fionaxua13278b2018-03-21 00:08:13 -07008755 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008756
8757 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008758 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8759 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008761 mApp, subId, callingPackage, callingFeatureId,
8762 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008763 return -1;
8764 }
8765
8766 final long identity = Binder.clearCallingIdentity();
8767 try {
8768 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8769 } finally {
8770 Binder.restoreCallingIdentity(identity);
8771 }
8772 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008773
8774 @Override
8775 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008776 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008777 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008778 mApp, subId, "getCdmaRoamingMode");
8779
8780 final long identity = Binder.clearCallingIdentity();
8781 try {
8782 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8783 } finally {
8784 Binder.restoreCallingIdentity(identity);
8785 }
8786 }
8787
8788 @Override
8789 public boolean setCdmaRoamingMode(int subId, int mode) {
8790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8791 mApp, subId, "setCdmaRoamingMode");
8792
8793 final long identity = Binder.clearCallingIdentity();
8794 try {
8795 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8796 } finally {
8797 Binder.restoreCallingIdentity(identity);
8798 }
8799 }
8800
8801 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008802 public int getCdmaSubscriptionMode(int subId) {
8803 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008804 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008805 mApp, subId, "getCdmaSubscriptionMode");
8806
8807 final long identity = Binder.clearCallingIdentity();
8808 try {
8809 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
8813 }
8814
8815 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008816 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8818 mApp, subId, "setCdmaSubscriptionMode");
8819
8820 final long identity = Binder.clearCallingIdentity();
8821 try {
8822 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8823 } finally {
8824 Binder.restoreCallingIdentity(identity);
8825 }
8826 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008827
sqianc5eccab2018-10-19 18:46:41 -07008828 @Override
sqian8c685422019-02-22 15:55:18 -08008829 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008830 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008832 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8833 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008834 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8835 }
8836 final long identity = Binder.clearCallingIdentity();
8837 try {
sqian854d44b2018-12-12 16:48:18 -08008838 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8839 for (Phone phone: PhoneFactory.getPhones()) {
8840 if (phone.getEmergencyNumberTracker() != null
8841 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8842 emergencyNumberListInternal.put(
8843 phone.getSubId(),
8844 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8845 }
sqian11b7a0e2018-12-05 18:48:28 -08008846 }
sqian854d44b2018-12-12 16:48:18 -08008847 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008848 } finally {
8849 Binder.restoreCallingIdentity(identity);
8850 }
sqianc5eccab2018-10-19 18:46:41 -07008851 }
8852
8853 @Override
sqian8c685422019-02-22 15:55:18 -08008854 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008855 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008856 if (!exactMatch) {
8857 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008858 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008859 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008860 }
8861 final long identity = Binder.clearCallingIdentity();
8862 try {
sqian854d44b2018-12-12 16:48:18 -08008863 for (Phone phone: PhoneFactory.getPhones()) {
8864 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008865 && phone.getEmergencyNumberTracker()
8866 .isEmergencyNumber(number, exactMatch)) {
8867 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008868 }
sqian11b7a0e2018-12-05 18:48:28 -08008869 }
8870 return false;
8871 } finally {
8872 Binder.restoreCallingIdentity(identity);
8873 }
8874 }
8875
sqianf4ca7ed2019-01-15 18:32:07 -08008876 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008877 * Start emergency callback mode for GsmCdmaPhone for testing.
8878 */
8879 @Override
8880 public void startEmergencyCallbackMode() {
8881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8882 "startEmergencyCallbackMode");
8883 enforceModifyPermission();
8884 final long identity = Binder.clearCallingIdentity();
8885 try {
8886 for (Phone phone : PhoneFactory.getPhones()) {
8887 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8888 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8889 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8890 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8891 gsmCdmaPhone.obtainMessage(
8892 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8893 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8894 }
8895 }
8896 } finally {
8897 Binder.restoreCallingIdentity(identity);
8898 }
8899 }
8900
8901 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008902 * Update emergency number list for test mode.
8903 */
8904 @Override
8905 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8906 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8907 "updateEmergencyNumberListTestMode");
8908
8909 final long identity = Binder.clearCallingIdentity();
8910 try {
8911 for (Phone phone: PhoneFactory.getPhones()) {
8912 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8913 if (tracker != null) {
8914 tracker.executeEmergencyNumberTestModeCommand(action, num);
8915 }
8916 }
8917 } finally {
8918 Binder.restoreCallingIdentity(identity);
8919 }
8920 }
8921
8922 /**
8923 * Get the full emergency number list for test mode.
8924 */
8925 @Override
8926 public List<String> getEmergencyNumberListTestMode() {
8927 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8928 "getEmergencyNumberListTestMode");
8929
8930 final long identity = Binder.clearCallingIdentity();
8931 try {
8932 Set<String> emergencyNumbers = new HashSet<>();
8933 for (Phone phone: PhoneFactory.getPhones()) {
8934 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8935 if (tracker != null) {
8936 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8937 emergencyNumbers.add(num.getNumber());
8938 }
8939 }
8940 }
8941 return new ArrayList<>(emergencyNumbers);
8942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
8945 }
8946
chen xud6b45bd2018-10-30 22:27:10 -07008947 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008948 public int getEmergencyNumberDbVersion(int subId) {
8949 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8950
8951 final long identity = Binder.clearCallingIdentity();
8952 try {
8953 final Phone phone = getPhone(subId);
8954 if (phone == null) {
8955 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8956 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8957 }
8958 return phone.getEmergencyNumberDbVersion();
8959 } finally {
8960 Binder.restoreCallingIdentity(identity);
8961 }
8962 }
8963
8964 @Override
8965 public void notifyOtaEmergencyNumberDbInstalled() {
8966 enforceModifyPermission();
8967
8968 final long identity = Binder.clearCallingIdentity();
8969 try {
8970 for (Phone phone: PhoneFactory.getPhones()) {
8971 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8972 if (tracker != null) {
8973 tracker.updateOtaEmergencyNumberDatabase();
8974 }
8975 }
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
8978 }
8979 }
8980
8981 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008982 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008983 enforceActiveEmergencySessionPermission();
8984
8985 final long identity = Binder.clearCallingIdentity();
8986 try {
8987 for (Phone phone: PhoneFactory.getPhones()) {
8988 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8989 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008990 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8991 }
8992 }
8993 } finally {
8994 Binder.restoreCallingIdentity(identity);
8995 }
8996 }
8997
8998 @Override
8999 public void resetOtaEmergencyNumberDbFilePath() {
9000 enforceActiveEmergencySessionPermission();
9001
9002 final long identity = Binder.clearCallingIdentity();
9003 try {
9004 for (Phone phone: PhoneFactory.getPhones()) {
9005 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
9006 if (tracker != null) {
9007 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08009008 }
9009 }
9010 } finally {
9011 Binder.restoreCallingIdentity(identity);
9012 }
9013 }
9014
9015 @Override
chen xud6b45bd2018-10-30 22:27:10 -07009016 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
9017 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
9018 Phone phone = getPhone(subId);
9019 if (phone == null) {
9020 return null;
9021 }
9022 final long identity = Binder.clearCallingIdentity();
9023 try {
9024 UiccProfile profile = UiccController.getInstance()
9025 .getUiccProfileForPhone(phone.getPhoneId());
9026 if (profile != null) {
9027 return profile.getCertsFromCarrierPrivilegeAccessRules();
9028 }
9029 } finally {
9030 Binder.restoreCallingIdentity(identity);
9031 }
9032 return null;
9033 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08009034
9035 /**
9036 * Enable or disable a modem stack.
9037 */
9038 @Override
9039 public boolean enableModemForSlot(int slotIndex, boolean enable) {
9040 enforceModifyPermission();
9041
9042 final long identity = Binder.clearCallingIdentity();
9043 try {
9044 Phone phone = PhoneFactory.getPhone(slotIndex);
9045 if (phone == null) {
9046 return false;
9047 } else {
9048 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
9049 }
9050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
9053 }
Michelecea4cf22018-12-21 15:00:11 -08009054
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009055 /**
9056 * Whether a modem stack is enabled or not.
9057 */
9058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009059 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
9060 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009061 Phone phone = PhoneFactory.getPhone(slotIndex);
9062 if (phone == null) return false;
9063
9064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009065 mApp, phone.getSubId(), callingPackage, callingFeatureId,
9066 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009067 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9068 }
9069
9070 final long identity = Binder.clearCallingIdentity();
9071 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07009072 try {
9073 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
9074 } catch (NoSuchElementException ex) {
9075 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
9076 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07009077 } finally {
9078 Binder.restoreCallingIdentity(identity);
9079 }
9080 }
9081
Michelecea4cf22018-12-21 15:00:11 -08009082 @Override
Michele0ea7d782019-03-19 14:58:42 -07009083 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08009084 enforceModifyPermission();
9085
9086 final long identity = Binder.clearCallingIdentity();
9087 try {
9088 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07009089 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08009090 .commit();
9091 } finally {
9092 Binder.restoreCallingIdentity(identity);
9093 }
9094 }
9095
9096 @Override
Michele0ea7d782019-03-19 14:58:42 -07009097 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009098 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009099 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009100 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9101 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009102 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009103 }
Michelecea4cf22018-12-21 15:00:11 -08009104
9105 final long identity = Binder.clearCallingIdentity();
9106 try {
Michele0ea7d782019-03-19 14:58:42 -07009107 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009108 } finally {
9109 Binder.restoreCallingIdentity(identity);
9110 }
9111 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009112
Michele0ea7d782019-03-19 14:58:42 -07009113 @TelephonyManager.IsMultiSimSupportedResult
9114 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009115 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9116 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9117 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009118 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9119 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009120 }
9121 // Check if the hardware supports multisim functionality. If usage of multisim is not
9122 // supported by the modem, indicate that it is restricted.
9123 PhoneCapability staticCapability =
9124 mPhoneConfigurationManager.getStaticPhoneCapability();
9125 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009126 loge("isMultiSimSupportedInternal: no static configuration available");
9127 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009128 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009129 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009130 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9131 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009132 }
9133 // Check if support of multiple SIMs is restricted by carrier
9134 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009135 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009136 }
9137
Michele0ea7d782019-03-19 14:58:42 -07009138 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009139 }
9140
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009141 /**
9142 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009143 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9144 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9145 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009146 * @param numOfSims number of active sims we want to switch to
9147 */
9148 @Override
9149 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009150 if (numOfSims == 1) {
9151 enforceModifyPermission();
9152 } else {
9153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9154 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9155 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009156 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009157
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009158 try {
Michele30b57b22019-03-01 12:01:14 -08009159 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009160 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009161 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9162 return;
9163 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009164 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
9169
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009170 @Override
9171 public boolean isApplicationOnUicc(int subId, int appType) {
9172 enforceReadPrivilegedPermission("isApplicationOnUicc");
9173 Phone phone = getPhone(subId);
9174 if (phone == null) {
9175 return false;
9176 }
9177 final long identity = Binder.clearCallingIdentity();
9178 try {
9179 UiccCard uiccCard = phone.getUiccCard();
9180 if (uiccCard == null) {
9181 return false;
9182 }
9183 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9184 if (uiccProfile == null) {
9185 return false;
9186 }
9187 if (TelephonyManager.APPTYPE_SIM <= appType
9188 && appType <= TelephonyManager.APPTYPE_ISIM) {
9189 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9190 }
9191 return false;
9192 } finally {
9193 Binder.restoreCallingIdentity(identity);
9194 }
9195 }
9196
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009197 /**
chen xub4baa772019-04-03 10:23:41 -07009198 * Get whether making changes to modem configurations will trigger reboot.
9199 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009200 */
9201 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009202 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9203 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009204 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009205 mApp, subId, callingPackage, callingFeatureId,
9206 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009207 return false;
9208 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
9215 }
9216
Nathan Harold29f5f052019-02-15 13:41:57 -08009217 private void updateModemStateMetrics() {
9218 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9219 // TODO: check the state for each modem if the api is ready.
9220 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9221 }
9222
Pengquan Meng3889a572019-01-23 11:16:29 -08009223 @Override
9224 public int[] getSlotsMapping() {
9225 enforceReadPrivilegedPermission("getSlotsMapping");
9226
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9230 // All logical slots should have a mapping to a physical slot.
9231 int[] logicalSlotsMapping = new int[phoneCount];
9232 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9233 for (int i = 0; i < slotInfos.length; i++) {
9234 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9235 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9236 }
9237 }
9238 return logicalSlotsMapping;
9239 } finally {
9240 Binder.restoreCallingIdentity(identity);
9241 }
9242 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009243
9244 /**
9245 * Get the IRadio HAL Version
9246 */
9247 @Override
9248 public int getRadioHalVersion() {
9249 Phone phone = getDefaultPhone();
9250 if (phone == null) return -1;
9251 HalVersion hv = phone.getHalVersion();
9252 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9253 return hv.major * 100 + hv.minor;
9254 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009255
9256 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009257 * Get the current calling package name.
9258 * @return the current calling package name
9259 */
9260 @Override
9261 public String getCurrentPackageName() {
9262 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9263 }
9264
9265 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009266 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9267 * corresponding network requests on a subId.
9268 *
9269 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009270 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009271 * 2) APN is un-metered for this subscription, or
9272 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009273 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009274 *
9275 * @return whether data is allowed for a apn type.
9276 *
9277 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009278 */
9279 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009280 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009281 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9282 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009283
9284 // Now that all security checks passes, perform the operation as ourselves.
9285 final long identity = Binder.clearCallingIdentity();
9286 try {
9287 Phone phone = getPhone(subId);
9288 if (phone == null) return false;
9289
Jack Yu41407ee2019-05-13 16:54:09 -07009290 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009291 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9292 } finally {
9293 Binder.restoreCallingIdentity(identity);
9294 }
9295 }
9296
9297 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009298 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009299 enforceReadPrivilegedPermission("isApnMetered");
9300
9301 // Now that all security checks passes, perform the operation as ourselves.
9302 final long identity = Binder.clearCallingIdentity();
9303 try {
9304 Phone phone = getPhone(subId);
9305 if (phone == null) return true; // By default return true.
9306
Jack Yu41407ee2019-05-13 16:54:09 -07009307 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009308 } finally {
9309 Binder.restoreCallingIdentity(identity);
9310 }
9311 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009312
9313 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009314 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9315 int subscriptionId, IBooleanConsumer resultCallback) {
9316 enforceModifyPermission();
9317 long token = Binder.clearCallingIdentity();
9318 try {
9319 Phone phone = getPhone(subscriptionId);
9320 if (phone == null) {
9321 try {
9322 if (resultCallback != null) {
9323 resultCallback.accept(false);
9324 }
9325 } catch (RemoteException e) {
9326 // ignore
9327 }
9328 return;
9329 }
9330 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9331 Pair.create(specifiers, (x) -> {
9332 try {
9333 if (resultCallback != null) {
9334 resultCallback.accept(x);
9335 }
9336 } catch (RemoteException e) {
9337 // ignore
9338 }
9339 });
9340 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9341 } finally {
9342 Binder.restoreCallingIdentity(token);
9343 }
9344 }
9345
9346 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009347 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9348 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009349 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009350 mApp, subId, "getSystemSelectionChannels");
9351 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009354 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9355 if (result instanceof IllegalStateException) {
9356 throw (IllegalStateException) result;
9357 }
9358 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009359 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9360 return specifiers;
9361 } finally {
9362 Binder.restoreCallingIdentity(identity);
9363 }
9364 }
9365
9366 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009367 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009368 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009369 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9370 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9371 if (iccRecords == null) {
9372 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9373 return false;
9374 }
9375 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9376 }
9377
9378 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009379 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9380 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009381 if (callingPackage == null) {
9382 callingPackage = getCurrentPackageName();
9383 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009384 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9385 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009386 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9387 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009388 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9389 }
9390 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9391 Intent intent = new Intent();
9392 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9393 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9394 // Bring up choose default SMS subscription dialog right now
9395 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9396 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9397 mApp.startActivity(intent);
9398 }
chen xud5ca2d52019-05-28 15:20:57 -07009399
9400 @Override
9401 public String getMmsUAProfUrl(int subId) {
9402 //TODO investigate if this API should require proper permission check in R b/133791609
9403 final long identity = Binder.clearCallingIdentity();
9404 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009405 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9406 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9407 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9408 return carrierUAProfUrl;
9409 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009410 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9411 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009412 } finally {
9413 Binder.restoreCallingIdentity(identity);
9414 }
9415 }
9416
9417 @Override
9418 public String getMmsUserAgent(int subId) {
9419 //TODO investigate if this API should require proper permission check in R b/133791609
9420 final long identity = Binder.clearCallingIdentity();
9421 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009422 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9423 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9424 if (!TextUtils.isEmpty(carrierUserAgent)) {
9425 return carrierUserAgent;
9426 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009427 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9428 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009429 } finally {
9430 Binder.restoreCallingIdentity(identity);
9431 }
9432 }
Jack Yub07d4972019-05-28 16:12:25 -07009433
9434 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009435 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9436 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009437
Jack Yub07d4972019-05-28 16:12:25 -07009438 final long identity = Binder.clearCallingIdentity();
9439 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009440 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009441 if (phone == null) return false;
9442
Hall Liua62f5da2020-09-25 10:42:19 -07009443 switch (policy) {
9444 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9445 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9446 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9447 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9448 default:
9449 throw new IllegalArgumentException(policy + " is not a valid policy");
9450 }
Jack Yub07d4972019-05-28 16:12:25 -07009451 } finally {
9452 Binder.restoreCallingIdentity(identity);
9453 }
9454 }
9455
9456 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009457 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009458 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009459 enforceModifyPermission();
9460
changbettyd5c246e2019-12-24 15:40:37 +08009461 final long identity = Binder.clearCallingIdentity();
9462 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009463 Phone phone = getPhone(subscriptionId);
9464 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009465
Hall Liua62f5da2020-09-25 10:42:19 -07009466 switch (policy) {
9467 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9468 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9469 break;
9470 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9471 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9472 break;
9473 default:
9474 throw new IllegalArgumentException(policy + " is not a valid policy");
9475 }
changbettyd5c246e2019-12-24 15:40:37 +08009476 } finally {
9477 Binder.restoreCallingIdentity(identity);
9478 }
9479 }
9480
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009481 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009482 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009483 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9484 * otherwise.
9485 */
9486 @Override
9487 public void setCepEnabled(boolean isCepEnabled) {
9488 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9489
9490 final long identity = Binder.clearCallingIdentity();
9491 try {
9492 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9493 for (Phone phone : PhoneFactory.getPhones()) {
9494 Phone defaultPhone = phone.getImsPhone();
9495 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9496 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9497 ImsPhoneCallTracker imsPhoneCallTracker =
9498 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9499 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9500 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9501 + imsPhone.getMsisdn());
9502 }
9503 }
9504 } finally {
9505 Binder.restoreCallingIdentity(identity);
9506 }
9507 }
allenwtsu46dcc572020-01-08 18:24:03 +08009508
9509 /**
9510 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9511 *
9512 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9513 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9514 * before being read.
9515 */
9516 @Override
9517 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9518 isCompressed) {
9519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9520 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009521 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9522 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9523 }
9524 if (!isImsAvailableOnDevice()) {
9525 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9526 "IMS not available on device.");
9527 }
9528
9529 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009530 try {
Hui Wang761a6682020-10-31 05:12:53 +00009531 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9532 } finally {
9533 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009534 }
9535 }
zoey chene02881a2019-12-30 16:11:23 +08009536
9537 @Override
9538 public boolean isIccLockEnabled(int subId) {
9539 enforceReadPrivilegedPermission("isIccLockEnabled");
9540
9541 // Now that all security checks passes, perform the operation as ourselves.
9542 final long identity = Binder.clearCallingIdentity();
9543 try {
9544 Phone phone = getPhone(subId);
9545 if (phone != null && phone.getIccCard() != null) {
9546 return phone.getIccCard().getIccLockEnabled();
9547 } else {
9548 return false;
9549 }
9550 } finally {
9551 Binder.restoreCallingIdentity(identity);
9552 }
9553 }
9554
9555 /**
9556 * Set the ICC pin lock enabled or disabled.
9557 *
9558 * @return an integer representing the status of IccLock enabled or disabled in the following
9559 * three cases:
9560 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9561 * successfully.
9562 * - Positive number and zero for remaining password attempts.
9563 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9564 *
9565 */
9566 @Override
9567 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9568 enforceModifyPermission();
9569
9570 Phone phone = getPhone(subId);
9571 if (phone == null) {
9572 return 0;
9573 }
9574 // Now that all security checks passes, perform the operation as ourselves.
9575 final long identity = Binder.clearCallingIdentity();
9576 try {
9577 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9578 new Pair<Boolean, String>(enabled, password), phone, null);
9579 return attemptsRemaining;
9580
9581 } catch (Exception e) {
9582 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 return 0;
9587 }
9588
9589 /**
9590 * Change the ICC password used in ICC pin lock.
9591 *
9592 * @return an integer representing the status of IccLock changed in the following three cases:
9593 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9594 * - Positive number and zero for remaining password attempts.
9595 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9596 *
9597 */
9598 @Override
9599 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9600 enforceModifyPermission();
9601
9602 Phone phone = getPhone(subId);
9603 if (phone == null) {
9604 return 0;
9605 }
9606 // Now that all security checks passes, perform the operation as ourselves.
9607 final long identity = Binder.clearCallingIdentity();
9608 try {
9609 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9610 new Pair<String, String>(oldPassword, newPassword), phone, null);
9611 return attemptsRemaining;
9612
9613 } catch (Exception e) {
9614 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9615 } finally {
9616 Binder.restoreCallingIdentity(identity);
9617 }
9618 return 0;
9619 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009620
9621 /**
9622 * Request for receiving user activity notification
9623 */
9624 @Override
9625 public void requestUserActivityNotification() {
9626 if (!mNotifyUserActivity.get()
9627 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9628 mNotifyUserActivity.set(true);
9629 }
9630 }
9631
9632 /**
9633 * Called when userActivity is signalled in the power manager.
9634 * This is safe to call from any thread, with any window manager locks held or not.
9635 */
9636 @Override
9637 public void userActivity() {
9638 // ***************************************
9639 // * Inherited from PhoneWindowManager *
9640 // ***************************************
9641 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9642 // WITH ITS LOCKS HELD.
9643 //
9644 // This code must be VERY careful about the locks
9645 // it acquires.
9646 // In fact, the current code acquires way too many,
9647 // and probably has lurking deadlocks.
9648
9649 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9650 throw new SecurityException("Only the OS may call notifyUserActivity()");
9651 }
9652
9653 if (mNotifyUserActivity.getAndSet(false)) {
9654 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9655 USER_ACTIVITY_NOTIFICATION_DELAY);
9656 }
9657 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009658
9659 @Override
9660 public boolean canConnectTo5GInDsdsMode() {
9661 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9662 }
Jack Yud10cdd42020-09-28 20:28:01 -07009663
9664 @Override
9665 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9666 String callingFeatureId) {
9667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9668 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9669 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9670 }
9671
9672 Phone phone = getPhone(subId);
9673 if (phone == null) {
9674 throw new RuntimeException("phone is not available");
9675 }
9676 // Now that all security checks passes, perform the operation as ourselves.
9677 final long identity = Binder.clearCallingIdentity();
9678 try {
9679 return phone.getEquivalentHomePlmns();
9680 } finally {
9681 Binder.restoreCallingIdentity(identity);
9682 }
9683 }
Daniel Bright59e67312020-11-13 11:49:37 -08009684
9685 @Override
9686 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009687 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9688 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009689 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009690 if (radioInterfaceCapabilities == null) {
9691 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009692 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009693 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009694 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009695
Hui Wang641e81c2020-10-12 12:14:23 -07009696 @Override
9697 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9698 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009699 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9700 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9701 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9702 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9703 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009704 if (DBG) {
9705 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9706 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9707 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9708 }
9709
9710 if (!SubscriptionManager.isValidSubscriptionId(subId)
9711 || appType < TelephonyManager.APPTYPE_UNKNOWN
9712 || appType > TelephonyManager.APPTYPE_ISIM
9713 || nafUrl == null || securityProtocol == null || callback == null) {
9714 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9715 if (callback != null) {
9716 try {
9717 callback.onAuthenticationFailure(
9718 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9719 } catch (RemoteException exception) {
9720 log("Fail to notify onAuthenticationFailure due to " + exception);
9721 }
9722 return;
9723 }
9724 }
9725
9726 final long token = Binder.clearCallingIdentity();
9727 try {
9728 getGbaManager(subId).bootstrapAuthenticationRequest(
9729 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9730 forceBootStrapping, callback));
9731 } finally {
9732 Binder.restoreCallingIdentity(token);
9733 }
9734 }
9735
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009736 /**
9737 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9738 * requested radio power state will actually be set. See {@link
9739 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9740 *
9741 * @param subId the subscription ID of the phone requesting to set the radio power state.
9742 * @param enable {@code true} if trying to turn radio on.
9743 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9744 * false}.
9745 */
9746 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9747 Phone phone = getPhone(subId);
9748 if (phone != null) {
9749 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9750 return true;
9751 }
9752 return false;
9753 }
9754
9755 private int handleDataThrottlingRequest(int subId,
9756 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009757 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9758 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9759 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9760 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9761 throw new IllegalArgumentException("modem does not support data throttling");
9762 }
9763
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009764 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9765 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9766 if (!setRadioPowerForThermal(subId, true)) {
9767 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9768 }
9769
9770 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9771
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009772 if (isDataThrottlingSupported) {
9773 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009774 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009775 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9776 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9777 } else if (thermalMitigationResult
9778 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9779 throw new IllegalArgumentException("modem does not support data throttling");
9780 }
9781 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009782 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009783
9784 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009785 }
9786
Jack Nudelman644b91a2021-03-12 14:09:48 -08009787 private static List<String> getThermalMitigationAllowlist(Context context) {
9788 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9789 for (String pckg : context.getResources()
9790 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9791 sThermalMitigationAllowlistedPackages.add(pckg);
9792 }
9793 }
9794
9795 return sThermalMitigationAllowlistedPackages;
9796 }
9797
9798 /**
9799 * Used by shell commands to add an authorized package name for thermal mitigation.
9800 * @param packageName name of package to be allowlisted
9801 * @param context
9802 */
9803 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9804 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9805 sThermalMitigationAllowlistedPackages.add(packageName);
9806 }
9807
9808 /**
9809 * Used by shell commands to remove an authorized package name for thermal mitigation.
9810 * @param packageName name of package to remove from allowlist
9811 * @param context
9812 */
9813 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9814 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9815 sThermalMitigationAllowlistedPackages.remove(packageName);
9816 }
9817
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009818 /**
9819 * Thermal mitigation request to control functionalities at modem.
9820 *
9821 * @param subId the id of the subscription.
9822 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009823 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009824 *
9825 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9826 */
9827 @Override
9828 @ThermalMitigationResult
9829 public int sendThermalMitigationRequest(
9830 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009831 ThermalMitigationRequest thermalMitigationRequest,
9832 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009833 enforceModifyPermission();
9834
Jack Nudelman644b91a2021-03-12 14:09:48 -08009835 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9836 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9837 .contains(callingPackage)) {
9838 throw new SecurityException("Calling package must be configured in the device config. "
9839 + "calling package: " + callingPackage);
9840 }
9841
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009842 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9843 final long identity = Binder.clearCallingIdentity();
9844
9845 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9846 try {
9847 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9848 switch (thermalMitigationAction) {
9849 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9850 thermalMitigationResult =
9851 handleDataThrottlingRequest(subId,
9852 thermalMitigationRequest.getDataThrottlingRequest());
9853 break;
9854 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9855 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9856 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9857 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9858 }
9859
9860 // Ensure that radio is on. If not able to power on due to phone being
9861 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9862 if (!setRadioPowerForThermal(subId, true)) {
9863 thermalMitigationResult =
9864 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9865 break;
9866 }
9867
9868 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9869 false);
9870 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9871 break;
9872 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9873 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9874 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9875 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9876 }
9877
9878 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9879 if (registry != null) {
9880 TelephonyConnectionService service =
9881 registry.getTelephonyConnectionService();
9882 Phone phone = getPhone(subId);
9883 if (phone == null) {
9884 thermalMitigationResult =
9885 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9886 break;
9887 }
9888
9889 if (PhoneConstantConversions.convertCallState(phone.getState())
9890 != TelephonyManager.CALL_STATE_IDLE
9891 || phone.isInEmergencySmsMode() || phone.isInEcm()
9892 || (service != null && service.isEmergencyCallPending())) {
9893 String errorMessage = "Phone state is not valid. call state = "
9894 + PhoneConstantConversions.convertCallState(phone.getState())
9895 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9896 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9897 errorMessage += service == null
9898 ? " TelephonyConnectionService is null"
9899 : " isEmergencyCallPending = "
9900 + service.isEmergencyCallPending();
9901 Log.e(LOG_TAG, errorMessage);
9902 thermalMitigationResult =
9903 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9904 break;
9905 }
9906 } else {
9907 thermalMitigationResult =
9908 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9909 break;
9910 }
9911
9912 // Turn radio off. If not able to power off due to phone being unavailable,
9913 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9914 if (!setRadioPowerForThermal(subId, false)) {
9915 thermalMitigationResult =
9916 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9917 break;
9918 }
9919 thermalMitigationResult =
9920 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9921 break;
9922 default:
9923 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9924 + "not exist. Requested action: " + thermalMitigationAction);
9925 }
9926 } catch (IllegalArgumentException e) {
9927 throw e;
9928 } catch (Exception e) {
9929 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9930 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9931 } finally {
9932 Binder.restoreCallingIdentity(identity);
9933 }
9934
9935 if (DBG) {
9936 log("thermalMitigationRequest returning with thermalMitigationResult: "
9937 + thermalMitigationResult);
9938 }
9939
9940 return thermalMitigationResult;
9941 }
Hui Wang641e81c2020-10-12 12:14:23 -07009942
9943 /**
9944 * Set the GbaService Package Name that Telephony will bind to.
9945 *
9946 * @param subId The sim that the GbaService is associated with.
9947 * @param packageName The name of the package to be replaced with.
9948 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9949 */
9950 @Override
9951 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9952 enforceModifyPermission();
9953
9954 final long identity = Binder.clearCallingIdentity();
9955 try {
9956 return getGbaManager(subId).overrideServicePackage(packageName);
9957 } finally {
9958 Binder.restoreCallingIdentity(identity);
9959 }
9960 }
9961
9962 /**
9963 * Return the package name of the currently bound GbaService.
9964 *
9965 * @param subId The sim that the GbaService is associated with.
9966 * @return the package name of the GbaService configuration, null if GBA is not supported.
9967 */
9968 @Override
9969 public String getBoundGbaService(int subId) {
9970 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9971
9972 final long identity = Binder.clearCallingIdentity();
9973 try {
9974 return getGbaManager(subId).getServicePackage();
9975 } finally {
9976 Binder.restoreCallingIdentity(identity);
9977 }
9978 }
9979
9980 /**
9981 * Set the release time for telephony to unbind GbaService.
9982 *
9983 * @param subId The sim that the GbaService is associated with.
9984 * @param interval The release time to unbind GbaService by millisecond.
9985 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9986 */
9987 @Override
9988 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9989 enforceModifyPermission();
9990
9991 final long identity = Binder.clearCallingIdentity();
9992 try {
9993 return getGbaManager(subId).overrideReleaseTime(interval);
9994 } finally {
9995 Binder.restoreCallingIdentity(identity);
9996 }
9997 }
9998
9999 /**
10000 * Return the release time for telephony to unbind GbaService.
10001 *
10002 * @param subId The sim that the GbaService is associated with.
10003 * @return The release time to unbind GbaService by millisecond.
10004 */
10005 @Override
10006 public int getGbaReleaseTime(int subId) {
10007 enforceReadPrivilegedPermission("getGbaReleaseTime");
10008
10009 final long identity = Binder.clearCallingIdentity();
10010 try {
10011 return getGbaManager(subId).getReleaseTime();
10012 } finally {
10013 Binder.restoreCallingIdentity(identity);
10014 }
10015 }
10016
10017 private GbaManager getGbaManager(int subId) {
10018 GbaManager instance = GbaManager.getInstance(subId);
10019 if (instance == null) {
10020 String packageName = mApp.getResources().getString(R.string.config_gba_package);
10021 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
10022 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
10023 }
10024 return instance;
10025 }
Hui Wang761a6682020-10-31 05:12:53 +000010026
10027 /**
10028 * indicate whether the device and the carrier can support
10029 * RCS VoLTE single registration.
10030 */
10031 @Override
10032 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010033 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
10034 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
10035 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10036 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010037
10038 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10039 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10040 }
10041
10042 final long identity = Binder.clearCallingIdentity();
10043 try {
10044 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
10045 if (rpm != null) {
10046 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
10047 }
10048 return false;
10049 } finally {
10050 Binder.restoreCallingIdentity(identity);
10051 }
10052 }
10053
10054 /**
10055 * Register RCS provisioning callback.
10056 */
10057 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010058 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010059 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010060 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010061 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010062 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10063 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010064
10065 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10066 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10067 }
10068 if (!isImsAvailableOnDevice()) {
10069 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10070 "IMS not available on device.");
10071 }
10072
10073 final long identity = Binder.clearCallingIdentity();
10074 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010075 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010076 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -080010077 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10078 "Service not available for the subscription.");
10079 }
Hui Wang761a6682020-10-31 05:12:53 +000010080 } finally {
10081 Binder.restoreCallingIdentity(identity);
10082 }
10083 }
10084
10085 /**
10086 * Unregister RCS provisioning callback.
10087 */
10088 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -080010089 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +000010090 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010091 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -080010092 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +000010093 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
10094 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +000010095
10096 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10097 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10098 }
10099 if (!isImsAvailableOnDevice()) {
10100 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10101 "IMS not available on device.");
10102 }
10103
10104 final long identity = Binder.clearCallingIdentity();
10105 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010106 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010107 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010108 } finally {
10109 Binder.restoreCallingIdentity(identity);
10110 }
10111 }
10112
10113 /**
10114 * trigger RCS reconfiguration.
10115 */
10116 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010117 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10118 "triggerRcsReconfiguration",
10119 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010120
10121 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10122 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10123 }
10124 if (!isImsAvailableOnDevice()) {
10125 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10126 "IMS not available on device.");
10127 }
10128
10129 final long identity = Binder.clearCallingIdentity();
10130 try {
10131 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10132 } finally {
10133 Binder.restoreCallingIdentity(identity);
10134 }
10135 }
10136
10137 /**
10138 * Provide the client configuration parameters of the RCS application.
10139 */
10140 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010141 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10142 "setRcsClientConfiguration",
10143 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010144
10145 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10146 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10147 }
10148 if (!isImsAvailableOnDevice()) {
10149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10150 "IMS not available on device.");
10151 }
10152
10153 final long identity = Binder.clearCallingIdentity();
10154
10155 try {
10156 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10157 if (configBinder == null) {
10158 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
10159 } else {
10160 configBinder.setRcsClientConfiguration(rcc);
10161 }
10162 } catch (RemoteException e) {
10163 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
10164 } finally {
10165 Binder.restoreCallingIdentity(identity);
10166 }
10167 }
10168
10169 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010170 * Enables or disables the test mode for RCS VoLTE single registration.
10171 */
10172 @Override
10173 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10174 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10175 "setRcsSingleRegistrationTestModeEnabled");
10176
10177 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10178 }
10179
10180 /**
10181 * Gets the test mode for RCS VoLTE single registration.
10182 */
10183 @Override
10184 public boolean getRcsSingleRegistrationTestModeEnabled() {
10185 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10186 "getRcsSingleRegistrationTestModeEnabled");
10187
10188 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10189 }
10190
10191 /**
Hui Wang761a6682020-10-31 05:12:53 +000010192 * Overrides the config of RCS VoLTE single registration enabled for the device.
10193 */
10194 @Override
10195 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10196 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10197 "setDeviceSingleRegistrationEnabledOverride");
10198 enforceModifyPermission();
10199
10200 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10201 : Boolean.parseBoolean(enabledStr);
10202 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010203 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010204 }
10205
10206 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010207 * Sends a device to device communication message. Only usable via shell.
10208 * @param message message to send.
10209 * @param value message value.
10210 */
10211 @Override
10212 public void sendDeviceToDeviceMessage(int message, int value) {
10213 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010214 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010215 enforceModifyPermission();
10216
10217 final long identity = Binder.clearCallingIdentity();
10218 try {
10219 TelephonyConnectionService service =
10220 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10221 if (service == null) {
10222 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10223 return;
10224 }
10225 service.sendTestDeviceToDeviceMessage(message, value);
10226 } finally {
10227 Binder.restoreCallingIdentity(identity);
10228 }
10229 }
10230
Tyler Gunnbabbda02021-02-10 11:05:02 -080010231 /**
10232 * Sets the specified device to device transport active.
10233 * @param transport The transport to set active.
10234 */
10235 @Override
10236 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10237 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10238 "setActiveDeviceToDeviceTransport");
10239 enforceModifyPermission();
10240
10241 final long identity = Binder.clearCallingIdentity();
10242 try {
10243 TelephonyConnectionService service =
10244 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10245 if (service == null) {
10246 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10247 return;
10248 }
10249 service.setActiveDeviceToDeviceTransport(transport);
10250 } finally {
10251 Binder.restoreCallingIdentity(identity);
10252 }
10253 }
Tyler Gunn92479152021-01-20 16:30:10 -080010254
10255 /**
Hui Wang761a6682020-10-31 05:12:53 +000010256 * Gets the config of RCS VoLTE single registration enabled for the device.
10257 */
10258 @Override
10259 public boolean getDeviceSingleRegistrationEnabled() {
10260 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10261 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10262 }
10263
10264 /**
10265 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10266 */
10267 @Override
10268 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10269 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10270 "setCarrierSingleRegistrationEnabledOverride");
10271 enforceModifyPermission();
10272
10273 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10274 : Boolean.parseBoolean(enabledStr);
10275 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10276 subId, enabled);
10277 }
10278
10279 /**
10280 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10281 */
10282 @Override
10283 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10284 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10285 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10286 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010287
10288 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010289 * Overrides the ims feature validation result
10290 */
10291 @Override
10292 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10293 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10294 "setImsFeatureValidationOverride");
10295
10296 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10297 : Boolean.parseBoolean(enabledStr);
10298 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10299 subId, enabled);
10300 }
10301
10302 /**
10303 * Gets the ims feature validation override value
10304 */
10305 @Override
10306 public boolean getImsFeatureValidationOverride(int subId) {
10307 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10308 "getImsFeatureValidationOverride");
10309 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10310 }
10311
10312 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010313 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10314 * their mobile plan.
10315 */
10316 @Override
10317 public String getMobileProvisioningUrl() {
10318 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10319 final long identity = Binder.clearCallingIdentity();
10320 try {
10321 return getDefaultPhone().getMobileProvisioningUrl();
10322 } finally {
10323 Binder.restoreCallingIdentity(identity);
10324 }
10325 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010326
James.cf Linbcdf8b32021-01-14 16:44:13 +080010327 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010328 * Get the EAB contact from the EAB database.
10329 */
10330 @Override
10331 public String getContactFromEab(String contact) {
10332 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10333 enforceModifyPermission();
10334 final long identity = Binder.clearCallingIdentity();
10335 try {
10336 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10337 } finally {
10338 Binder.restoreCallingIdentity(identity);
10339 }
10340 }
10341
10342 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010343 * Remove the EAB contacts from the EAB database.
10344 */
10345 @Override
10346 public int removeContactFromEab(int subId, String contacts) {
10347 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10348 enforceModifyPermission();
10349 final long identity = Binder.clearCallingIdentity();
10350 try {
10351 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10352 } finally {
10353 Binder.restoreCallingIdentity(identity);
10354 }
10355 }
10356
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010357 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010358 public boolean getDeviceUceEnabled() {
10359 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10360 final long identity = Binder.clearCallingIdentity();
10361 try {
10362 return mApp.getDeviceUceEnabled();
10363 } finally {
10364 Binder.restoreCallingIdentity(identity);
10365 }
10366 }
10367
10368 @Override
10369 public void setDeviceUceEnabled(boolean isEnabled) {
10370 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10371 final long identity = Binder.clearCallingIdentity();
10372 try {
10373 mApp.setDeviceUceEnabled(isEnabled);
10374 } finally {
10375 Binder.restoreCallingIdentity(identity);
10376 }
10377 }
10378
Brad Ebinger14d467f2021-02-12 06:18:28 +000010379 /**
10380 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10381 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10382 */
10383 // Used for SHELL command only right now.
10384 @Override
10385 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10386 List<String> featureTags) {
10387 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10388 "addUceRegistrationOverrideShell");
10389 final long identity = Binder.clearCallingIdentity();
10390 try {
10391 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10392 new ArraySet<>(featureTags));
10393 } catch (ImsException e) {
10394 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10395 } finally {
10396 Binder.restoreCallingIdentity(identity);
10397 }
10398 }
10399
10400 /**
10401 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10402 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10403 */
10404 // Used for SHELL command only right now.
10405 @Override
10406 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10407 List<String> featureTags) {
10408 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10409 "removeUceRegistrationOverrideShell");
10410 final long identity = Binder.clearCallingIdentity();
10411 try {
10412 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10413 new ArraySet<>(featureTags));
10414 } catch (ImsException e) {
10415 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10416 } finally {
10417 Binder.restoreCallingIdentity(identity);
10418 }
10419 }
10420
10421 /**
10422 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10423 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10424 */
10425 // Used for SHELL command only right now.
10426 @Override
10427 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10428 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10429 "clearUceRegistrationOverrideShell");
10430 final long identity = Binder.clearCallingIdentity();
10431 try {
10432 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10433 } catch (ImsException e) {
10434 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10435 } finally {
10436 Binder.restoreCallingIdentity(identity);
10437 }
10438 }
10439
10440 /**
10441 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10442 */
10443 // Used for SHELL command only right now.
10444 @Override
10445 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10446 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10447 "getLatestRcsContactUceCapabilityShell");
10448 final long identity = Binder.clearCallingIdentity();
10449 try {
10450 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10451 } catch (ImsException e) {
10452 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10453 } finally {
10454 Binder.restoreCallingIdentity(identity);
10455 }
10456 }
10457
10458 /**
10459 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10460 * device does not have an active PUBLISH.
10461 */
10462 // Used for SHELL command only right now.
10463 @Override
10464 public String getLastUcePidfXmlShell(int subId) {
10465 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10466 final long identity = Binder.clearCallingIdentity();
10467 try {
10468 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10469 } catch (ImsException e) {
10470 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10471 } finally {
10472 Binder.restoreCallingIdentity(identity);
10473 }
10474 }
10475
10476
James.cf Lin4b784aa2021-01-31 03:25:15 +080010477 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010478 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10479 String callingPackage) {
10480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10481 mApp, subId, "setSignalStrengthUpdateRequest");
10482
10483 final int callingUid = Binder.getCallingUid();
10484 // Verify that tha callingPackage belongs to the calling UID
10485 mApp.getSystemService(AppOpsManager.class)
10486 .checkPackage(callingUid, callingPackage);
10487
10488 validateSignalStrengthUpdateRequest(request, callingUid);
10489
10490 final long identity = Binder.clearCallingIdentity();
10491 try {
10492 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10493 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10494
10495 if (result instanceof IllegalStateException) {
10496 throw (IllegalStateException) result;
10497 }
10498 } finally {
10499 Binder.restoreCallingIdentity(identity);
10500 }
10501 }
10502
10503 @Override
10504 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10505 String callingPackage) {
10506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10507 mApp, subId, "clearSignalStrengthUpdateRequest");
10508
10509 final int callingUid = Binder.getCallingUid();
10510 // Verify that tha callingPackage belongs to the calling UID
10511 mApp.getSystemService(AppOpsManager.class)
10512 .checkPackage(callingUid, callingPackage);
10513
10514 final long identity = Binder.clearCallingIdentity();
10515 try {
10516 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10517 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10518
10519 if (result instanceof IllegalStateException) {
10520 throw (IllegalStateException) result;
10521 }
10522 } finally {
10523 Binder.restoreCallingIdentity(identity);
10524 }
10525 }
10526
10527 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10528 int callingUid) {
10529 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10530 // phone/system process do not have further restriction on request
10531 return;
10532 }
10533
10534 // Applications has restrictions on how to use the request:
10535 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10536 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10537 // This is not system caller which has been checked above
10538 throw new IllegalArgumentException(
10539 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10540 }
10541
10542 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10543 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10544 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10545 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10546 || info.isEnabled()) {
10547 throw new IllegalArgumentException(
10548 "Only system can set hide fields in SignalThresholdInfo");
10549 }
10550
10551 // Thresholds length for each RAN need in range. This has been validated in
10552 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10553 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10554 final int[] thresholds = info.getThresholds();
10555 Objects.requireNonNull(thresholds);
10556 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10557 || thresholds.length
10558 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10559 throw new IllegalArgumentException(
10560 "thresholds length is out of range: " + thresholds.length);
10561 }
10562 }
10563 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010564
10565 /**
10566 * Gets the current phone capability.
10567 *
10568 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10569 * @return the PhoneCapability which describes the data connection capability of modem.
10570 * It's used to evaluate possible phone config change, for example from single
10571 * SIM device to multi-SIM device.
10572 */
10573 @Override
10574 public PhoneCapability getPhoneCapability() {
10575 enforceReadPrivilegedPermission("getPhoneCapability");
10576 final long identity = Binder.clearCallingIdentity();
10577 try {
10578 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10579 } finally {
10580 Binder.restoreCallingIdentity(identity);
10581 }
10582 }
Michele Berionne5e411512020-11-13 02:36:59 +000010583
10584 /**
10585 * Prepare TelephonyManager for an unattended reboot. The reboot is
10586 * required to be done shortly after the API is invoked.
10587 */
10588 @Override
10589 @TelephonyManager.PrepareUnattendedRebootResult
10590 public int prepareForUnattendedReboot() {
10591 enforceRebootPermission();
10592
10593 final long identity = Binder.clearCallingIdentity();
10594 try {
10595 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10596 } finally {
10597 Binder.restoreCallingIdentity(identity);
10598 }
10599 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010600
10601 /**
10602 * Request to get the current slicing configuration including URSP rules and
10603 * NSSAIs (configured, allowed and rejected).
10604 *
10605 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10606 */
10607 @Override
10608 public void getSlicingConfig(ResultReceiver callback) {
10609 enforceReadPrivilegedPermission("getSlicingConfig");
10610
10611 final long identity = Binder.clearCallingIdentity();
10612 try {
10613 Phone phone = getDefaultPhone();
10614 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10615 } finally {
10616 Binder.restoreCallingIdentity(identity);
10617 }
10618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010619}