blob: 23cb919b2b41c27f024eeea65d1000886804199b [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;
Hall Liu82694d52020-12-11 18:22:04 -080032import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070033import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070034import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.content.Context;
36import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070037import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070038import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080039import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070040import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.net.Uri;
42import android.os.AsyncResult;
43import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080044import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Bundle;
46import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.Looper;
49import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070050import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080051import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070052import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070053import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080054import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080055import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070056import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070057import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080058import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070060import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070062import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070063import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080064import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070065import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090066import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080067import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080068import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070069import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070070import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080071import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080072import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070073import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080074import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070075import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080076import android.telephony.CellIdentityCdma;
77import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070079import android.telephony.CellInfoGsm;
80import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080082import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070083import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070084import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070085import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080086import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070087import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080088import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070089import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080090import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080091import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070092import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080095import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080096import android.telephony.SignalStrengthUpdateRequest;
97import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080098import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080099import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800100import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700101import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700102import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800103import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800104import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800105import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000106import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700107import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700108import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800109import android.telephony.data.ApnSetting;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800110import android.telephony.data.SlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800111import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700112import android.telephony.gba.GbaAuthRequest;
113import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700114import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000116import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000117import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700118import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800120import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700121import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800122import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700123import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000124import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700125import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800127import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800128import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800129import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800131import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700132import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800134import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800135
Andrew Lee312e8172014-10-23 17:01:36 -0700136import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800137import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800138import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800139import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700141import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700142import com.android.internal.telephony.CarrierInfoManager;
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;
351
Wink Saville3ab207e2014-11-20 13:07:20 -0800352 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800353 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800354 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700355 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800356 private AppOpsManager mAppOps;
357 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800358 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700360 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800361 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Peter Wangdafb9ac2020-01-15 14:13:38 -0800363 /** User Activity */
364 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800365 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
366
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700367 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
368
Derek Tan97ebb422014-09-05 16:55:38 -0700369 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
370 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800371 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800372 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700373
Michelecea4cf22018-12-21 15:00:11 -0800374 // String to store multi SIM allowed
375 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
376
Derek Tan740e1672017-06-27 14:56:27 -0700377 // The AID of ISD-R.
378 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
379
yinxub1bed742017-04-17 11:45:04 -0700380 private NetworkScanRequestTracker mNetworkScanRequestTracker;
381
David Kelly5e06a7f2018-03-12 14:10:59 +0000382 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
383 private static final int MANUFACTURER_CODE_LENGTH = 8;
384
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800385 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800386 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800387
Derek Tan89e89d42014-07-08 17:00:10 -0700388 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700389 * Experiment flag to enable erase modem config on reset network, default value is false
390 */
391 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
392 "reset_network_erase_modem_config_enabled";
393
Rambo Wang0f050d82021-02-12 11:43:36 -0800394 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
395
Naina Nallurid63128d2019-09-17 14:10:30 -0700396 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700397 * A request object to use for transmitting data to an ICC.
398 */
399 private static final class IccAPDUArgument {
400 public int channel, cla, command, p1, p2, p3;
401 public String data;
402
403 public IccAPDUArgument(int channel, int cla, int command,
404 int p1, int p2, int p3, String data) {
405 this.channel = channel;
406 this.cla = cla;
407 this.command = command;
408 this.p1 = p1;
409 this.p2 = p2;
410 this.p3 = p3;
411 this.data = data;
412 }
413 }
414
415 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700416 * A request object to use for transmitting data to an ICC.
417 */
418 private static final class ManualNetworkSelectionArgument {
419 public OperatorInfo operatorInfo;
420 public boolean persistSelection;
421
422 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
423 this.operatorInfo = operatorInfo;
424 this.persistSelection = persistSelection;
425 }
426 }
427
428 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
430 * request after sending. The main thread will notify the request when it is complete.
431 */
432 private static final class MainThreadRequest {
433 /** The argument to use for the request */
434 public Object argument;
435 /** The result of the request that is run on the main thread */
436 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800437 // The subscriber id that this request applies to. Defaults to
438 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
439 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440
Nathan Harold92bed182018-10-12 18:16:49 -0700441 // In cases where subId is unavailable, the caller needs to specify the phone.
442 public Phone phone;
443
vagdeviaf9a5b92018-08-15 16:01:53 -0700444 public WorkSource workSource;
445
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 public MainThreadRequest(Object argument) {
447 this.argument = argument;
448 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800449
Nathan Harold92bed182018-10-12 18:16:49 -0700450 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
451 this.argument = argument;
452 if (phone != null) {
453 this.phone = phone;
454 }
455 this.workSource = workSource;
456 }
457
vagdeviaf9a5b92018-08-15 16:01:53 -0700458 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800459 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800460 if (subId != null) {
461 this.subId = subId;
462 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700463 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 }
466
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800467 private static final class IncomingThirdPartyCallArgs {
468 public final ComponentName component;
469 public final String callId;
470 public final String callerDisplayName;
471
472 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
473 String callerDisplayName) {
474 this.component = component;
475 this.callId = callId;
476 this.callerDisplayName = callerDisplayName;
477 }
478 }
479
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480 /**
481 * A handler that processes messages on the main thread in the phone process. Since many
482 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
483 * inbound binder threads to the main thread in the phone process. The Binder thread
484 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
485 * on, which will be notified when the operation completes and will contain the result of the
486 * request.
487 *
488 * <p>If a MainThreadRequest object is provided in the msg.obj field,
489 * note that request.result must be set to something non-null for the calling thread to
490 * unblock.
491 */
492 private final class MainThreadHandler extends Handler {
493 @Override
494 public void handleMessage(Message msg) {
495 MainThreadRequest request;
496 Message onCompleted;
497 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800500 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501
502 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 case CMD_HANDLE_USSD_REQUEST: {
504 request = (MainThreadRequest) msg.obj;
505 final Phone phone = getPhoneFromRequest(request);
506 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
507 String ussdRequest = ussdObject.first;
508 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700509
Pengquan Menga1bb6272018-09-06 09:59:22 -0700510 if (!isUssdApiAllowed(request.subId)) {
511 // Carrier does not support use of this API, return failure.
512 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
513 UssdResponse response = new UssdResponse(ussdRequest, null);
514 Bundle returnData = new Bundle();
515 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
516 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700517
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 request.result = true;
519 notifyRequester(request);
520 return;
521 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700522
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 try {
524 request.result = phone != null
525 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
526 } catch (CallStateException cse) {
527 request.result = false;
528 }
529 // Wake up the requesting thread
530 notifyRequester(request);
531 break;
pkanwar32d516d2016-10-14 19:37:38 -0700532 }
533
Yorke Lee716f67e2015-06-17 15:39:16 -0700534 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700536 final Phone phone = getPhoneFromRequest(request);
537 request.result = phone != null ?
538 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
539 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800548 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 if (uiccCard == null) {
550 loge("iccTransmitApduLogicalChannel: No UICC");
551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
555 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 iccArgument.channel, iccArgument.cla, iccArgument.command,
558 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 break;
562
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
566 if (ar.exception == null && ar.result != null) {
567 request.result = ar.result;
568 } else {
569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
570 if (ar.result == null) {
571 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800572 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800574 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 } else {
576 loge("iccTransmitApduLogicalChannel: Unknown exception");
577 }
578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 break;
581
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
583 request = (MainThreadRequest) msg.obj;
584 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800585 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 if (uiccCard == null) {
587 loge("iccTransmitApduBasicChannel: No UICC");
588 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 } else {
591 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
592 request);
593 uiccCard.iccTransmitApduBasicChannel(
594 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
595 iccArgument.p3, iccArgument.data, onCompleted);
596 }
597 break;
598
599 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
600 ar = (AsyncResult) msg.obj;
601 request = (MainThreadRequest) ar.userObj;
602 if (ar.exception == null && ar.result != null) {
603 request.result = ar.result;
604 } else {
605 request.result = new IccIoResult(0x6F, 0, (byte[])null);
606 if (ar.result == null) {
607 loge("iccTransmitApduBasicChannel: Empty response");
608 } else if (ar.exception instanceof CommandException) {
609 loge("iccTransmitApduBasicChannel: CommandException: " +
610 ar.exception);
611 } else {
612 loge("iccTransmitApduBasicChannel: Unknown exception");
613 }
614 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 break;
617
618 case CMD_EXCHANGE_SIM_IO:
619 request = (MainThreadRequest) msg.obj;
620 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800621 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 if (uiccCard == null) {
623 loge("iccExchangeSimIO: No UICC");
624 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 } else {
627 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
628 request);
629 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
630 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
631 iccArgument.data, onCompleted);
632 }
633 break;
634
635 case EVENT_EXCHANGE_SIM_IO_DONE:
636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
638 if (ar.exception == null && ar.result != null) {
639 request.result = ar.result;
640 } else {
641 request.result = new IccIoResult(0x6f, 0, (byte[])null);
642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 break;
645
Derek Tan4d5e5c12014-02-04 11:54:58 -0800646 case CMD_SEND_ENVELOPE:
647 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800648 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 if (uiccCard == null) {
650 loge("sendEnvelopeWithStatus: No UICC");
651 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 } else {
654 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
655 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
656 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800657 break;
658
659 case EVENT_SEND_ENVELOPE_DONE:
660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800664 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700665 request.result = new IccIoResult(0x6F, 0, (byte[])null);
666 if (ar.result == null) {
667 loge("sendEnvelopeWithStatus: Empty response");
668 } else if (ar.exception instanceof CommandException) {
669 loge("sendEnvelopeWithStatus: CommandException: " +
670 ar.exception);
671 } else {
672 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
673 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800676 break;
677
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 case CMD_OPEN_CHANNEL:
679 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800680 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800681 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 if (uiccCard == null) {
683 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800684 request.result = new IccOpenLogicalChannelResponse(-1,
685 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700686 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700687 } else {
688 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800689 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
690 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
694 case EVENT_OPEN_CHANNEL_DONE:
695 ar = (AsyncResult) msg.obj;
696 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 int[] result = (int[]) ar.result;
700 int channelId = result[0];
701 byte[] selectResponse = null;
702 if (result.length > 1) {
703 selectResponse = new byte[result.length - 1];
704 for (int i = 1; i < result.length; ++i) {
705 selectResponse[i - 1] = (byte) result[i];
706 }
707 }
708 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700709 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 if (ar.result == null) {
712 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 if (ar.exception != null) {
715 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
716 }
717
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700718 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700719 if (ar.exception instanceof CommandException) {
720 CommandException.Error error =
721 ((CommandException) (ar.exception)).getCommandError();
722 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700723 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700724 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700725 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 }
727 }
728 openChannelResp = new IccOpenLogicalChannelResponse(
729 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700731 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 break;
734
735 case CMD_CLOSE_CHANNEL:
736 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800737 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700738 if (uiccCard == null) {
739 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900740 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 } else {
743 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
744 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
745 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700746 break;
747
748 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800749 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
750 break;
751
752 case CMD_NV_READ_ITEM:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800755 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
756 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800757 break;
758
759 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800762 if (ar.exception == null && ar.result != null) {
763 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800765 request.result = "";
766 if (ar.result == null) {
767 loge("nvReadItem: Empty response");
768 } else if (ar.exception instanceof CommandException) {
769 loge("nvReadItem: CommandException: " +
770 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700771 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800772 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 }
774 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 break;
777
Jake Hambye994d462014-02-03 13:10:13 -0800778 case CMD_NV_WRITE_ITEM:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
781 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700783 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
786 case EVENT_NV_WRITE_ITEM_DONE:
787 handleNullReturnEvent(msg, "nvWriteItem");
788 break;
789
790 case CMD_NV_WRITE_CDMA_PRL:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800793 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800794 break;
795
796 case EVENT_NV_WRITE_CDMA_PRL_DONE:
797 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
798 break;
799
chen xu6dac5ab2018-10-26 17:39:23 -0700800 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800801 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700802 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800803 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800804 break;
805
chen xu6dac5ab2018-10-26 17:39:23 -0700806 case EVENT_RESET_MODEM_CONFIG_DONE:
807 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800808 break;
809
Sooraj Sasindran37444802020-08-11 10:40:43 -0700810 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
811 request = (MainThreadRequest) msg.obj;
812 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
813 request);
814 Phone phone = getPhoneFromRequest(request);
815 if (phone != null) {
816 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
817 } else {
818 loge("isNRDualConnectivityEnabled: No phone object");
819 request.result = false;
820 notifyRequester(request);
821 }
822 break;
823 }
824
825 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
826 ar = (AsyncResult) msg.obj;
827 request = (MainThreadRequest) ar.userObj;
828 if (ar.exception == null && ar.result != null) {
829 request.result = ar.result;
830 } else {
831 // request.result must be set to something non-null
832 // for the calling thread to unblock
833 if (request.result != null) {
834 request.result = ar.result;
835 } else {
836 request.result = false;
837 }
838 if (ar.result == null) {
839 loge("isNRDualConnectivityEnabled: Empty response");
840 } else if (ar.exception instanceof CommandException) {
841 loge("isNRDualConnectivityEnabled: CommandException: "
842 + ar.exception);
843 } else {
844 loge("isNRDualConnectivityEnabled: Unknown exception");
845 }
846 }
847 notifyRequester(request);
848 break;
849
850 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
851 request = (MainThreadRequest) msg.obj;
852 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
853 Phone phone = getPhoneFromRequest(request);
854 if (phone != null) {
855 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
856 request.workSource);
857 } else {
858 loge("enableNrDualConnectivity: No phone object");
859 request.result =
860 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
861 notifyRequester(request);
862 }
863 break;
864 }
865
866 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null) {
870 request.result =
871 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
872 } else {
873 request.result =
874 TelephonyManager
875 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
876 if (ar.exception instanceof CommandException) {
877 CommandException.Error error =
878 ((CommandException) (ar.exception)).getCommandError();
879 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
880 request.result =
881 TelephonyManager
882 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000883 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
884 request.result =
885 TelephonyManager
886 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700887 }
888 loge("enableNrDualConnectivity" + ": CommandException: "
889 + ar.exception);
890 } else {
891 loge("enableNrDualConnectivity" + ": Unknown exception");
892 }
893 }
894 notifyRequester(request);
895 break;
896 }
897
SongFerngWang3ef3e072020-12-21 16:41:52 +0800898 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800899 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800900 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
901 request);
902 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 break;
904
SongFerngWang3ef3e072020-12-21 16:41:52 +0800905 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 ar = (AsyncResult) msg.obj;
907 request = (MainThreadRequest) ar.userObj;
908 if (ar.exception == null && ar.result != null) {
909 request.result = ar.result; // Integer
910 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530911 // request.result must be set to something non-null
912 // for the calling thread to unblock
913 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800914 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800915 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800916 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800917 loge("getAllowedNetworkTypesBitmask: CommandException: "
918 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800920 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 }
922 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800924 break;
925
SongFerngWang3ef3e072020-12-21 16:41:52 +0800926 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800927 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800928 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
929 request);
930 Pair<Integer, Long> reasonWithNetworkTypes =
931 (Pair<Integer, Long>) request.argument;
932 getPhoneFromRequest(request).setAllowedNetworkTypes(
933 reasonWithNetworkTypes.first,
934 reasonWithNetworkTypes.second,
935 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800936 break;
937
SongFerngWang3ef3e072020-12-21 16:41:52 +0800938 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
939 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800940 break;
941
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000942 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
943 request = (MainThreadRequest)msg.obj;
944 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800945 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000946 break;
947
948 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
949 ar = (AsyncResult)msg.obj;
950 request = (MainThreadRequest)ar.userObj;
951 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700952 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000953 break;
954
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800955 case CMD_SET_VOICEMAIL_NUMBER:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
958 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800959 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
960 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800961 break;
962
963 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
964 handleNullReturnEvent(msg, "setVoicemailNumber");
965 break;
966
Stuart Scott54788802015-03-30 13:18:01 -0700967 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
970 request);
971 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
972 break;
973
974 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
975 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
976 break;
977
Shishir Agrawal302c8692015-06-19 13:49:39 -0700978 case CMD_PERFORM_NETWORK_SCAN:
979 request = (MainThreadRequest) msg.obj;
980 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
981 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
982 break;
983
Hall Liu27d24262020-09-18 19:04:59 -0700984 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700987 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
988 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
989 request.argument;
990 int callForwardingReason = args.first;
991 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800992 break;
Hall Liu27d24262020-09-18 19:04:59 -0700993 }
994 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700997 TelephonyManager.CallForwardingInfoCallback callback =
998 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
999 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001000 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001001 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001002 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1003 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1004 // Service Class is a bit mask per 3gpp 27.007. Search for
1005 // any service for voice call.
1006 if ((callForwardInfo.serviceClass
1007 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001008 callForwardingInfo = new CallForwardingInfo(true,
1009 callForwardInfo.reason,
1010 callForwardInfo.number,
1011 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001012 break;
1013 }
1014 }
1015 // Didn't find a call forward info for voice call.
1016 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001017 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1018 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001019 }
Hall Liu27d24262020-09-18 19:04:59 -07001020 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001021 } else {
1022 if (ar.result == null) {
1023 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1024 }
1025 if (ar.exception != null) {
1026 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1027 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001028 int errorCode = TelephonyManager
1029 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001030 if (ar.exception instanceof CommandException) {
1031 CommandException.Error error =
1032 ((CommandException) (ar.exception)).getCommandError();
1033 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001034 errorCode = TelephonyManager
1035 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001036 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001037 errorCode = TelephonyManager
1038 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001039 }
1040 }
Hall Liu27d24262020-09-18 19:04:59 -07001041 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001042 }
Shuo Qian4a594052020-01-23 11:59:30 -08001043 break;
Hall Liu27d24262020-09-18 19:04:59 -07001044 }
Shuo Qian4a594052020-01-23 11:59:30 -08001045
Hall Liu27d24262020-09-18 19:04:59 -07001046 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001049 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001050 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001051 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1052 request.argument).first;
1053 request.phone.setCallForwardingOption(
1054 callForwardingInfoToSet.isEnabled()
1055 ? CommandsInterface.CF_ACTION_ENABLE
1056 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001057 callForwardingInfoToSet.getReason(),
1058 callForwardingInfoToSet.getNumber(),
1059 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1060 break;
Hall Liu27d24262020-09-18 19:04:59 -07001061 }
Shuo Qian4a594052020-01-23 11:59:30 -08001062
Hall Liu27d24262020-09-18 19:04:59 -07001063 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001066 Consumer<Integer> callback =
1067 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1068 request.argument).second;
1069 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001070 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001071 int errorCode = TelephonyManager.CallForwardingInfoCallback
1072 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001073 if (ar.exception instanceof CommandException) {
1074 CommandException.Error error =
1075 ((CommandException) (ar.exception)).getCommandError();
1076 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001077 errorCode = TelephonyManager.CallForwardingInfoCallback
1078 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001079 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001080 errorCode = TelephonyManager.CallForwardingInfoCallback
1081 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001082 }
1083 }
1084 callback.accept(errorCode);
1085 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001086 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001087 }
Shuo Qian4a594052020-01-23 11:59:30 -08001088 break;
Hall Liu27d24262020-09-18 19:04:59 -07001089 }
Shuo Qian4a594052020-01-23 11:59:30 -08001090
Hall Liu27d24262020-09-18 19:04:59 -07001091 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001092 request = (MainThreadRequest) msg.obj;
1093 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1094 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1095 break;
Hall Liu27d24262020-09-18 19:04:59 -07001096 }
Shuo Qian4a594052020-01-23 11:59:30 -08001097
Hall Liu27d24262020-09-18 19:04:59 -07001098 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001101 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001102 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1103 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001104 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001105 // Service Class is a bit mask per 3gpp 27.007.
1106 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001107 if (callForwardResults.length > 1
1108 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001109 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001110 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001111 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1112 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001113 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001114 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001115 }
1116 } else {
1117 if (ar.result == null) {
1118 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1119 }
1120 if (ar.exception != null) {
1121 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1122 }
1123 if (ar.exception instanceof CommandException) {
1124 CommandException.Error error =
1125 ((CommandException) (ar.exception)).getCommandError();
1126 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1127 callForwardingStatus =
1128 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1129 }
1130 }
1131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 break;
Hall Liu27d24262020-09-18 19:04:59 -07001134 }
Shuo Qian4a594052020-01-23 11:59:30 -08001135
Hall Liu27d24262020-09-18 19:04:59 -07001136 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001137 request = (MainThreadRequest) msg.obj;
1138 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001139 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1140 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001141 break;
Hall Liu27d24262020-09-18 19:04:59 -07001142 }
Shuo Qian4a594052020-01-23 11:59:30 -08001143
Hall Liu27d24262020-09-18 19:04:59 -07001144 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001147 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1148 Consumer<Integer> callback =
1149 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1150 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001151 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001152 if (ar.exception instanceof CommandException) {
1153 CommandException.Error error =
1154 ((CommandException) (ar.exception)).getCommandError();
1155 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1156 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1157 } else {
1158 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1159 }
1160 } else {
1161 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1162 }
1163 } else {
1164 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1165 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001166 }
Shuo Qian4a594052020-01-23 11:59:30 -08001167 break;
Hall Liu27d24262020-09-18 19:04:59 -07001168 }
Shuo Qian4a594052020-01-23 11:59:30 -08001169
Shishir Agrawal302c8692015-06-19 13:49:39 -07001170 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 CellNetworkScanResult cellScanResult;
1174 if (ar.exception == null && ar.result != null) {
1175 cellScanResult = new CellNetworkScanResult(
1176 CellNetworkScanResult.STATUS_SUCCESS,
1177 (List<OperatorInfo>) ar.result);
1178 } else {
1179 if (ar.result == null) {
1180 loge("getCellNetworkScanResults: Empty response");
1181 }
1182 if (ar.exception != null) {
1183 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1184 }
1185 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1186 if (ar.exception instanceof CommandException) {
1187 CommandException.Error error =
1188 ((CommandException) (ar.exception)).getCommandError();
1189 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1190 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1191 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1192 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1193 }
1194 }
1195 cellScanResult = new CellNetworkScanResult(errorCode, null);
1196 }
1197 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001198 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 break;
1200
1201 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1202 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001203 ManualNetworkSelectionArgument selArg =
1204 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001205 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1206 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001207 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1208 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001209 break;
1210
1211 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
1214 if (ar.exception == null) {
1215 request.result = true;
1216 } else {
1217 request.result = false;
1218 loge("setNetworkSelectionModeManual " + ar.exception);
1219 }
1220 notifyRequester(request);
1221 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001222 break;
1223
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001224 case CMD_GET_MODEM_ACTIVITY_INFO:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001227 if (defaultPhone != null) {
1228 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001229 } else {
1230 ResultReceiver result = (ResultReceiver) request.argument;
1231 Bundle bundle = new Bundle();
1232 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001233 new ModemActivityInfo(0, 0, 0,
1234 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001235 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001236 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001237 break;
1238
Hall Liud0f208c2020-10-14 16:54:44 -07001239 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 ar = (AsyncResult) msg.obj;
1241 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001242 ResultReceiver result = (ResultReceiver) request.argument;
1243
Hall Liud0f208c2020-10-14 16:54:44 -07001244 ModemActivityInfo ret = null;
1245 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001246 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001247 // Update the last modem activity info and the result of the request.
1248 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1249 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001250 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001251 int[] txTimeMs = info.getTransmitTimeMillis();
1252 int[] lastModemTxTimeMs = mLastModemActivityInfo
1253 .getTransmitTimeMillis();
1254 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1255 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1256 }
Hall Liu49656c02020-10-09 19:00:11 -07001257 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001258 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1259 + mLastModemActivityInfo.getSleepTimeMillis());
1260 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1261 + mLastModemActivityInfo.getIdleTimeMillis());
1262 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1263 mLastModemActivityInfo.setReceiveTimeMillis(
1264 info.getReceiveTimeMillis()
1265 + mLastModemActivityInfo.getReceiveTimeMillis());
1266 }
Hall Liu49656c02020-10-09 19:00:11 -07001267 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001268 mLastModemActivityInfo.getSleepTimeMillis(),
1269 mLastModemActivityInfo.getIdleTimeMillis(),
1270 mLastModemActivityInfo.getTransmitTimeMillis(),
1271 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001272 } else {
1273 if (ar.result == null) {
1274 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001275 error = TelephonyManager.ModemActivityInfoException
1276 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001277 } else if (ar.exception instanceof CommandException) {
1278 loge("queryModemActivityInfo: CommandException: " +
1279 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001280 error = TelephonyManager.ModemActivityInfoException
1281 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001282 } else {
1283 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001284 error = TelephonyManager.ModemActivityInfoException
1285 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001286 }
1287 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001288 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001289 if (ret != null) {
1290 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1291 } else {
1292 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1293 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001294 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001295 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001296 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001297 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001298
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 case CMD_SET_ALLOWED_CARRIERS:
1300 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001301 CarrierRestrictionRules argument =
1302 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001304 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001305 break;
1306
1307 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
1310 if (ar.exception == null && ar.result != null) {
1311 request.result = ar.result;
1312 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001313 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1314 if (ar.exception instanceof CommandException) {
1315 loge("setAllowedCarriers: CommandException: " + ar.exception);
1316 CommandException.Error error =
1317 ((CommandException) (ar.exception)).getCommandError();
1318 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1319 request.result =
1320 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1321 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001322 } else {
1323 loge("setAllowedCarriers: Unknown exception");
1324 }
1325 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001326 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001327 break;
1328
1329 case CMD_GET_ALLOWED_CARRIERS:
1330 request = (MainThreadRequest) msg.obj;
1331 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001332 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001333 break;
1334
1335 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
1338 if (ar.exception == null && ar.result != null) {
1339 request.result = ar.result;
1340 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001341 request.result = new IllegalStateException(
1342 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001343 if (ar.result == null) {
1344 loge("getAllowedCarriers: Empty response");
1345 } else if (ar.exception instanceof CommandException) {
1346 loge("getAllowedCarriers: CommandException: " +
1347 ar.exception);
1348 } else {
1349 loge("getAllowedCarriers: Unknown exception");
1350 }
1351 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001352 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001353 break;
1354
Nathan Haroldb3014052017-01-25 15:57:32 -08001355 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1356 ar = (AsyncResult) msg.obj;
1357 request = (MainThreadRequest) ar.userObj;
1358 if (ar.exception == null && ar.result != null) {
1359 request.result = ar.result;
1360 } else {
1361 request.result = new IllegalArgumentException(
1362 "Failed to retrieve Forbidden Plmns");
1363 if (ar.result == null) {
1364 loge("getForbiddenPlmns: Empty response");
1365 } else {
1366 loge("getForbiddenPlmns: Unknown exception");
1367 }
1368 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001370 break;
1371
1372 case CMD_GET_FORBIDDEN_PLMNS:
1373 request = (MainThreadRequest) msg.obj;
1374 uiccCard = getUiccCardFromRequest(request);
1375 if (uiccCard == null) {
1376 loge("getForbiddenPlmns() UiccCard is null");
1377 request.result = new IllegalArgumentException(
1378 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001379 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001380 break;
1381 }
1382 Integer appType = (Integer) request.argument;
1383 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1384 if (uiccApp == null) {
1385 loge("getForbiddenPlmns() no app with specified type -- "
1386 + appType);
1387 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001388 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001389 break;
1390 } else {
1391 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1392 + " specified type -- " + appType);
1393 }
1394 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1395 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1396 onCompleted);
1397 break;
1398
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001399 case CMD_SWITCH_SLOTS:
1400 request = (MainThreadRequest) msg.obj;
1401 int[] physicalSlots = (int[]) request.argument;
1402 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1403 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1404 break;
1405
1406 case EVENT_SWITCH_SLOTS_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001410 notifyRequester(request);
1411 break;
1412 case CMD_GET_NETWORK_SELECTION_MODE:
1413 request = (MainThreadRequest) msg.obj;
1414 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1415 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1416 break;
1417
1418 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception != null) {
1422 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1423 } else {
1424 int mode = ((int[]) ar.result)[0];
1425 if (mode == 0) {
1426 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1427 } else {
1428 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1429 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001430 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001431 notifyRequester(request);
1432 break;
1433 case CMD_GET_CDMA_ROAMING_MODE:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1436 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1437 break;
1438 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 if (ar.exception != null) {
1442 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1443 } else {
1444 request.result = ((int[]) ar.result)[0];
1445 }
1446 notifyRequester(request);
1447 break;
1448 case CMD_SET_CDMA_ROAMING_MODE:
1449 request = (MainThreadRequest) msg.obj;
1450 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1451 int mode = (int) request.argument;
1452 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1453 break;
1454 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1455 ar = (AsyncResult) msg.obj;
1456 request = (MainThreadRequest) ar.userObj;
1457 request.result = ar.exception == null;
1458 notifyRequester(request);
1459 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001460 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1461 request = (MainThreadRequest) msg.obj;
1462 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1463 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1464 break;
1465 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1466 ar = (AsyncResult) msg.obj;
1467 request = (MainThreadRequest) ar.userObj;
1468 if (ar.exception != null) {
1469 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1470 } else {
1471 request.result = ((int[]) ar.result)[0];
1472 }
1473 notifyRequester(request);
1474 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001475 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1476 request = (MainThreadRequest) msg.obj;
1477 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1478 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001479 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1480 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001481 break;
1482 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1483 ar = (AsyncResult) msg.obj;
1484 request = (MainThreadRequest) ar.userObj;
1485 request.result = ar.exception == null;
1486 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001487 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001488 case CMD_GET_ALL_CELL_INFO:
1489 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001491 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 case EVENT_GET_ALL_CELL_INFO_DONE:
1494 ar = (AsyncResult) msg.obj;
1495 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001496 // If a timeout occurs, the response will be null
1497 request.result = (ar.exception == null && ar.result != null)
1498 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001499 synchronized (request) {
1500 request.notifyAll();
1501 }
1502 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001503 case CMD_REQUEST_CELL_INFO_UPDATE:
1504 request = (MainThreadRequest) msg.obj;
1505 request.phone.requestCellInfoUpdate(request.workSource,
1506 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1507 break;
1508 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1512 try {
1513 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001514 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001515 cb.onError(
1516 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1517 ar.exception.getClass().getName(),
1518 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001519 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001520 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001521 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001522 } else {
1523 // use the result as returned
1524 cb.onCellInfo((List<CellInfo>) ar.result);
1525 }
1526 } catch (RemoteException re) {
1527 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1528 }
1529 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001530 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001531 request = (MainThreadRequest) msg.obj;
1532 WorkSource ws = (WorkSource) request.argument;
1533 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001534 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001535 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001536 }
1537 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001538 ar = (AsyncResult) msg.obj;
1539 request = (MainThreadRequest) ar.userObj;
1540 if (ar.exception == null) {
1541 request.result = ar.result;
1542 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001543 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001544 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001545 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001546 }
1547
1548 synchronized (request) {
1549 request.notifyAll();
1550 }
1551 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001552 }
chen xu6dac5ab2018-10-26 17:39:23 -07001553 case CMD_MODEM_REBOOT:
1554 request = (MainThreadRequest) msg.obj;
1555 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001556 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001557 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001558 case EVENT_CMD_MODEM_REBOOT_DONE:
1559 handleNullReturnEvent(msg, "rebootModem");
1560 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001561 case CMD_REQUEST_ENABLE_MODEM:
1562 request = (MainThreadRequest) msg.obj;
1563 boolean enable = (boolean) request.argument;
1564 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001565 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001566 PhoneConfigurationManager.getInstance()
1567 .enablePhone(request.phone, enable, onCompleted);
1568 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001569 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001570 ar = (AsyncResult) msg.obj;
1571 request = (MainThreadRequest) ar.userObj;
1572 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001573 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001574 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001575 if ((boolean) request.result) {
1576 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1577 updateModemStateMetrics();
1578 } else {
1579 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1580 + ar.exception);
1581 }
1582 notifyRequester(request);
1583 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001584 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001585 case CMD_GET_MODEM_STATUS:
1586 request = (MainThreadRequest) msg.obj;
1587 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1588 PhoneConfigurationManager.getInstance()
1589 .getPhoneStatusFromModem(request.phone, onCompleted);
1590 break;
1591 case EVENT_GET_MODEM_STATUS_DONE:
1592 ar = (AsyncResult) msg.obj;
1593 request = (MainThreadRequest) ar.userObj;
1594 int id = request.phone.getPhoneId();
1595 if (ar.exception == null && ar.result != null) {
1596 request.result = ar.result;
1597 //update the cache as modem status has changed
1598 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1599 (boolean) request.result);
1600 } else {
1601 // Return true if modem status cannot be retrieved. For most cases,
1602 // modem status is on. And for older version modems, GET_MODEM_STATUS
1603 // and disable modem are not supported. Modem is always on.
1604 // TODO: this should be fixed in R to support a third
1605 // status UNKNOWN b/131631629
1606 request.result = true;
1607 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1608 + ar.exception);
1609 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001610 notifyRequester(request);
1611 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001612 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1613 request = (MainThreadRequest) msg.obj;
1614 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1615 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1616 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1617 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1618 break;
1619 }
1620 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1624 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1625 args.second.accept(ar.exception == null);
1626 notifyRequester(request);
1627 break;
1628 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001629 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1630 request = (MainThreadRequest) msg.obj;
1631 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1632 Phone phone = getPhoneFromRequest(request);
1633 if (phone != null) {
1634 phone.getSystemSelectionChannels(onCompleted);
1635 } else {
1636 loge("getSystemSelectionChannels: No phone object");
1637 request.result = new ArrayList<RadioAccessSpecifier>();
1638 notifyRequester(request);
1639 }
1640 break;
1641 }
1642 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1643 ar = (AsyncResult) msg.obj;
1644 request = (MainThreadRequest) ar.userObj;
1645 if (ar.exception == null && ar.result != null) {
1646 request.result = ar.result;
1647 } else {
1648 request.result = new IllegalArgumentException(
1649 "Failed to retrieve system selection channels");
1650 if (ar.result == null) {
1651 loge("getSystemSelectionChannels: Empty response");
1652 } else {
1653 loge("getSystemSelectionChannels: Unknown exception");
1654 }
1655 }
1656 notifyRequester(request);
1657 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001658 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 if (ar.exception == null && ar.result != null) {
1662 request.result = ar.result;
1663 } else {
1664 request.result = -1;
1665 loge("Failed to set Forbidden Plmns");
1666 if (ar.result == null) {
1667 loge("setForbidenPlmns: Empty response");
1668 } else if (ar.exception != null) {
1669 loge("setForbiddenPlmns: Exception: " + ar.exception);
1670 request.result = -1;
1671 } else {
1672 loge("setForbiddenPlmns: Unknown exception");
1673 }
1674 }
1675 notifyRequester(request);
1676 break;
1677 case CMD_SET_FORBIDDEN_PLMNS:
1678 request = (MainThreadRequest) msg.obj;
1679 uiccCard = getUiccCardFromRequest(request);
1680 if (uiccCard == null) {
1681 loge("setForbiddenPlmns: UiccCard is null");
1682 request.result = -1;
1683 notifyRequester(request);
1684 break;
1685 }
1686 Pair<Integer, List<String>> setFplmnsArgs =
1687 (Pair<Integer, List<String>>) request.argument;
1688 appType = setFplmnsArgs.first;
1689 List<String> fplmns = setFplmnsArgs.second;
1690 uiccApp = uiccCard.getApplicationByType(appType);
1691 if (uiccApp == null) {
1692 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1693 request.result = -1;
1694 loge("Failed to get UICC App");
1695 notifyRequester(request);
1696 } else {
1697 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1698 ((SIMRecords) uiccApp.getIccRecords())
1699 .setForbiddenPlmns(onCompleted, fplmns);
1700 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001701 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001702 case CMD_ERASE_MODEM_CONFIG:
1703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1705 defaultPhone.eraseModemConfig(onCompleted);
1706 break;
1707 case EVENT_ERASE_MODEM_CONFIG_DONE:
1708 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001709 break;
zoey chene02881a2019-12-30 16:11:23 +08001710
Kai Shif70f46f2021-03-03 13:59:46 -08001711 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1712 request = (MainThreadRequest) msg.obj;
1713 request.result = defaultPhone.eraseDataInSharedPreferences();
1714 notifyRequester(request);
1715 break;
1716
zoey chene02881a2019-12-30 16:11:23 +08001717 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1718 request = (MainThreadRequest) msg.obj;
1719 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1720 Pair<String, String> changed = (Pair<String, String>) request.argument;
1721 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1722 changed.first, changed.second, onCompleted);
1723 break;
1724 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1725 ar = (AsyncResult) msg.obj;
1726 request = (MainThreadRequest) ar.userObj;
1727 if (ar.exception == null) {
1728 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001729 // If the operation is successful, update the PIN storage
1730 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1731 int phoneId = getPhoneFromRequest(request).getPhoneId();
1732 UiccController.getInstance().getPinStorage()
1733 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001734 } else {
1735 request.result = msg.arg1;
1736 }
1737 notifyRequester(request);
1738 break;
1739
Michele Berionne5e411512020-11-13 02:36:59 +00001740 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001741 request = (MainThreadRequest) msg.obj;
1742 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1743 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1744 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1745 enabled.first, enabled.second, onCompleted);
1746 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001747 }
zoey chene02881a2019-12-30 16:11:23 +08001748 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1749 ar = (AsyncResult) msg.obj;
1750 request = (MainThreadRequest) ar.userObj;
1751 if (ar.exception == null) {
1752 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001753 // If the operation is successful, update the PIN storage
1754 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1755 int phoneId = getPhoneFromRequest(request).getPhoneId();
1756 if (enabled.first) {
1757 UiccController.getInstance().getPinStorage()
1758 .storePin(enabled.second, phoneId);
1759 } else {
1760 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1761 }
zoey chene02881a2019-12-30 16:11:23 +08001762 } else {
1763 request.result = msg.arg1;
1764 }
Michele Berionne5e411512020-11-13 02:36:59 +00001765
1766
zoey chene02881a2019-12-30 16:11:23 +08001767 notifyRequester(request);
1768 break;
1769
Peter Wangdafb9ac2020-01-15 14:13:38 -08001770 case MSG_NOTIFY_USER_ACTIVITY:
1771 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001772 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001773 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1774 getDefaultPhone().getContext().sendBroadcastAsUser(
1775 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1776 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001777
1778 case CMD_SET_DATA_THROTTLING: {
1779 request = (MainThreadRequest) msg.obj;
1780 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1781 DataThrottlingRequest dataThrottlingRequest =
1782 (DataThrottlingRequest) request.argument;
1783 Phone phone = getPhoneFromRequest(request);
1784 if (phone != null) {
1785 phone.setDataThrottling(onCompleted,
1786 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1787 dataThrottlingRequest.getCompletionDurationMillis());
1788 } else {
1789 loge("setDataThrottling: No phone object");
1790 request.result =
1791 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1792 notifyRequester(request);
1793 }
1794
1795 break;
1796 }
1797 case EVENT_SET_DATA_THROTTLING_DONE:
1798 ar = (AsyncResult) msg.obj;
1799 request = (MainThreadRequest) ar.userObj;
1800
1801 if (ar.exception == null) {
1802 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1803 } else if (ar.exception instanceof CommandException) {
1804 loge("setDataThrottling: CommandException: " + ar.exception);
1805 CommandException.Error error =
1806 ((CommandException) (ar.exception)).getCommandError();
1807
1808 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1809 request.result = TelephonyManager
1810 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1811 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1812 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001813 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1814 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001815 } else {
1816 request.result =
1817 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1818 }
1819 } else {
1820 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1821 }
1822 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1823 notifyRequester(request);
1824 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001825
1826 case CMD_SET_SIM_POWER: {
1827 request = (MainThreadRequest) msg.obj;
1828 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1829 request = (MainThreadRequest) msg.obj;
1830 int stateToSet =
1831 ((Pair<Integer, IIntegerConsumer>)
1832 request.argument).first;
1833 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1834 break;
1835 }
1836 case EVENT_SET_SIM_POWER_DONE: {
1837 ar = (AsyncResult) msg.obj;
1838 request = (MainThreadRequest) ar.userObj;
1839 IIntegerConsumer callback =
1840 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1841 if (ar.exception != null) {
1842 loge("setSimPower exception: " + ar.exception);
1843 int errorCode = TelephonyManager.CallForwardingInfoCallback
1844 .RESULT_ERROR_UNKNOWN;
1845 if (ar.exception instanceof CommandException) {
1846 CommandException.Error error =
1847 ((CommandException) (ar.exception)).getCommandError();
1848 if (error == CommandException.Error.SIM_ERR) {
1849 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1850 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1851 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1852 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1853 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1854 } else {
1855 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1856 }
1857 }
1858 try {
1859 callback.accept(errorCode);
1860 } catch (RemoteException e) {
1861 // Ignore if the remote process is no longer available to call back.
1862 Log.w(LOG_TAG, "setSimPower: callback not available.");
1863 }
1864 } else {
1865 try {
1866 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1867 } catch (RemoteException e) {
1868 // Ignore if the remote process is no longer available to call back.
1869 Log.w(LOG_TAG, "setSimPower: callback not available.");
1870 }
1871 }
1872 break;
1873 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001874 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1875 request = (MainThreadRequest) msg.obj;
1876
1877 final Phone phone = getPhoneFromRequest(request);
1878 if (phone == null || phone.getServiceStateTracker() == null) {
1879 request.result = new IllegalStateException("Phone or SST is null");
1880 notifyRequester(request);
1881 break;
1882 }
1883
1884 Pair<Integer, SignalStrengthUpdateRequest> pair =
1885 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1886 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1887 request);
1888 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1889 request.subId, pair.first /*callingUid*/,
1890 pair.second /*request*/, onCompleted);
1891 break;
1892 }
1893 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1894 ar = (AsyncResult) msg.obj;
1895 request = (MainThreadRequest) ar.userObj;
1896 // request.result will be the exception of ar if present, true otherwise.
1897 // Be cautious not to leave result null which will wait() forever
1898 request.result = ar.exception != null ? ar.exception : true;
1899 notifyRequester(request);
1900 break;
1901 }
1902 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1903 request = (MainThreadRequest) msg.obj;
1904
1905 Phone phone = getPhoneFromRequest(request);
1906 if (phone == null || phone.getServiceStateTracker() == null) {
1907 request.result = new IllegalStateException("Phone or SST is null");
1908 notifyRequester(request);
1909 break;
1910 }
1911
1912 Pair<Integer, SignalStrengthUpdateRequest> pair =
1913 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1914 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1915 request);
1916 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1917 request.subId, pair.first /*callingUid*/,
1918 pair.second /*request*/, onCompleted);
1919 break;
1920 }
1921 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1922 ar = (AsyncResult) msg.obj;
1923 request = (MainThreadRequest) ar.userObj;
1924 request.result = ar.exception != null ? ar.exception : true;
1925 notifyRequester(request);
1926 break;
1927 }
Jordan Liu109698e2020-11-24 14:50:34 -08001928
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001929 case CMD_GET_SLICING_CONFIG: {
1930 request = (MainThreadRequest) msg.obj;
1931 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1932 request.phone.getSlicingConfig(onCompleted);
1933 break;
1934 }
1935 case EVENT_GET_SLICING_CONFIG_DONE: {
1936 ar = (AsyncResult) msg.obj;
1937 request = (MainThreadRequest) ar.userObj;
1938 ResultReceiver result = (ResultReceiver) request.argument;
1939
1940 SlicingConfig slicingConfig = null;
1941 Bundle bundle = new Bundle();
1942 int resultCode = 0;
1943 if (ar.exception != null) {
1944 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1945 + ar.exception);
1946 resultCode = TelephonyManager.SlicingException.ERROR_MODEM_ERROR;
1947 } else if (ar.result == null) {
1948 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
1949 resultCode = TelephonyManager.SlicingException.ERROR_TIMEOUT;
1950 } else {
1951 // use the result as returned
1952 resultCode = TelephonyManager.SlicingException.SUCCESS;
1953 slicingConfig = (SlicingConfig) ar.result;
1954 }
1955
1956 if (slicingConfig == null) {
1957 slicingConfig = new SlicingConfig();
1958 }
1959 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1960 result.send(resultCode, bundle);
1961 notifyRequester(request);
1962 break;
1963 }
1964
Michele Berionne5e411512020-11-13 02:36:59 +00001965 case CMD_PREPARE_UNATTENDED_REBOOT:
1966 request = (MainThreadRequest) msg.obj;
1967 request.result =
1968 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1969 notifyRequester(request);
1970 break;
1971
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 default:
1973 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1974 break;
1975 }
1976 }
Jake Hambye994d462014-02-03 13:10:13 -08001977
Pengquan Menga1bb6272018-09-06 09:59:22 -07001978 private void notifyRequester(MainThreadRequest request) {
1979 synchronized (request) {
1980 request.notifyAll();
1981 }
1982 }
1983
Jake Hambye994d462014-02-03 13:10:13 -08001984 private void handleNullReturnEvent(Message msg, String command) {
1985 AsyncResult ar = (AsyncResult) msg.obj;
1986 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1987 if (ar.exception == null) {
1988 request.result = true;
1989 } else {
1990 request.result = false;
1991 if (ar.exception instanceof CommandException) {
1992 loge(command + ": CommandException: " + ar.exception);
1993 } else {
1994 loge(command + ": Unknown exception");
1995 }
1996 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001997 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000
2001 /**
2002 * Posts the specified command to be executed on the main thread,
2003 * waits for the request to complete, and returns the result.
2004 * @see #sendRequestAsync
2005 */
2006 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002007 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2008 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002009 }
2010
2011 /**
2012 * Posts the specified command to be executed on the main thread,
2013 * waits for the request to complete, and returns the result.
2014 * @see #sendRequestAsync
2015 */
2016 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2017 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002018 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002019 }
2020
2021 /**
2022 * Posts the specified command to be executed on the main thread,
2023 * waits for the request to complete, and returns the result.
2024 * @see #sendRequestAsync
2025 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002026 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002027 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2028 }
2029
2030 /**
2031 * Posts the specified command to be executed on the main thread,
2032 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2033 * if not timeout or null otherwise.
2034 * @see #sendRequestAsync
2035 */
2036 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2037 long timeoutInMs) {
2038 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002039 }
2040
2041 /**
2042 * Posts the specified command to be executed on the main thread,
2043 * waits for the request to complete, and returns the result.
2044 * @see #sendRequestAsync
2045 */
Nathan Harold92bed182018-10-12 18:16:49 -07002046 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002047 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002048 }
2049
2050 /**
2051 * Posts the specified command to be executed on the main thread,
2052 * waits for the request to complete, and returns the result.
2053 * @see #sendRequestAsync
2054 */
2055 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002056 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2057 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002058 }
2059
2060 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002061 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2062 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2063 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002064 * @see #sendRequestAsync
2065 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002066 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2067 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2069 throw new RuntimeException("This method will deadlock if called from the main thread.");
2070 }
2071
Nathan Harold92bed182018-10-12 18:16:49 -07002072 MainThreadRequest request = null;
2073 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2074 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2075 } else if (phone != null) {
2076 request = new MainThreadRequest(argument, phone, workSource);
2077 } else {
2078 request = new MainThreadRequest(argument, subId, workSource);
2079 }
2080
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 Message msg = mMainThreadHandler.obtainMessage(command, request);
2082 msg.sendToTarget();
2083
Rambo Wang0f050d82021-02-12 11:43:36 -08002084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002086 if (timeoutInMs >= 0) {
2087 // Wait for at least timeoutInMs before returning null request result
2088 long now = SystemClock.elapsedRealtime();
2089 long deadline = now + timeoutInMs;
2090 while (request == null && now < deadline) {
2091 try {
2092 request.wait(deadline - now);
2093 } catch (InterruptedException e) {
2094 // Do nothing, go back and check if request is completed or timeout
2095 } finally {
2096 now = SystemClock.elapsedRealtime();
2097 }
2098 }
2099 } else {
2100 // Wait for the request to complete
2101 while (request.result == null) {
2102 try {
2103 request.wait();
2104 } catch (InterruptedException e) {
2105 // Do nothing, go back and wait until the request is complete
2106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 }
2108 }
2109 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002110 if (request.result == null) {
2111 Log.wtf(LOG_TAG,
2112 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 return request.result;
2115 }
2116
2117 /**
2118 * Asynchronous ("fire and forget") version of sendRequest():
2119 * Posts the specified command to be executed on the main thread, and
2120 * returns immediately.
2121 * @see #sendRequest
2122 */
2123 private void sendRequestAsync(int command) {
2124 mMainThreadHandler.sendEmptyMessage(command);
2125 }
2126
2127 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002128 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002129 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002130 */
2131 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002132 sendRequestAsync(command, argument, null, null);
2133 }
2134
2135 /**
2136 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2137 * @see {@link #sendRequest(int,Object)}
2138 */
2139 private void sendRequestAsync(
2140 int command, Object argument, Phone phone, WorkSource workSource) {
2141 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002142 Message msg = mMainThreadHandler.obtainMessage(command, request);
2143 msg.sendToTarget();
2144 }
2145
2146 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 * Initialize the singleton PhoneInterfaceManager instance.
2148 * This is only done once, at startup, from PhoneApp.onCreate().
2149 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002150 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 synchronized (PhoneInterfaceManager.class) {
2152 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002153 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 } else {
2155 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2156 }
2157 return sInstance;
2158 }
2159 }
2160
2161 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002162 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002165 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002166 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2168 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002169 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002170 mTelephonySharedPreferences =
2171 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002172 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002173 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002174 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002175 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 publish();
2178 }
2179
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002180 private Phone getDefaultPhone() {
2181 Phone thePhone = getPhone(getDefaultSubscription());
2182 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2183 }
2184
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 private void publish() {
2186 if (DBG) log("publish: " + this);
2187
Peter Wangc035ce42020-01-08 21:00:22 -08002188 TelephonyFrameworkInitializer
2189 .getTelephonyServiceManager()
2190 .getTelephonyServiceRegisterer()
2191 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
Stuart Scott584921c2015-01-15 17:10:34 -08002194 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002195 if (request.phone != null) {
2196 return request.phone;
2197 } else {
2198 return getPhoneFromSubId(request.subId);
2199 }
2200 }
2201
2202 private Phone getPhoneFromSubId(int subId) {
2203 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2204 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002205 }
2206
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002207 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2208 Phone phone = getPhoneFromRequest(request);
2209 return phone == null ? null :
2210 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2211 }
2212
Wink Saville36469e72014-06-11 15:17:00 -07002213 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002214 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002215 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217
Kai Shif70f46f2021-03-03 13:59:46 -08002218 private void sendEraseModemConfig(@NonNull Phone phone) {
2219 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2220 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2221 }
2222
2223 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2224 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2225 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002226 }
2227
Peter Wang44b186e2020-01-13 23:33:09 -08002228 private boolean isImsAvailableOnDevice() {
2229 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2230 if (pm == null) {
2231 // For some reason package manger is not available.. This will fail internally anyway,
2232 // so do not throw error and allow.
2233 return true;
2234 }
2235 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2236 }
2237
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002239 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002240 }
2241
Wink Savilleb564aae2014-10-23 10:18:09 -07002242 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002243 if (DBG) log("dial: " + number);
2244 // No permission check needed here: This is just a wrapper around the
2245 // ACTION_DIAL intent, which is available to any app since it puts up
2246 // the UI before it does anything.
2247
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002248 final long identity = Binder.clearCallingIdentity();
2249 try {
2250 String url = createTelUrl(number);
2251 if (url == null) {
2252 return;
2253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255 // PENDING: should we just silently fail if phone is offhook or ringing?
2256 PhoneConstants.State state = mCM.getState(subId);
2257 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2258 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2259 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2260 mApp.startActivity(intent);
2261 }
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002264 }
2265 }
2266
2267 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002268 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002269 }
2270
Wink Savilleb564aae2014-10-23 10:18:09 -07002271 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 if (DBG) log("call: " + number);
2273
2274 // This is just a wrapper around the ACTION_CALL intent, but we still
2275 // need to do a permission check since we're calling startActivity()
2276 // from the context of the phone app.
2277 enforceCallPermission();
2278
Jordan Liu1617b712019-07-10 15:06:26 -07002279 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 != AppOpsManager.MODE_ALLOWED) {
2281 return;
2282 }
2283
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284 final long identity = Binder.clearCallingIdentity();
2285 try {
2286 String url = createTelUrl(number);
2287 if (url == null) {
2288 return;
2289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002291 boolean isValid = false;
2292 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2293 if (slist != null) {
2294 for (SubscriptionInfo subInfoRecord : slist) {
2295 if (subInfoRecord.getSubscriptionId() == subId) {
2296 isValid = true;
2297 break;
2298 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002299 }
Wink Saville08874612014-08-31 19:19:58 -07002300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 if (!isValid) {
2302 return;
2303 }
Wink Saville08874612014-08-31 19:19:58 -07002304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2306 intent.putExtra(SUBSCRIPTION_KEY, subId);
2307 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2308 mApp.startActivity(intent);
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
Wink Savilleb564aae2014-10-23 10:18:09 -07002314 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002315 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002316 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2317 }
2318
Wink Savilleb564aae2014-10-23 10:18:09 -07002319 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002320 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002321 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2322 }
2323
Wink Savilleb564aae2014-10-23 10:18:09 -07002324 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002329 Phone phone = getPhone(subId);
2330 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002331 checkSimPin.start();
2332 return checkSimPin.unlockSim(null, pin);
2333 } finally {
2334 Binder.restoreCallingIdentity(identity);
2335 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 }
2337
Wink Savilleb564aae2014-10-23 10:18:09 -07002338 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340
2341 final long identity = Binder.clearCallingIdentity();
2342 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002343 Phone phone = getPhone(subId);
2344 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345 checkSimPuk.start();
2346 return checkSimPuk.unlockSim(puk, pin);
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 }
2351
2352 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002353 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 * a synchronous one.
2355 */
2356 private static class UnlockSim extends Thread {
2357
2358 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002359 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360
2361 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002362 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2363 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364
2365 // For replies from SimCard interface
2366 private Handler mHandler;
2367
2368 // For async handler to identify request type
2369 private static final int SUPPLY_PIN_COMPLETE = 100;
2370
Michele Berionne5e411512020-11-13 02:36:59 +00002371 UnlockSim(int phoneId, IccCard simCard) {
2372 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 mSimCard = simCard;
2374 }
2375
2376 @Override
2377 public void run() {
2378 Looper.prepare();
2379 synchronized (UnlockSim.this) {
2380 mHandler = new Handler() {
2381 @Override
2382 public void handleMessage(Message msg) {
2383 AsyncResult ar = (AsyncResult) msg.obj;
2384 switch (msg.what) {
2385 case SUPPLY_PIN_COMPLETE:
2386 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2387 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002388 mRetryCount = msg.arg1;
2389 if (ar.exception != null) {
2390 if (ar.exception instanceof CommandException &&
2391 ((CommandException)(ar.exception)).getCommandError()
2392 == CommandException.Error.PASSWORD_INCORRECT) {
2393 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002394 } //When UiccCardApp dispose,handle message and return exception
2395 else if (ar.exception instanceof CommandException &&
2396 ((CommandException) (ar.exception)).getCommandError()
2397 == CommandException.Error.ABORTED) {
2398 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002399 } else {
2400 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2401 }
2402 } else {
2403 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 mDone = true;
2406 UnlockSim.this.notifyAll();
2407 }
2408 break;
2409 }
2410 }
2411 };
2412 UnlockSim.this.notifyAll();
2413 }
2414 Looper.loop();
2415 }
2416
2417 /*
2418 * Use PIN or PUK to unlock SIM card
2419 *
2420 * If PUK is null, unlock SIM card with PIN
2421 *
2422 * If PUK is not null, unlock SIM card with PUK and set PIN code
2423 */
Wink Saville9de0f752013-10-22 19:04:03 -07002424 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425
2426 while (mHandler == null) {
2427 try {
2428 wait();
2429 } catch (InterruptedException e) {
2430 Thread.currentThread().interrupt();
2431 }
2432 }
2433 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2434
2435 if (puk == null) {
2436 mSimCard.supplyPin(pin, callback);
2437 } else {
2438 mSimCard.supplyPuk(puk, pin, callback);
2439 }
2440
2441 while (!mDone) {
2442 try {
2443 Log.d(LOG_TAG, "wait for done");
2444 wait();
2445 } catch (InterruptedException e) {
2446 // Restore the interrupted status
2447 Thread.currentThread().interrupt();
2448 }
2449 }
2450 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002451 int[] resultArray = new int[2];
2452 resultArray[0] = mResult;
2453 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002454
2455 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2456 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2457 }
2458
Wink Saville9de0f752013-10-22 19:04:03 -07002459 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 }
2461 }
2462
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002463 /**
2464 * This method has been removed due to privacy and stability concerns.
2465 */
2466 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002468 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2469 return;
Wink Saville36469e72014-06-11 15:17:00 -07002470 }
2471
Nathan Harold1f889d82020-06-04 17:05:26 -07002472 @Override
2473 public void updateServiceLocationWithPackageName(String callingPackage) {
2474 mApp.getSystemService(AppOpsManager.class)
2475 .checkPackage(Binder.getCallingUid(), callingPackage);
2476
Nathan Haroldf096d982020-11-18 17:18:06 -08002477 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002478 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2479 // Callers targeting S have no business invoking this method.
2480 return;
2481 }
2482
2483 LocationAccessPolicy.LocationPermissionResult locationResult =
2484 LocationAccessPolicy.checkLocationPermission(mApp,
2485 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2486 .setCallingPackage(callingPackage)
2487 .setCallingFeatureId(null)
2488 .setCallingPid(Binder.getCallingPid())
2489 .setCallingUid(Binder.getCallingUid())
2490 .setMethod("updateServiceLocation")
2491 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2492 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2493 .build());
2494 // Apps that lack location permission have no business calling this method;
2495 // however, because no permission was declared in the public API, denials must
2496 // all be "soft".
2497 switch (locationResult) {
2498 case DENIED_HARD: /* fall through */
2499 case DENIED_SOFT:
2500 return;
2501 }
2502
2503 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 final long identity = Binder.clearCallingIdentity();
2505 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002506 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002508 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 }
2510 } finally {
2511 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002513 }
2514
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002515 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002516 @Override
2517 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002518 return isRadioOnWithFeature(callingPackage, null);
2519 }
2520
2521
2522 @Override
2523 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2524 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2525 callingFeatureId);
2526 }
2527
2528 @Deprecated
2529 @Override
2530 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2531 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002532 }
2533
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002535 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2536 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002538 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002539 return false;
2540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541
2542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 return isRadioOnForSubscriber(subId);
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002548 }
2549
2550 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551 final long identity = Binder.clearCallingIdentity();
2552 try {
2553 final Phone phone = getPhone(subId);
2554 if (phone != null) {
2555 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2556 } else {
2557 return false;
2558 }
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002562 }
2563
2564 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002565 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
Wink Saville36469e72014-06-11 15:17:00 -07002567
Wink Savilleb564aae2014-10-23 10:18:09 -07002568 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null) {
2575 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2576 }
2577 } finally {
2578 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002579 }
Wink Saville36469e72014-06-11 15:17:00 -07002580 }
2581
2582 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002583 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Wink Savilleb564aae2014-10-23 10:18:09 -07002586 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002587 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
2589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 final Phone phone = getPhone(subId);
2592 if (phone == null) {
2593 return false;
2594 }
2595 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2596 toggleRadioOnOffForSubscriber(subId);
2597 }
2598 return true;
2599 } finally {
2600 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002602 }
Wink Saville36469e72014-06-11 15:17:00 -07002603
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002604 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002605 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002606 /*
2607 * If any of the Radios are available, it will need to be
2608 * shutdown. So return true if any Radio is available.
2609 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002610 final long identity = Binder.clearCallingIdentity();
2611 try {
2612 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2613 Phone phone = PhoneFactory.getPhone(i);
2614 if (phone != null && phone.isRadioAvailable()) return true;
2615 }
2616 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2617 return false;
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002620 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002621 }
2622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002624 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 enforceModifyPermission();
2626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2630 logv("Shutting down Phone " + i);
2631 shutdownRadioUsingPhoneId(i);
2632 }
2633 } finally {
2634 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002635 }
2636 }
2637
2638 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002639 Phone phone = PhoneFactory.getPhone(phoneId);
2640 if (phone != null && phone.isRadioAvailable()) {
2641 phone.shutdownRadio();
2642 }
2643 }
2644
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002645 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002646 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647
2648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2651 if (defaultPhone != null) {
2652 defaultPhone.setRadioPower(turnOn);
2653 return true;
2654 } else {
2655 loge("There's no default phone.");
2656 return false;
2657 }
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002660 }
Wink Saville36469e72014-06-11 15:17:00 -07002661 }
2662
Wink Savilleb564aae2014-10-23 10:18:09 -07002663 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665
2666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 final Phone phone = getPhone(subId);
2669 if (phone != null) {
2670 phone.setRadioPower(turnOn);
2671 return true;
2672 } else {
2673 return false;
2674 }
2675 } finally {
2676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002678 }
2679
Wink Saville36469e72014-06-11 15:17:00 -07002680 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002681 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 public boolean enableDataConnectivity() {
2683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684
2685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 int subId = mSubscriptionController.getDefaultDataSubId();
2688 final Phone phone = getPhone(subId);
2689 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002690 phone.getDataEnabledSettings().setDataEnabled(
2691 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 return true;
2693 } else {
2694 return false;
2695 }
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002699 }
2700
Wink Saville36469e72014-06-11 15:17:00 -07002701 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002702 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 public boolean disableDataConnectivity() {
2704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 int subId = mSubscriptionController.getDefaultDataSubId();
2709 final Phone phone = getPhone(subId);
2710 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002711 phone.getDataEnabledSettings().setDataEnabled(
2712 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 return true;
2714 } else {
2715 return false;
2716 }
2717 } finally {
2718 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 }
2721
Sanket Padawe356d7632015-06-22 14:03:32 -07002722 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002723 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 final Phone phone = getPhone(subId);
2727 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002728 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729 } else {
2730 return false;
2731 }
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002735 }
2736
2737 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002738 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002739 }
2740
pkanwarae03a6b2016-11-06 20:37:09 -08002741 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002742 enforceCallPermission();
2743
2744 final long identity = Binder.clearCallingIdentity();
2745 try {
2746 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2747 return;
2748 }
2749 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2750 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2751 } finally {
2752 Binder.restoreCallingIdentity(identity);
2753 }
pkanwar32d516d2016-10-14 19:37:38 -07002754 };
2755
Wink Savilleb564aae2014-10-23 10:18:09 -07002756 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758
2759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2762 return false;
2763 }
2764 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2765 } finally {
2766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 }
2769
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002771 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002772 }
2773
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002774 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 Phone phone = PhoneFactory.getPhone(slotIndex);
2778 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2779 PhoneConstantConversions.convertCallState(phone.getState());
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
2782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
2784
Sanket Padawe356d7632015-06-22 14:03:32 -07002785 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002786 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002787 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2788 }
2789
2790 @Override
2791 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 final long identity = Binder.clearCallingIdentity();
2793 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002794 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 if (phone != null) {
2796 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2797 } else {
2798 return PhoneConstantConversions.convertDataState(
2799 PhoneConstants.DataState.DISCONNECTED);
2800 }
2801 } finally {
2802 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002804 }
2805
Sanket Padawe356d7632015-06-22 14:03:32 -07002806 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002807 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002808 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2809 }
2810
2811 @Override
2812 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 final long identity = Binder.clearCallingIdentity();
2814 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002815 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816 if (phone != null) {
2817 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2818 } else {
2819 return TelephonyManager.DATA_ACTIVITY_NONE;
2820 }
2821 } finally {
2822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 }
2825
2826 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002827 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002828 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002829 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002830
2831 LocationAccessPolicy.LocationPermissionResult locationResult =
2832 LocationAccessPolicy.checkLocationPermission(mApp,
2833 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2834 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002835 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002836 .setCallingPid(Binder.getCallingPid())
2837 .setCallingUid(Binder.getCallingUid())
2838 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002839 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002840 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2841 .build());
2842 switch (locationResult) {
2843 case DENIED_HARD:
2844 throw new SecurityException("Not allowed to access cell location");
2845 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002846 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2847 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 }
2849
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002850 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 final long identity = Binder.clearCallingIdentity();
2852 try {
2853 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002854 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002855 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
Svetoslav64fad262015-04-14 14:35:21 -07002859 }
2860
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002862 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002863 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2864 // registered cell info, so return a NULL country instead.
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002867 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2868 // Get default phone in this case.
2869 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2870 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002871 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002872 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002873 if (phone == null) return "";
2874 ServiceStateTracker sst = phone.getServiceStateTracker();
2875 if (sst == null) return "";
2876 LocaleTracker lt = sst.getLocaleTracker();
2877 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002878 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002879 } finally {
2880 Binder.restoreCallingIdentity(identity);
2881 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002882 }
2883
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002884 /**
2885 * This method was removed due to potential issues caused by performing partial
2886 * updates of service state, and lack of a credible use case.
2887 *
2888 * This has the ability to break the telephony implementation by disabling notification of
2889 * changes in device connectivity. DO NOT USE THIS!
2890 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002891 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 public void enableLocationUpdates() {
2893 mApp.enforceCallingOrSelfPermission(
2894 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002897 /**
2898 * This method was removed due to potential issues caused by performing partial
2899 * updates of service state, and lack of a credible use case.
2900 *
2901 * This has the ability to break the telephony implementation by disabling notification of
2902 * changes in device connectivity. DO NOT USE THIS!
2903 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002904 @Override
2905 public void disableLocationUpdates() {
2906 mApp.enforceCallingOrSelfPermission(
2907 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002908 }
2909
2910 @Override
2911 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002912 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2913 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002914 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002915 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2916 throw new SecurityException(
2917 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2918 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002919
Jordan Liu1617b712019-07-10 15:06:26 -07002920 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002921 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2922 return null;
2923 }
Svetoslav64fad262015-04-14 14:35:21 -07002924
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002925 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002927 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002928 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002929
Nathan Haroldf180aac2018-06-01 18:43:55 -07002930 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2931 for (CellInfo ci : info) {
2932 if (ci instanceof CellInfoGsm) {
2933 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2934 } else if (ci instanceof CellInfoWcdma) {
2935 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002938 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 }
2940
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002941 private List<CellInfo> getCachedCellInfo() {
2942 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2943 for (Phone phone : PhoneFactory.getPhones()) {
2944 List<CellInfo> info = phone.getAllCellInfo();
2945 if (info != null) cellInfos.addAll(info);
2946 }
2947 return cellInfos;
2948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949
2950 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002951 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002952 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002953 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002954
2955 LocationAccessPolicy.LocationPermissionResult locationResult =
2956 LocationAccessPolicy.checkLocationPermission(mApp,
2957 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2958 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002959 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002960 .setCallingPid(Binder.getCallingPid())
2961 .setCallingUid(Binder.getCallingUid())
2962 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002963 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002964 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2965 .build());
2966 switch (locationResult) {
2967 case DENIED_HARD:
2968 throw new SecurityException("Not allowed to access cell info");
2969 case DENIED_SOFT:
2970 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
2972
Nathan Haroldf096d982020-11-18 17:18:06 -08002973 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002974 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2975 return getCachedCellInfo();
2976 }
2977
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002978 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2983 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002984 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002985 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 if (info != null) cellInfos.addAll(info);
2987 }
2988 return cellInfos;
2989 } finally {
2990 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002991 }
2992 }
2993
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002994 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002995 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2996 String callingFeatureId) {
2997 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2998 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002999 }
3000
3001 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003002 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3003 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003004 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003005 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003006 }
3007
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003008 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3009 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003010 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003011 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003012
3013 LocationAccessPolicy.LocationPermissionResult locationResult =
3014 LocationAccessPolicy.checkLocationPermission(mApp,
3015 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3016 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003017 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003018 .setCallingPid(Binder.getCallingPid())
3019 .setCallingUid(Binder.getCallingUid())
3020 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003021 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3022 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003023 .build());
3024 switch (locationResult) {
3025 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003026 if (TelephonyPermissions
3027 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003028 // Safetynet logging for b/154934934
3029 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3030 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003031 throw new SecurityException("Not allowed to access cell info");
3032 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003033 if (TelephonyPermissions
3034 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003035 // Safetynet logging for b/154934934
3036 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3037 }
Nathan Harold5320c422019-05-09 10:26:08 -07003038 try {
3039 cb.onCellInfo(new ArrayList<CellInfo>());
3040 } catch (RemoteException re) {
3041 // Drop without consequences
3042 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003043 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003044 }
3045
Nathan Harolda939a962019-05-09 10:13:47 -07003046
3047 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003048 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3049
3050 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3051 }
3052
3053 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003054 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003055 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003056 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003057
3058 final long identity = Binder.clearCallingIdentity();
3059 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003060 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003064 }
3065
Shishir Agrawala9f32182016-04-12 12:00:16 -07003066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003067 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003068 Phone phone = PhoneFactory.getPhone(slotIndex);
3069 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003070 return null;
3071 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003072 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003073 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003074 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003075 return null;
3076 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 return phone.getImei();
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003084 }
3085
3086 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003087 public String getTypeAllocationCodeForSlot(int slotIndex) {
3088 Phone phone = PhoneFactory.getPhone(slotIndex);
3089 String tac = null;
3090 if (phone != null) {
3091 String imei = phone.getImei();
3092 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3093 }
3094 return tac;
3095 }
3096
3097 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003098 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003099 Phone phone = PhoneFactory.getPhone(slotIndex);
3100 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003101 return null;
3102 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003103
Jeff Davidson913390f2018-02-23 17:11:49 -08003104 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003105 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003106 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003107 return null;
3108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003109
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 return phone.getMeid();
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
3115 }
Jack Yu2af8d712017-03-15 17:14:14 -07003116 }
3117
3118 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003119 public String getManufacturerCodeForSlot(int slotIndex) {
3120 Phone phone = PhoneFactory.getPhone(slotIndex);
3121 String manufacturerCode = null;
3122 if (phone != null) {
3123 String meid = phone.getMeid();
3124 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3125 }
3126 return manufacturerCode;
3127 }
3128
3129 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003130 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3131 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003132 Phone phone = PhoneFactory.getPhone(slotIndex);
3133 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003134 return null;
3135 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003136 int subId = phone.getSubId();
3137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003138 mApp, subId, callingPackage, callingFeatureId,
3139 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003140 return null;
3141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142
3143 final long identity = Binder.clearCallingIdentity();
3144 try {
3145 return phone.getDeviceSvn();
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
3148 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003149 }
3150
fionaxu43304da2017-11-27 22:51:16 -08003151 @Override
3152 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003153 final long identity = Binder.clearCallingIdentity();
3154 try {
3155 final Phone phone = getPhone(subId);
3156 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
fionaxu43304da2017-11-27 22:51:16 -08003160 }
3161
3162 @Override
3163 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 final Phone phone = getPhone(subId);
3167 return phone == null ? null : phone.getCarrierName();
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
fionaxu43304da2017-11-27 22:51:16 -08003171 }
3172
calvinpanffe225e2018-11-01 19:43:06 +08003173 @Override
chen xu0026ca62019-03-06 15:28:50 -08003174 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 final Phone phone = getPhone(subId);
3178 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003179 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003180 } finally {
3181 Binder.restoreCallingIdentity(identity);
3182 }
3183 }
3184
3185 @Override
chen xu0026ca62019-03-06 15:28:50 -08003186 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003190 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003191 } finally {
3192 Binder.restoreCallingIdentity(identity);
3193 }
3194 }
3195
chen xu651eec72018-11-11 19:03:44 -08003196 @Override
chen xu864e11c2018-12-06 22:10:03 -08003197 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3198 if (!isSubscriptionMccMnc) {
3199 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3200 }
chen xu651eec72018-11-11 19:03:44 -08003201 final Phone phone = PhoneFactory.getPhone(slotIndex);
3202 if (phone == null) {
3203 return TelephonyManager.UNKNOWN_CARRIER_ID;
3204 }
3205 final long identity = Binder.clearCallingIdentity();
3206 try {
3207 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
3210 }
3211 }
3212
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003213 //
3214 // Internal helper methods.
3215 //
3216
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003217 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003218 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3219 *
3220 * @throws SecurityException if the caller does not have the required permission
3221 */
3222 private void enforceModifyPermission() {
3223 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3224 }
3225
Shuo Qiancd19c462020-01-16 20:51:11 -08003226 /**
3227 * Make sure the caller is system.
3228 *
3229 * @throws SecurityException if the caller is not system.
3230 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003231 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003232 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3233 throw new SecurityException("Caller must be system");
3234 }
3235 }
3236
Shuo Qian3b6ee772019-11-13 17:43:31 -08003237 private void enforceActiveEmergencySessionPermission() {
3238 mApp.enforceCallingOrSelfPermission(
3239 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3240 }
3241
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003242 /**
3243 * Make sure the caller has the CALL_PHONE permission.
3244 *
3245 * @throws SecurityException if the caller does not have the required permission
3246 */
3247 private void enforceCallPermission() {
3248 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3249 }
3250
paulhu5a773602019-08-23 19:17:33 +08003251 private void enforceSettingsPermission() {
3252 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003253 }
3254
Michele Berionne5e411512020-11-13 02:36:59 +00003255 private void enforceRebootPermission() {
3256 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3257 }
3258
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 private String createTelUrl(String number) {
3260 if (TextUtils.isEmpty(number)) {
3261 return null;
3262 }
3263
Jake Hambye994d462014-02-03 13:10:13 -08003264 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 }
3266
Ihab Awadf9e92732013-12-05 18:02:52 -08003267 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3269 }
3270
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003271 private static void logv(String msg) {
3272 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3273 }
3274
Ihab Awadf9e92732013-12-05 18:02:52 -08003275 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003276 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3277 }
3278
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003279 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003280 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003281 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003282 }
3283
Sanket Padawe356d7632015-06-22 14:03:32 -07003284 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003285 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003286 final long identity = Binder.clearCallingIdentity();
3287 try {
3288 final Phone phone = PhoneFactory.getPhone(slotIndex);
3289 if (phone == null) {
3290 return PhoneConstants.PHONE_TYPE_NONE;
3291 } else {
3292 return phone.getPhoneType();
3293 }
3294 } finally {
3295 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003297 }
3298
3299 /**
3300 * Returns the CDMA ERI icon index to display
3301 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003302 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003303 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3304 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3305 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003306 }
3307
Sanket Padawe356d7632015-06-22 14:03:32 -07003308 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003309 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3310 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003312 mApp, subId, callingPackage, callingFeatureId,
3313 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003314 return -1;
3315 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003316
3317 final long identity = Binder.clearCallingIdentity();
3318 try {
3319 final Phone phone = getPhone(subId);
3320 if (phone != null) {
3321 return phone.getCdmaEriIconIndex();
3322 } else {
3323 return -1;
3324 }
3325 } finally {
3326 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003328 }
3329
3330 /**
3331 * Returns the CDMA ERI icon mode,
3332 * 0 - ON
3333 * 1 - FLASHING
3334 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003336 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3337 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3338 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003339 }
3340
Sanket Padawe356d7632015-06-22 14:03:32 -07003341 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003342 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3343 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003345 mApp, subId, callingPackage, callingFeatureId,
3346 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003347 return -1;
3348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349
3350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 final Phone phone = getPhone(subId);
3353 if (phone != null) {
3354 return phone.getCdmaEriIconMode();
3355 } else {
3356 return -1;
3357 }
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003361 }
3362
3363 /**
3364 * Returns the CDMA ERI text,
3365 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003366 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003367 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3368 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3369 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003370 }
3371
Sanket Padawe356d7632015-06-22 14:03:32 -07003372 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003373 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3374 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003376 mApp, subId, callingPackage, callingFeatureId,
3377 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003378 return null;
3379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 final Phone phone = getPhone(subId);
3384 if (phone != null) {
3385 return phone.getCdmaEriText();
3386 } else {
3387 return null;
3388 }
3389 } finally {
3390 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003392 }
3393
3394 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003395 * Returns the CDMA MDN.
3396 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003397 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003398 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3400 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003401
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003405 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406 return phone.getLine1Number();
3407 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003408 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003409 return null;
3410 }
3411 } finally {
3412 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003413 }
3414 }
3415
3416 /**
3417 * Returns the CDMA MIN.
3418 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003419 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003420 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3422 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003423
3424 final long identity = Binder.clearCallingIdentity();
3425 try {
3426 final Phone phone = getPhone(subId);
3427 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3428 return phone.getCdmaMin();
3429 } else {
3430 return null;
3431 }
3432 } finally {
3433 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003434 }
3435 }
3436
Hall Liud892bec2018-11-30 14:51:45 -08003437 @Override
3438 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3439 INumberVerificationCallback callback, String callingPackage) {
3440 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3441 != PERMISSION_GRANTED) {
3442 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3443 }
3444 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3445
3446 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3447 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003448 throw new SecurityException("Calling package must be configured in the device config: "
3449 + "calling package: " + callingPackage
3450 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003451 }
3452
3453 if (range == null) {
3454 throw new NullPointerException("Range must be non-null");
3455 }
3456
3457 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003458 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003459
3460 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3461 }
3462
Junda Liuca05d5d2014-08-14 22:36:34 -07003463 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003464 * Returns true if CDMA provisioning needs to run.
3465 */
3466 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003467 final long identity = Binder.clearCallingIdentity();
3468 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003469 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003470 } finally {
3471 Binder.restoreCallingIdentity(identity);
3472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003473 }
3474
3475 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003476 * Sets the voice mail number of a given subId.
3477 */
3478 @Override
3479 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003480 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3481 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003482
3483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3486 new Pair<String, String>(alphaTag, number), new Integer(subId));
3487 return success;
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
3490 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003491 }
3492
Ta-wei Yen87c49842016-05-13 21:19:52 -07003493 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003494 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3495 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003496 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3497 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003498 if (!TextUtils.equals(callingPackage, systemDialer)) {
3499 throw new SecurityException("caller must be system dialer");
3500 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3505 if (phoneAccountHandle == null) {
3506 return null;
3507 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003508 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509 } finally {
3510 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003511 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003512 }
3513
3514 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003515 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3516 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003517 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003518 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003519 mApp, subId, callingPackage, callingFeatureId,
3520 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003521 return null;
3522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003524 final long identity = Binder.clearCallingIdentity();
3525 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003526 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003530 }
3531
3532 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003533 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3534 VisualVoicemailSmsFilterSettings settings) {
3535 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536
3537 final long identity = Binder.clearCallingIdentity();
3538 try {
3539 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003540 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003544 }
3545
3546 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003547 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3548 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003553 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003554 } finally {
3555 Binder.restoreCallingIdentity(identity);
3556 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003557 }
3558
3559 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003560 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3561 String callingPackage, int subId) {
3562 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563
3564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003567 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003568 } finally {
3569 Binder.restoreCallingIdentity(identity);
3570 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003571 }
3572
3573 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003574 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003576
3577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003580 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 } finally {
3582 Binder.restoreCallingIdentity(identity);
3583 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003584 }
3585
3586 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003587 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3588 String callingAttributionTag, int subId, String number, int port, String text,
3589 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003591 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003592 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003593 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003594 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3595 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003596 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003597
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003598 /**
fionaxu0152e512016-11-14 13:36:14 -08003599 * Sets the voice activation state of a given subId.
3600 */
3601 @Override
3602 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003603 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3604 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003605
3606 final long identity = Binder.clearCallingIdentity();
3607 try {
3608 final Phone phone = getPhone(subId);
3609 if (phone != null) {
3610 phone.setVoiceActivationState(activationState);
3611 } else {
3612 loge("setVoiceActivationState fails with invalid subId: " + subId);
3613 }
3614 } finally {
3615 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003616 }
3617 }
3618
3619 /**
3620 * Sets the data activation state of a given subId.
3621 */
3622 @Override
3623 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3625 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003626
3627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 final Phone phone = getPhone(subId);
3630 if (phone != null) {
3631 phone.setDataActivationState(activationState);
3632 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003633 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003634 }
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003637 }
3638 }
3639
3640 /**
3641 * Returns the voice activation state of a given subId.
3642 */
3643 @Override
3644 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003645 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646
fionaxu0152e512016-11-14 13:36:14 -08003647 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 if (phone != null) {
3651 return phone.getVoiceActivationState();
3652 } else {
3653 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3654 }
3655 } finally {
3656 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003657 }
3658 }
3659
3660 /**
3661 * Returns the data activation state of a given subId.
3662 */
3663 @Override
3664 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666
fionaxu0152e512016-11-14 13:36:14 -08003667 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003668 final long identity = Binder.clearCallingIdentity();
3669 try {
3670 if (phone != null) {
3671 return phone.getDataActivationState();
3672 } else {
3673 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3674 }
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003677 }
3678 }
3679
3680 /**
Wink Saville36469e72014-06-11 15:17:00 -07003681 * Returns the unread count of voicemails for a subId
3682 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003683 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003684 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3685 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003686 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003687 mApp, subId, callingPackage, callingFeatureId,
3688 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003689 return 0;
3690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 final Phone phone = getPhone(subId);
3694 if (phone != null) {
3695 return phone.getVoiceMessageCount();
3696 } else {
3697 return 0;
3698 }
3699 } finally {
3700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003702 }
3703
3704 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003705 * returns true, if the device is in a state where both voice and data
3706 * are supported simultaneously. This can change based on location or network condition.
3707 */
3708 @Override
3709 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 final Phone phone = getPhone(subId);
3713 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003717 }
3718
3719 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003720 * Send the dialer code if called from the current default dialer or the caller has
3721 * carrier privilege.
3722 * @param inputCode The dialer code to send
3723 */
3724 @Override
3725 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003726 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003727 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003728 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3729 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003730 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003731 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003732 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003733 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734
3735 final long identity = Binder.clearCallingIdentity();
3736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003737 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
fionaxu235cc5e2017-03-06 22:25:57 -08003741 }
3742
Pengquan Menga1bb6272018-09-06 09:59:22 -07003743 @Override
3744 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003745 TelephonyPermissions
3746 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3747 mApp, subId, "getNetworkSelectionMode");
3748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 if (!isActiveSubscription(subId)) {
3751 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3752 }
3753 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003756 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003757 }
3758
Brad Ebinger35c841c2018-10-01 10:40:55 -07003759 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003760 public boolean isInEmergencySmsMode() {
3761 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3762 final long identity = Binder.clearCallingIdentity();
3763 try {
3764 for (Phone phone : PhoneFactory.getPhones()) {
3765 if (phone.isInEmergencySmsMode()) {
3766 return true;
3767 }
3768 }
3769 } finally {
3770 Binder.restoreCallingIdentity(identity);
3771 }
3772 return false;
3773 }
3774
shilu366312e2019-12-17 09:28:10 -08003775 /**
3776 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3777 * @param subId The subscription to use to check the configuration.
3778 * @param c The callback that will be used to send the result.
3779 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003780 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003781 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3782 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003783 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3784 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003785
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003786 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3788 "IMS not available on device.");
3789 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003790 final long token = Binder.clearCallingIdentity();
3791 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003793 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003794 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003795 } catch (ImsException e) {
3796 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003797 } finally {
3798 Binder.restoreCallingIdentity(token);
3799 }
3800 }
3801
shilu366312e2019-12-17 09:28:10 -08003802 /**
3803 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3804 * @param subId The subscription to use to check the configuration.
3805 * @param c The callback that will be used to send the result.
3806 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003807 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003808 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003809 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3810 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003811 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3812 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3813 }
Meng Wangafbc5852019-09-19 17:37:13 -07003814 final long token = Binder.clearCallingIdentity();
3815 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003816 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003817 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3818 .removeRegistrationCallbackForSubscription(c, subId);
3819 } catch (ImsException e) {
3820 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3821 + "is inactive, ignoring unregister.");
3822 // If the subscription is no longer active, just return, since the callback
3823 // will already have been removed internally.
3824 } finally {
3825 Binder.restoreCallingIdentity(token);
3826 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 }
3828
Brad Ebingera34a6c22019-10-22 17:36:18 -07003829 /**
3830 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3831 */
3832 @Override
3833 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3834 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3835 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3836 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3837 "IMS not available on device.");
3838 }
3839 final long token = Binder.clearCallingIdentity();
3840 try {
3841 Phone phone = getPhone(subId);
3842 if (phone == null) {
3843 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3844 + subId + "'");
3845 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3846 }
3847 phone.getImsRegistrationState(regState -> {
3848 try {
3849 consumer.accept((regState == null)
3850 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3851 } catch (RemoteException e) {
3852 // Ignore if the remote process is no longer available to call back.
3853 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3854 }
3855 });
3856 } finally {
3857 Binder.restoreCallingIdentity(token);
3858 }
3859 }
3860
3861 /**
3862 * Get the transport type for the IMS service registration state.
3863 */
3864 @Override
3865 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003866 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3867 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003868 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3869 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3870 "IMS not available on device.");
3871 }
3872 final long token = Binder.clearCallingIdentity();
3873 try {
3874 Phone phone = getPhone(subId);
3875 if (phone == null) {
3876 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3877 + subId + "'");
3878 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3879 }
3880 phone.getImsRegistrationTech(regTech -> {
3881 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3882 int regTechConverted = (regTech == null)
3883 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3884 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3885 regTechConverted);
3886 try {
3887 consumer.accept(regTechConverted);
3888 } catch (RemoteException e) {
3889 // Ignore if the remote process is no longer available to call back.
3890 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3891 }
3892 });
3893 } finally {
3894 Binder.restoreCallingIdentity(token);
3895 }
3896 }
3897
shilu366312e2019-12-17 09:28:10 -08003898 /**
3899 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3900 * @param subId The subscription to use to check the configuration.
3901 * @param c The callback that will be used to send the result.
3902 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003904 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3905 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003906 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3907 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003908 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3909 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3910 "IMS not available on device.");
3911 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003912 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3913 final long token = Binder.clearCallingIdentity();
3914 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003915 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003916 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003917 } catch (ImsException e) {
3918 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 } finally {
3920 Binder.restoreCallingIdentity(token);
3921 }
3922 }
3923
shilu366312e2019-12-17 09:28:10 -08003924 /**
3925 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3926 * @param subId The subscription to use to check the configuration.
3927 * @param c The callback that will be used to send the result.
3928 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003930 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003931 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3932 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3934 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3935 }
Meng Wangafbc5852019-09-19 17:37:13 -07003936
3937 final long token = Binder.clearCallingIdentity();
3938 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003939 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003940 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003941 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003942 } catch (ImsException e) {
3943 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3944 + "is inactive, ignoring unregister.");
3945 // If the subscription is no longer active, just return, since the callback
3946 // will already have been removed internally.
3947 } finally {
3948 Binder.restoreCallingIdentity(token);
3949 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003950 }
3951
3952 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003953 public boolean isCapable(int subId, int capability, int regTech) {
3954 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3956 final long token = Binder.clearCallingIdentity();
3957 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003958 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003960 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3962 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003963 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003964 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3965 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 } finally {
3967 Binder.restoreCallingIdentity(token);
3968 }
3969 }
3970
3971 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003972 public boolean isAvailable(int subId, int capability, int regTech) {
3973 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 final long token = Binder.clearCallingIdentity();
3975 try {
3976 Phone phone = getPhone(subId);
3977 if (phone == null) return false;
3978 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003979 } catch (com.android.ims.ImsException e) {
3980 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3981 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 } finally {
3983 Binder.restoreCallingIdentity(token);
3984 }
3985 }
3986
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003987 /**
3988 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3989 * subscription.
3990 * @param subId The subscription to use to check the configuration.
3991 * @param callback The callback that will be used to send the result.
3992 * @param capability The MmTelFeature capability that will be used to send the result.
3993 * @param transportType The transport type of the MmTelFeature capability.
3994 */
3995 @Override
3996 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3997 int transportType) {
3998 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3999 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4000 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4001 "IMS not available on device.");
4002 }
4003 final long token = Binder.clearCallingIdentity();
4004 try {
4005 int slotId = getSlotIndex(subId);
4006 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4007 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4008 + subId + "'");
4009 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4010 }
4011 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4012 transportType, aBoolean -> {
4013 try {
4014 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4015 } catch (RemoteException e) {
4016 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4017 + "running. Ignore");
4018 }
4019 });
4020 } finally {
4021 Binder.restoreCallingIdentity(token);
4022 }
4023 }
4024
shilu366312e2019-12-17 09:28:10 -08004025 /**
4026 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4027 * @param subId The subscription to use to check the configuration.
4028 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 @Override
4030 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004031 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4032 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004033
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4035 final long token = Binder.clearCallingIdentity();
4036 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004037 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004039 } catch (ImsException e) {
4040 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 } finally {
4042 Binder.restoreCallingIdentity(token);
4043 }
4044 }
4045
4046 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004047 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004049 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004053 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004055 } catch (ImsException e) {
4056 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
4060 }
4061
shilu366312e2019-12-17 09:28:10 -08004062 /**
4063 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4064 * @param subId The subscription to use to check the configuration.
4065 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004067 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004068 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4069 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 final long identity = Binder.clearCallingIdentity();
4071 try {
4072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004073 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4074 } catch (ImsException e) {
4075 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
4079 }
4080
4081 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004082 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004084 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004088 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004089 } catch (ImsException e) {
4090 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
4094 }
4095
shilu366312e2019-12-17 09:28:10 -08004096 /**
4097 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4098 * @param subId The subscription to use to check the configuration.
4099 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004100 @Override
4101 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004102 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4103 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004107 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004109 } catch (ImsException e) {
4110 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
4114 }
4115
4116 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004117 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004119 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004123 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (ImsException e) {
4125 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
4129 }
4130
shilu366312e2019-12-17 09:28:10 -08004131 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004132 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4133 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4134 * @param subId The subscription to use to check the configuration.
4135 */
4136 @Override
4137 public boolean isCrossSimCallingEnabledByUser(int subId) {
4138 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4139 mApp, subId, "isCrossSimCallingEnabledByUser");
4140 final long identity = Binder.clearCallingIdentity();
4141 try {
4142 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4143 return ImsManager.getInstance(mApp,
4144 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4145 } catch (ImsException e) {
4146 throw new ServiceSpecificException(e.getCode());
4147 } finally {
4148 Binder.restoreCallingIdentity(identity);
4149 }
4150 }
4151
4152 /**
4153 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4154 * Requires MODIFY_PHONE_STATE permission.
4155 * @param subId The subscription to use to check the configuration.
4156 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4157 * false otherwise
4158 */
4159 @Override
4160 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4162 "setCrossSimCallingEnabled");
4163 final long identity = Binder.clearCallingIdentity();
4164 try {
4165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4166 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4167 .setCrossSimCallingEnabled(isEnabled);
4168 } catch (ImsException e) {
4169 throw new ServiceSpecificException(e.getCode());
4170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
4173 }
4174
4175 /**
shilu366312e2019-12-17 09:28:10 -08004176 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4177 * @param subId The subscription to use to check the configuration.
4178 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004179 @Override
4180 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004181 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4182 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 final long identity = Binder.clearCallingIdentity();
4184 try {
4185 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004186 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004188 } catch (ImsException e) {
4189 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 } finally {
4191 Binder.restoreCallingIdentity(identity);
4192 }
4193 }
4194
4195 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004196 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004198 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004199 final long identity = Binder.clearCallingIdentity();
4200 try {
4201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004202 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004204 } catch (ImsException e) {
4205 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 } finally {
4207 Binder.restoreCallingIdentity(identity);
4208 }
4209 }
4210
4211 @Override
4212 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4214 "setVoWiFiNonPersistent");
4215 final long identity = Binder.clearCallingIdentity();
4216 try {
4217 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004218 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004219 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004220 } catch (ImsException e) {
4221 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004222 } finally {
4223 Binder.restoreCallingIdentity(identity);
4224 }
4225 }
4226
shilu366312e2019-12-17 09:28:10 -08004227 /**
4228 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4229 * @param subId The subscription to use to check the configuration.
4230 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 @Override
4232 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004233 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4234 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004235 final long identity = Binder.clearCallingIdentity();
4236 try {
4237 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004238 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004240 } catch (ImsException e) {
4241 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
4245 }
4246
4247 @Override
4248 public void setVoWiFiModeSetting(int subId, int mode) {
4249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4250 "setVoWiFiModeSetting");
4251 final long identity = Binder.clearCallingIdentity();
4252 try {
4253 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004254 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004256 } catch (ImsException e) {
4257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
4260 }
4261 }
4262
4263 @Override
4264 public int getVoWiFiRoamingModeSetting(int subId) {
4265 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4266 final long identity = Binder.clearCallingIdentity();
4267 try {
4268 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004269 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004271 } catch (ImsException e) {
4272 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 } finally {
4274 Binder.restoreCallingIdentity(identity);
4275 }
4276 }
4277
4278 @Override
4279 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4281 "setVoWiFiRoamingModeSetting");
4282 final long identity = Binder.clearCallingIdentity();
4283 try {
4284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004285 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004287 } catch (ImsException e) {
4288 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 } finally {
4290 Binder.restoreCallingIdentity(identity);
4291 }
4292 }
4293
4294 @Override
4295 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4297 "setRttCapabilityEnabled");
4298 final long identity = Binder.clearCallingIdentity();
4299 try {
4300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004301 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4302 } catch (ImsException e) {
4303 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307 }
4308
shilu366312e2019-12-17 09:28:10 -08004309 /**
4310 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4311 * @param subId The subscription to use to check the configuration.
4312 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004313 @Override
4314 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004315 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4316 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004317 final long identity = Binder.clearCallingIdentity();
4318 try {
4319 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004320 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004322 } catch (ImsException e) {
4323 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
4327 }
4328
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004329 @Override
4330 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4331 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004334 if (!isImsAvailableOnDevice()) {
4335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4336 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004337 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004338 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004339 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004340 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004341 } catch (ImsException e) {
4342 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004343 } finally {
4344 Binder.restoreCallingIdentity(identity);
4345 }
4346 }
4347
4348 @Override
4349 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4350 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4351 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004352 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4353 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4354 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004355 try {
4356 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004357 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004358 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004359 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004360 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4361 + "is inactive, ignoring unregister.");
4362 // If the subscription is no longer active, just return, since the callback will already
4363 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
4367 }
4368
allenwtsu99c623b2020-01-03 18:24:23 +08004369
4370 private void checkModifyPhoneStatePermission(int subId, String message) {
4371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4372 message);
4373 }
4374
4375 private boolean isImsProvisioningRequired(int subId, int capability,
4376 boolean isMmtelCapability) {
4377 Phone phone = getPhone(subId);
4378 if (phone == null) {
4379 loge("phone instance null for subid " + subId);
4380 return false;
4381 }
4382 if (isMmtelCapability) {
4383 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4384 return false;
4385 }
4386 } else {
4387 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4388 return false;
4389 }
4390 }
4391 return true;
4392 }
4393
4394 @Override
4395 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4396 boolean isProvisioned) {
4397 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4398
4399 final long identity = Binder.clearCallingIdentity();
4400 try {
4401 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4402 if (!isImsProvisioningRequired(subId, capability, false)) {
4403 return;
4404 }
4405
4406 // this capability requires provisioning, route to the correct API.
4407 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4408 switch (capability) {
4409 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4410 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4411 ims.setEabProvisioned(isProvisioned);
4412 break;
4413 default: {
4414 throw new IllegalArgumentException("Tried to set provisioning for "
4415 + "rcs capability '" + capability + "', which does not require "
4416 + "provisioning.");
4417 }
4418 }
4419 } finally {
4420 Binder.restoreCallingIdentity(identity);
4421 }
4422
4423 }
4424
4425
4426 @Override
4427 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4428 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4429 final long identity = Binder.clearCallingIdentity();
4430 try {
4431 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4432 if (!isImsProvisioningRequired(subId, capability, false)) {
4433 return true;
4434 }
4435
4436 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4437 switch (capability) {
4438 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4439 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4440 return ims.isEabProvisionedOnDevice();
4441
4442 default: {
4443 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4444 + "capability '" + capability + "', which does not require "
4445 + "provisioning.");
4446 }
4447 }
4448
4449 } finally {
4450 Binder.restoreCallingIdentity(identity);
4451 }
4452 }
4453
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004454 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004455 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4456 boolean isProvisioned) {
4457 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4458 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4459 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4460 }
allenwtsu99c623b2020-01-03 18:24:23 +08004461 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004462 final long identity = Binder.clearCallingIdentity();
4463 try {
4464 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004465 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004466 return;
4467 }
4468
4469 // this capability requires provisioning, route to the correct API.
4470 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4471 switch (capability) {
4472 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4473 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4474 ims.setVolteProvisioned(isProvisioned);
4475 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4476 ims.setWfcProvisioned(isProvisioned);
4477 }
4478 break;
4479 }
4480 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4481 // There is currently no difference in VT provisioning type.
4482 ims.setVtProvisioned(isProvisioned);
4483 break;
4484 }
4485 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4486 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4487 // change the capability of the feature instead if needed.
4488 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4489 == isProvisioned) {
4490 // No change in provisioning.
4491 return;
4492 }
4493 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4494 try {
4495 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004496 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004497 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4498 + ", Exception" + e.getMessage());
4499 }
4500 break;
4501 }
4502 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004503 throw new IllegalArgumentException("Tried to set provisioning for "
4504 + "MmTel capability '" + capability + "', which does not require "
4505 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004506 }
4507 }
4508
4509 } finally {
4510 Binder.restoreCallingIdentity(identity);
4511 }
4512 }
4513
4514 @Override
4515 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4516 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4517 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4518 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4519 }
4520 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4521 final long identity = Binder.clearCallingIdentity();
4522 try {
4523 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004524 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004525 return true;
4526 }
4527
4528 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4529 switch (capability) {
4530 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4531 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4532 return ims.isVolteProvisionedOnDevice();
4533 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4534 return ims.isWfcProvisionedOnDevice();
4535 }
4536 // This should never happen, since we are checking tech above to make sure it
4537 // is either LTE or IWLAN.
4538 throw new IllegalArgumentException("Invalid radio technology for voice "
4539 + "capability.");
4540 }
4541 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4542 // There is currently no difference in VT provisioning type.
4543 return ims.isVtProvisionedOnDevice();
4544 }
4545 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4546 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4547 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4548 }
4549 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004550 throw new IllegalArgumentException(
4551 "Tried to get provisioning for MmTel capability '" + capability
4552 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004553 }
4554 }
4555
4556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
4559 }
4560
4561 @Override
4562 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4563 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4564 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4565 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4566 }
4567 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4568 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4569 return (provisionedBits & capability) > 0;
4570 }
4571
4572 @Override
4573 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4574 boolean isProvisioned) {
4575 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4576 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4577 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4578 }
4579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4580 "setProvisioningStatusForCapability");
4581 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4582 // If the current provisioning status for capability already matches isProvisioned,
4583 // do nothing.
4584 if (((provisionedBits & capability) > 0) == isProvisioned) {
4585 return;
4586 }
4587 if (isProvisioned) {
4588 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4589 } else {
4590 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4591 }
4592 }
4593
4594 /**
4595 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4596 * technology. The bitfield should mirror the bitfield defined by
4597 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4598 */
4599 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4600 String key = getMmTelProvisioningKey(subId, tech);
4601 // Default is no capabilities are provisioned.
4602 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4603 }
4604
4605 /**
4606 * Sets the MmTel capability provisioning bitfield (defined by
4607 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4608 * technology specified.
4609 *
4610 * Note: This is a synchronous command and should not be called on UI thread.
4611 */
4612 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4613 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4614 String key = getMmTelProvisioningKey(subId, tech);
4615 editor.putInt(key, newField);
4616 editor.commit();
4617 }
4618
4619 private static String getMmTelProvisioningKey(int subId, int tech) {
4620 // resulting key is provision_ims_mmtel_{subId}_{tech}
4621 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4622 }
4623
4624 /**
4625 * Query CarrierConfig to see if the specified capability requires provisioning for the
4626 * carrier associated with the subscription id.
4627 */
4628 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4629 int capability) {
4630 CarrierConfigManager configManager = new CarrierConfigManager(context);
4631 PersistableBundle c = configManager.getConfigForSubId(subId);
4632 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004633 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004634 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4635 false);
4636 boolean requireVoiceVtProvisioning = c.getBoolean(
4637 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4638
4639 // First check to make sure that the capability requires provisioning.
4640 switch (capability) {
4641 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4642 // intentional fallthrough
4643 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4644 if (requireVoiceVtProvisioning) {
4645 // Voice and Video requires provisioning
4646 return true;
4647 }
4648 break;
4649 }
4650 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4651 if (requireUtProvisioning) {
4652 // UT requires provisioning
4653 return true;
4654 }
4655 break;
4656 }
4657 }
4658 return false;
4659 }
4660
allenwtsu99c623b2020-01-03 18:24:23 +08004661 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4662 int capability) {
4663 CarrierConfigManager configManager = new CarrierConfigManager(context);
4664 PersistableBundle c = configManager.getConfigForSubId(subId);
4665
4666 boolean requireRcsProvisioning = c.getBoolean(
4667 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4668
4669 // First check to make sure that the capability requires provisioning.
4670 switch (capability) {
4671 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4672 // intentional fallthrough
4673 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4674 if (requireRcsProvisioning) {
4675 // OPTION or PRESENCE requires provisioning
4676 return true;
4677 }
4678 break;
4679 }
4680 }
4681 return false;
4682 }
4683
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004684 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004685 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4687 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4688 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004689 enforceReadPrivilegedPermission("getImsProvisioningInt");
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004693 int slotId = getSlotIndex(subId);
4694 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4695 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4696 + subId + "' for key:" + key);
4697 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4698 }
calvinpanb5a34062021-02-08 19:59:36 +08004699 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004700 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004701 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4702 + subId + "' for key:" + key);
4703 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004704 } finally {
4705 Binder.restoreCallingIdentity(identity);
4706 }
4707 }
4708
4709 @Override
4710 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004711 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4712 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4713 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004714 enforceReadPrivilegedPermission("getImsProvisioningString");
4715 final long identity = Binder.clearCallingIdentity();
4716 try {
4717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718 int slotId = getSlotIndex(subId);
4719 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4720 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4721 + subId + "' for key:" + key);
4722 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4723 }
calvinpanb5a34062021-02-08 19:59:36 +08004724 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004725 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004726 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4727 + subId + "' for key:" + key);
4728 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004729 } finally {
4730 Binder.restoreCallingIdentity(identity);
4731 }
4732 }
4733
4734 @Override
4735 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4737 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4738 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4740 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004744 int slotId = getSlotIndex(subId);
4745 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4746 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4747 + subId + "' for key:" + key);
4748 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4749 }
calvinpanb5a34062021-02-08 19:59:36 +08004750 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4751 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004752 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004753 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004754 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004755 } finally {
4756 Binder.restoreCallingIdentity(identity);
4757 }
4758 }
4759
4760 @Override
4761 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004762 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4763 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4764 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4766 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004767 final long identity = Binder.clearCallingIdentity();
4768 try {
4769 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004770 int slotId = getSlotIndex(subId);
4771 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4772 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4773 + subId + "' for key:" + key);
4774 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4775 }
calvinpanb5a34062021-02-08 19:59:36 +08004776 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4777 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004778 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004779 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004780 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
4784 }
4785
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004786 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004787 int slotId = SubscriptionManager.getSlotIndex(subId);
4788 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004789 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4790 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004791 }
4792 return slotId;
4793 }
4794
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004795 private int getSlotIndex(int subId) {
4796 int slotId = SubscriptionManager.getSlotIndex(subId);
4797 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4798 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4799 }
4800 return slotId;
4801 }
4802
Wink Saville36469e72014-06-11 15:17:00 -07004803 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004804 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004805 */
4806 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004807 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4808 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004809 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004810 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004811 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004812 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004813 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004814 mApp, subId, callingPackage, callingFeatureId,
4815 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004816 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4817 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 final long identity = Binder.clearCallingIdentity();
4820 try {
4821 final Phone phone = getPhone(subId);
4822 if (phone != null) {
4823 return phone.getServiceState().getDataNetworkType();
4824 } else {
4825 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4826 }
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004830 }
4831
4832 /**
4833 * Returns the data network type
4834 */
4835 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004836 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4837 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4838 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004839 }
4840
4841 /**
4842 * Returns the data network type for a subId
4843 */
4844 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004845 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4846 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004847 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004848 mApp, subId, callingPackage, callingFeatureId,
4849 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004850 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4851 }
4852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 final long identity = Binder.clearCallingIdentity();
4854 try {
4855 final Phone phone = getPhone(subId);
4856 if (phone != null) {
4857 return phone.getServiceState().getDataNetworkType();
4858 } else {
4859 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4860 }
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004864 }
4865
4866 /**
Wink Saville36469e72014-06-11 15:17:00 -07004867 * Returns the Voice network type for a subId
4868 */
4869 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004870 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4871 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004872 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004873 mApp, subId, callingPackage, callingFeatureId,
4874 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004875 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4876 }
4877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878 final long identity = Binder.clearCallingIdentity();
4879 try {
4880 final Phone phone = getPhone(subId);
4881 if (phone != null) {
4882 return phone.getServiceState().getVoiceNetworkType();
4883 } else {
4884 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4885 }
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004889 }
4890
4891 /**
4892 * @return true if a ICC card is present
4893 */
4894 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004895 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004896 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4897 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004898 }
4899
4900 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004901 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004902 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004903 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004904 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905 final long identity = Binder.clearCallingIdentity();
4906 try {
4907 final Phone phone = PhoneFactory.getPhone(slotIndex);
4908 if (phone != null) {
4909 return phone.getIccCard().hasIccCard();
4910 } else {
4911 return false;
4912 }
4913 } finally {
4914 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004916 }
4917
4918 /**
4919 * Return if the current radio is LTE on CDMA. This
4920 * is a tri-state return value as for a period of time
4921 * the mode may be unknown.
4922 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004923 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004924 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004925 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004926 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004928 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4929 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4930 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004931 }
4932
Sanket Padawe356d7632015-06-22 14:03:32 -07004933 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004934 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4935 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004936 try {
4937 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4938 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004939 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4940 }
4941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942 final long identity = Binder.clearCallingIdentity();
4943 try {
4944 final Phone phone = getPhone(subId);
4945 if (phone == null) {
4946 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4947 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004948 return TelephonyProperties.lte_on_cdma_device()
4949 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 }
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004953 }
Wink Saville36469e72014-06-11 15:17:00 -07004954 }
4955
Wink Saville36469e72014-06-11 15:17:00 -07004956 /**
4957 * {@hide}
4958 * Returns Default subId, 0 in the case of single standby.
4959 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004960 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004961 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004962 }
4963
Shishir Agrawala9f32182016-04-12 12:00:16 -07004964 private int getSlotForDefaultSubscription() {
4965 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4966 }
4967
Wink Savilleb564aae2014-10-23 10:18:09 -07004968 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004969 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004970 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004971
Pengquan Menge92a50d2018-09-21 15:54:48 -07004972 private boolean isActiveSubscription(int subId) {
4973 return mSubscriptionController.isActiveSubId(subId);
4974 }
4975
Ihab Awadf2177b72013-11-25 13:33:23 -08004976 /**
4977 * @see android.telephony.TelephonyManager.WifiCallingChoices
4978 */
4979 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 final long identity = Binder.clearCallingIdentity();
4981 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004982 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4984 getWhenToMakeWifiCallsDefaultPreference());
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004988 }
4989
4990 /**
4991 * @see android.telephony.TelephonyManager.WifiCallingChoices
4992 */
4993 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994 final long identity = Binder.clearCallingIdentity();
4995 try {
4996 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004997 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005002 }
5003
Sailesh Nepald1e68152013-12-12 19:08:02 -08005004 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005005 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005006 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005007 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005008
Jordan Liu4c733742019-02-28 12:03:40 -08005009 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5010 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5011 if (phoneId == -1) {
5012 throw new IllegalArgumentException("Given slot index: " + slotIndex
5013 + " does not correspond to an active phone");
5014 }
5015 return PhoneFactory.getPhone(phoneId);
5016 }
5017
Shishir Agrawal566b7612013-10-28 14:41:00 -07005018 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005019 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5020 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5022 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005024 if (DBG) {
5025 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5026 }
5027 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5028 p2);
5029 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005030
Jordan Liu4c733742019-02-28 12:03:40 -08005031
5032 @Override
5033 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5034 int slotIndex, String callingPackage, String aid, int p2) {
5035 enforceModifyPermission();
5036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5037 if (DBG) {
5038 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5039 }
5040 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5041 callingPackage, aid, p2);
5042 }
5043
5044 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5045 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 if (TextUtils.equals(ISDR_AID, aid)) {
5049 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005050 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5051 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 if (bestComponent == null
5053 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5054 loge("The calling package is not allowed to access ISD-R.");
5055 throw new SecurityException(
5056 "The calling package is not allowed to access ISD-R.");
5057 }
Derek Tan740e1672017-06-27 14:56:27 -07005058 }
Derek Tan740e1672017-06-27 14:56:27 -07005059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005061 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5062 null /* workSource */);
5063 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064 return response;
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005068 }
5069
5070 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005071 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5073 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005074 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5075 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5076 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005077
Jordan Liu4c733742019-02-28 12:03:40 -08005078 @Override
5079 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5080 enforceModifyPermission();
5081 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5082 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5083 channel);
5084 }
5085
5086 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 if (channel < 0) {
5090 return false;
5091 }
Jordan Liu4c733742019-02-28 12:03:40 -08005092 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5093 null /* workSource */);
5094 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005095 return success;
5096 } finally {
5097 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005098 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005099 }
5100
5101 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005102 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005103 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5105 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005106 if (DBG) {
5107 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5108 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5109 + p3 + " data=" + data);
5110 }
5111 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5112 command, p1, p2, p3, data);
5113 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005114
Jordan Liu4c733742019-02-28 12:03:40 -08005115 @Override
5116 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5117 int command, int p1, int p2, int p3, String data) {
5118 enforceModifyPermission();
5119 if (DBG) {
5120 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5121 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5122 + p3 + " data=" + data);
5123 }
5124 return iccTransmitApduLogicalChannelWithPermission(
5125 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5126 data);
5127 }
5128
5129 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5130 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 final long identity = Binder.clearCallingIdentity();
5132 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005133 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 return "";
5135 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005138 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5139 null /* workSource */);
5140 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 // Append the returned status code to the end of the response payload.
5143 String s = Integer.toHexString(
5144 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5145 if (response.payload != null) {
5146 s = IccUtils.bytesToHexString(response.payload) + s;
5147 }
5148 return s;
5149 } finally {
5150 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005151 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005152 }
Jake Hambye994d462014-02-03 13:10:13 -08005153
Evan Charltonc66da362014-05-16 14:06:40 -07005154 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005155 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5156 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5158 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005159 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005160 if (DBG) {
5161 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5162 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5163 }
5164 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5165 cla, command, p1, p2, p3, data);
5166 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005167
Jordan Liu4c733742019-02-28 12:03:40 -08005168 @Override
5169 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5170 int command, int p1, int p2, int p3, String data) {
5171 enforceModifyPermission();
5172 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5173 if (DBG) {
5174 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5175 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5176 + " data=" + data);
5177 }
5178
5179 return iccTransmitApduBasicChannelWithPermission(
5180 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5181 p2, p3, data);
5182 }
5183
5184 // open APDU basic channel assuming the caller has sufficient permissions
5185 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5186 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5190 && TextUtils.equals(ISDR_AID, data)) {
5191 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005192 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5193 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005194 if (bestComponent == null
5195 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5196 loge("The calling package is not allowed to select ISD-R.");
5197 throw new SecurityException(
5198 "The calling package is not allowed to select ISD-R.");
5199 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005200 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005201
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005203 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5204 null /* workSource */);
5205 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 // Append the returned status code to the end of the response payload.
5208 String s = Integer.toHexString(
5209 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5210 if (response.payload != null) {
5211 s = IccUtils.bytesToHexString(response.payload) + s;
5212 }
5213 return s;
5214 } finally {
5215 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005216 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005217 }
5218
5219 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005220 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005221 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5223 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
5227 if (DBG) {
5228 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5229 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5230 }
5231
5232 IccIoResult response =
5233 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5234 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5235 subId);
5236
5237 if (DBG) {
5238 log("Exchange SIM_IO [R]" + response);
5239 }
5240
5241 byte[] result = null;
5242 int length = 2;
5243 if (response.payload != null) {
5244 length = 2 + response.payload.length;
5245 result = new byte[length];
5246 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5247 } else {
5248 result = new byte[length];
5249 }
5250
5251 result[length - 1] = (byte) response.sw2;
5252 result[length - 2] = (byte) response.sw1;
5253 return result;
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005256 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005257 }
5258
Nathan Haroldb3014052017-01-25 15:57:32 -08005259 /**
5260 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5261 * on a particular subscription
5262 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005263 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5264 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005266 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005267 return null;
5268 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 if (appType != TelephonyManager.APPTYPE_USIM
5273 && appType != TelephonyManager.APPTYPE_SIM) {
5274 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5275 return null;
5276 }
5277 Object response = sendRequest(
5278 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5279 if (response instanceof String[]) {
5280 return (String[]) response;
5281 }
yincheng zhao2737e882019-09-06 17:06:54 -07005282 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005284 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 } finally {
5286 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005287 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005288 }
5289
yincheng zhao2737e882019-09-06 17:06:54 -07005290 /**
5291 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5292 * subscription.
5293 *
5294 * @param subId the id of the subscription.
5295 * @param appType the uicc app type, must be USIM or SIM.
5296 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5297 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005298 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005299 * @return number of fplmns that is successfully written to the SIM.
5300 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005301 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5302 String callingFeatureId) {
5303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5304 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005305 if (DBG) logv("no permissions for setForbiddenplmns");
5306 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5307 }
5308 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5309 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5310 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5311 }
5312 if (fplmns == null) {
5313 throw new IllegalArgumentException("Fplmn List provided is null");
5314 }
5315 for (String fplmn : fplmns) {
5316 if (!CellIdentity.isValidPlmn(fplmn)) {
5317 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5318 }
5319 }
5320 final long identity = Binder.clearCallingIdentity();
5321 try {
5322 Object response = sendRequest(
5323 CMD_SET_FORBIDDEN_PLMNS,
5324 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5325 subId);
5326 return (int) response;
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
5329 }
5330 }
5331
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005332 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005333 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5335 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5340 if (response.payload == null) {
5341 return "";
5342 }
Evan Charltonc66da362014-05-16 14:06:40 -07005343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344 // Append the returned status code to the end of the response payload.
5345 String s = Integer.toHexString(
5346 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5347 s = IccUtils.bytesToHexString(response.payload) + s;
5348 return s;
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
Evan Charltonc66da362014-05-16 14:06:40 -07005352 }
5353
Jake Hambye994d462014-02-03 13:10:13 -08005354 /**
5355 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5356 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5357 *
5358 * @param itemID the ID of the item to read
5359 * @return the NV item as a String, or null on error.
5360 */
5361 @Override
5362 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005363 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5365 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366
5367 final long identity = Binder.clearCallingIdentity();
5368 try {
5369 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005370 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5372 return value;
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
Jake Hambye994d462014-02-03 13:10:13 -08005376 }
5377
5378 /**
5379 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5380 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5381 *
5382 * @param itemID the ID of the item to read
5383 * @param itemValue the value to write, as a String
5384 * @return true on success; false on any failure
5385 */
5386 @Override
5387 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005388 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5390 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391
5392 final long identity = Binder.clearCallingIdentity();
5393 try {
5394 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5395 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005396 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5398 return success;
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
Jake Hambye994d462014-02-03 13:10:13 -08005402 }
5403
5404 /**
5405 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5406 * Used for device configuration by some CDMA operators.
5407 *
5408 * @param preferredRoamingList byte array containing the new PRL
5409 * @return true on success; false on any failure
5410 */
5411 @Override
5412 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5414 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415
5416 final long identity = Binder.clearCallingIdentity();
5417 try {
5418 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5419 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5420 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5421 return success;
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
Jake Hambye994d462014-02-03 13:10:13 -08005425 }
5426
5427 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005428 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005429 * Used for device configuration by some CDMA operators.
5430 *
chen xu6dac5ab2018-10-26 17:39:23 -07005431 * @param slotIndex - device slot.
5432 *
Jake Hambye994d462014-02-03 13:10:13 -08005433 * @return true on success; false on any failure
5434 */
5435 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005436 public boolean resetModemConfig(int slotIndex) {
5437 Phone phone = PhoneFactory.getPhone(slotIndex);
5438 if (phone != null) {
5439 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5440 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441
chen xu6dac5ab2018-10-26 17:39:23 -07005442 final long identity = Binder.clearCallingIdentity();
5443 try {
5444 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5445 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5446 return success;
5447 } finally {
5448 Binder.restoreCallingIdentity(identity);
5449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 }
chen xu6dac5ab2018-10-26 17:39:23 -07005451 return false;
5452 }
5453
5454 /**
5455 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5456 *
5457 * @param slotIndex - device slot.
5458 *
5459 * @return true on success; false on any failure
5460 */
5461 @Override
5462 public boolean rebootModem(int slotIndex) {
5463 Phone phone = PhoneFactory.getPhone(slotIndex);
5464 if (phone != null) {
5465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5466 mApp, phone.getSubId(), "rebootModem");
5467
5468 final long identity = Binder.clearCallingIdentity();
5469 try {
5470 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5471 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5472 return success;
5473 } finally {
5474 Binder.restoreCallingIdentity(identity);
5475 }
5476 }
5477 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005478 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005479
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005480 public String[] getPcscfAddress(String apnType, String callingPackage,
5481 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005482 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005483 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5484 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005485 return new String[0];
5486 }
5487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 final long identity = Binder.clearCallingIdentity();
5489 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005490 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 } finally {
5492 Binder.restoreCallingIdentity(identity);
5493 }
Wink Saville36469e72014-06-11 15:17:00 -07005494 }
5495
Brad Ebinger51f743a2017-01-23 13:50:20 -08005496 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005497 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5498 * {@link #disableIms(int)}.
5499 * @param slotIndex device slot.
5500 */
5501 public void resetIms(int slotIndex) {
5502 enforceModifyPermission();
5503
5504 final long identity = Binder.clearCallingIdentity();
5505 try {
5506 if (mImsResolver == null) {
5507 // may happen if the does not support IMS.
5508 return;
5509 }
5510 mImsResolver.disableIms(slotIndex);
5511 mImsResolver.enableIms(slotIndex);
5512 } finally {
5513 Binder.restoreCallingIdentity(identity);
5514 }
5515 }
5516
5517 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005518 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5519 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005520 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005521 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523
5524 final long identity = Binder.clearCallingIdentity();
5525 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005526 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005527 // may happen if the device does not support IMS.
5528 return;
5529 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005530 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005534 }
5535
5536 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005537 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5538 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005539 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005540 public void disableIms(int slotId) {
5541 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542
5543 final long identity = Binder.clearCallingIdentity();
5544 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005545 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005546 // may happen if the device does not support IMS.
5547 return;
5548 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005549 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005553 }
5554
5555 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005556 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5557 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005558 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005559 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005560 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005561 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562
5563 final long identity = Binder.clearCallingIdentity();
5564 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005565 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005566 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5567 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005568 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005569 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005573 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005574 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005575 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5576 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005577 @Override
5578 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005579 enforceModifyPermission();
5580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005584 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
5588 }
5589
5590 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005591 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005592 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005593 */
5594 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596
5597 final long identity = Binder.clearCallingIdentity();
5598 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005599 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005600 // may happen if the device does not support IMS.
5601 return null;
5602 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005603 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005607 }
5608
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005609 /**
5610 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005611 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005612 */
5613 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5614 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005618 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005619 // may happen if the device does not support IMS.
5620 return null;
5621 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005622 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005626 }
5627
Brad Ebinger884c07b2018-02-15 16:17:40 -08005628 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005629 * Sets the ImsService Package Name that Telephony will bind to.
5630 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005631 * @param slotIndex the slot ID that the ImsService should bind for.
5632 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005633 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005634 * @param featureTypes An integer array of feature types associated with a packageName.
5635 * @param packageName The name of the package that the current configuration will be replaced
5636 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005637 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005638 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005639 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5640 int[] featureTypes, String packageName) {
5641 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5642 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5644 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005645 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005646
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005647 final long identity = Binder.clearCallingIdentity();
5648 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005649 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005650 // may happen if the device does not support IMS.
5651 return false;
5652 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005653 Map<Integer, String> featureConfig = new HashMap<>();
5654 for (int featureType : featureTypes) {
5655 featureConfig.put(featureType, packageName);
5656 }
5657 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5658 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005662 }
5663
5664 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005665 * Clears any carrier ImsService overrides for the slot index specified that were previously
5666 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5667 *
5668 * This should only be used for testing.
5669 *
5670 * @param slotIndex the slot ID that the ImsService should bind for.
5671 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5672 */
5673 @Override
5674 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5675 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5676 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5677 "clearCarrierImsServiceOverride");
5678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5679 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5680 "clearCarrierImsServiceOverride");
5681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
5684 if (mImsResolver == null) {
5685 // may happen if the device does not support IMS.
5686 return false;
5687 }
5688 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5689 } finally {
5690 Binder.restoreCallingIdentity(identity);
5691 }
5692 }
5693
5694 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005695 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005696 *
5697 * @param slotId The slot that the ImsService is associated with.
5698 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5699 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005700 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005701 * @return the package name of the ImsService configuration.
5702 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005703 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5704 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005705 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005706 TelephonyPermissions
5707 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5708 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5709 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 final long identity = Binder.clearCallingIdentity();
5712 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005713 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005714 // may happen if the device does not support IMS.
5715 return "";
5716 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005717 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005718 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5719 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005720 } finally {
5721 Binder.restoreCallingIdentity(identity);
5722 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005723 }
5724
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005725 /**
5726 * Get the MmTelFeature state associated with the requested subscription id.
5727 * @param subId The subscription that the MmTelFeature is associated with.
5728 * @param callback A callback with an integer containing the
5729 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5730 */
5731 @Override
5732 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5733 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5734 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5735 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5736 "IMS not available on device.");
5737 }
5738 final long token = Binder.clearCallingIdentity();
5739 try {
5740 int slotId = getSlotIndex(subId);
5741 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5742 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5743 + subId + "'");
5744 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5745 }
5746 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5747 try {
5748 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5749 } catch (RemoteException e) {
5750 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5751 + "Ignore");
5752 }
5753 });
5754 } finally {
5755 Binder.restoreCallingIdentity(token);
5756 }
5757 }
5758
Daniel Brightbb5840b2021-01-12 15:48:18 -08005759 /**
5760 * Sets the ims registration state on all valid {@link Phone}s.
5761 */
5762 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005763 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764
5765 final long identity = Binder.clearCallingIdentity();
5766 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005767 // NOTE: Before S, this method only set the default phone.
5768 for (final Phone phone : PhoneFactory.getPhones()) {
5769 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5770 phone.setImsRegistrationState(registered);
5771 }
5772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 } finally {
5774 Binder.restoreCallingIdentity(identity);
5775 }
Wink Saville36469e72014-06-11 15:17:00 -07005776 }
5777
5778 /**
Stuart Scott54788802015-03-30 13:18:01 -07005779 * Set the network selection mode to automatic.
5780 *
5781 */
5782 @Override
5783 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5785 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786
5787 final long identity = Binder.clearCallingIdentity();
5788 try {
shilufc958392020-01-20 11:36:01 -08005789 if (!isActiveSubscription(subId)) {
5790 return;
5791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005793 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5794 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005795 } finally {
5796 Binder.restoreCallingIdentity(identity);
5797 }
Stuart Scott54788802015-03-30 13:18:01 -07005798 }
5799
Jack Yud10cdd42020-09-28 20:28:01 -07005800 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005801 * Ask the radio to connect to the input network and change selection mode to manual.
5802 *
5803 * @param subId the id of the subscription.
5804 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5805 * the operator to attach to.
5806 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5807 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5808 * normal network selection next time.
5809 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005810 */
5811 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005812 public boolean setNetworkSelectionModeManual(
5813 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5815 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005816
5817 if (!isActiveSubscription(subId)) {
5818 return false;
5819 }
5820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 final long identity = Binder.clearCallingIdentity();
5822 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005823 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005825 if (DBG) {
5826 log("setNetworkSelectionModeManual: subId: " + subId
5827 + " operator: " + operatorInfo);
5828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5830 } finally {
5831 Binder.restoreCallingIdentity(identity);
5832 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005833 }
shilu84f6e8b2019-12-19 13:58:01 -08005834 /**
5835 * Get the manual network selection
5836 *
5837 * @param subId the id of the subscription.
5838 *
5839 * @return the previously saved user selected PLMN
5840 */
5841 @Override
5842 public String getManualNetworkSelectionPlmn(int subId) {
5843 TelephonyPermissions
5844 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5845 mApp, subId, "getManualNetworkSelectionPlmn");
5846
5847 final long identity = Binder.clearCallingIdentity();
5848 try {
5849 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005850 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005851 }
5852
5853 final Phone phone = getPhone(subId);
5854 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005855 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005856 }
5857 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5858 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5859 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
5863 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005864
5865 /**
5866 * Scans for available networks.
5867 */
5868 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005869 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5870 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005871 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5872 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005873 LocationAccessPolicy.LocationPermissionResult locationResult =
5874 LocationAccessPolicy.checkLocationPermission(mApp,
5875 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5876 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005877 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005878 .setCallingPid(Binder.getCallingPid())
5879 .setCallingUid(Binder.getCallingUid())
5880 .setMethod("getCellNetworkScanResults")
5881 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005882 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5883 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005884 .build());
5885 switch (locationResult) {
5886 case DENIED_HARD:
5887 throw new SecurityException("Not allowed to access scan results -- location");
5888 case DENIED_SOFT:
5889 return null;
5890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891
Pengquan Menga1bb6272018-09-06 09:59:22 -07005892 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 try {
5894 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005895 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 } finally {
5898 Binder.restoreCallingIdentity(identity);
5899 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005900 }
5901
5902 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005903 * Get the call forwarding info, given the call forwarding reason.
5904 */
5905 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005906 public void getCallForwarding(int subId, int callForwardingReason,
5907 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005908 enforceReadPrivilegedPermission("getCallForwarding");
5909 long identity = Binder.clearCallingIdentity();
5910 try {
5911 if (DBG) {
5912 log("getCallForwarding: subId " + subId
5913 + " callForwardingReason" + callForwardingReason);
5914 }
Hall Liu27d24262020-09-18 19:04:59 -07005915
5916 Phone phone = getPhone(subId);
5917 if (phone == null) {
5918 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005919 callback.onError(
5920 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005921 } catch (RemoteException e) {
5922 // ignore
5923 }
5924 return;
5925 }
5926
5927 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5928 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5929 @Override
5930 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5931 try {
5932 callback.onCallForwardingInfoAvailable(info);
5933 } catch (RemoteException e) {
5934 // ignore
5935 }
5936 }
5937
5938 @Override
5939 public void onError(int error) {
5940 try {
5941 callback.onError(error);
5942 } catch (RemoteException e) {
5943 // ignore
5944 }
5945 }
5946 });
5947 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
5951 }
5952
5953 /**
5954 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5955 * reason, the number to forward, and the timeout before the forwarding is attempted.
5956 */
5957 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005958 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5959 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005960 enforceModifyPermission();
5961 long identity = Binder.clearCallingIdentity();
5962 try {
5963 if (DBG) {
5964 log("setCallForwarding: subId " + subId
5965 + " callForwardingInfo" + callForwardingInfo);
5966 }
Hall Liu27d24262020-09-18 19:04:59 -07005967
5968 Phone phone = getPhone(subId);
5969 if (phone == null) {
5970 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005971 callback.accept(
5972 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005973 } catch (RemoteException e) {
5974 // ignore
5975 }
5976 return;
5977 }
5978
5979 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5980 FunctionalUtils.ignoreRemoteException(callback::accept));
5981
5982 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
5986 }
5987
5988 /**
Hall Liu27d24262020-09-18 19:04:59 -07005989 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005990 */
5991 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005992 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005993 enforceReadPrivilegedPermission("getCallForwarding");
5994 long identity = Binder.clearCallingIdentity();
5995 try {
Hall Liu27d24262020-09-18 19:04:59 -07005996
5997 Phone phone = getPhone(subId);
5998 if (phone == null) {
5999 try {
6000 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6001 } catch (RemoteException e) {
6002 // ignore
6003 }
6004 return;
6005 }
6006
6007 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
6008
Shuo Qian4a594052020-01-23 11:59:30 -08006009 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07006010 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
6014 }
6015
6016 /**
Hall Liu27d24262020-09-18 19:04:59 -07006017 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006018 */
6019 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006020 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006021 enforceModifyPermission();
6022 long identity = Binder.clearCallingIdentity();
6023 try {
Hall Liu27d24262020-09-18 19:04:59 -07006024 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6025
6026 Phone phone = getPhone(subId);
6027 if (phone == null) {
6028 try {
6029 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6030 } catch (RemoteException e) {
6031 // ignore
6032 }
6033 return;
6034 }
6035
6036 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6037 FunctionalUtils.ignoreRemoteException(callback::accept));
6038
6039 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006040 } finally {
6041 Binder.restoreCallingIdentity(identity);
6042 }
6043 }
6044
6045 /**
yinxub1bed742017-04-17 11:45:04 -07006046 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006047 *
yinxub1bed742017-04-17 11:45:04 -07006048 * @param subId id of the subscription
6049 * @param request contains the radio access networks with bands/channels to scan
6050 * @param messenger callback messenger for scan results or errors
6051 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006052 * @return the id of the requested scan which can be used to stop the scan.
6053 */
6054 @Override
6055 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006056 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6058 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006059 LocationAccessPolicy.LocationPermissionResult locationResult =
6060 LocationAccessPolicy.checkLocationPermission(mApp,
6061 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6062 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006063 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006064 .setCallingPid(Binder.getCallingPid())
6065 .setCallingUid(Binder.getCallingUid())
6066 .setMethod("requestNetworkScan")
6067 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006068 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6069 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006070 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006071 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006072 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6073 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006074 if (e != null) {
6075 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6076 throw e;
6077 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006078 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006079 return TelephonyScanManager.INVALID_SCAN_ID;
6080 }
6081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006082 }
Hall Liu912dfd32019-04-25 14:02:26 -07006083 int callingUid = Binder.getCallingUid();
6084 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 return mNetworkScanRequestTracker.startNetworkScan(
6088 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006089 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
yinxu504e1392017-04-12 16:03:22 -07006093 }
6094
Hall Liub2ac8ef2019-02-28 15:56:23 -08006095 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006096 NetworkScanRequest request, int subId, String callingPackage) {
6097 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006098 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6099 boolean hasNetworkScanPermission =
6100 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6101 == PERMISSION_GRANTED;
6102
6103 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6104 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6105 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006106 }
6107
6108 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6109 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006110 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6111 return new SecurityException("Specific channels must not be"
6112 + " scanned without location access.");
6113 }
6114 }
6115 }
6116
Hall Liub2ac8ef2019-02-28 15:56:23 -08006117 return null;
6118 }
6119
yinxu504e1392017-04-12 16:03:22 -07006120 /**
6121 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006122 *
6123 * @param subId id of the subscription
6124 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006125 */
6126 @Override
6127 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6129 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130
Hall Liu912dfd32019-04-25 14:02:26 -07006131 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 final long identity = Binder.clearCallingIdentity();
6133 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006134 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
yinxu504e1392017-04-12 16:03:22 -07006138 }
6139
6140 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006141 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006142 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006143 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006144 */
6145 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006146 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006147 TelephonyPermissions
6148 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006149 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150
6151 final long identity = Binder.clearCallingIdentity();
6152 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006153 if (DBG) log("getAllowedNetworkTypesBitmask");
6154 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6155 int networkTypesBitmask = (result != null ? result[0] : -1);
6156 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6157 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 } finally {
6159 Binder.restoreCallingIdentity(identity);
6160 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006161 }
6162
6163 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006164 * Get the allowed network types for certain reason.
6165 *
6166 * @param subId the id of the subscription.
6167 * @param reason the reason the allowed network type change is taking place
6168 * @return the allowed network types.
6169 */
6170 @Override
6171 public long getAllowedNetworkTypesForReason(int subId,
6172 @TelephonyManager.AllowedNetworkTypesReason int reason) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006173 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6174 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006175 final long identity = Binder.clearCallingIdentity();
6176 try {
6177 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
6180 }
6181 }
6182
6183 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006184 * Enable/Disable E-UTRA-NR Dual Connectivity
6185 * @param subId subscription id of the sim card
6186 * @param nrDualConnectivityState expected NR dual connectivity state
6187 * This can be passed following states
6188 * <ol>
6189 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6190 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6191 * <li>Disable NR dual connectivity and force secondary cell to be released
6192 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6193 * </ol>
6194 * @return operation result.
6195 */
6196 @Override
6197 public int setNrDualConnectivityState(int subId,
6198 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6200 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006201 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006202 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6203 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6204 }
6205
Sooraj Sasindran37444802020-08-11 10:40:43 -07006206 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6207 final long identity = Binder.clearCallingIdentity();
6208 try {
6209 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6210 nrDualConnectivityState, subId,
6211 workSource);
6212 if (DBG) log("enableNRDualConnectivity result: " + result);
6213 return result;
6214 } finally {
6215 Binder.restoreCallingIdentity(identity);
6216 }
6217 }
6218
6219 /**
6220 * Is E-UTRA-NR Dual Connectivity enabled
6221 * @return true if dual connectivity is enabled else false
6222 */
6223 @Override
6224 public boolean isNrDualConnectivityEnabled(int subId) {
6225 TelephonyPermissions
6226 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6227 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006228 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006229 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6230 return false;
6231 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006232 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6233 final long identity = Binder.clearCallingIdentity();
6234 try {
6235 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6236 null, subId, workSource);
6237 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6238 return isEnabled;
6239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
6242 }
6243
6244 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006245 * Set the allowed network types of the device and
6246 * provide the reason triggering the allowed network change.
6247 *
6248 * @param subId the id of the subscription.
6249 * @param reason the reason the allowed network type change is taking place
6250 * @param allowedNetworkTypes the allowed network types.
6251 * @return true on success; false on any failure.
6252 */
6253 @Override
6254 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006255 @TelephonyManager.AllowedNetworkTypesReason int reason,
6256 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006257 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6258 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006259 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6260 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6261 return false;
6262 }
6263
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006264 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6265 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6266
6267
6268 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6269 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6270 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006271 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006272
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006273 final long identity = Binder.clearCallingIdentity();
6274 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006275 Boolean success = (Boolean) sendRequest(
6276 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6277 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6278
6279 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6280 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006281 } finally {
6282 Binder.restoreCallingIdentity(identity);
6283 }
6284 }
6285
6286 /**
Miaoa84611c2019-03-15 09:21:10 +08006287 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006288 *
Miaoa84611c2019-03-15 09:21:10 +08006289 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006290 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006291 * @hide
6292 */
6293 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006294 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006295 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006297 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 try {
Miaoa84611c2019-03-15 09:21:10 +08006299 if (phone != null) {
6300 return phone.hasMatchedTetherApnSetting();
6301 } else {
6302 return false;
6303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 } finally {
6305 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006306 }
Junda Liu475951f2014-11-07 16:45:03 -08006307 }
6308
6309 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006310 * Enable or disable always reporting signal strength changes from radio.
6311 *
6312 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6313 */
6314 @Override
6315 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6316 enforceModifyPermission();
6317 enforceSystemCaller();
6318
6319 final long identity = Binder.clearCallingIdentity();
6320 final Phone phone = getPhone(subId);
6321 try {
6322 if (phone != null) {
6323 if (DBG) {
6324 log("setAlwaysReportSignalStrength: subId=" + subId
6325 + " isEnable=" + isEnable);
6326 }
6327 phone.setAlwaysReportSignalStrength(isEnable);
6328 } else {
6329 loge("setAlwaysReportSignalStrength: no phone found for subId="
6330 + subId);
6331 }
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
6335 }
6336
6337 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006338 * Get the user enabled state of Mobile Data.
6339 *
6340 * TODO: remove and use isUserDataEnabled.
6341 * This can't be removed now because some vendor codes
6342 * calls through ITelephony directly while they should
6343 * use TelephonyManager.
6344 *
6345 * @return true on enabled
6346 */
6347 @Override
6348 public boolean getDataEnabled(int subId) {
6349 return isUserDataEnabled(subId);
6350 }
6351
6352 /**
6353 * Get whether mobile data is enabled per user setting.
6354 *
6355 * There are other factors deciding whether mobile data is actually enabled, but they are
6356 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006357 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006358 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006359 *
6360 * @return {@code true} if data is enabled else {@code false}
6361 */
6362 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006363 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006364 try {
6365 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6366 null);
6367 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6369 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371
6372 final long identity = Binder.clearCallingIdentity();
6373 try {
6374 int phoneId = mSubscriptionController.getPhoneId(subId);
6375 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6376 Phone phone = PhoneFactory.getPhone(phoneId);
6377 if (phone != null) {
6378 boolean retVal = phone.isUserDataEnabled();
6379 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6380 return retVal;
6381 } else {
6382 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6383 return false;
6384 }
6385 } finally {
6386 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006387 }
6388 }
6389
6390 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006391 * Checks if the device is capable of mobile data by considering whether whether the
6392 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6393 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006394 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006395 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006396 */
6397 @Override
6398 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006399 try {
6400 try {
6401 mApp.enforceCallingOrSelfPermission(
6402 android.Manifest.permission.ACCESS_NETWORK_STATE,
6403 null);
6404 } catch (Exception e) {
6405 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6406 "isDataEnabled");
6407 }
6408 } catch (Exception e) {
6409 enforceReadPrivilegedPermission("isDataEnabled");
6410 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411
6412 final long identity = Binder.clearCallingIdentity();
6413 try {
6414 int phoneId = mSubscriptionController.getPhoneId(subId);
6415 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6416 Phone phone = PhoneFactory.getPhone(phoneId);
6417 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006418 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6420 return retVal;
6421 } else {
6422 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6423 return false;
6424 }
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006427 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006428 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006429
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006430 /**
6431 * Check if data is enabled for a specific reason
6432 * @param subId Subscription index
6433 * @param reason the reason the data enable change is taking place
6434 * @return {@code true} if the overall data is enabled; {@code false} if not.
6435 */
6436 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006437 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006438 @TelephonyManager.DataEnabledReason int reason) {
6439 try {
6440 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6441 null);
6442 } catch (Exception e) {
6443 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006444 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006445 }
6446
6447
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 int phoneId = mSubscriptionController.getPhoneId(subId);
6451 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006452 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006453 + " reason=" + reason);
6454 }
6455 Phone phone = PhoneFactory.getPhone(phoneId);
6456 if (phone != null) {
6457 boolean retVal;
6458 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6459 retVal = phone.isUserDataEnabled();
6460 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006461 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006462 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006463 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006464 return retVal;
6465 } else {
6466 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006467 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006468 + subId + " retVal=false");
6469 }
6470 return false;
6471 }
6472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
6475 }
6476
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006477 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006478 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006479 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6480 // Skip the check if it's one of these special uids
6481 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6482 }
6483
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006484 //load access rules from carrier configs, and check those as well: b/139133814
6485 SubscriptionController subController = SubscriptionController.getInstance();
6486 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6487 || subController == null) return privilegeFromSim;
6488
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006489 PackageManager pkgMgr = phone.getContext().getPackageManager();
6490 String[] packages = pkgMgr.getPackagesForUid(uid);
6491
6492 final long identity = Binder.clearCallingIdentity();
6493 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006494 int subId = phone.getSubId();
6495 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6496 // A test override is in place for the privileges for this subId, so don't try to
6497 // read the subscription privileges.
6498 return privilegeFromSim;
6499 }
6500 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006501 SubscriptionManager subManager = (SubscriptionManager)
6502 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6503 for (String pkg : packages) {
6504 if (subManager.canManageSubscription(subInfo, pkg)) {
6505 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6506 }
6507 }
6508 return privilegeFromSim;
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
6512 }
6513
6514 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6515 String pkgName) {
6516 //load access rules from carrier configs, and check those as well: b/139133814
6517 SubscriptionController subController = SubscriptionController.getInstance();
6518 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6519 || subController == null) return privilegeFromSim;
6520
6521 final long identity = Binder.clearCallingIdentity();
6522 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006523 int subId = phone.getSubId();
6524 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6525 // A test override is in place for the privileges for this subId, so don't try to
6526 // read the subscription privileges.
6527 return privilegeFromSim;
6528 }
6529 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006530 SubscriptionManager subManager = (SubscriptionManager)
6531 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6532 return subManager.canManageSubscription(subInfo, pkgName)
6533 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6534 } finally {
6535 Binder.restoreCallingIdentity(identity);
6536 }
6537 }
6538
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006539 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006540 public int getCarrierPrivilegeStatus(int subId) {
6541 final Phone phone = getPhone(subId);
6542 if (phone == null) {
6543 loge("getCarrierPrivilegeStatus: Invalid subId");
6544 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6545 }
6546 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006547 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006548 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006549 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6550 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006551
6552 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6553 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006554 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006555 }
Junda Liu29340342014-07-10 15:23:27 -07006556
6557 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006558 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006559 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006560 final Phone phone = getPhone(subId);
6561 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006562 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006563 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6564 }
6565 UiccProfile profile =
6566 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6567 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006568 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006569 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6570 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006571 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006572 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006573 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006574 }
6575
6576 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006577 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6578 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006579 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006580 }
6581
6582 int phoneId = SubscriptionManager.getPhoneId(subId);
6583 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006584 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006585 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006586 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6587 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006588 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6589 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6590 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006591 }
6592
6593 @Override
6594 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006595 if (TextUtils.isEmpty(pkgName))
6596 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006597 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6598 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6599 UiccCard card = UiccController.getInstance().getUiccCard(i);
6600 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006601 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006602 continue;
6603 }
6604
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006605 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6606 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6607 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006608 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6609 break;
6610 }
6611 }
6612
6613 return result;
Junda Liu29340342014-07-10 15:23:27 -07006614 }
Derek Tan89e89d42014-07-08 17:00:10 -07006615
6616 @Override
Junda Liue64de782015-04-16 17:19:16 -07006617 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6618 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6619 loge("phoneId " + phoneId + " is not valid.");
6620 return null;
6621 }
6622 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006623 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006624 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006625 return null ;
6626 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006627 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006628 }
6629
Amith Yamasani6e118872016-02-19 12:53:51 -08006630 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006631 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006632 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006633 List<String> privilegedPackages = new ArrayList<>();
6634 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006635 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6636 // has UICC in that slot.
6637 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006638 if (card.hasCarrierPrivilegeRules()) {
6639 if (packages == null) {
6640 // Only check packages in user 0 for now
6641 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006642 PackageManager.MATCH_DISABLED_COMPONENTS
6643 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006644 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006645 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006646 }
6647 for (int p = packages.size() - 1; p >= 0; p--) {
6648 PackageInfo pkgInfo = packages.get(p);
6649 if (pkgInfo != null && pkgInfo.packageName != null
6650 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006651 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006652 privilegedPackages.add(pkgInfo.packageName);
6653 }
6654 }
6655 }
6656 }
6657 return privilegedPackages;
6658 }
6659
chen xuf7e9fe82019-05-09 19:31:02 -07006660 @Override
6661 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006662 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6663
6664 final long identity = Binder.clearCallingIdentity();
6665
chen xuf7e9fe82019-05-09 19:31:02 -07006666 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006667 try {
6668 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6669 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6670 }
6671 } finally {
6672 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006673 }
6674 return privilegedPackages;
6675 }
6676
Wink Savilleb564aae2014-10-23 10:18:09 -07006677 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006678 final Phone phone = getPhone(subId);
6679 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006680 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006681 return null;
6682 }
6683 String iccId = card.getIccId();
6684 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006685 return null;
6686 }
6687 return iccId;
6688 }
6689
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006690 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006691 public void setCallComposerStatus(int subId, int status) {
6692 enforceModifyPermission();
6693
6694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 Phone phone = getPhone(subId);
6697 if (phone != null) {
6698 Phone defaultPhone = phone.getImsPhone();
6699 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6700 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6701 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006702 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6703 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006704 }
6705 }
Shuo Qian284ae752020-12-22 19:10:14 -08006706 } catch (ImsException e) {
6707 throw new ServiceSpecificException(e.getCode());
6708 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006709 Binder.restoreCallingIdentity(identity);
6710 }
6711 }
6712
6713 @Override
6714 public int getCallComposerStatus(int subId) {
6715 enforceReadPrivilegedPermission("getCallComposerStatus");
6716
6717 final long identity = Binder.clearCallingIdentity();
6718 try {
6719 Phone phone = getPhone(subId);
6720 if (phone != null) {
6721 Phone defaultPhone = phone.getImsPhone();
6722 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6723 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6724 return imsPhone.getCallComposerStatus();
6725 }
6726 }
6727 } finally {
6728 Binder.restoreCallingIdentity(identity);
6729 }
6730 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6731 }
6732
6733 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006734 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6735 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006736 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006737 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006738
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739 final long identity = Binder.clearCallingIdentity();
6740 try {
6741 final String iccId = getIccId(subId);
6742 final Phone phone = getPhone(subId);
6743 if (phone == null) {
6744 return false;
6745 }
6746 final String subscriberId = phone.getSubscriberId();
6747
6748 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006749 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 + subscriberId + " to " + number);
6751 }
6752
6753 if (TextUtils.isEmpty(iccId)) {
6754 return false;
6755 }
6756
6757 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6758
6759 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6760 if (alphaTag == null) {
6761 editor.remove(alphaTagPrefKey);
6762 } else {
6763 editor.putString(alphaTagPrefKey, alphaTag);
6764 }
6765
6766 // Record both the line number and IMSI for this ICCID, since we need to
6767 // track all merged IMSIs based on line number
6768 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6769 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6770 if (number == null) {
6771 editor.remove(numberPrefKey);
6772 editor.remove(subscriberPrefKey);
6773 } else {
6774 editor.putString(numberPrefKey, number);
6775 editor.putString(subscriberPrefKey, subscriberId);
6776 }
6777
6778 editor.commit();
6779 return true;
6780 } finally {
6781 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006782 }
Derek Tan7226c842014-07-02 17:42:23 -07006783 }
6784
6785 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006786 public String getLine1NumberForDisplay(int subId, String callingPackage,
6787 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006788 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006790 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006791 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006792 return null;
6793 }
Derek Tan97ebb422014-09-05 16:55:38 -07006794
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 final long identity = Binder.clearCallingIdentity();
6796 try {
6797 String iccId = getIccId(subId);
6798 if (iccId != null) {
6799 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6800 if (DBG_MERGE) {
6801 log("getLine1NumberForDisplay returning "
6802 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6803 }
6804 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6807 return null;
6808 } finally {
6809 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006810 }
Derek Tan7226c842014-07-02 17:42:23 -07006811 }
6812
6813 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006814 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6815 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006816 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006817 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006818 return null;
6819 }
Derek Tan97ebb422014-09-05 16:55:38 -07006820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 final long identity = Binder.clearCallingIdentity();
6822 try {
6823 String iccId = getIccId(subId);
6824 if (iccId != null) {
6825 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6826 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6827 }
6828 return null;
6829 } finally {
6830 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006831 }
Derek Tan7226c842014-07-02 17:42:23 -07006832 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006833
6834 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006835 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6836 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006837 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6838 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006839 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006840 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006841 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006842 return null;
6843 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006844
Jordan Liub49b04b2019-05-06 14:45:15 -07006845 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6846 // the process, where TelephonyManager was instantiated.
6847 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006848 final long identity = Binder.clearCallingIdentity();
6849 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006850 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851 final TelephonyManager tele = TelephonyManager.from(context);
6852 final SubscriptionManager sub = SubscriptionManager.from(context);
6853
6854 // Figure out what subscribers are currently active
6855 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856
Jordan Liub49b04b2019-05-06 14:45:15 -07006857 // Only consider subs which match the current subId
6858 // This logic can be simplified. See b/131189269 for progress.
6859 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006860 activeSubscriberIds.add(tele.getSubscriberId(subId));
6861 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862
6863 // First pass, find a number override for an active subscriber
6864 String mergeNumber = null;
6865 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6866 for (String key : prefs.keySet()) {
6867 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6868 final String subscriberId = (String) prefs.get(key);
6869 if (activeSubscriberIds.contains(subscriberId)) {
6870 final String iccId = key.substring(
6871 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6872 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6873 mergeNumber = (String) prefs.get(numberKey);
6874 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006875 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006876 + " for active subscriber " + subscriberId);
6877 }
6878 if (!TextUtils.isEmpty(mergeNumber)) {
6879 break;
6880 }
6881 }
6882 }
6883 }
6884
6885 // Shortcut when no active merged subscribers
6886 if (TextUtils.isEmpty(mergeNumber)) {
6887 return null;
6888 }
6889
6890 // Second pass, find all subscribers under that line override
6891 final ArraySet<String> result = new ArraySet<>();
6892 for (String key : prefs.keySet()) {
6893 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6894 final String number = (String) prefs.get(key);
6895 if (mergeNumber.equals(number)) {
6896 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6897 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6898 final String subscriberId = (String) prefs.get(subscriberKey);
6899 if (!TextUtils.isEmpty(subscriberId)) {
6900 result.add(subscriberId);
6901 }
6902 }
6903 }
6904 }
6905
6906 final String[] resultArray = result.toArray(new String[result.size()]);
6907 Arrays.sort(resultArray);
6908 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006909 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6911 }
6912 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006913 } finally {
6914 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006915 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006916 }
6917
6918 @Override
zoey chen38003472019-12-13 17:16:31 +08006919 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6920 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 final TelephonyManager telephonyManager = mApp.getSystemService(
6925 TelephonyManager.class);
6926 String subscriberId = telephonyManager.getSubscriberId(subId);
6927 if (subscriberId == null) {
6928 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006929 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006930 + subId);
6931 }
6932 return null;
6933 }
6934
6935 final SubscriptionInfo info = SubscriptionController.getInstance()
6936 .getSubscriptionInfo(subId);
6937 final ParcelUuid groupUuid = info.getGroupUuid();
6938 // If it doesn't belong to any group, return just subscriberId of itself.
6939 if (groupUuid == null) {
6940 return new String[]{subscriberId};
6941 }
6942
6943 // Get all subscriberIds from the group.
6944 final List<String> mergedSubscriberIds = new ArrayList<>();
6945 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006946 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006947 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006948 for (SubscriptionInfo subInfo : groupInfos) {
6949 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6950 if (subscriberId != null) {
6951 mergedSubscriberIds.add(subscriberId);
6952 }
6953 }
6954
6955 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
6958
6959 }
6960 }
6961
6962 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006963 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006964 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006965 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966
6967 final long identity = Binder.clearCallingIdentity();
6968 try {
6969 final Phone phone = getPhone(subId);
6970 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6971 } finally {
6972 Binder.restoreCallingIdentity(identity);
6973 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006974 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006975
6976 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006977 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006978 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6979 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006980 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6981 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982
6983 final long identity = Binder.clearCallingIdentity();
6984 try {
6985 final Phone phone = getPhone(subId);
6986 if (phone == null) {
6987 return false;
6988 }
6989 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6990 cdmaNonRoamingList);
6991 } finally {
6992 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006993 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006994 }
6995
6996 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006997 @Deprecated
6998 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6999 enforceModifyPermission();
7000
7001 int returnValue = 0;
7002 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007003 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007004 if(result.exception == null) {
7005 if (result.result != null) {
7006 byte[] responseData = (byte[])(result.result);
7007 if(responseData.length > oemResp.length) {
7008 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7009 responseData.length + "bytes. Buffer Size is " +
7010 oemResp.length + "bytes.");
7011 }
7012 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7013 returnValue = responseData.length;
7014 }
7015 } else {
7016 CommandException ex = (CommandException) result.exception;
7017 returnValue = ex.getCommandError().ordinal();
7018 if(returnValue > 0) returnValue *= -1;
7019 }
7020 } catch (RuntimeException e) {
7021 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7022 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7023 if(returnValue > 0) returnValue *= -1;
7024 }
7025
7026 return returnValue;
7027 }
7028
7029 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007030 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007031 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007032 try {
7033 TelephonyPermissions
7034 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7035 mApp, phone.getSubId(), "getRadioAccessFamily");
7036 } catch (SecurityException e) {
7037 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7038 throw e;
7039 }
chen xub97461a2018-10-26 14:17:57 -07007040 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007041 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007042 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007043 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 final long identity = Binder.clearCallingIdentity();
7045 try {
chen xub97461a2018-10-26 14:17:57 -07007046 TelephonyPermissions
7047 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7048 mApp, phone.getSubId(), "getRadioAccessFamily");
7049 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 } finally {
7051 Binder.restoreCallingIdentity(identity);
7052 }
chen xub97461a2018-10-26 14:17:57 -07007053 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007054 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007055
7056 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007057 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007058 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007059 try {
7060 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7061 Binder.getCallingUid())) {
7062 throw new SecurityException("Package uid and package name do not match: "
7063 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7064 }
7065 } catch (PackageManager.NameNotFoundException e) {
7066 throw new SecurityException("Package name invalid:" + callingPackage);
7067 }
7068 RoleManager rm = mApp.getSystemService(RoleManager.class);
7069 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7070 if (!dialerRoleHolders.contains(callingPackage)) {
7071 throw new SecurityException("App must be the dialer role holder to"
7072 + " upload a call composer pic");
7073 }
7074
7075 Executors.newSingleThreadExecutor().execute(() -> {
7076 ByteArrayOutputStream output = new ByteArrayOutputStream(
7077 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7078 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7079 boolean readUntilEnd = false;
7080 int totalBytesRead = 0;
7081 byte[] buffer = new byte[16 * 1024];
7082 while (true) {
7083 int numRead;
7084 try {
7085 numRead = input.read(buffer);
7086 } catch (IOException e) {
7087 try {
7088 fd.checkError();
7089 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7090 null);
7091 } catch (IOException e1) {
7092 // This means that the other side closed explicitly with an error. If this
7093 // happens, log and ignore.
7094 loge("Remote end of call composer picture pipe closed: " + e1);
7095 }
7096 break;
7097 }
7098 if (numRead == -1) {
7099 readUntilEnd = true;
7100 break;
7101 }
7102 totalBytesRead += numRead;
7103 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7104 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7105 try {
7106 input.close();
7107 } catch (IOException e) {
7108 // ignore
7109 }
7110 break;
7111 }
7112 output.write(buffer, 0, numRead);
7113 }
7114 // Generally, the remote end will close the file descriptors. The only case where we
7115 // close is above, where the picture size is too big.
7116
7117 try {
7118 fd.checkError();
7119 } catch (IOException e) {
7120 loge("Remote end for call composer closed with an error: " + e);
7121 return;
7122 }
7123
Hall Liuaa4211e2021-01-20 15:43:39 -08007124 if (!readUntilEnd) {
7125 loge("Did not finish reading entire image; aborting");
7126 return;
7127 }
Hall Liu82694d52020-12-11 18:22:04 -08007128
Hall Liuaa4211e2021-01-20 15:43:39 -08007129 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7130 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7131 new CallComposerPictureTransfer.Factory() {},
7132 imageData,
7133 (result) -> {
7134 if (result.first != null) {
7135 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7136 Bundle outputResult = new Bundle();
7137 outputResult.putParcelable(
7138 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7139 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7140 outputResult);
7141 } else {
7142 callback.send(result.second, null);
7143 }
7144 }
7145 );
Hall Liu82694d52020-12-11 18:22:04 -08007146 });
7147 }
7148
7149 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007150 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007151 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007156 ImsManager.getInstance(defaultPhone.getContext(),
7157 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 } finally {
7159 Binder.restoreCallingIdentity(identity);
7160 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007161 }
7162
7163 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007164 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007165 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007166 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7167 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007168 return false;
7169 }
Svet Ganovb320e182015-04-16 12:30:10 -07007170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 final long identity = Binder.clearCallingIdentity();
7172 try {
7173 // Check the user preference and the system-level IMS setting. Even if the user has
7174 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7175 // In the long run, we may instead need to check if there exists a connection service
7176 // which can support video calling.
7177 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007178 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 return imsManager.isVtEnabledByPlatform()
7180 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7181 && imsManager.isVtEnabledByUser();
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
7184 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007185 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007186
Andrew Leea1239f22015-03-02 17:44:07 -08007187 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007188 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7189 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007191 mApp, subId, callingPackage, callingFeatureId,
7192 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 return false;
7194 }
7195
7196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 CarrierConfigManager configManager =
7199 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007200 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
Andrew Leea1239f22015-03-02 17:44:07 -08007205 }
7206
7207 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007208 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007210 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 return false;
7212 }
7213
7214 final long identity = Binder.clearCallingIdentity();
7215 try {
7216 CarrierConfigManager configManager =
7217 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007218 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7220 } finally {
7221 Binder.restoreCallingIdentity(identity);
7222 }
Andrew Leea1239f22015-03-02 17:44:07 -08007223 }
7224
Andrew Lee9431b832015-03-09 18:46:45 -07007225 @Override
7226 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007227 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007228 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007229 }
7230
7231 @Override
7232 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 final long identity = Binder.clearCallingIdentity();
7234 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007235 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
Andrew Lee9431b832015-03-09 18:46:45 -07007239 }
7240
Hall Liuf6668912018-10-31 17:05:23 -07007241 /**
7242 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7243 * support for the feature and device firmware support.
7244 *
7245 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7246 */
7247 @Override
7248 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007250 final Phone phone = getPhone(subscriptionId);
7251 if (phone == null) {
7252 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7253 return false;
7254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007256 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7258 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007259 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 return isCarrierSupported && isDeviceSupported;
7261 } finally {
7262 Binder.restoreCallingIdentity(identity);
7263 }
Hall Liu98187582018-01-22 19:15:32 -08007264 }
7265
Hall Liuf6668912018-10-31 17:05:23 -07007266 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007267 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7268 * RTT setting, will return true if the device and carrier both support RTT.
7269 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007270 */
7271 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007272 final long identity = Binder.clearCallingIdentity();
7273 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007274 boolean isRttSupported = isRttSupported(subscriptionId);
7275 boolean isUserRttSettingOn = Settings.Secure.getInt(
7276 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7277 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7278 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7279 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007283 }
7284
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007285 @Deprecated
7286 @Override
7287 public String getDeviceId(String callingPackage) {
7288 return getDeviceIdWithFeature(callingPackage, null);
7289 }
7290
Sanket Padawe7310cc72015-01-14 09:53:20 -08007291 /**
7292 * Returns the unique device ID of phone, for example, the IMEI for
7293 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7294 *
7295 * <p>Requires Permission:
7296 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7297 */
7298 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007299 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007300 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007301 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007302 return null;
7303 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007304 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007305 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007306 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007307 return null;
7308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309
7310 final long identity = Binder.clearCallingIdentity();
7311 try {
7312 return phone.getDeviceId();
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
7315 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007316 }
7317
Ping Sunc67b7c22016-03-02 19:16:45 +08007318 /**
7319 * {@hide}
7320 * Returns the IMS Registration Status on a particular subid
7321 *
7322 * @param subId
7323 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007324 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007325 Phone phone = getPhone(subId);
7326 if (phone != null) {
7327 return phone.isImsRegistered();
7328 } else {
7329 return false;
7330 }
7331 }
7332
Santos Cordon7a1885b2015-02-03 11:15:19 -08007333 @Override
7334 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 final long identity = Binder.clearCallingIdentity();
7336 try {
7337 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007341 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007342
Tyler Gunnf70ed162019-04-03 15:28:53 -07007343 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007344 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007345 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007347 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007348 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7349 }
7350 final long identity = Binder.clearCallingIdentity();
7351 try {
7352 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7353 } finally {
7354 Binder.restoreCallingIdentity(identity);
7355 }
7356 }
7357
7358 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007359 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007360 TelephonyPermissions
7361 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7362 mApp,
7363 subscriptionId,
7364 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007365 final long identity = Binder.clearCallingIdentity();
7366 try {
7367 Phone phone = getPhone(subscriptionId);
7368 if (phone == null) {
7369 return null;
7370 }
7371 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7372 } finally {
7373 Binder.restoreCallingIdentity(identity);
7374 }
7375 }
7376
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007377 /**
7378 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007379 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007380 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 final long identity = Binder.clearCallingIdentity();
7382 try {
7383 Phone phone = getPhone(subId);
7384 if (phone != null) {
7385 return phone.isWifiCallingEnabled();
7386 } else {
7387 return false;
7388 }
7389 } finally {
7390 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007391 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007392 }
7393
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007394 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007395 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007396 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007397 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007398 final long identity = Binder.clearCallingIdentity();
7399 try {
7400 Phone phone = getPhone(subId);
7401 if (phone != null) {
7402 return phone.isVideoEnabled();
7403 } else {
7404 return false;
7405 }
7406 } finally {
7407 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007408 }
7409 }
7410
7411 /**
7412 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7413 * defined in {@link ImsRegistrationImplBase}.
7414 */
7415 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 final long identity = Binder.clearCallingIdentity();
7417 try {
7418 Phone phone = getPhone(subId);
7419 if (phone != null) {
7420 return phone.getImsRegistrationTech();
7421 } else {
7422 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7423 }
7424 } finally {
7425 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007426 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007427 }
7428
Stuart Scott8eef64f2015-04-08 15:13:54 -07007429 @Override
7430 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007431 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007432 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7433 return;
7434 }
Kai Shif70f46f2021-03-03 13:59:46 -08007435 Phone defaultPhone = getDefaultPhone();
7436 if (defaultPhone != null) {
7437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7438 mApp, getDefaultPhone().getSubId(), "factoryReset");
7439 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007440 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007441
Svet Ganovcc087f82015-05-12 20:35:54 -07007442 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007443 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7444 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007445 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007446 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007447 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007448 Phone phone = getPhone(subId);
7449 if (phone != null) {
7450 SubscriptionManager.setSubscriptionProperty(subId,
7451 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7452 "user=" + RadioAccessFamily.getRafFromNetworkType(
7453 RILConstants.PREFERRED_NETWORK_MODE));
7454 phone.loadAllowedNetworksFromSubscriptionDatabase();
7455 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007456 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7457 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007458 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007459 // There has been issues when Sms raw table somehow stores orphan
7460 // fragments. They lead to garbled message when new fragments come
7461 // in and combined with those stale ones. In case this happens again,
7462 // user can reset all network settings which will clean up this table.
7463 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007464 // Clean up IMS settings as well here.
7465 int slotId = getSlotIndex(subId);
7466 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7467 ImsManager.getInstance(mApp, slotId).factoryReset();
7468 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007469
Kai Shif70f46f2021-03-03 13:59:46 -08007470 if (defaultPhone == null) {
7471 return;
7472 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007473 // Erase modem config if erase modem on network setting is enabled.
7474 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7475 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7476 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007477 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007478 }
Kai Shif70f46f2021-03-03 13:59:46 -08007479
7480 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007481 } finally {
7482 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007483 }
7484 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007485
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007486 private void cleanUpSmsRawTable(Context context) {
7487 ContentResolver resolver = context.getContentResolver();
7488 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7489 resolver.delete(uri, null, null);
7490 }
7491
Narayan Kamath1c496c22015-04-16 14:40:19 +01007492 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007493 public String getSimLocaleForSubscriber(int subId) {
7494 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7495 final Phone phone = getPhone(subId);
7496 if (phone == null) {
7497 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007498 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 final long identity = Binder.clearCallingIdentity();
7501 try {
chen xu5d3637b2019-01-21 23:31:38 -08007502 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007503 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007504 if (info == null) {
7505 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7506 return null;
7507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 // Try and fetch the locale from the carrier properties or from the SIM language
7509 // preferences (EF-PL and EF-LI)...
7510 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007512 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7513 if (localeFromDefaultSim != null) {
7514 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7515 if (DBG) log("Using locale from subId: " + subId + " locale: "
7516 + localeFromDefaultSim);
7517 return localeFromDefaultSim.toLanguageTag();
7518 } else {
7519 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 }
7521 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007522
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007523 // The SIM language preferences only store a language (e.g. fr = French), not an
7524 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7525 // the SIM and carrier preferences does not include a country we add the country
7526 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007527 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007529 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007530 return mccLocale.toLanguageTag();
7531 }
7532
7533 if (DBG) log("No locale found - returning null");
7534 return null;
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007538 }
7539
7540 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007541 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007542 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007543 }
7544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 /**
7546 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7547 */
7548 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007549 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007550 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007551 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007552
Chenjie Yu1ba97252018-01-11 18:16:20 -08007553 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007554 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007555
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007556 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007557 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7558 * representing the state of the modem.
7559 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007560 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7561 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007562 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007563 */
7564 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007565 public void requestModemActivityInfo(ResultReceiver result) {
7566 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007567 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007568
7569 final long identity = Binder.clearCallingIdentity();
7570 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007571 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 } finally {
7573 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007574 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007575 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007576
Siddharth Rayb8114062018-06-17 15:02:38 -07007577 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7578 // less than total activity duration.
7579 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7580 if (info == null) {
7581 return false;
7582 }
7583 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007584 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7585 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7586
Siddharth Rayb8114062018-06-17 15:02:38 -07007587 return (info.isValid()
7588 && (info.getSleepTimeMillis() <= activityDurationMs)
7589 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007590 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007591 && (totalTxTimeMs <= activityDurationMs));
7592 }
7593
Jack Yu85bd38a2015-11-09 11:34:32 -08007594 /**
7595 * {@hide}
7596 * Returns the service state information on specified subscription.
7597 */
7598 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007599 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7600 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007601 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007602 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007603 return null;
7604 }
7605
Hall Liuf19c44f2018-11-27 14:38:17 -08007606 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7607 LocationAccessPolicy.checkLocationPermission(mApp,
7608 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7609 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007610 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007611 .setCallingPid(Binder.getCallingPid())
7612 .setCallingUid(Binder.getCallingUid())
7613 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007614 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007615 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007616 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7617 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007618 .build());
7619
7620 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7621 LocationAccessPolicy.checkLocationPermission(mApp,
7622 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7623 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007624 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007625 .setCallingPid(Binder.getCallingPid())
7626 .setCallingUid(Binder.getCallingUid())
7627 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007628 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007629 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007630 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7631 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007632 .build());
7633 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7634 boolean hasFinePermission =
7635 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7636 boolean hasCoarsePermission =
7637 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7638
Jack Yu479f40e2020-10-27 21:29:25 -07007639 final Phone phone = getPhone(subId);
7640 if (phone == null) {
7641 return null;
7642 }
7643
Jordan Liu0f2bc442020-11-18 16:47:37 -08007644 final long identity = Binder.clearCallingIdentity();
7645
Jack Yu479f40e2020-10-27 21:29:25 -07007646 boolean isCallingPackageDataService = phone.getDataServicePackages()
7647 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007649 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7650 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7651 Rlog.d(LOG_TAG,
7652 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7653 return null;
7654 }
7655
Hall Liuf19c44f2018-11-27 14:38:17 -08007656 ServiceState ss = phone.getServiceState();
7657
7658 // Scrub out the location info in ServiceState depending on what level of access
7659 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007660 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007661 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7662 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663 } finally {
7664 Binder.restoreCallingIdentity(identity);
7665 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007666 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007667
7668 /**
7669 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7670 *
7671 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7672 * voicemail ringtone.
7673 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7674 * PhoneAccount.
7675 */
7676 @Override
7677 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7681 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007682 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007683 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007689 }
7690
7691 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007692 * Sets the per-account voicemail ringtone.
7693 *
7694 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7695 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7696 *
7697 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7698 * voicemail ringtone.
7699 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7700 * PhoneAccount.
7701 */
7702 @Override
7703 public void setVoicemailRingtoneUri(String callingPackage,
7704 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007705 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007707 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7708 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7710 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7711 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713
7714 final long identity = Binder.clearCallingIdentity();
7715 try {
7716 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7717 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007718 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 }
7720 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7721 } finally {
7722 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007723 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007724 }
7725
7726 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007727 * Returns whether vibration is set for voicemail notification in Phone settings.
7728 *
7729 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7730 * voicemail vibration setting.
7731 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7732 */
7733 @Override
7734 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 final long identity = Binder.clearCallingIdentity();
7736 try {
7737 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7738 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007739 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007742 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
7745 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007746 }
7747
Youhan Wange64578a2016-05-02 15:32:42 -07007748 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007749 * Sets the per-account voicemail vibration.
7750 *
7751 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7752 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7753 *
7754 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7755 * voicemail vibration setting.
7756 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7757 * specific PhoneAccount.
7758 */
7759 @Override
7760 public void setVoicemailVibrationEnabled(String callingPackage,
7761 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007762 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007764 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7765 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7767 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7768 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007769 }
7770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007771 final long identity = Binder.clearCallingIdentity();
7772 try {
7773 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7774 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007775 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 }
7777 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007780 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007781 }
7782
7783 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007784 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7785 *
7786 * @throws SecurityException if the caller does not have the required permission
7787 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007788 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007789 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007790 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007791 }
7792
7793 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007794 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7795 * permission.
7796 *
7797 * @throws SecurityException if the caller does not have the required permission
7798 */
7799 private void enforceSendSmsPermission() {
7800 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7801 }
7802
7803 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007804 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007805 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007806 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007807 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007808 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809 final long identity = Binder.clearCallingIdentity();
7810 try {
7811 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007812 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 if (componentName == null) {
7814 throw new SecurityException(
7815 "Caller not current active visual voicemail package[null]");
7816 }
7817 String vvmPackage = componentName.getPackageName();
7818 if (!callingPackage.equals(vvmPackage)) {
7819 throw new SecurityException("Caller not current active visual voicemail package["
7820 + vvmPackage + "]");
7821 }
7822 } finally {
7823 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007824 }
7825 }
7826
7827 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007828 * Return the application ID for the app type.
7829 *
7830 * @param subId the subscription ID that this request applies to.
7831 * @param appType the uicc app type.
7832 * @return Application ID for specificied app type, or null if no uicc.
7833 */
7834 @Override
7835 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007836 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007837 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838
7839 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007840 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841 if (phone == null) {
7842 return null;
7843 }
7844 String aid = null;
7845 try {
7846 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7847 .getApplicationByType(appType).getAid();
7848 } catch (Exception e) {
7849 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7850 }
7851 return aid;
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007854 }
Youhan Wange64578a2016-05-02 15:32:42 -07007855 }
7856
Youhan Wang4001d252016-05-11 10:29:41 -07007857 /**
7858 * Return the Electronic Serial Number.
7859 *
7860 * @param subId the subscription ID that this request applies to.
7861 * @return ESN or null if error.
7862 */
7863 @Override
7864 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007865 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007866 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007867
7868 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007869 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007870 if (phone == null) {
7871 return null;
7872 }
7873 String esn = null;
7874 try {
7875 esn = phone.getEsn();
7876 } catch (Exception e) {
7877 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7878 }
7879 return esn;
7880 } finally {
7881 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007882 }
Youhan Wang4001d252016-05-11 10:29:41 -07007883 }
7884
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007885 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007886 * Return the Preferred Roaming List Version.
7887 *
7888 * @param subId the subscription ID that this request applies to.
7889 * @return PRLVersion or null if error.
7890 */
7891 @Override
7892 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007893 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007894 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895
7896 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007897 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007898 if (phone == null) {
7899 return null;
7900 }
7901 String cdmaPrlVersion = null;
7902 try {
7903 cdmaPrlVersion = phone.getCdmaPrlVersion();
7904 } catch (Exception e) {
7905 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7906 }
7907 return cdmaPrlVersion;
7908 } finally {
7909 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007910 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007911 }
7912
7913 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007914 * Get snapshot of Telephony histograms
7915 * @return List of Telephony histograms
7916 * @hide
7917 */
7918 @Override
7919 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7921 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007922
7923 final long identity = Binder.clearCallingIdentity();
7924 try {
7925 return RIL.getTelephonyRILTimingHistograms();
7926 } finally {
7927 Binder.restoreCallingIdentity(identity);
7928 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007929 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007930
7931 /**
7932 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007933 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7934 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007935 * Require system privileges. In the future we may add this to carrier APIs.
7936 *
Michele Berionne482f8202018-11-27 18:57:59 -08007937 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007938 */
7939 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007940 @TelephonyManager.SetCarrierRestrictionResult
7941 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007942 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007943 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007944
Michele Berionne482f8202018-11-27 18:57:59 -08007945 if (carrierRestrictionRules == null) {
7946 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007947 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949 final long identity = Binder.clearCallingIdentity();
7950 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007951 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007952 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007953 } finally {
7954 Binder.restoreCallingIdentity(identity);
7955 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007956 }
7957
7958 /**
7959 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007960 * Get the allowed carrier list and the excluded carrier list, including the priority between
7961 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007962 * Require system privileges. In the future we may add this to carrier APIs.
7963 *
Michele Berionne482f8202018-11-27 18:57:59 -08007964 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007965 */
7966 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007967 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007968 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007969 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007970
7971 final long identity = Binder.clearCallingIdentity();
7972 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007973 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7974 if (response instanceof CarrierRestrictionRules) {
7975 return (CarrierRestrictionRules) response;
7976 }
7977 // Response is an Exception of some kind,
7978 // which is signalled to the user as a NULL retval
7979 return null;
7980 } catch (Exception e) {
7981 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7982 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983 } finally {
7984 Binder.restoreCallingIdentity(identity);
7985 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007986 }
7987
fionaxu59545b42016-05-25 15:53:37 -07007988 /**
fionaxu59545b42016-05-25 15:53:37 -07007989 * Action set from carrier signalling broadcast receivers to enable/disable radio
7990 * @param subId the subscription ID that this action applies to.
7991 * @param enabled control enable or disable radio.
7992 * {@hide}
7993 */
7994 @Override
7995 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7996 enforceModifyPermission();
7997 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007998
7999 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008000 if (phone == null) {
8001 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8002 return;
8003 }
8004 try {
8005 phone.carrierActionSetRadioEnabled(enabled);
8006 } catch (Exception e) {
8007 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008 } finally {
8009 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008010 }
8011 }
8012
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008013 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008014 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8015 * network status based on which carrier apps could apply actions accordingly,
8016 * enable/disable default url handler for example.
8017 *
8018 * @param subId the subscription ID that this action applies to.
8019 * @param report control start/stop reporting the default network status.
8020 * {@hide}
8021 */
8022 @Override
8023 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8024 enforceModifyPermission();
8025 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008026
8027 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008028 if (phone == null) {
8029 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8030 return;
8031 }
8032 try {
8033 phone.carrierActionReportDefaultNetworkStatus(report);
8034 } catch (Exception e) {
8035 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036 } finally {
8037 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008038 }
8039 }
8040
8041 /**
fionaxud9622282017-07-17 17:51:30 -07008042 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8043 * @param subId the subscription ID that this action applies to.
8044 * {@hide}
8045 */
8046 @Override
8047 public void carrierActionResetAll(int subId) {
8048 enforceModifyPermission();
8049 final Phone phone = getPhone(subId);
8050 if (phone == null) {
8051 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8052 return;
8053 }
8054 try {
8055 phone.carrierActionResetAll();
8056 } catch (Exception e) {
8057 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8058 }
8059 }
8060
8061 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008062 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8063 * bug report is being generated.
8064 */
8065 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008066 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008067 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8068 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008069 writer.println("Permission Denial: can't dump Phone from pid="
8070 + Binder.getCallingPid()
8071 + ", uid=" + Binder.getCallingUid()
8072 + "without permission "
8073 + android.Manifest.permission.DUMP);
8074 return;
8075 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008076 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008077 }
Jack Yueb89b242016-06-22 13:27:47 -07008078
Brad Ebingerdac2f002018-04-03 15:17:52 -07008079 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008080 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8081 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8082 @NonNull String[] args) {
8083 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8084 this, in.getFileDescriptor(), out.getFileDescriptor(),
8085 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008086 }
8087
Jack Yueb89b242016-06-22 13:27:47 -07008088 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008089 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008090 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008091 * @param reason the reason the data enable change is taking place
8092 * @param enabled True if enabling the data, otherwise disabling.
8093 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008094 */
8095 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008096 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008097 boolean enabled) {
8098 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8099 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8100 try {
8101 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008102 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008103 } catch (SecurityException se) {
8104 enforceModifyPermission();
8105 }
8106 } else {
8107 enforceModifyPermission();
8108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008109
8110 final long identity = Binder.clearCallingIdentity();
8111 try {
8112 Phone phone = getPhone(subId);
8113 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008114 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8115 phone.carrierActionSetMeteredApnsEnabled(enabled);
8116 } else {
8117 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8118 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119 }
8120 } finally {
8121 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008122 }
8123 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008124
8125 /**
8126 * Get Client request stats
8127 * @return List of Client Request Stats
8128 * @hide
8129 */
8130 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008131 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8132 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008134 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008135 return null;
8136 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008137 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008139 final long identity = Binder.clearCallingIdentity();
8140 try {
8141 if (phone != null) {
8142 return phone.getClientRequestStats();
8143 }
8144
8145 return null;
8146 } finally {
8147 Binder.restoreCallingIdentity(identity);
8148 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008149 }
8150
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008151 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008152 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008153 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008154 }
Jack Yueb4124c2017-02-16 15:32:43 -08008155
8156 /**
Grace Chen70990072017-03-24 17:21:30 -07008157 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008158 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008159 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008160 * @param state State of SIM (power down, power up, pass through)
8161 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8162 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8163 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008164 *
8165 **/
8166 @Override
Grace Chen70990072017-03-24 17:21:30 -07008167 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008168 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008169 Phone phone = PhoneFactory.getPhone(slotIndex);
8170
vagdeviaf9a5b92018-08-15 16:01:53 -07008171 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 final long identity = Binder.clearCallingIdentity();
8174 try {
8175 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008176 phone.setSimPowerState(state, null, workSource);
8177 }
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
8180 }
8181 }
8182
8183 /**
8184 * Set SIM card power state.
8185 *
8186 * @param slotIndex SIM slot id.
8187 * @param state State of SIM (power down, power up, pass through)
8188 * @param callback callback to trigger after success or failure
8189 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8190 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8191 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8192 *
8193 **/
8194 @Override
8195 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8196 IIntegerConsumer callback) {
8197 enforceModifyPermission();
8198 Phone phone = PhoneFactory.getPhone(slotIndex);
8199
8200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8201
8202 final long identity = Binder.clearCallingIdentity();
8203 try {
8204 if (phone != null) {
8205 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8206 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008207 }
8208 } finally {
8209 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008210 }
8211 }
Shuo Qiandd210312017-04-12 22:11:33 +00008212
Tyler Gunn65d45c22017-06-05 11:22:26 -07008213 private boolean isUssdApiAllowed(int subId) {
8214 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008215 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008216 if (configManager == null) {
8217 return false;
8218 }
8219 PersistableBundle pb = configManager.getConfigForSubId(subId);
8220 if (pb == null) {
8221 return false;
8222 }
8223 return pb.getBoolean(
8224 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8225 }
8226
Shuo Qiandd210312017-04-12 22:11:33 +00008227 /**
8228 * Check if phone is in emergency callback mode
8229 * @return true if phone is in emergency callback mode
8230 * @param subId sub id
8231 */
goneil9c5f4872017-12-05 14:07:56 -08008232 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008233 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008234 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008235 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008236
8237 final long identity = Binder.clearCallingIdentity();
8238 try {
8239 if (phone != null) {
8240 return phone.isInEcm();
8241 } else {
8242 return false;
8243 }
8244 } finally {
8245 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008246 }
8247 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008248
8249 /**
8250 * Get the current signal strength information for the given subscription.
8251 * Because this information is not updated when the device is in a low power state
8252 * it should not be relied-upon to be current.
8253 * @param subId Subscription index
8254 * @return the most recent cached signal strength info from the modem
8255 */
8256 @Override
8257 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008258 final long identity = Binder.clearCallingIdentity();
8259 try {
8260 Phone p = getPhone(subId);
8261 if (p == null) {
8262 return null;
8263 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008264
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008265 return p.getSignalStrength();
8266 } finally {
8267 Binder.restoreCallingIdentity(identity);
8268 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008269 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008270
Pengquan Meng77b7f132018-08-22 14:49:57 -07008271 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008272 * Get the current modem radio state for the given slot.
8273 * @param slotIndex slot index.
8274 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008275 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008276 * @return the current radio power state from the modem
8277 */
8278 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008279 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008280 Phone phone = PhoneFactory.getPhone(slotIndex);
8281 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8283 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008284 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8285 }
8286
8287 final long identity = Binder.clearCallingIdentity();
8288 try {
8289 return phone.getRadioPowerState();
8290 } finally {
8291 Binder.restoreCallingIdentity(identity);
8292 }
8293 }
8294 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8295 }
8296
8297 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008298 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8299 *
8300 * <p>Requires one of the following permissions:
8301 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8302 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8303 * privileges.
8304 *
8305 * @param subId subscription id
8306 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8307 * {@code false}.
8308 */
8309 @Override
8310 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008311 try {
8312 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8313 null);
8314 } catch (Exception e) {
8315 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8316 mApp, subId, "isDataRoamingEnabled");
8317 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008318
Pengquan Menga1bb6272018-09-06 09:59:22 -07008319 boolean isEnabled = false;
8320 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008321 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008322 Phone phone = getPhone(subId);
8323 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008324 } finally {
8325 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008326 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008327 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008328 }
8329
8330
8331 /**
8332 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8333 *
8334 * <p> Requires permission:
8335 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8336 * privileges.
8337 *
8338 * @param subId subscription id
8339 * @param isEnabled {@code true} means enable, {@code false} means disable.
8340 */
8341 @Override
8342 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008343 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8344 mApp, subId, "setDataRoamingEnabled");
8345
Pengquan Menga1bb6272018-09-06 09:59:22 -07008346 final long identity = Binder.clearCallingIdentity();
8347 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008348 Phone phone = getPhone(subId);
8349 if (phone != null) {
8350 phone.setDataRoamingEnabled(isEnabled);
8351 }
8352 } finally {
8353 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008354 }
8355 }
8356
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008357 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008358 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008359 TelephonyPermissions
8360 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008361 mApp, subId, "isManualNetworkSelectionAllowed");
8362
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008363 boolean isAllowed = true;
8364 final long identity = Binder.clearCallingIdentity();
8365 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008366 Phone phone = getPhone(subId);
8367 if (phone != null) {
8368 isAllowed = phone.isCspPlmnEnabled();
8369 }
8370 } finally {
8371 Binder.restoreCallingIdentity(identity);
8372 }
8373 return isAllowed;
8374 }
8375
8376 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008377 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008378 // Verify that tha callingPackage belongs to the calling UID
8379 mApp.getSystemService(AppOpsManager.class)
8380 .checkPackage(Binder.getCallingUid(), callingPackage);
8381
Jordan Liu1e142fc2019-04-22 15:10:43 -07008382 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008383 try {
8384 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008385 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008386 } catch (SecurityException e) {
8387 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8388 // has carrier privileges on an active UICC
8389 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8390 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008391 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008392 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008393 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008394
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008397 UiccController uiccController = UiccController.getInstance();
8398 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008399 if (hasReadPermission) {
8400 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008401 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008402
8403 // Remove private info if the caller doesn't have access
8404 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8405 for (UiccCardInfo cardInfo : cardInfos) {
8406 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8407 // is available
8408 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8409 if (card == null || card.getUiccProfile() == null) {
8410 // assume no access if the card or profile is unavailable
8411 filteredInfos.add(cardInfo.getUnprivileged());
8412 continue;
8413 }
8414 UiccProfile profile = card.getUiccProfile();
8415 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8416 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8417 filteredInfos.add(cardInfo);
8418 } else {
8419 filteredInfos.add(cardInfo.getUnprivileged());
8420 }
8421 }
8422 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008423 } finally {
8424 Binder.restoreCallingIdentity(identity);
8425 }
8426 }
8427
8428 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008429 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008430 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008432 final long identity = Binder.clearCallingIdentity();
8433 try {
8434 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8435 if (slots == null) {
8436 Rlog.i(LOG_TAG, "slots is null.");
8437 return null;
8438 }
8439
8440 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8441 for (int i = 0; i < slots.length; i++) {
8442 UiccSlot slot = slots[i];
8443 if (slot == null) {
8444 continue;
8445 }
8446
Jordan Liu7be7e652019-05-06 18:55:02 +00008447 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008448 UiccCard card = slot.getUiccCard();
8449 if (card != null) {
8450 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008451 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008452 cardId = slot.getEid();
8453 if (TextUtils.isEmpty(cardId)) {
8454 cardId = slot.getIccId();
8455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008456 }
8457
Jordan Liu857451f2019-05-09 16:35:35 -07008458 if (cardId != null) {
8459 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8460 // if cardId is an EID, it's all digits so this is fine
8461 cardId = IccUtils.stripTrailingFs(cardId);
8462 }
8463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008464 int cardState = 0;
8465 switch (slot.getCardState()) {
8466 case CARDSTATE_ABSENT:
8467 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8468 break;
8469 case CARDSTATE_PRESENT:
8470 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8471 break;
8472 case CARDSTATE_ERROR:
8473 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8474 break;
8475 case CARDSTATE_RESTRICTED:
8476 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8477 break;
8478 default:
8479 break;
8480
8481 }
8482
8483 infos[i] = new UiccSlotInfo(
8484 slot.isActive(),
8485 slot.isEuicc(),
8486 cardId,
8487 cardState,
8488 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008489 slot.isExtendedApduSupported(),
8490 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008491 }
8492 return infos;
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008495 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008496 }
8497
8498 @Override
8499 public boolean switchSlots(int[] physicalSlots) {
8500 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008501
8502 final long identity = Binder.clearCallingIdentity();
8503 try {
8504 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8505 } finally {
8506 Binder.restoreCallingIdentity(identity);
8507 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008508 }
Jack Yu4c988042018-02-27 15:30:01 -08008509
8510 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008511 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 return UiccController.getInstance().getCardIdForDefaultEuicc();
8515 } finally {
8516 Binder.restoreCallingIdentity(identity);
8517 }
8518 }
8519
Pengquan Meng85728fb2018-03-12 16:31:21 -07008520 /**
goneil47ffb6e2018-04-06 15:40:58 -07008521 * A test API to reload the UICC profile.
8522 *
8523 * <p>Requires that the calling app has permission
8524 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8525 * @hide
8526 */
8527 @Override
8528 public void refreshUiccProfile(int subId) {
8529 enforceModifyPermission();
8530
8531 final long identity = Binder.clearCallingIdentity();
8532 try {
8533 Phone phone = getPhone(subId);
8534 if (phone == null) {
8535 return;
8536 }
8537 UiccCard uiccCard = phone.getUiccCard();
8538 if (uiccCard == null) {
8539 return;
8540 }
8541 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8542 if (uiccProfile == null) {
8543 return;
8544 }
8545 uiccProfile.refresh();
8546 } finally {
8547 Binder.restoreCallingIdentity(identity);
8548 }
8549 }
8550
8551 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008552 * Returns false if the mobile data is disabled by default, otherwise return true.
8553 */
8554 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008555 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008556 }
8557
8558 /**
8559 * Returns true if the data roaming is enabled by default, i.e the system property
8560 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8561 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8562 */
8563 private boolean getDefaultDataRoamingEnabled(int subId) {
8564 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008565 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008566 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008567 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8568 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8569 return isDataRoamingEnabled;
8570 }
8571
8572 /**
8573 * Returns the default network type for the given {@code subId}, if the default network type is
8574 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8575 */
8576 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008577 List<Integer> list = TelephonyProperties.default_network();
8578 int phoneId = mSubscriptionController.getPhoneId(subId);
8579 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8580 return list.get(phoneId);
8581 }
8582 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008583 }
fionaxua13278b2018-03-21 00:08:13 -07008584
8585 @Override
8586 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008587 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008589
8590 final long identity = Binder.clearCallingIdentity();
8591 try {
8592 final Phone phone = getPhone(subId);
8593 if (phone == null) {
8594 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8595 return;
8596 }
chen xueaba88a2019-03-15 13:15:10 -07008597 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8598 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008599 if (carrierPrivilegeRules == null) {
8600 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8601 } else {
8602 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008604 } finally {
8605 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008606 }
fionaxua13278b2018-03-21 00:08:13 -07008607 }
8608
8609 @Override
8610 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008611 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008612
8613 final long identity = Binder.clearCallingIdentity();
8614 try {
8615 final Phone phone = getPhone(subId);
8616 if (phone == null) {
8617 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8618 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8619 }
8620 return phone.getCarrierIdListVersion();
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008623 }
fionaxua13278b2018-03-21 00:08:13 -07008624 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008625
8626 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008627 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8628 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008630 mApp, subId, callingPackage, callingFeatureId,
8631 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008632 return -1;
8633 }
8634
8635 final long identity = Binder.clearCallingIdentity();
8636 try {
8637 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8638 } finally {
8639 Binder.restoreCallingIdentity(identity);
8640 }
8641 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008642
8643 @Override
8644 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008645 TelephonyPermissions
8646 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008647 mApp, subId, "getCdmaRoamingMode");
8648
8649 final long identity = Binder.clearCallingIdentity();
8650 try {
8651 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8652 } finally {
8653 Binder.restoreCallingIdentity(identity);
8654 }
8655 }
8656
8657 @Override
8658 public boolean setCdmaRoamingMode(int subId, int mode) {
8659 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8660 mApp, subId, "setCdmaRoamingMode");
8661
8662 final long identity = Binder.clearCallingIdentity();
8663 try {
8664 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8665 } finally {
8666 Binder.restoreCallingIdentity(identity);
8667 }
8668 }
8669
8670 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008671 public int getCdmaSubscriptionMode(int subId) {
8672 TelephonyPermissions
8673 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8674 mApp, subId, "getCdmaSubscriptionMode");
8675
8676 final long identity = Binder.clearCallingIdentity();
8677 try {
8678 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8679 } finally {
8680 Binder.restoreCallingIdentity(identity);
8681 }
8682 }
8683
8684 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008685 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8687 mApp, subId, "setCdmaSubscriptionMode");
8688
8689 final long identity = Binder.clearCallingIdentity();
8690 try {
8691 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8692 } finally {
8693 Binder.restoreCallingIdentity(identity);
8694 }
8695 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008696
sqianc5eccab2018-10-19 18:46:41 -07008697 @Override
sqian8c685422019-02-22 15:55:18 -08008698 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008699 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008701 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8702 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008703 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8704 }
8705 final long identity = Binder.clearCallingIdentity();
8706 try {
sqian854d44b2018-12-12 16:48:18 -08008707 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8708 for (Phone phone: PhoneFactory.getPhones()) {
8709 if (phone.getEmergencyNumberTracker() != null
8710 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8711 emergencyNumberListInternal.put(
8712 phone.getSubId(),
8713 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8714 }
sqian11b7a0e2018-12-05 18:48:28 -08008715 }
sqian854d44b2018-12-12 16:48:18 -08008716 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
sqianc5eccab2018-10-19 18:46:41 -07008720 }
8721
8722 @Override
sqian8c685422019-02-22 15:55:18 -08008723 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008724 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008725 if (!exactMatch) {
8726 TelephonyPermissions
8727 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008728 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008729 }
8730 final long identity = Binder.clearCallingIdentity();
8731 try {
sqian854d44b2018-12-12 16:48:18 -08008732 for (Phone phone: PhoneFactory.getPhones()) {
8733 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008734 && phone.getEmergencyNumberTracker()
8735 .isEmergencyNumber(number, exactMatch)) {
8736 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008737 }
sqian11b7a0e2018-12-05 18:48:28 -08008738 }
8739 return false;
8740 } finally {
8741 Binder.restoreCallingIdentity(identity);
8742 }
8743 }
8744
sqianf4ca7ed2019-01-15 18:32:07 -08008745 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008746 * Start emergency callback mode for GsmCdmaPhone for testing.
8747 */
8748 @Override
8749 public void startEmergencyCallbackMode() {
8750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8751 "startEmergencyCallbackMode");
8752 enforceModifyPermission();
8753 final long identity = Binder.clearCallingIdentity();
8754 try {
8755 for (Phone phone : PhoneFactory.getPhones()) {
8756 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8757 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8758 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8759 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8760 gsmCdmaPhone.obtainMessage(
8761 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8762 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8763 }
8764 }
8765 } finally {
8766 Binder.restoreCallingIdentity(identity);
8767 }
8768 }
8769
8770 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008771 * Update emergency number list for test mode.
8772 */
8773 @Override
8774 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8775 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8776 "updateEmergencyNumberListTestMode");
8777
8778 final long identity = Binder.clearCallingIdentity();
8779 try {
8780 for (Phone phone: PhoneFactory.getPhones()) {
8781 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8782 if (tracker != null) {
8783 tracker.executeEmergencyNumberTestModeCommand(action, num);
8784 }
8785 }
8786 } finally {
8787 Binder.restoreCallingIdentity(identity);
8788 }
8789 }
8790
8791 /**
8792 * Get the full emergency number list for test mode.
8793 */
8794 @Override
8795 public List<String> getEmergencyNumberListTestMode() {
8796 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8797 "getEmergencyNumberListTestMode");
8798
8799 final long identity = Binder.clearCallingIdentity();
8800 try {
8801 Set<String> emergencyNumbers = new HashSet<>();
8802 for (Phone phone: PhoneFactory.getPhones()) {
8803 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8804 if (tracker != null) {
8805 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8806 emergencyNumbers.add(num.getNumber());
8807 }
8808 }
8809 }
8810 return new ArrayList<>(emergencyNumbers);
8811 } finally {
8812 Binder.restoreCallingIdentity(identity);
8813 }
8814 }
8815
chen xud6b45bd2018-10-30 22:27:10 -07008816 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008817 public int getEmergencyNumberDbVersion(int subId) {
8818 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8819
8820 final long identity = Binder.clearCallingIdentity();
8821 try {
8822 final Phone phone = getPhone(subId);
8823 if (phone == null) {
8824 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8825 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8826 }
8827 return phone.getEmergencyNumberDbVersion();
8828 } finally {
8829 Binder.restoreCallingIdentity(identity);
8830 }
8831 }
8832
8833 @Override
8834 public void notifyOtaEmergencyNumberDbInstalled() {
8835 enforceModifyPermission();
8836
8837 final long identity = Binder.clearCallingIdentity();
8838 try {
8839 for (Phone phone: PhoneFactory.getPhones()) {
8840 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8841 if (tracker != null) {
8842 tracker.updateOtaEmergencyNumberDatabase();
8843 }
8844 }
8845 } finally {
8846 Binder.restoreCallingIdentity(identity);
8847 }
8848 }
8849
8850 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008851 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008852 enforceActiveEmergencySessionPermission();
8853
8854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 for (Phone phone: PhoneFactory.getPhones()) {
8857 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8858 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008859 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8860 }
8861 }
8862 } finally {
8863 Binder.restoreCallingIdentity(identity);
8864 }
8865 }
8866
8867 @Override
8868 public void resetOtaEmergencyNumberDbFilePath() {
8869 enforceActiveEmergencySessionPermission();
8870
8871 final long identity = Binder.clearCallingIdentity();
8872 try {
8873 for (Phone phone: PhoneFactory.getPhones()) {
8874 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8875 if (tracker != null) {
8876 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008877 }
8878 }
8879 } finally {
8880 Binder.restoreCallingIdentity(identity);
8881 }
8882 }
8883
8884 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008885 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8886 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8887 Phone phone = getPhone(subId);
8888 if (phone == null) {
8889 return null;
8890 }
8891 final long identity = Binder.clearCallingIdentity();
8892 try {
8893 UiccProfile profile = UiccController.getInstance()
8894 .getUiccProfileForPhone(phone.getPhoneId());
8895 if (profile != null) {
8896 return profile.getCertsFromCarrierPrivilegeAccessRules();
8897 }
8898 } finally {
8899 Binder.restoreCallingIdentity(identity);
8900 }
8901 return null;
8902 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008903
8904 /**
8905 * Enable or disable a modem stack.
8906 */
8907 @Override
8908 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8909 enforceModifyPermission();
8910
8911 final long identity = Binder.clearCallingIdentity();
8912 try {
8913 Phone phone = PhoneFactory.getPhone(slotIndex);
8914 if (phone == null) {
8915 return false;
8916 } else {
8917 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8918 }
8919 } finally {
8920 Binder.restoreCallingIdentity(identity);
8921 }
8922 }
Michelecea4cf22018-12-21 15:00:11 -08008923
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008924 /**
8925 * Whether a modem stack is enabled or not.
8926 */
8927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008928 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8929 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008930 Phone phone = PhoneFactory.getPhone(slotIndex);
8931 if (phone == null) return false;
8932
8933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008934 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8935 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008936 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8937 }
8938
8939 final long identity = Binder.clearCallingIdentity();
8940 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008941 try {
8942 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8943 } catch (NoSuchElementException ex) {
8944 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8945 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008946 } finally {
8947 Binder.restoreCallingIdentity(identity);
8948 }
8949 }
8950
Michelecea4cf22018-12-21 15:00:11 -08008951 @Override
Michele0ea7d782019-03-19 14:58:42 -07008952 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008953 enforceModifyPermission();
8954
8955 final long identity = Binder.clearCallingIdentity();
8956 try {
8957 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008958 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008959 .commit();
8960 } finally {
8961 Binder.restoreCallingIdentity(identity);
8962 }
8963 }
8964
8965 @Override
Michele0ea7d782019-03-19 14:58:42 -07008966 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008967 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008968 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008969 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8970 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008971 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008972 }
Michelecea4cf22018-12-21 15:00:11 -08008973
8974 final long identity = Binder.clearCallingIdentity();
8975 try {
Michele0ea7d782019-03-19 14:58:42 -07008976 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008977 } finally {
8978 Binder.restoreCallingIdentity(identity);
8979 }
8980 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008981
Michele0ea7d782019-03-19 14:58:42 -07008982 @TelephonyManager.IsMultiSimSupportedResult
8983 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008984 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8985 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8986 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008987 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8988 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008989 }
8990 // Check if the hardware supports multisim functionality. If usage of multisim is not
8991 // supported by the modem, indicate that it is restricted.
8992 PhoneCapability staticCapability =
8993 mPhoneConfigurationManager.getStaticPhoneCapability();
8994 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008995 loge("isMultiSimSupportedInternal: no static configuration available");
8996 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008997 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008998 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008999 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9000 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009001 }
9002 // Check if support of multiple SIMs is restricted by carrier
9003 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009004 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009005 }
9006
Michele0ea7d782019-03-19 14:58:42 -07009007 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009008 }
9009
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009010 /**
9011 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009012 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9013 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9014 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009015 * @param numOfSims number of active sims we want to switch to
9016 */
9017 @Override
9018 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009019 if (numOfSims == 1) {
9020 enforceModifyPermission();
9021 } else {
9022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9023 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9024 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009025 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009026
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009027 try {
Michele30b57b22019-03-01 12:01:14 -08009028 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009029 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009030 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9031 return;
9032 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009033 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9034 } finally {
9035 Binder.restoreCallingIdentity(identity);
9036 }
9037 }
9038
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009039 @Override
9040 public boolean isApplicationOnUicc(int subId, int appType) {
9041 enforceReadPrivilegedPermission("isApplicationOnUicc");
9042 Phone phone = getPhone(subId);
9043 if (phone == null) {
9044 return false;
9045 }
9046 final long identity = Binder.clearCallingIdentity();
9047 try {
9048 UiccCard uiccCard = phone.getUiccCard();
9049 if (uiccCard == null) {
9050 return false;
9051 }
9052 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9053 if (uiccProfile == null) {
9054 return false;
9055 }
9056 if (TelephonyManager.APPTYPE_SIM <= appType
9057 && appType <= TelephonyManager.APPTYPE_ISIM) {
9058 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9059 }
9060 return false;
9061 } finally {
9062 Binder.restoreCallingIdentity(identity);
9063 }
9064 }
9065
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009066 /**
chen xub4baa772019-04-03 10:23:41 -07009067 * Get whether making changes to modem configurations will trigger reboot.
9068 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009069 */
9070 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009071 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9072 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009074 mApp, subId, callingPackage, callingFeatureId,
9075 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009076 return false;
9077 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009078 final long identity = Binder.clearCallingIdentity();
9079 try {
9080 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9081 } finally {
9082 Binder.restoreCallingIdentity(identity);
9083 }
9084 }
9085
Nathan Harold29f5f052019-02-15 13:41:57 -08009086 private void updateModemStateMetrics() {
9087 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9088 // TODO: check the state for each modem if the api is ready.
9089 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9090 }
9091
Pengquan Meng3889a572019-01-23 11:16:29 -08009092 @Override
9093 public int[] getSlotsMapping() {
9094 enforceReadPrivilegedPermission("getSlotsMapping");
9095
9096 final long identity = Binder.clearCallingIdentity();
9097 try {
9098 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9099 // All logical slots should have a mapping to a physical slot.
9100 int[] logicalSlotsMapping = new int[phoneCount];
9101 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9102 for (int i = 0; i < slotInfos.length; i++) {
9103 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9104 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9105 }
9106 }
9107 return logicalSlotsMapping;
9108 } finally {
9109 Binder.restoreCallingIdentity(identity);
9110 }
9111 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009112
9113 /**
9114 * Get the IRadio HAL Version
9115 */
9116 @Override
9117 public int getRadioHalVersion() {
9118 Phone phone = getDefaultPhone();
9119 if (phone == null) return -1;
9120 HalVersion hv = phone.getHalVersion();
9121 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9122 return hv.major * 100 + hv.minor;
9123 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009124
9125 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009126 * Get the current calling package name.
9127 * @return the current calling package name
9128 */
9129 @Override
9130 public String getCurrentPackageName() {
9131 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9132 }
9133
9134 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009135 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9136 * corresponding network requests on a subId.
9137 *
9138 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009139 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009140 * 2) APN is un-metered for this subscription, or
9141 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009142 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009143 *
9144 * @return whether data is allowed for a apn type.
9145 *
9146 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009147 */
9148 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009149 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009150 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9151 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009152
9153 // Now that all security checks passes, perform the operation as ourselves.
9154 final long identity = Binder.clearCallingIdentity();
9155 try {
9156 Phone phone = getPhone(subId);
9157 if (phone == null) return false;
9158
Jack Yu41407ee2019-05-13 16:54:09 -07009159 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009160 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9161 } finally {
9162 Binder.restoreCallingIdentity(identity);
9163 }
9164 }
9165
9166 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009167 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009168 enforceReadPrivilegedPermission("isApnMetered");
9169
9170 // Now that all security checks passes, perform the operation as ourselves.
9171 final long identity = Binder.clearCallingIdentity();
9172 try {
9173 Phone phone = getPhone(subId);
9174 if (phone == null) return true; // By default return true.
9175
Jack Yu41407ee2019-05-13 16:54:09 -07009176 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009177 } finally {
9178 Binder.restoreCallingIdentity(identity);
9179 }
9180 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009181
9182 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009183 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9184 int subscriptionId, IBooleanConsumer resultCallback) {
9185 enforceModifyPermission();
9186 long token = Binder.clearCallingIdentity();
9187 try {
9188 Phone phone = getPhone(subscriptionId);
9189 if (phone == null) {
9190 try {
9191 if (resultCallback != null) {
9192 resultCallback.accept(false);
9193 }
9194 } catch (RemoteException e) {
9195 // ignore
9196 }
9197 return;
9198 }
9199 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9200 Pair.create(specifiers, (x) -> {
9201 try {
9202 if (resultCallback != null) {
9203 resultCallback.accept(x);
9204 }
9205 } catch (RemoteException e) {
9206 // ignore
9207 }
9208 });
9209 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9210 } finally {
9211 Binder.restoreCallingIdentity(token);
9212 }
9213 }
9214
9215 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009216 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9217 TelephonyPermissions
9218 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9219 mApp, subId, "getSystemSelectionChannels");
9220 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9221 final long identity = Binder.clearCallingIdentity();
9222 try {
9223 List<RadioAccessSpecifier> specifiers =
9224 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9225 null, subId, workSource);
9226 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9227 return specifiers;
9228 } finally {
9229 Binder.restoreCallingIdentity(identity);
9230 }
9231 }
9232
9233 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009234 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009235 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009236 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9237 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9238 if (iccRecords == null) {
9239 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9240 return false;
9241 }
9242 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9243 }
9244
9245 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009246 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9247 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009248 if (callingPackage == null) {
9249 callingPackage = getCurrentPackageName();
9250 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009251 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9252 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009253 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9254 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009255 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9256 }
9257 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9258 Intent intent = new Intent();
9259 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9260 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9261 // Bring up choose default SMS subscription dialog right now
9262 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9263 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9264 mApp.startActivity(intent);
9265 }
chen xud5ca2d52019-05-28 15:20:57 -07009266
9267 @Override
9268 public String getMmsUAProfUrl(int subId) {
9269 //TODO investigate if this API should require proper permission check in R b/133791609
9270 final long identity = Binder.clearCallingIdentity();
9271 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009272 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9273 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9274 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9275 return carrierUAProfUrl;
9276 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009277 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9278 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009279 } finally {
9280 Binder.restoreCallingIdentity(identity);
9281 }
9282 }
9283
9284 @Override
9285 public String getMmsUserAgent(int subId) {
9286 //TODO investigate if this API should require proper permission check in R b/133791609
9287 final long identity = Binder.clearCallingIdentity();
9288 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009289 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9290 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9291 if (!TextUtils.isEmpty(carrierUserAgent)) {
9292 return carrierUserAgent;
9293 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009294 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9295 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009296 } finally {
9297 Binder.restoreCallingIdentity(identity);
9298 }
9299 }
Jack Yub07d4972019-05-28 16:12:25 -07009300
9301 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009302 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9303 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009304
Jack Yub07d4972019-05-28 16:12:25 -07009305 final long identity = Binder.clearCallingIdentity();
9306 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009307 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009308 if (phone == null) return false;
9309
Hall Liua62f5da2020-09-25 10:42:19 -07009310 switch (policy) {
9311 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9312 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9313 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9314 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9315 default:
9316 throw new IllegalArgumentException(policy + " is not a valid policy");
9317 }
Jack Yub07d4972019-05-28 16:12:25 -07009318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
9322
9323 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009324 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009325 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009326 enforceModifyPermission();
9327
changbettyd5c246e2019-12-24 15:40:37 +08009328 final long identity = Binder.clearCallingIdentity();
9329 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009330 Phone phone = getPhone(subscriptionId);
9331 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009332
Hall Liua62f5da2020-09-25 10:42:19 -07009333 switch (policy) {
9334 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9335 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9336 break;
9337 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9338 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9339 break;
9340 default:
9341 throw new IllegalArgumentException(policy + " is not a valid policy");
9342 }
changbettyd5c246e2019-12-24 15:40:37 +08009343 } finally {
9344 Binder.restoreCallingIdentity(identity);
9345 }
9346 }
9347
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009348 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009349 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009350 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9351 * otherwise.
9352 */
9353 @Override
9354 public void setCepEnabled(boolean isCepEnabled) {
9355 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9356
9357 final long identity = Binder.clearCallingIdentity();
9358 try {
9359 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9360 for (Phone phone : PhoneFactory.getPhones()) {
9361 Phone defaultPhone = phone.getImsPhone();
9362 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9363 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9364 ImsPhoneCallTracker imsPhoneCallTracker =
9365 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9366 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9367 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9368 + imsPhone.getMsisdn());
9369 }
9370 }
9371 } finally {
9372 Binder.restoreCallingIdentity(identity);
9373 }
9374 }
allenwtsu46dcc572020-01-08 18:24:03 +08009375
9376 /**
9377 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9378 *
9379 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9380 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9381 * before being read.
9382 */
9383 @Override
9384 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9385 isCompressed) {
9386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9387 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009388 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9389 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9390 }
9391 if (!isImsAvailableOnDevice()) {
9392 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9393 "IMS not available on device.");
9394 }
9395
9396 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009397 try {
Hui Wang761a6682020-10-31 05:12:53 +00009398 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009401 }
9402 }
zoey chene02881a2019-12-30 16:11:23 +08009403
9404 @Override
9405 public boolean isIccLockEnabled(int subId) {
9406 enforceReadPrivilegedPermission("isIccLockEnabled");
9407
9408 // Now that all security checks passes, perform the operation as ourselves.
9409 final long identity = Binder.clearCallingIdentity();
9410 try {
9411 Phone phone = getPhone(subId);
9412 if (phone != null && phone.getIccCard() != null) {
9413 return phone.getIccCard().getIccLockEnabled();
9414 } else {
9415 return false;
9416 }
9417 } finally {
9418 Binder.restoreCallingIdentity(identity);
9419 }
9420 }
9421
9422 /**
9423 * Set the ICC pin lock enabled or disabled.
9424 *
9425 * @return an integer representing the status of IccLock enabled or disabled in the following
9426 * three cases:
9427 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9428 * successfully.
9429 * - Positive number and zero for remaining password attempts.
9430 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9431 *
9432 */
9433 @Override
9434 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9435 enforceModifyPermission();
9436
9437 Phone phone = getPhone(subId);
9438 if (phone == null) {
9439 return 0;
9440 }
9441 // Now that all security checks passes, perform the operation as ourselves.
9442 final long identity = Binder.clearCallingIdentity();
9443 try {
9444 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9445 new Pair<Boolean, String>(enabled, password), phone, null);
9446 return attemptsRemaining;
9447
9448 } catch (Exception e) {
9449 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9450 } finally {
9451 Binder.restoreCallingIdentity(identity);
9452 }
9453 return 0;
9454 }
9455
9456 /**
9457 * Change the ICC password used in ICC pin lock.
9458 *
9459 * @return an integer representing the status of IccLock changed in the following three cases:
9460 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9461 * - Positive number and zero for remaining password attempts.
9462 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9463 *
9464 */
9465 @Override
9466 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9467 enforceModifyPermission();
9468
9469 Phone phone = getPhone(subId);
9470 if (phone == null) {
9471 return 0;
9472 }
9473 // Now that all security checks passes, perform the operation as ourselves.
9474 final long identity = Binder.clearCallingIdentity();
9475 try {
9476 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9477 new Pair<String, String>(oldPassword, newPassword), phone, null);
9478 return attemptsRemaining;
9479
9480 } catch (Exception e) {
9481 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9482 } finally {
9483 Binder.restoreCallingIdentity(identity);
9484 }
9485 return 0;
9486 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009487
9488 /**
9489 * Request for receiving user activity notification
9490 */
9491 @Override
9492 public void requestUserActivityNotification() {
9493 if (!mNotifyUserActivity.get()
9494 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9495 mNotifyUserActivity.set(true);
9496 }
9497 }
9498
9499 /**
9500 * Called when userActivity is signalled in the power manager.
9501 * This is safe to call from any thread, with any window manager locks held or not.
9502 */
9503 @Override
9504 public void userActivity() {
9505 // ***************************************
9506 // * Inherited from PhoneWindowManager *
9507 // ***************************************
9508 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9509 // WITH ITS LOCKS HELD.
9510 //
9511 // This code must be VERY careful about the locks
9512 // it acquires.
9513 // In fact, the current code acquires way too many,
9514 // and probably has lurking deadlocks.
9515
9516 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9517 throw new SecurityException("Only the OS may call notifyUserActivity()");
9518 }
9519
9520 if (mNotifyUserActivity.getAndSet(false)) {
9521 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9522 USER_ACTIVITY_NOTIFICATION_DELAY);
9523 }
9524 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009525
9526 @Override
9527 public boolean canConnectTo5GInDsdsMode() {
9528 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9529 }
Jack Yud10cdd42020-09-28 20:28:01 -07009530
9531 @Override
9532 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9533 String callingFeatureId) {
9534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9535 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9536 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9537 }
9538
9539 Phone phone = getPhone(subId);
9540 if (phone == null) {
9541 throw new RuntimeException("phone is not available");
9542 }
9543 // Now that all security checks passes, perform the operation as ourselves.
9544 final long identity = Binder.clearCallingIdentity();
9545 try {
9546 return phone.getEquivalentHomePlmns();
9547 } finally {
9548 Binder.restoreCallingIdentity(identity);
9549 }
9550 }
Daniel Bright59e67312020-11-13 11:49:37 -08009551
9552 @Override
9553 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009554 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9555 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009556 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009557 if (radioInterfaceCapabilities == null) {
9558 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009559 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009560 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009561 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009562
Hui Wang641e81c2020-10-12 12:14:23 -07009563 @Override
9564 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9565 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009566 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9567 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9568 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9569 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9570 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009571 if (DBG) {
9572 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9573 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9574 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9575 }
9576
9577 if (!SubscriptionManager.isValidSubscriptionId(subId)
9578 || appType < TelephonyManager.APPTYPE_UNKNOWN
9579 || appType > TelephonyManager.APPTYPE_ISIM
9580 || nafUrl == null || securityProtocol == null || callback == null) {
9581 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9582 if (callback != null) {
9583 try {
9584 callback.onAuthenticationFailure(
9585 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9586 } catch (RemoteException exception) {
9587 log("Fail to notify onAuthenticationFailure due to " + exception);
9588 }
9589 return;
9590 }
9591 }
9592
9593 final long token = Binder.clearCallingIdentity();
9594 try {
9595 getGbaManager(subId).bootstrapAuthenticationRequest(
9596 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9597 forceBootStrapping, callback));
9598 } finally {
9599 Binder.restoreCallingIdentity(token);
9600 }
9601 }
9602
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009603 /**
9604 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9605 * requested radio power state will actually be set. See {@link
9606 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9607 *
9608 * @param subId the subscription ID of the phone requesting to set the radio power state.
9609 * @param enable {@code true} if trying to turn radio on.
9610 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9611 * false}.
9612 */
9613 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9614 Phone phone = getPhone(subId);
9615 if (phone != null) {
9616 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9617 return true;
9618 }
9619 return false;
9620 }
9621
9622 private int handleDataThrottlingRequest(int subId,
9623 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009624 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9625 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9626 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9627 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9628 throw new IllegalArgumentException("modem does not support data throttling");
9629 }
9630
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009631 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9632 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9633 if (!setRadioPowerForThermal(subId, true)) {
9634 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9635 }
9636
9637 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9638
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009639 if (isDataThrottlingSupported) {
9640 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009641 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009642 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9643 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9644 } else if (thermalMitigationResult
9645 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9646 throw new IllegalArgumentException("modem does not support data throttling");
9647 }
9648 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009649 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009650
9651 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009652 }
9653
9654 /**
9655 * Thermal mitigation request to control functionalities at modem.
9656 *
9657 * @param subId the id of the subscription.
9658 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9659 *
9660 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9661 */
9662 @Override
9663 @ThermalMitigationResult
9664 public int sendThermalMitigationRequest(
9665 int subId,
9666 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9667 enforceModifyPermission();
9668
9669 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9670 final long identity = Binder.clearCallingIdentity();
9671
9672 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9673 try {
9674 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9675 switch (thermalMitigationAction) {
9676 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9677 thermalMitigationResult =
9678 handleDataThrottlingRequest(subId,
9679 thermalMitigationRequest.getDataThrottlingRequest());
9680 break;
9681 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9682 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9683 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9684 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9685 }
9686
9687 // Ensure that radio is on. If not able to power on due to phone being
9688 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9689 if (!setRadioPowerForThermal(subId, true)) {
9690 thermalMitigationResult =
9691 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9692 break;
9693 }
9694
9695 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9696 false);
9697 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9698 break;
9699 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9700 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9701 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9702 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9703 }
9704
9705 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9706 if (registry != null) {
9707 TelephonyConnectionService service =
9708 registry.getTelephonyConnectionService();
9709 Phone phone = getPhone(subId);
9710 if (phone == null) {
9711 thermalMitigationResult =
9712 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9713 break;
9714 }
9715
9716 if (PhoneConstantConversions.convertCallState(phone.getState())
9717 != TelephonyManager.CALL_STATE_IDLE
9718 || phone.isInEmergencySmsMode() || phone.isInEcm()
9719 || (service != null && service.isEmergencyCallPending())) {
9720 String errorMessage = "Phone state is not valid. call state = "
9721 + PhoneConstantConversions.convertCallState(phone.getState())
9722 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9723 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9724 errorMessage += service == null
9725 ? " TelephonyConnectionService is null"
9726 : " isEmergencyCallPending = "
9727 + service.isEmergencyCallPending();
9728 Log.e(LOG_TAG, errorMessage);
9729 thermalMitigationResult =
9730 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9731 break;
9732 }
9733 } else {
9734 thermalMitigationResult =
9735 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9736 break;
9737 }
9738
9739 // Turn radio off. If not able to power off due to phone being unavailable,
9740 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9741 if (!setRadioPowerForThermal(subId, false)) {
9742 thermalMitigationResult =
9743 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9744 break;
9745 }
9746 thermalMitigationResult =
9747 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9748 break;
9749 default:
9750 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9751 + "not exist. Requested action: " + thermalMitigationAction);
9752 }
9753 } catch (IllegalArgumentException e) {
9754 throw e;
9755 } catch (Exception e) {
9756 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9757 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9758 } finally {
9759 Binder.restoreCallingIdentity(identity);
9760 }
9761
9762 if (DBG) {
9763 log("thermalMitigationRequest returning with thermalMitigationResult: "
9764 + thermalMitigationResult);
9765 }
9766
9767 return thermalMitigationResult;
9768 }
Hui Wang641e81c2020-10-12 12:14:23 -07009769
9770 /**
9771 * Set the GbaService Package Name that Telephony will bind to.
9772 *
9773 * @param subId The sim that the GbaService is associated with.
9774 * @param packageName The name of the package to be replaced with.
9775 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9776 */
9777 @Override
9778 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9779 enforceModifyPermission();
9780
9781 final long identity = Binder.clearCallingIdentity();
9782 try {
9783 return getGbaManager(subId).overrideServicePackage(packageName);
9784 } finally {
9785 Binder.restoreCallingIdentity(identity);
9786 }
9787 }
9788
9789 /**
9790 * Return the package name of the currently bound GbaService.
9791 *
9792 * @param subId The sim that the GbaService is associated with.
9793 * @return the package name of the GbaService configuration, null if GBA is not supported.
9794 */
9795 @Override
9796 public String getBoundGbaService(int subId) {
9797 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9798
9799 final long identity = Binder.clearCallingIdentity();
9800 try {
9801 return getGbaManager(subId).getServicePackage();
9802 } finally {
9803 Binder.restoreCallingIdentity(identity);
9804 }
9805 }
9806
9807 /**
9808 * Set the release time for telephony to unbind GbaService.
9809 *
9810 * @param subId The sim that the GbaService is associated with.
9811 * @param interval The release time to unbind GbaService by millisecond.
9812 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9813 */
9814 @Override
9815 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9816 enforceModifyPermission();
9817
9818 final long identity = Binder.clearCallingIdentity();
9819 try {
9820 return getGbaManager(subId).overrideReleaseTime(interval);
9821 } finally {
9822 Binder.restoreCallingIdentity(identity);
9823 }
9824 }
9825
9826 /**
9827 * Return the release time for telephony to unbind GbaService.
9828 *
9829 * @param subId The sim that the GbaService is associated with.
9830 * @return The release time to unbind GbaService by millisecond.
9831 */
9832 @Override
9833 public int getGbaReleaseTime(int subId) {
9834 enforceReadPrivilegedPermission("getGbaReleaseTime");
9835
9836 final long identity = Binder.clearCallingIdentity();
9837 try {
9838 return getGbaManager(subId).getReleaseTime();
9839 } finally {
9840 Binder.restoreCallingIdentity(identity);
9841 }
9842 }
9843
9844 private GbaManager getGbaManager(int subId) {
9845 GbaManager instance = GbaManager.getInstance(subId);
9846 if (instance == null) {
9847 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9848 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9849 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9850 }
9851 return instance;
9852 }
Hui Wang761a6682020-10-31 05:12:53 +00009853
9854 /**
9855 * indicate whether the device and the carrier can support
9856 * RCS VoLTE single registration.
9857 */
9858 @Override
9859 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009860 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9861 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9862 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9863 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009864
9865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9866 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9867 }
9868
9869 final long identity = Binder.clearCallingIdentity();
9870 try {
9871 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9872 if (rpm != null) {
9873 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9874 }
9875 return false;
9876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
9880
9881 /**
9882 * Register RCS provisioning callback.
9883 */
9884 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009885 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009886 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009887 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009888 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009889 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9890 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009891
9892 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9893 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9894 }
9895 if (!isImsAvailableOnDevice()) {
9896 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9897 "IMS not available on device.");
9898 }
9899
9900 final long identity = Binder.clearCallingIdentity();
9901 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009902 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009903 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -08009904 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9905 "Service not available for the subscription.");
9906 }
Hui Wang761a6682020-10-31 05:12:53 +00009907 } finally {
9908 Binder.restoreCallingIdentity(identity);
9909 }
9910 }
9911
9912 /**
9913 * Unregister RCS provisioning callback.
9914 */
9915 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009916 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009917 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009918 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009919 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009920 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9921 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009922
9923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9924 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9925 }
9926 if (!isImsAvailableOnDevice()) {
9927 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9928 "IMS not available on device.");
9929 }
9930
9931 final long identity = Binder.clearCallingIdentity();
9932 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009933 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009934 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009935 } finally {
9936 Binder.restoreCallingIdentity(identity);
9937 }
9938 }
9939
9940 /**
9941 * trigger RCS reconfiguration.
9942 */
9943 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009944 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9945 "triggerRcsReconfiguration",
9946 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009947
9948 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9949 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9950 }
9951 if (!isImsAvailableOnDevice()) {
9952 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9953 "IMS not available on device.");
9954 }
9955
9956 final long identity = Binder.clearCallingIdentity();
9957 try {
9958 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9959 } finally {
9960 Binder.restoreCallingIdentity(identity);
9961 }
9962 }
9963
9964 /**
9965 * Provide the client configuration parameters of the RCS application.
9966 */
9967 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009968 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9969 "setRcsClientConfiguration",
9970 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009971
9972 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9973 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9974 }
9975 if (!isImsAvailableOnDevice()) {
9976 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9977 "IMS not available on device.");
9978 }
9979
9980 final long identity = Binder.clearCallingIdentity();
9981
9982 try {
9983 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9984 if (configBinder == null) {
9985 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9986 } else {
9987 configBinder.setRcsClientConfiguration(rcc);
9988 }
9989 } catch (RemoteException e) {
9990 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9991 } finally {
9992 Binder.restoreCallingIdentity(identity);
9993 }
9994 }
9995
9996 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -08009997 * Enables or disables the test mode for RCS VoLTE single registration.
9998 */
9999 @Override
10000 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10001 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10002 "setRcsSingleRegistrationTestModeEnabled");
10003
10004 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10005 }
10006
10007 /**
10008 * Gets the test mode for RCS VoLTE single registration.
10009 */
10010 @Override
10011 public boolean getRcsSingleRegistrationTestModeEnabled() {
10012 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10013 "getRcsSingleRegistrationTestModeEnabled");
10014
10015 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10016 }
10017
10018 /**
Hui Wang761a6682020-10-31 05:12:53 +000010019 * Overrides the config of RCS VoLTE single registration enabled for the device.
10020 */
10021 @Override
10022 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10023 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10024 "setDeviceSingleRegistrationEnabledOverride");
10025 enforceModifyPermission();
10026
10027 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10028 : Boolean.parseBoolean(enabledStr);
10029 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010030 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010031 }
10032
10033 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010034 * Sends a device to device communication message. Only usable via shell.
10035 * @param message message to send.
10036 * @param value message value.
10037 */
10038 @Override
10039 public void sendDeviceToDeviceMessage(int message, int value) {
10040 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010041 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010042 enforceModifyPermission();
10043
10044 final long identity = Binder.clearCallingIdentity();
10045 try {
10046 TelephonyConnectionService service =
10047 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10048 if (service == null) {
10049 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10050 return;
10051 }
10052 service.sendTestDeviceToDeviceMessage(message, value);
10053 } finally {
10054 Binder.restoreCallingIdentity(identity);
10055 }
10056 }
10057
Tyler Gunnbabbda02021-02-10 11:05:02 -080010058 /**
10059 * Sets the specified device to device transport active.
10060 * @param transport The transport to set active.
10061 */
10062 @Override
10063 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10064 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10065 "setActiveDeviceToDeviceTransport");
10066 enforceModifyPermission();
10067
10068 final long identity = Binder.clearCallingIdentity();
10069 try {
10070 TelephonyConnectionService service =
10071 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10072 if (service == null) {
10073 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10074 return;
10075 }
10076 service.setActiveDeviceToDeviceTransport(transport);
10077 } finally {
10078 Binder.restoreCallingIdentity(identity);
10079 }
10080 }
Tyler Gunn92479152021-01-20 16:30:10 -080010081
10082 /**
Hui Wang761a6682020-10-31 05:12:53 +000010083 * Gets the config of RCS VoLTE single registration enabled for the device.
10084 */
10085 @Override
10086 public boolean getDeviceSingleRegistrationEnabled() {
10087 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10088 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10089 }
10090
10091 /**
10092 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10093 */
10094 @Override
10095 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10096 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10097 "setCarrierSingleRegistrationEnabledOverride");
10098 enforceModifyPermission();
10099
10100 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10101 : Boolean.parseBoolean(enabledStr);
10102 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10103 subId, enabled);
10104 }
10105
10106 /**
10107 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10108 */
10109 @Override
10110 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10111 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10112 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10113 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010114
10115 /**
10116 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10117 * their mobile plan.
10118 */
10119 @Override
10120 public String getMobileProvisioningUrl() {
10121 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10122 final long identity = Binder.clearCallingIdentity();
10123 try {
10124 return getDefaultPhone().getMobileProvisioningUrl();
10125 } finally {
10126 Binder.restoreCallingIdentity(identity);
10127 }
10128 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010129
James.cf Linbcdf8b32021-01-14 16:44:13 +080010130 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010131 * Get the EAB contact from the EAB database.
10132 */
10133 @Override
10134 public String getContactFromEab(String contact) {
10135 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10136 enforceModifyPermission();
10137 final long identity = Binder.clearCallingIdentity();
10138 try {
10139 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10140 } finally {
10141 Binder.restoreCallingIdentity(identity);
10142 }
10143 }
10144
10145 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010146 * Remove the EAB contacts from the EAB database.
10147 */
10148 @Override
10149 public int removeContactFromEab(int subId, String contacts) {
10150 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10151 enforceModifyPermission();
10152 final long identity = Binder.clearCallingIdentity();
10153 try {
10154 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10155 } finally {
10156 Binder.restoreCallingIdentity(identity);
10157 }
10158 }
10159
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010160 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010161 public boolean getDeviceUceEnabled() {
10162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10163 final long identity = Binder.clearCallingIdentity();
10164 try {
10165 return mApp.getDeviceUceEnabled();
10166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169 }
10170
10171 @Override
10172 public void setDeviceUceEnabled(boolean isEnabled) {
10173 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10174 final long identity = Binder.clearCallingIdentity();
10175 try {
10176 mApp.setDeviceUceEnabled(isEnabled);
10177 } finally {
10178 Binder.restoreCallingIdentity(identity);
10179 }
10180 }
10181
Brad Ebinger14d467f2021-02-12 06:18:28 +000010182 /**
10183 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10184 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10185 */
10186 // Used for SHELL command only right now.
10187 @Override
10188 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10189 List<String> featureTags) {
10190 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10191 "addUceRegistrationOverrideShell");
10192 final long identity = Binder.clearCallingIdentity();
10193 try {
10194 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10195 new ArraySet<>(featureTags));
10196 } catch (ImsException e) {
10197 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10198 } finally {
10199 Binder.restoreCallingIdentity(identity);
10200 }
10201 }
10202
10203 /**
10204 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10205 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10206 */
10207 // Used for SHELL command only right now.
10208 @Override
10209 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10210 List<String> featureTags) {
10211 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10212 "removeUceRegistrationOverrideShell");
10213 final long identity = Binder.clearCallingIdentity();
10214 try {
10215 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10216 new ArraySet<>(featureTags));
10217 } catch (ImsException e) {
10218 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10219 } finally {
10220 Binder.restoreCallingIdentity(identity);
10221 }
10222 }
10223
10224 /**
10225 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10226 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10227 */
10228 // Used for SHELL command only right now.
10229 @Override
10230 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10231 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10232 "clearUceRegistrationOverrideShell");
10233 final long identity = Binder.clearCallingIdentity();
10234 try {
10235 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10236 } catch (ImsException e) {
10237 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10238 } finally {
10239 Binder.restoreCallingIdentity(identity);
10240 }
10241 }
10242
10243 /**
10244 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10245 */
10246 // Used for SHELL command only right now.
10247 @Override
10248 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10249 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10250 "getLatestRcsContactUceCapabilityShell");
10251 final long identity = Binder.clearCallingIdentity();
10252 try {
10253 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10254 } catch (ImsException e) {
10255 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10256 } finally {
10257 Binder.restoreCallingIdentity(identity);
10258 }
10259 }
10260
10261 /**
10262 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10263 * device does not have an active PUBLISH.
10264 */
10265 // Used for SHELL command only right now.
10266 @Override
10267 public String getLastUcePidfXmlShell(int subId) {
10268 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10269 final long identity = Binder.clearCallingIdentity();
10270 try {
10271 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10272 } catch (ImsException e) {
10273 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10274 } finally {
10275 Binder.restoreCallingIdentity(identity);
10276 }
10277 }
10278
10279
James.cf Lin4b784aa2021-01-31 03:25:15 +080010280 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010281 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10282 String callingPackage) {
10283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10284 mApp, subId, "setSignalStrengthUpdateRequest");
10285
10286 final int callingUid = Binder.getCallingUid();
10287 // Verify that tha callingPackage belongs to the calling UID
10288 mApp.getSystemService(AppOpsManager.class)
10289 .checkPackage(callingUid, callingPackage);
10290
10291 validateSignalStrengthUpdateRequest(request, callingUid);
10292
10293 final long identity = Binder.clearCallingIdentity();
10294 try {
10295 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10296 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10297
10298 if (result instanceof IllegalStateException) {
10299 throw (IllegalStateException) result;
10300 }
10301 } finally {
10302 Binder.restoreCallingIdentity(identity);
10303 }
10304 }
10305
10306 @Override
10307 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10308 String callingPackage) {
10309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10310 mApp, subId, "clearSignalStrengthUpdateRequest");
10311
10312 final int callingUid = Binder.getCallingUid();
10313 // Verify that tha callingPackage belongs to the calling UID
10314 mApp.getSystemService(AppOpsManager.class)
10315 .checkPackage(callingUid, callingPackage);
10316
10317 final long identity = Binder.clearCallingIdentity();
10318 try {
10319 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10320 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10321
10322 if (result instanceof IllegalStateException) {
10323 throw (IllegalStateException) result;
10324 }
10325 } finally {
10326 Binder.restoreCallingIdentity(identity);
10327 }
10328 }
10329
10330 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10331 int callingUid) {
10332 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10333 // phone/system process do not have further restriction on request
10334 return;
10335 }
10336
10337 // Applications has restrictions on how to use the request:
10338 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10339 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10340 // This is not system caller which has been checked above
10341 throw new IllegalArgumentException(
10342 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10343 }
10344
10345 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10346 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10347 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10348 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10349 || info.isEnabled()) {
10350 throw new IllegalArgumentException(
10351 "Only system can set hide fields in SignalThresholdInfo");
10352 }
10353
10354 // Thresholds length for each RAN need in range. This has been validated in
10355 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10356 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10357 final int[] thresholds = info.getThresholds();
10358 Objects.requireNonNull(thresholds);
10359 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10360 || thresholds.length
10361 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10362 throw new IllegalArgumentException(
10363 "thresholds length is out of range: " + thresholds.length);
10364 }
10365 }
10366 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010367
10368 /**
10369 * Gets the current phone capability.
10370 *
10371 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10372 * @return the PhoneCapability which describes the data connection capability of modem.
10373 * It's used to evaluate possible phone config change, for example from single
10374 * SIM device to multi-SIM device.
10375 */
10376 @Override
10377 public PhoneCapability getPhoneCapability() {
10378 enforceReadPrivilegedPermission("getPhoneCapability");
10379 final long identity = Binder.clearCallingIdentity();
10380 try {
10381 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10382 } finally {
10383 Binder.restoreCallingIdentity(identity);
10384 }
10385 }
Michele Berionne5e411512020-11-13 02:36:59 +000010386
10387 /**
10388 * Prepare TelephonyManager for an unattended reboot. The reboot is
10389 * required to be done shortly after the API is invoked.
10390 */
10391 @Override
10392 @TelephonyManager.PrepareUnattendedRebootResult
10393 public int prepareForUnattendedReboot() {
10394 enforceRebootPermission();
10395
10396 final long identity = Binder.clearCallingIdentity();
10397 try {
10398 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10399 } finally {
10400 Binder.restoreCallingIdentity(identity);
10401 }
10402 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010403
10404 /**
10405 * Request to get the current slicing configuration including URSP rules and
10406 * NSSAIs (configured, allowed and rejected).
10407 *
10408 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10409 */
10410 @Override
10411 public void getSlicingConfig(ResultReceiver callback) {
10412 enforceReadPrivilegedPermission("getSlicingConfig");
10413
10414 final long identity = Binder.clearCallingIdentity();
10415 try {
10416 Phone phone = getDefaultPhone();
10417 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10418 } finally {
10419 Binder.restoreCallingIdentity(identity);
10420 }
10421 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010422}