blob: 702dd7ff13c260cdb6b0d8bfe93fb87bbc64f888 [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;
110import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700111import android.telephony.gba.GbaAuthRequest;
112import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700113import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000115import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000116import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700117import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800119import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700120import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700122import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000123import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700124import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800125import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800126import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800128import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700131import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800133import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800134
Andrew Lee312e8172014-10-23 17:01:36 -0700135import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800136import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800137import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800138import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700139import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700140import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700141import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800142import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700143import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800145import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700147import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800148import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800149import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800150import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700151import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800153import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800155import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700156import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700157import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700158import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700159import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700160import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800161import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700162import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700163import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700164import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700165import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800166import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800167import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700168import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700169import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800171import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800172import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800173import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700174import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800175import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700176import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800177import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700178import com.android.internal.telephony.imsphone.ImsPhone;
179import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800180import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700181import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800183import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800185import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700186import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800187import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800189import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000190import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800191import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700192import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700193import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800194import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800195import com.android.phone.callcomposer.CallComposerPictureManager;
196import com.android.phone.callcomposer.CallComposerPictureTransfer;
197import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700198import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700199import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800200import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700201import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700202import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800203import com.android.services.telephony.TelecomAccountRegistry;
204import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800205import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800206
Hall Liu82694d52020-12-11 18:22:04 -0800207import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700208import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800209import java.io.IOException;
210import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700211import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800213import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800214import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800215import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800216import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100217import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800218import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700219import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800220import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800221import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800222import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800223import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800224import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700225
226/**
227 * Implementation of the ITelephony interface.
228 */
Santos Cordon117fee72014-05-16 17:56:12 -0700229public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700230 private static final String LOG_TAG = "PhoneInterfaceManager";
231 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
232 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800233 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700234
235 // Message codes used with mMainThreadHandler
236 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700237 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
238 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700239 private static final int CMD_OPEN_CHANNEL = 9;
240 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
241 private static final int CMD_CLOSE_CHANNEL = 11;
242 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800243 private static final int CMD_NV_READ_ITEM = 13;
244 private static final int EVENT_NV_READ_ITEM_DONE = 14;
245 private static final int CMD_NV_WRITE_ITEM = 15;
246 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
247 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
248 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700249 private static final int CMD_RESET_MODEM_CONFIG = 19;
250 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800251 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
252 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800253 private static final int CMD_SEND_ENVELOPE = 25;
254 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000255 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
256 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700257 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
258 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
259 private static final int CMD_EXCHANGE_SIM_IO = 31;
260 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800261 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
262 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700263 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
264 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700265 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
266 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700267 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
268 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
269 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
270 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700271 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
272 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
273 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
274 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700275 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800276 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
277 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000278 private static final int CMD_SWITCH_SLOTS = 50;
279 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700280 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
281 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
282 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
283 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
284 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
285 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
286 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
287 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700288 private static final int CMD_GET_ALL_CELL_INFO = 60;
289 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
290 private static final int CMD_GET_CELL_LOCATION = 62;
291 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700292 private static final int CMD_MODEM_REBOOT = 64;
293 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700294 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
295 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800296 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
297 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700298 private static final int CMD_GET_MODEM_STATUS = 70;
299 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700300 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
301 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700302 private static final int CMD_ERASE_MODEM_CONFIG = 74;
303 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800304 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
305 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
306 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
307 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800308 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
309 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800310 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800311 private static final int CMD_GET_CALL_FORWARDING = 83;
312 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
313 private static final int CMD_SET_CALL_FORWARDING = 85;
314 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
315 private static final int CMD_GET_CALL_WAITING = 87;
316 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
317 private static final int CMD_SET_CALL_WAITING = 89;
318 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700319 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
320 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
321 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
322 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700323 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
324 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800325 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
326 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800327 private static final int CMD_SET_DATA_THROTTLING = 99;
328 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800329 private static final int CMD_SET_SIM_POWER = 101;
330 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800331 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
332 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
333 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
334 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800335 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
336 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000337 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800339 // Parameters of select command.
340 private static final int SELECT_COMMAND = 0xA4;
341 private static final int SELECT_P1 = 0x04;
342 private static final int SELECT_P2 = 0;
343 private static final int SELECT_P3 = 0x10;
344
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 /** The singleton instance. */
346 private static PhoneInterfaceManager sInstance;
347
Wink Saville3ab207e2014-11-20 13:07:20 -0800348 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800349 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800350 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700351 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800352 private AppOpsManager mAppOps;
353 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800354 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800355 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700356 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800357 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
Peter Wangdafb9ac2020-01-15 14:13:38 -0800359 /** User Activity */
360 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800361 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
362
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700363 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
364
Derek Tan97ebb422014-09-05 16:55:38 -0700365 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
366 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800367 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800368 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700369
Michelecea4cf22018-12-21 15:00:11 -0800370 // String to store multi SIM allowed
371 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
372
Derek Tan740e1672017-06-27 14:56:27 -0700373 // The AID of ISD-R.
374 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
375
yinxub1bed742017-04-17 11:45:04 -0700376 private NetworkScanRequestTracker mNetworkScanRequestTracker;
377
David Kelly5e06a7f2018-03-12 14:10:59 +0000378 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
379 private static final int MANUFACTURER_CODE_LENGTH = 8;
380
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800381 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
382
Derek Tan89e89d42014-07-08 17:00:10 -0700383 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700384 * Experiment flag to enable erase modem config on reset network, default value is false
385 */
386 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
387 "reset_network_erase_modem_config_enabled";
388
Rambo Wang0f050d82021-02-12 11:43:36 -0800389 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
390
Naina Nallurid63128d2019-09-17 14:10:30 -0700391 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700392 * A request object to use for transmitting data to an ICC.
393 */
394 private static final class IccAPDUArgument {
395 public int channel, cla, command, p1, p2, p3;
396 public String data;
397
398 public IccAPDUArgument(int channel, int cla, int command,
399 int p1, int p2, int p3, String data) {
400 this.channel = channel;
401 this.cla = cla;
402 this.command = command;
403 this.p1 = p1;
404 this.p2 = p2;
405 this.p3 = p3;
406 this.data = data;
407 }
408 }
409
410 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700411 * A request object to use for transmitting data to an ICC.
412 */
413 private static final class ManualNetworkSelectionArgument {
414 public OperatorInfo operatorInfo;
415 public boolean persistSelection;
416
417 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
418 this.operatorInfo = operatorInfo;
419 this.persistSelection = persistSelection;
420 }
421 }
422
423 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
425 * request after sending. The main thread will notify the request when it is complete.
426 */
427 private static final class MainThreadRequest {
428 /** The argument to use for the request */
429 public Object argument;
430 /** The result of the request that is run on the main thread */
431 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800432 // The subscriber id that this request applies to. Defaults to
433 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
434 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435
Nathan Harold92bed182018-10-12 18:16:49 -0700436 // In cases where subId is unavailable, the caller needs to specify the phone.
437 public Phone phone;
438
vagdeviaf9a5b92018-08-15 16:01:53 -0700439 public WorkSource workSource;
440
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 public MainThreadRequest(Object argument) {
442 this.argument = argument;
443 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800444
Nathan Harold92bed182018-10-12 18:16:49 -0700445 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
446 this.argument = argument;
447 if (phone != null) {
448 this.phone = phone;
449 }
450 this.workSource = workSource;
451 }
452
vagdeviaf9a5b92018-08-15 16:01:53 -0700453 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800454 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800455 if (subId != null) {
456 this.subId = subId;
457 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700458 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 }
461
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800462 private static final class IncomingThirdPartyCallArgs {
463 public final ComponentName component;
464 public final String callId;
465 public final String callerDisplayName;
466
467 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
468 String callerDisplayName) {
469 this.component = component;
470 this.callId = callId;
471 this.callerDisplayName = callerDisplayName;
472 }
473 }
474
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 /**
476 * A handler that processes messages on the main thread in the phone process. Since many
477 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
478 * inbound binder threads to the main thread in the phone process. The Binder thread
479 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
480 * on, which will be notified when the operation completes and will contain the result of the
481 * request.
482 *
483 * <p>If a MainThreadRequest object is provided in the msg.obj field,
484 * note that request.result must be set to something non-null for the calling thread to
485 * unblock.
486 */
487 private final class MainThreadHandler extends Handler {
488 @Override
489 public void handleMessage(Message msg) {
490 MainThreadRequest request;
491 Message onCompleted;
492 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800493 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800495 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700496
497 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 case CMD_HANDLE_USSD_REQUEST: {
499 request = (MainThreadRequest) msg.obj;
500 final Phone phone = getPhoneFromRequest(request);
501 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
502 String ussdRequest = ussdObject.first;
503 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700504
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 if (!isUssdApiAllowed(request.subId)) {
506 // Carrier does not support use of this API, return failure.
507 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
508 UssdResponse response = new UssdResponse(ussdRequest, null);
509 Bundle returnData = new Bundle();
510 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
511 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700512
Pengquan Menga1bb6272018-09-06 09:59:22 -0700513 request.result = true;
514 notifyRequester(request);
515 return;
516 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700517
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 try {
519 request.result = phone != null
520 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
521 } catch (CallStateException cse) {
522 request.result = false;
523 }
524 // Wake up the requesting thread
525 notifyRequester(request);
526 break;
pkanwar32d516d2016-10-14 19:37:38 -0700527 }
528
Yorke Lee716f67e2015-06-17 15:39:16 -0700529 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700530 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700531 final Phone phone = getPhoneFromRequest(request);
532 request.result = phone != null ?
533 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
534 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700536 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700537 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800543 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700544 if (uiccCard == null) {
545 loge("iccTransmitApduLogicalChannel: No UICC");
546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700548 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700549 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
550 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 iccArgument.channel, iccArgument.cla, iccArgument.command,
553 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 break;
557
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 ar = (AsyncResult) msg.obj;
560 request = (MainThreadRequest) ar.userObj;
561 if (ar.exception == null && ar.result != null) {
562 request.result = ar.result;
563 } else {
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
565 if (ar.result == null) {
566 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800567 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800569 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 } else {
571 loge("iccTransmitApduLogicalChannel: Unknown exception");
572 }
573 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700574 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 break;
576
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
578 request = (MainThreadRequest) msg.obj;
579 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800580 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 if (uiccCard == null) {
582 loge("iccTransmitApduBasicChannel: No UICC");
583 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 } else {
586 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
587 request);
588 uiccCard.iccTransmitApduBasicChannel(
589 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
590 iccArgument.p3, iccArgument.data, onCompleted);
591 }
592 break;
593
594 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
597 if (ar.exception == null && ar.result != null) {
598 request.result = ar.result;
599 } else {
600 request.result = new IccIoResult(0x6F, 0, (byte[])null);
601 if (ar.result == null) {
602 loge("iccTransmitApduBasicChannel: Empty response");
603 } else if (ar.exception instanceof CommandException) {
604 loge("iccTransmitApduBasicChannel: CommandException: " +
605 ar.exception);
606 } else {
607 loge("iccTransmitApduBasicChannel: Unknown exception");
608 }
609 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700610 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 break;
612
613 case CMD_EXCHANGE_SIM_IO:
614 request = (MainThreadRequest) msg.obj;
615 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800616 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 if (uiccCard == null) {
618 loge("iccExchangeSimIO: No UICC");
619 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 } else {
622 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
623 request);
624 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
625 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
626 iccArgument.data, onCompleted);
627 }
628 break;
629
630 case EVENT_EXCHANGE_SIM_IO_DONE:
631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
633 if (ar.exception == null && ar.result != null) {
634 request.result = ar.result;
635 } else {
636 request.result = new IccIoResult(0x6f, 0, (byte[])null);
637 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 break;
640
Derek Tan4d5e5c12014-02-04 11:54:58 -0800641 case CMD_SEND_ENVELOPE:
642 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800643 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 if (uiccCard == null) {
645 loge("sendEnvelopeWithStatus: No UICC");
646 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 } else {
649 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
650 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
651 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800652 break;
653
654 case EVENT_SEND_ENVELOPE_DONE:
655 ar = (AsyncResult) msg.obj;
656 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700657 if (ar.exception == null && ar.result != null) {
658 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800659 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700660 request.result = new IccIoResult(0x6F, 0, (byte[])null);
661 if (ar.result == null) {
662 loge("sendEnvelopeWithStatus: Empty response");
663 } else if (ar.exception instanceof CommandException) {
664 loge("sendEnvelopeWithStatus: CommandException: " +
665 ar.exception);
666 } else {
667 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
668 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800669 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700670 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800671 break;
672
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 case CMD_OPEN_CHANNEL:
674 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800675 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800676 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700677 if (uiccCard == null) {
678 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800679 request.result = new IccOpenLogicalChannelResponse(-1,
680 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 } else {
683 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800684 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
685 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 break;
688
689 case EVENT_OPEN_CHANNEL_DONE:
690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700692 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 int[] result = (int[]) ar.result;
695 int channelId = result[0];
696 byte[] selectResponse = null;
697 if (result.length > 1) {
698 selectResponse = new byte[result.length - 1];
699 for (int i = 1; i < result.length; ++i) {
700 selectResponse[i - 1] = (byte) result[i];
701 }
702 }
703 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700704 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 if (ar.result == null) {
707 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700709 if (ar.exception != null) {
710 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
711 }
712
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700713 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700714 if (ar.exception instanceof CommandException) {
715 CommandException.Error error =
716 ((CommandException) (ar.exception)).getCommandError();
717 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700718 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700719 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700720 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700721 }
722 }
723 openChannelResp = new IccOpenLogicalChannelResponse(
724 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700725 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700726 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700727 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700728 break;
729
730 case CMD_CLOSE_CHANNEL:
731 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800732 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700733 if (uiccCard == null) {
734 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900735 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700737 } else {
738 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
739 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
740 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 break;
742
743 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800744 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
745 break;
746
747 case CMD_NV_READ_ITEM:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800750 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
751 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
754 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700755 ar = (AsyncResult) msg.obj;
756 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800757 if (ar.exception == null && ar.result != null) {
758 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800760 request.result = "";
761 if (ar.result == null) {
762 loge("nvReadItem: Empty response");
763 } else if (ar.exception instanceof CommandException) {
764 loge("nvReadItem: CommandException: " +
765 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700766 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800767 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700768 }
769 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700771 break;
772
Jake Hambye994d462014-02-03 13:10:13 -0800773 case CMD_NV_WRITE_ITEM:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
776 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800777 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700778 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800779 break;
780
781 case EVENT_NV_WRITE_ITEM_DONE:
782 handleNullReturnEvent(msg, "nvWriteItem");
783 break;
784
785 case CMD_NV_WRITE_CDMA_PRL:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800788 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
791 case EVENT_NV_WRITE_CDMA_PRL_DONE:
792 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
793 break;
794
chen xu6dac5ab2018-10-26 17:39:23 -0700795 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800796 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700797 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800798 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800799 break;
800
chen xu6dac5ab2018-10-26 17:39:23 -0700801 case EVENT_RESET_MODEM_CONFIG_DONE:
802 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800803 break;
804
Sooraj Sasindran37444802020-08-11 10:40:43 -0700805 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
808 request);
809 Phone phone = getPhoneFromRequest(request);
810 if (phone != null) {
811 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
812 } else {
813 loge("isNRDualConnectivityEnabled: No phone object");
814 request.result = false;
815 notifyRequester(request);
816 }
817 break;
818 }
819
820 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
821 ar = (AsyncResult) msg.obj;
822 request = (MainThreadRequest) ar.userObj;
823 if (ar.exception == null && ar.result != null) {
824 request.result = ar.result;
825 } else {
826 // request.result must be set to something non-null
827 // for the calling thread to unblock
828 if (request.result != null) {
829 request.result = ar.result;
830 } else {
831 request.result = false;
832 }
833 if (ar.result == null) {
834 loge("isNRDualConnectivityEnabled: Empty response");
835 } else if (ar.exception instanceof CommandException) {
836 loge("isNRDualConnectivityEnabled: CommandException: "
837 + ar.exception);
838 } else {
839 loge("isNRDualConnectivityEnabled: Unknown exception");
840 }
841 }
842 notifyRequester(request);
843 break;
844
845 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
846 request = (MainThreadRequest) msg.obj;
847 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
848 Phone phone = getPhoneFromRequest(request);
849 if (phone != null) {
850 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
851 request.workSource);
852 } else {
853 loge("enableNrDualConnectivity: No phone object");
854 request.result =
855 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
856 notifyRequester(request);
857 }
858 break;
859 }
860
861 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null) {
865 request.result =
866 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
867 } else {
868 request.result =
869 TelephonyManager
870 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
871 if (ar.exception instanceof CommandException) {
872 CommandException.Error error =
873 ((CommandException) (ar.exception)).getCommandError();
874 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
875 request.result =
876 TelephonyManager
877 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000878 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
879 request.result =
880 TelephonyManager
881 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700882 }
883 loge("enableNrDualConnectivity" + ": CommandException: "
884 + ar.exception);
885 } else {
886 loge("enableNrDualConnectivity" + ": Unknown exception");
887 }
888 }
889 notifyRequester(request);
890 break;
891 }
892
SongFerngWang3ef3e072020-12-21 16:41:52 +0800893 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800894 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800895 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
896 request);
897 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 break;
899
SongFerngWang3ef3e072020-12-21 16:41:52 +0800900 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result; // Integer
905 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530906 // request.result must be set to something non-null
907 // for the calling thread to unblock
908 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800909 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800910 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800911 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800912 loge("getAllowedNetworkTypesBitmask: CommandException: "
913 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800914 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800915 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800916 }
917 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700918 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 break;
920
SongFerngWang3ef3e072020-12-21 16:41:52 +0800921 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800922 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800923 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
924 request);
925 Pair<Integer, Long> reasonWithNetworkTypes =
926 (Pair<Integer, Long>) request.argument;
927 getPhoneFromRequest(request).setAllowedNetworkTypes(
928 reasonWithNetworkTypes.first,
929 reasonWithNetworkTypes.second,
930 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800931 break;
932
SongFerngWang3ef3e072020-12-21 16:41:52 +0800933 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
934 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800935 break;
936
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000937 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
938 request = (MainThreadRequest)msg.obj;
939 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800940 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000941 break;
942
943 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
944 ar = (AsyncResult)msg.obj;
945 request = (MainThreadRequest)ar.userObj;
946 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700947 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000948 break;
949
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800950 case CMD_SET_VOICEMAIL_NUMBER:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
953 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800954 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
955 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800956 break;
957
958 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
959 handleNullReturnEvent(msg, "setVoicemailNumber");
960 break;
961
Stuart Scott54788802015-03-30 13:18:01 -0700962 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
963 request = (MainThreadRequest) msg.obj;
964 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
965 request);
966 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
967 break;
968
969 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
970 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
971 break;
972
Shishir Agrawal302c8692015-06-19 13:49:39 -0700973 case CMD_PERFORM_NETWORK_SCAN:
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
976 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
977 break;
978
Hall Liu27d24262020-09-18 19:04:59 -0700979 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700982 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
983 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
984 request.argument;
985 int callForwardingReason = args.first;
986 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800987 break;
Hall Liu27d24262020-09-18 19:04:59 -0700988 }
989 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700992 TelephonyManager.CallForwardingInfoCallback callback =
993 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
994 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800995 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700996 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800997 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
998 for (CallForwardInfo callForwardInfo : callForwardInfos) {
999 // Service Class is a bit mask per 3gpp 27.007. Search for
1000 // any service for voice call.
1001 if ((callForwardInfo.serviceClass
1002 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001003 callForwardingInfo = new CallForwardingInfo(true,
1004 callForwardInfo.reason,
1005 callForwardInfo.number,
1006 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001007 break;
1008 }
1009 }
1010 // Didn't find a call forward info for voice call.
1011 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001012 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1013 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001014 }
Hall Liu27d24262020-09-18 19:04:59 -07001015 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001016 } else {
1017 if (ar.result == null) {
1018 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1019 }
1020 if (ar.exception != null) {
1021 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1022 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001023 int errorCode = TelephonyManager
1024 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001025 if (ar.exception instanceof CommandException) {
1026 CommandException.Error error =
1027 ((CommandException) (ar.exception)).getCommandError();
1028 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001029 errorCode = TelephonyManager
1030 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001031 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001032 errorCode = TelephonyManager
1033 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001034 }
1035 }
Hall Liu27d24262020-09-18 19:04:59 -07001036 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001037 }
Shuo Qian4a594052020-01-23 11:59:30 -08001038 break;
Hall Liu27d24262020-09-18 19:04:59 -07001039 }
Shuo Qian4a594052020-01-23 11:59:30 -08001040
Hall Liu27d24262020-09-18 19:04:59 -07001041 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001042 request = (MainThreadRequest) msg.obj;
1043 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001044 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001045 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001046 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1047 request.argument).first;
1048 request.phone.setCallForwardingOption(
1049 callForwardingInfoToSet.isEnabled()
1050 ? CommandsInterface.CF_ACTION_ENABLE
1051 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001052 callForwardingInfoToSet.getReason(),
1053 callForwardingInfoToSet.getNumber(),
1054 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1055 break;
Hall Liu27d24262020-09-18 19:04:59 -07001056 }
Shuo Qian4a594052020-01-23 11:59:30 -08001057
Hall Liu27d24262020-09-18 19:04:59 -07001058 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001061 Consumer<Integer> callback =
1062 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1063 request.argument).second;
1064 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001065 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001066 int errorCode = TelephonyManager.CallForwardingInfoCallback
1067 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001068 if (ar.exception instanceof CommandException) {
1069 CommandException.Error error =
1070 ((CommandException) (ar.exception)).getCommandError();
1071 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001072 errorCode = TelephonyManager.CallForwardingInfoCallback
1073 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001074 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001075 errorCode = TelephonyManager.CallForwardingInfoCallback
1076 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001077 }
1078 }
1079 callback.accept(errorCode);
1080 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001081 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001082 }
Shuo Qian4a594052020-01-23 11:59:30 -08001083 break;
Hall Liu27d24262020-09-18 19:04:59 -07001084 }
Shuo Qian4a594052020-01-23 11:59:30 -08001085
Hall Liu27d24262020-09-18 19:04:59 -07001086 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001087 request = (MainThreadRequest) msg.obj;
1088 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1089 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1090 break;
Hall Liu27d24262020-09-18 19:04:59 -07001091 }
Shuo Qian4a594052020-01-23 11:59:30 -08001092
Hall Liu27d24262020-09-18 19:04:59 -07001093 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001094 ar = (AsyncResult) msg.obj;
1095 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001096 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001097 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1098 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001099 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001100 // Service Class is a bit mask per 3gpp 27.007.
1101 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001102 if (callForwardResults.length > 1
1103 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001104 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001105 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001106 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1107 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001108 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001109 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001110 }
1111 } else {
1112 if (ar.result == null) {
1113 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1114 }
1115 if (ar.exception != null) {
1116 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1117 }
1118 if (ar.exception instanceof CommandException) {
1119 CommandException.Error error =
1120 ((CommandException) (ar.exception)).getCommandError();
1121 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1122 callForwardingStatus =
1123 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1124 }
1125 }
1126 }
Hall Liu27d24262020-09-18 19:04:59 -07001127 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001128 break;
Hall Liu27d24262020-09-18 19:04:59 -07001129 }
Shuo Qian4a594052020-01-23 11:59:30 -08001130
Hall Liu27d24262020-09-18 19:04:59 -07001131 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001132 request = (MainThreadRequest) msg.obj;
1133 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001134 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1135 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001136 break;
Hall Liu27d24262020-09-18 19:04:59 -07001137 }
Shuo Qian4a594052020-01-23 11:59:30 -08001138
Hall Liu27d24262020-09-18 19:04:59 -07001139 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001140 ar = (AsyncResult) msg.obj;
1141 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001142 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1143 Consumer<Integer> callback =
1144 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1145 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001146 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001147 if (ar.exception instanceof CommandException) {
1148 CommandException.Error error =
1149 ((CommandException) (ar.exception)).getCommandError();
1150 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1151 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1152 } else {
1153 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1154 }
1155 } else {
1156 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1157 }
1158 } else {
1159 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1160 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001161 }
Shuo Qian4a594052020-01-23 11:59:30 -08001162 break;
Hall Liu27d24262020-09-18 19:04:59 -07001163 }
Shuo Qian4a594052020-01-23 11:59:30 -08001164
Shishir Agrawal302c8692015-06-19 13:49:39 -07001165 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1166 ar = (AsyncResult) msg.obj;
1167 request = (MainThreadRequest) ar.userObj;
1168 CellNetworkScanResult cellScanResult;
1169 if (ar.exception == null && ar.result != null) {
1170 cellScanResult = new CellNetworkScanResult(
1171 CellNetworkScanResult.STATUS_SUCCESS,
1172 (List<OperatorInfo>) ar.result);
1173 } else {
1174 if (ar.result == null) {
1175 loge("getCellNetworkScanResults: Empty response");
1176 }
1177 if (ar.exception != null) {
1178 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1179 }
1180 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1181 if (ar.exception instanceof CommandException) {
1182 CommandException.Error error =
1183 ((CommandException) (ar.exception)).getCommandError();
1184 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1185 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1186 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1187 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1188 }
1189 }
1190 cellScanResult = new CellNetworkScanResult(errorCode, null);
1191 }
1192 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001193 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001194 break;
1195
1196 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1197 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001198 ManualNetworkSelectionArgument selArg =
1199 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001200 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1201 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001202 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1203 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001204 break;
1205
1206 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001207 ar = (AsyncResult) msg.obj;
1208 request = (MainThreadRequest) ar.userObj;
1209 if (ar.exception == null) {
1210 request.result = true;
1211 } else {
1212 request.result = false;
1213 loge("setNetworkSelectionModeManual " + ar.exception);
1214 }
1215 notifyRequester(request);
1216 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001217 break;
1218
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001219 case CMD_GET_MODEM_ACTIVITY_INFO:
1220 request = (MainThreadRequest) msg.obj;
1221 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001222 if (defaultPhone != null) {
1223 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001224 } else {
1225 ResultReceiver result = (ResultReceiver) request.argument;
1226 Bundle bundle = new Bundle();
1227 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001228 new ModemActivityInfo(0, 0, 0,
1229 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001230 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001231 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001232 break;
1233
Hall Liud0f208c2020-10-14 16:54:44 -07001234 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001235 ar = (AsyncResult) msg.obj;
1236 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001237 ResultReceiver result = (ResultReceiver) request.argument;
1238
Hall Liud0f208c2020-10-14 16:54:44 -07001239 ModemActivityInfo ret = null;
1240 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001241 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001242 // Update the last modem activity info and the result of the request.
1243 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1244 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001245 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001246 int[] txTimeMs = info.getTransmitTimeMillis();
1247 int[] lastModemTxTimeMs = mLastModemActivityInfo
1248 .getTransmitTimeMillis();
1249 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1250 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1251 }
Hall Liu49656c02020-10-09 19:00:11 -07001252 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001253 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1254 + mLastModemActivityInfo.getSleepTimeMillis());
1255 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1256 + mLastModemActivityInfo.getIdleTimeMillis());
1257 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1258 mLastModemActivityInfo.setReceiveTimeMillis(
1259 info.getReceiveTimeMillis()
1260 + mLastModemActivityInfo.getReceiveTimeMillis());
1261 }
Hall Liu49656c02020-10-09 19:00:11 -07001262 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001263 mLastModemActivityInfo.getSleepTimeMillis(),
1264 mLastModemActivityInfo.getIdleTimeMillis(),
1265 mLastModemActivityInfo.getTransmitTimeMillis(),
1266 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001267 } else {
1268 if (ar.result == null) {
1269 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001270 error = TelephonyManager.ModemActivityInfoException
1271 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001272 } else if (ar.exception instanceof CommandException) {
1273 loge("queryModemActivityInfo: CommandException: " +
1274 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001275 error = TelephonyManager.ModemActivityInfoException
1276 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001277 } else {
1278 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001279 error = TelephonyManager.ModemActivityInfoException
1280 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001281 }
1282 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001283 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001284 if (ret != null) {
1285 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1286 } else {
1287 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1288 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001289 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001290 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001291 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001292 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001293
Meng Wang1a7c35a2016-05-05 20:56:15 -07001294 case CMD_SET_ALLOWED_CARRIERS:
1295 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001296 CarrierRestrictionRules argument =
1297 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001298 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001299 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 break;
1301
1302 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null && ar.result != null) {
1306 request.result = ar.result;
1307 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001308 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1309 if (ar.exception instanceof CommandException) {
1310 loge("setAllowedCarriers: CommandException: " + ar.exception);
1311 CommandException.Error error =
1312 ((CommandException) (ar.exception)).getCommandError();
1313 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1314 request.result =
1315 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1316 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001317 } else {
1318 loge("setAllowedCarriers: Unknown exception");
1319 }
1320 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001321 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001322 break;
1323
1324 case CMD_GET_ALLOWED_CARRIERS:
1325 request = (MainThreadRequest) msg.obj;
1326 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001327 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001328 break;
1329
1330 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1331 ar = (AsyncResult) msg.obj;
1332 request = (MainThreadRequest) ar.userObj;
1333 if (ar.exception == null && ar.result != null) {
1334 request.result = ar.result;
1335 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001336 request.result = new IllegalStateException(
1337 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001338 if (ar.result == null) {
1339 loge("getAllowedCarriers: Empty response");
1340 } else if (ar.exception instanceof CommandException) {
1341 loge("getAllowedCarriers: CommandException: " +
1342 ar.exception);
1343 } else {
1344 loge("getAllowedCarriers: Unknown exception");
1345 }
1346 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001347 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001348 break;
1349
Nathan Haroldb3014052017-01-25 15:57:32 -08001350 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1351 ar = (AsyncResult) msg.obj;
1352 request = (MainThreadRequest) ar.userObj;
1353 if (ar.exception == null && ar.result != null) {
1354 request.result = ar.result;
1355 } else {
1356 request.result = new IllegalArgumentException(
1357 "Failed to retrieve Forbidden Plmns");
1358 if (ar.result == null) {
1359 loge("getForbiddenPlmns: Empty response");
1360 } else {
1361 loge("getForbiddenPlmns: Unknown exception");
1362 }
1363 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001364 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001365 break;
1366
1367 case CMD_GET_FORBIDDEN_PLMNS:
1368 request = (MainThreadRequest) msg.obj;
1369 uiccCard = getUiccCardFromRequest(request);
1370 if (uiccCard == null) {
1371 loge("getForbiddenPlmns() UiccCard is null");
1372 request.result = new IllegalArgumentException(
1373 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001374 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001375 break;
1376 }
1377 Integer appType = (Integer) request.argument;
1378 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1379 if (uiccApp == null) {
1380 loge("getForbiddenPlmns() no app with specified type -- "
1381 + appType);
1382 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001383 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001384 break;
1385 } else {
1386 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1387 + " specified type -- " + appType);
1388 }
1389 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1390 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1391 onCompleted);
1392 break;
1393
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001394 case CMD_SWITCH_SLOTS:
1395 request = (MainThreadRequest) msg.obj;
1396 int[] physicalSlots = (int[]) request.argument;
1397 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1398 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1399 break;
1400
1401 case EVENT_SWITCH_SLOTS_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001405 notifyRequester(request);
1406 break;
1407 case CMD_GET_NETWORK_SELECTION_MODE:
1408 request = (MainThreadRequest) msg.obj;
1409 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1410 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1411 break;
1412
1413 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1414 ar = (AsyncResult) msg.obj;
1415 request = (MainThreadRequest) ar.userObj;
1416 if (ar.exception != null) {
1417 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1418 } else {
1419 int mode = ((int[]) ar.result)[0];
1420 if (mode == 0) {
1421 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1422 } else {
1423 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1424 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001425 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001426 notifyRequester(request);
1427 break;
1428 case CMD_GET_CDMA_ROAMING_MODE:
1429 request = (MainThreadRequest) msg.obj;
1430 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1431 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1432 break;
1433 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1434 ar = (AsyncResult) msg.obj;
1435 request = (MainThreadRequest) ar.userObj;
1436 if (ar.exception != null) {
1437 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1438 } else {
1439 request.result = ((int[]) ar.result)[0];
1440 }
1441 notifyRequester(request);
1442 break;
1443 case CMD_SET_CDMA_ROAMING_MODE:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1446 int mode = (int) request.argument;
1447 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1448 break;
1449 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1450 ar = (AsyncResult) msg.obj;
1451 request = (MainThreadRequest) ar.userObj;
1452 request.result = ar.exception == null;
1453 notifyRequester(request);
1454 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001455 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1456 request = (MainThreadRequest) msg.obj;
1457 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1458 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1459 break;
1460 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1461 ar = (AsyncResult) msg.obj;
1462 request = (MainThreadRequest) ar.userObj;
1463 if (ar.exception != null) {
1464 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1465 } else {
1466 request.result = ((int[]) ar.result)[0];
1467 }
1468 notifyRequester(request);
1469 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001470 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1471 request = (MainThreadRequest) msg.obj;
1472 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1473 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001474 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1475 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001476 break;
1477 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 request.result = ar.exception == null;
1481 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001482 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001483 case CMD_GET_ALL_CELL_INFO:
1484 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001485 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001486 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001487 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001488 case EVENT_GET_ALL_CELL_INFO_DONE:
1489 ar = (AsyncResult) msg.obj;
1490 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001491 // If a timeout occurs, the response will be null
1492 request.result = (ar.exception == null && ar.result != null)
1493 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 synchronized (request) {
1495 request.notifyAll();
1496 }
1497 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001498 case CMD_REQUEST_CELL_INFO_UPDATE:
1499 request = (MainThreadRequest) msg.obj;
1500 request.phone.requestCellInfoUpdate(request.workSource,
1501 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1502 break;
1503 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1504 ar = (AsyncResult) msg.obj;
1505 request = (MainThreadRequest) ar.userObj;
1506 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1507 try {
1508 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001509 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001510 cb.onError(
1511 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1512 ar.exception.getClass().getName(),
1513 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001514 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001515 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001516 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001517 } else {
1518 // use the result as returned
1519 cb.onCellInfo((List<CellInfo>) ar.result);
1520 }
1521 } catch (RemoteException re) {
1522 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1523 }
1524 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001525 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001526 request = (MainThreadRequest) msg.obj;
1527 WorkSource ws = (WorkSource) request.argument;
1528 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001529 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001530 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001531 }
1532 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001533 ar = (AsyncResult) msg.obj;
1534 request = (MainThreadRequest) ar.userObj;
1535 if (ar.exception == null) {
1536 request.result = ar.result;
1537 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001538 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001539 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001540 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001541 }
1542
1543 synchronized (request) {
1544 request.notifyAll();
1545 }
1546 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001547 }
chen xu6dac5ab2018-10-26 17:39:23 -07001548 case CMD_MODEM_REBOOT:
1549 request = (MainThreadRequest) msg.obj;
1550 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001551 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001552 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001553 case EVENT_CMD_MODEM_REBOOT_DONE:
1554 handleNullReturnEvent(msg, "rebootModem");
1555 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001556 case CMD_REQUEST_ENABLE_MODEM:
1557 request = (MainThreadRequest) msg.obj;
1558 boolean enable = (boolean) request.argument;
1559 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001560 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001561 PhoneConfigurationManager.getInstance()
1562 .enablePhone(request.phone, enable, onCompleted);
1563 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001564 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001565 ar = (AsyncResult) msg.obj;
1566 request = (MainThreadRequest) ar.userObj;
1567 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001568 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001569 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001570 if ((boolean) request.result) {
1571 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1572 updateModemStateMetrics();
1573 } else {
1574 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1575 + ar.exception);
1576 }
1577 notifyRequester(request);
1578 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001579 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001580 case CMD_GET_MODEM_STATUS:
1581 request = (MainThreadRequest) msg.obj;
1582 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1583 PhoneConfigurationManager.getInstance()
1584 .getPhoneStatusFromModem(request.phone, onCompleted);
1585 break;
1586 case EVENT_GET_MODEM_STATUS_DONE:
1587 ar = (AsyncResult) msg.obj;
1588 request = (MainThreadRequest) ar.userObj;
1589 int id = request.phone.getPhoneId();
1590 if (ar.exception == null && ar.result != null) {
1591 request.result = ar.result;
1592 //update the cache as modem status has changed
1593 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1594 (boolean) request.result);
1595 } else {
1596 // Return true if modem status cannot be retrieved. For most cases,
1597 // modem status is on. And for older version modems, GET_MODEM_STATUS
1598 // and disable modem are not supported. Modem is always on.
1599 // TODO: this should be fixed in R to support a third
1600 // status UNKNOWN b/131631629
1601 request.result = true;
1602 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1603 + ar.exception);
1604 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001605 notifyRequester(request);
1606 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001607 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1608 request = (MainThreadRequest) msg.obj;
1609 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1610 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1611 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1612 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1613 break;
1614 }
1615 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1619 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1620 args.second.accept(ar.exception == null);
1621 notifyRequester(request);
1622 break;
1623 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001624 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1625 request = (MainThreadRequest) msg.obj;
1626 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1627 Phone phone = getPhoneFromRequest(request);
1628 if (phone != null) {
1629 phone.getSystemSelectionChannels(onCompleted);
1630 } else {
1631 loge("getSystemSelectionChannels: No phone object");
1632 request.result = new ArrayList<RadioAccessSpecifier>();
1633 notifyRequester(request);
1634 }
1635 break;
1636 }
1637 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1638 ar = (AsyncResult) msg.obj;
1639 request = (MainThreadRequest) ar.userObj;
1640 if (ar.exception == null && ar.result != null) {
1641 request.result = ar.result;
1642 } else {
1643 request.result = new IllegalArgumentException(
1644 "Failed to retrieve system selection channels");
1645 if (ar.result == null) {
1646 loge("getSystemSelectionChannels: Empty response");
1647 } else {
1648 loge("getSystemSelectionChannels: Unknown exception");
1649 }
1650 }
1651 notifyRequester(request);
1652 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001653 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1654 ar = (AsyncResult) msg.obj;
1655 request = (MainThreadRequest) ar.userObj;
1656 if (ar.exception == null && ar.result != null) {
1657 request.result = ar.result;
1658 } else {
1659 request.result = -1;
1660 loge("Failed to set Forbidden Plmns");
1661 if (ar.result == null) {
1662 loge("setForbidenPlmns: Empty response");
1663 } else if (ar.exception != null) {
1664 loge("setForbiddenPlmns: Exception: " + ar.exception);
1665 request.result = -1;
1666 } else {
1667 loge("setForbiddenPlmns: Unknown exception");
1668 }
1669 }
1670 notifyRequester(request);
1671 break;
1672 case CMD_SET_FORBIDDEN_PLMNS:
1673 request = (MainThreadRequest) msg.obj;
1674 uiccCard = getUiccCardFromRequest(request);
1675 if (uiccCard == null) {
1676 loge("setForbiddenPlmns: UiccCard is null");
1677 request.result = -1;
1678 notifyRequester(request);
1679 break;
1680 }
1681 Pair<Integer, List<String>> setFplmnsArgs =
1682 (Pair<Integer, List<String>>) request.argument;
1683 appType = setFplmnsArgs.first;
1684 List<String> fplmns = setFplmnsArgs.second;
1685 uiccApp = uiccCard.getApplicationByType(appType);
1686 if (uiccApp == null) {
1687 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1688 request.result = -1;
1689 loge("Failed to get UICC App");
1690 notifyRequester(request);
1691 } else {
1692 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1693 ((SIMRecords) uiccApp.getIccRecords())
1694 .setForbiddenPlmns(onCompleted, fplmns);
1695 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001696 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001697 case CMD_ERASE_MODEM_CONFIG:
1698 request = (MainThreadRequest) msg.obj;
1699 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1700 defaultPhone.eraseModemConfig(onCompleted);
1701 break;
1702 case EVENT_ERASE_MODEM_CONFIG_DONE:
1703 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001704 break;
zoey chene02881a2019-12-30 16:11:23 +08001705
1706 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1707 request = (MainThreadRequest) msg.obj;
1708 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1709 Pair<String, String> changed = (Pair<String, String>) request.argument;
1710 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1711 changed.first, changed.second, onCompleted);
1712 break;
1713 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1714 ar = (AsyncResult) msg.obj;
1715 request = (MainThreadRequest) ar.userObj;
1716 if (ar.exception == null) {
1717 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001718 // If the operation is successful, update the PIN storage
1719 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1720 int phoneId = getPhoneFromRequest(request).getPhoneId();
1721 UiccController.getInstance().getPinStorage()
1722 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001723 } else {
1724 request.result = msg.arg1;
1725 }
1726 notifyRequester(request);
1727 break;
1728
Michele Berionne5e411512020-11-13 02:36:59 +00001729 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001730 request = (MainThreadRequest) msg.obj;
1731 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1732 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1733 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1734 enabled.first, enabled.second, onCompleted);
1735 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001736 }
zoey chene02881a2019-12-30 16:11:23 +08001737 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1738 ar = (AsyncResult) msg.obj;
1739 request = (MainThreadRequest) ar.userObj;
1740 if (ar.exception == null) {
1741 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001742 // If the operation is successful, update the PIN storage
1743 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1744 int phoneId = getPhoneFromRequest(request).getPhoneId();
1745 if (enabled.first) {
1746 UiccController.getInstance().getPinStorage()
1747 .storePin(enabled.second, phoneId);
1748 } else {
1749 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1750 }
zoey chene02881a2019-12-30 16:11:23 +08001751 } else {
1752 request.result = msg.arg1;
1753 }
Michele Berionne5e411512020-11-13 02:36:59 +00001754
1755
zoey chene02881a2019-12-30 16:11:23 +08001756 notifyRequester(request);
1757 break;
1758
Peter Wangdafb9ac2020-01-15 14:13:38 -08001759 case MSG_NOTIFY_USER_ACTIVITY:
1760 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001761 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001762 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1763 getDefaultPhone().getContext().sendBroadcastAsUser(
1764 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1765 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001766
1767 case CMD_SET_DATA_THROTTLING: {
1768 request = (MainThreadRequest) msg.obj;
1769 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1770 DataThrottlingRequest dataThrottlingRequest =
1771 (DataThrottlingRequest) request.argument;
1772 Phone phone = getPhoneFromRequest(request);
1773 if (phone != null) {
1774 phone.setDataThrottling(onCompleted,
1775 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1776 dataThrottlingRequest.getCompletionDurationMillis());
1777 } else {
1778 loge("setDataThrottling: No phone object");
1779 request.result =
1780 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1781 notifyRequester(request);
1782 }
1783
1784 break;
1785 }
1786 case EVENT_SET_DATA_THROTTLING_DONE:
1787 ar = (AsyncResult) msg.obj;
1788 request = (MainThreadRequest) ar.userObj;
1789
1790 if (ar.exception == null) {
1791 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1792 } else if (ar.exception instanceof CommandException) {
1793 loge("setDataThrottling: CommandException: " + ar.exception);
1794 CommandException.Error error =
1795 ((CommandException) (ar.exception)).getCommandError();
1796
1797 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1798 request.result = TelephonyManager
1799 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1800 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1801 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1802 } else {
1803 request.result =
1804 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1805 }
1806 } else {
1807 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1808 }
1809 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1810 notifyRequester(request);
1811 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001812
1813 case CMD_SET_SIM_POWER: {
1814 request = (MainThreadRequest) msg.obj;
1815 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1816 request = (MainThreadRequest) msg.obj;
1817 int stateToSet =
1818 ((Pair<Integer, IIntegerConsumer>)
1819 request.argument).first;
1820 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1821 break;
1822 }
1823 case EVENT_SET_SIM_POWER_DONE: {
1824 ar = (AsyncResult) msg.obj;
1825 request = (MainThreadRequest) ar.userObj;
1826 IIntegerConsumer callback =
1827 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1828 if (ar.exception != null) {
1829 loge("setSimPower exception: " + ar.exception);
1830 int errorCode = TelephonyManager.CallForwardingInfoCallback
1831 .RESULT_ERROR_UNKNOWN;
1832 if (ar.exception instanceof CommandException) {
1833 CommandException.Error error =
1834 ((CommandException) (ar.exception)).getCommandError();
1835 if (error == CommandException.Error.SIM_ERR) {
1836 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1837 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1838 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1839 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1840 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1841 } else {
1842 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1843 }
1844 }
1845 try {
1846 callback.accept(errorCode);
1847 } catch (RemoteException e) {
1848 // Ignore if the remote process is no longer available to call back.
1849 Log.w(LOG_TAG, "setSimPower: callback not available.");
1850 }
1851 } else {
1852 try {
1853 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1854 } catch (RemoteException e) {
1855 // Ignore if the remote process is no longer available to call back.
1856 Log.w(LOG_TAG, "setSimPower: callback not available.");
1857 }
1858 }
1859 break;
1860 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001861 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1862 request = (MainThreadRequest) msg.obj;
1863
1864 final Phone phone = getPhoneFromRequest(request);
1865 if (phone == null || phone.getServiceStateTracker() == null) {
1866 request.result = new IllegalStateException("Phone or SST is null");
1867 notifyRequester(request);
1868 break;
1869 }
1870
1871 Pair<Integer, SignalStrengthUpdateRequest> pair =
1872 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1873 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1874 request);
1875 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1876 request.subId, pair.first /*callingUid*/,
1877 pair.second /*request*/, onCompleted);
1878 break;
1879 }
1880 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1881 ar = (AsyncResult) msg.obj;
1882 request = (MainThreadRequest) ar.userObj;
1883 // request.result will be the exception of ar if present, true otherwise.
1884 // Be cautious not to leave result null which will wait() forever
1885 request.result = ar.exception != null ? ar.exception : true;
1886 notifyRequester(request);
1887 break;
1888 }
1889 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1890 request = (MainThreadRequest) msg.obj;
1891
1892 Phone phone = getPhoneFromRequest(request);
1893 if (phone == null || phone.getServiceStateTracker() == null) {
1894 request.result = new IllegalStateException("Phone or SST is null");
1895 notifyRequester(request);
1896 break;
1897 }
1898
1899 Pair<Integer, SignalStrengthUpdateRequest> pair =
1900 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1901 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1902 request);
1903 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1904 request.subId, pair.first /*callingUid*/,
1905 pair.second /*request*/, onCompleted);
1906 break;
1907 }
1908 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1909 ar = (AsyncResult) msg.obj;
1910 request = (MainThreadRequest) ar.userObj;
1911 request.result = ar.exception != null ? ar.exception : true;
1912 notifyRequester(request);
1913 break;
1914 }
Jordan Liu109698e2020-11-24 14:50:34 -08001915
Michele Berionne5e411512020-11-13 02:36:59 +00001916 case CMD_PREPARE_UNATTENDED_REBOOT:
1917 request = (MainThreadRequest) msg.obj;
1918 request.result =
1919 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1920 notifyRequester(request);
1921 break;
1922
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 default:
1924 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1925 break;
1926 }
1927 }
Jake Hambye994d462014-02-03 13:10:13 -08001928
Pengquan Menga1bb6272018-09-06 09:59:22 -07001929 private void notifyRequester(MainThreadRequest request) {
1930 synchronized (request) {
1931 request.notifyAll();
1932 }
1933 }
1934
Jake Hambye994d462014-02-03 13:10:13 -08001935 private void handleNullReturnEvent(Message msg, String command) {
1936 AsyncResult ar = (AsyncResult) msg.obj;
1937 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1938 if (ar.exception == null) {
1939 request.result = true;
1940 } else {
1941 request.result = false;
1942 if (ar.exception instanceof CommandException) {
1943 loge(command + ": CommandException: " + ar.exception);
1944 } else {
1945 loge(command + ": Unknown exception");
1946 }
1947 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001948 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 }
1951
1952 /**
1953 * Posts the specified command to be executed on the main thread,
1954 * waits for the request to complete, and returns the result.
1955 * @see #sendRequestAsync
1956 */
1957 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001958 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1959 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001960 }
1961
1962 /**
1963 * Posts the specified command to be executed on the main thread,
1964 * waits for the request to complete, and returns the result.
1965 * @see #sendRequestAsync
1966 */
1967 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1968 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001969 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001970 }
1971
1972 /**
1973 * Posts the specified command to be executed on the main thread,
1974 * waits for the request to complete, and returns the result.
1975 * @see #sendRequestAsync
1976 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001977 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001978 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1979 }
1980
1981 /**
1982 * Posts the specified command to be executed on the main thread,
1983 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1984 * if not timeout or null otherwise.
1985 * @see #sendRequestAsync
1986 */
1987 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1988 long timeoutInMs) {
1989 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001990 }
1991
1992 /**
1993 * Posts the specified command to be executed on the main thread,
1994 * waits for the request to complete, and returns the result.
1995 * @see #sendRequestAsync
1996 */
Nathan Harold92bed182018-10-12 18:16:49 -07001997 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001998 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -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, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002007 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2008 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002009 }
2010
2011 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002012 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2013 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2014 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002015 * @see #sendRequestAsync
2016 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002017 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2018 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002019 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2020 throw new RuntimeException("This method will deadlock if called from the main thread.");
2021 }
2022
Nathan Harold92bed182018-10-12 18:16:49 -07002023 MainThreadRequest request = null;
2024 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2025 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2026 } else if (phone != null) {
2027 request = new MainThreadRequest(argument, phone, workSource);
2028 } else {
2029 request = new MainThreadRequest(argument, subId, workSource);
2030 }
2031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 Message msg = mMainThreadHandler.obtainMessage(command, request);
2033 msg.sendToTarget();
2034
Rambo Wang0f050d82021-02-12 11:43:36 -08002035
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002037 if (timeoutInMs >= 0) {
2038 // Wait for at least timeoutInMs before returning null request result
2039 long now = SystemClock.elapsedRealtime();
2040 long deadline = now + timeoutInMs;
2041 while (request == null && now < deadline) {
2042 try {
2043 request.wait(deadline - now);
2044 } catch (InterruptedException e) {
2045 // Do nothing, go back and check if request is completed or timeout
2046 } finally {
2047 now = SystemClock.elapsedRealtime();
2048 }
2049 }
2050 } else {
2051 // Wait for the request to complete
2052 while (request.result == null) {
2053 try {
2054 request.wait();
2055 } catch (InterruptedException e) {
2056 // Do nothing, go back and wait until the request is complete
2057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 }
2059 }
2060 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002061 if (request.result == null) {
2062 Log.wtf(LOG_TAG,
2063 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 return request.result;
2066 }
2067
2068 /**
2069 * Asynchronous ("fire and forget") version of sendRequest():
2070 * Posts the specified command to be executed on the main thread, and
2071 * returns immediately.
2072 * @see #sendRequest
2073 */
2074 private void sendRequestAsync(int command) {
2075 mMainThreadHandler.sendEmptyMessage(command);
2076 }
2077
2078 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002079 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002080 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002081 */
2082 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002083 sendRequestAsync(command, argument, null, null);
2084 }
2085
2086 /**
2087 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2088 * @see {@link #sendRequest(int,Object)}
2089 */
2090 private void sendRequestAsync(
2091 int command, Object argument, Phone phone, WorkSource workSource) {
2092 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002093 Message msg = mMainThreadHandler.obtainMessage(command, request);
2094 msg.sendToTarget();
2095 }
2096
2097 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 * Initialize the singleton PhoneInterfaceManager instance.
2099 * This is only done once, at startup, from PhoneApp.onCreate().
2100 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002101 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 synchronized (PhoneInterfaceManager.class) {
2103 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002104 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 } else {
2106 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2107 }
2108 return sInstance;
2109 }
2110 }
2111
2112 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002113 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002114 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002116 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002117 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2119 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002120 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002121 mTelephonySharedPreferences =
2122 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002123 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002124 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002125 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002126 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002127
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 publish();
2129 }
2130
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002131 private Phone getDefaultPhone() {
2132 Phone thePhone = getPhone(getDefaultSubscription());
2133 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2134 }
2135
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 private void publish() {
2137 if (DBG) log("publish: " + this);
2138
Peter Wangc035ce42020-01-08 21:00:22 -08002139 TelephonyFrameworkInitializer
2140 .getTelephonyServiceManager()
2141 .getTelephonyServiceRegisterer()
2142 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 }
2144
Stuart Scott584921c2015-01-15 17:10:34 -08002145 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002146 if (request.phone != null) {
2147 return request.phone;
2148 } else {
2149 return getPhoneFromSubId(request.subId);
2150 }
2151 }
2152
2153 private Phone getPhoneFromSubId(int subId) {
2154 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2155 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002156 }
2157
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002158 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2159 Phone phone = getPhoneFromRequest(request);
2160 return phone == null ? null :
2161 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2162 }
2163
Wink Saville36469e72014-06-11 15:17:00 -07002164 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002165 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002166 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168
Naina Nallurid63128d2019-09-17 14:10:30 -07002169 private void sendEraseModemConfig(Phone phone) {
2170 if (phone != null) {
2171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2172 mApp, phone.getSubId(), "eraseModemConfig");
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2176 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2177 } finally {
2178 Binder.restoreCallingIdentity(identity);
2179 }
2180 }
2181 }
2182
Peter Wang44b186e2020-01-13 23:33:09 -08002183 private boolean isImsAvailableOnDevice() {
2184 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2185 if (pm == null) {
2186 // For some reason package manger is not available.. This will fail internally anyway,
2187 // so do not throw error and allow.
2188 return true;
2189 }
2190 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2191 }
2192
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002194 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002195 }
2196
Wink Savilleb564aae2014-10-23 10:18:09 -07002197 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 if (DBG) log("dial: " + number);
2199 // No permission check needed here: This is just a wrapper around the
2200 // ACTION_DIAL intent, which is available to any app since it puts up
2201 // the UI before it does anything.
2202
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002203 final long identity = Binder.clearCallingIdentity();
2204 try {
2205 String url = createTelUrl(number);
2206 if (url == null) {
2207 return;
2208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210 // PENDING: should we just silently fail if phone is offhook or ringing?
2211 PhoneConstants.State state = mCM.getState(subId);
2212 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2213 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2214 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2215 mApp.startActivity(intent);
2216 }
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 }
2220 }
2221
2222 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002223 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002224 }
2225
Wink Savilleb564aae2014-10-23 10:18:09 -07002226 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 if (DBG) log("call: " + number);
2228
2229 // This is just a wrapper around the ACTION_CALL intent, but we still
2230 // need to do a permission check since we're calling startActivity()
2231 // from the context of the phone app.
2232 enforceCallPermission();
2233
Jordan Liu1617b712019-07-10 15:06:26 -07002234 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 != AppOpsManager.MODE_ALLOWED) {
2236 return;
2237 }
2238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 String url = createTelUrl(number);
2242 if (url == null) {
2243 return;
2244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246 boolean isValid = false;
2247 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2248 if (slist != null) {
2249 for (SubscriptionInfo subInfoRecord : slist) {
2250 if (subInfoRecord.getSubscriptionId() == subId) {
2251 isValid = true;
2252 break;
2253 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002254 }
Wink Saville08874612014-08-31 19:19:58 -07002255 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256 if (!isValid) {
2257 return;
2258 }
Wink Saville08874612014-08-31 19:19:58 -07002259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2261 intent.putExtra(SUBSCRIPTION_KEY, subId);
2262 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2263 mApp.startActivity(intent);
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 }
2268
Wink Savilleb564aae2014-10-23 10:18:09 -07002269 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002270 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002271 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2272 }
2273
Wink Savilleb564aae2014-10-23 10:18:09 -07002274 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002275 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002276 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2277 }
2278
Wink Savilleb564aae2014-10-23 10:18:09 -07002279 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281
2282 final long identity = Binder.clearCallingIdentity();
2283 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002284 Phone phone = getPhone(subId);
2285 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286 checkSimPin.start();
2287 return checkSimPin.unlockSim(null, pin);
2288 } finally {
2289 Binder.restoreCallingIdentity(identity);
2290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 }
2292
Wink Savilleb564aae2014-10-23 10:18:09 -07002293 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002298 Phone phone = getPhone(subId);
2299 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002300 checkSimPuk.start();
2301 return checkSimPuk.unlockSim(puk, pin);
2302 } finally {
2303 Binder.restoreCallingIdentity(identity);
2304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 }
2306
2307 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002308 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 * a synchronous one.
2310 */
2311 private static class UnlockSim extends Thread {
2312
2313 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002314 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315
2316 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002317 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2318 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319
2320 // For replies from SimCard interface
2321 private Handler mHandler;
2322
2323 // For async handler to identify request type
2324 private static final int SUPPLY_PIN_COMPLETE = 100;
2325
Michele Berionne5e411512020-11-13 02:36:59 +00002326 UnlockSim(int phoneId, IccCard simCard) {
2327 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 mSimCard = simCard;
2329 }
2330
2331 @Override
2332 public void run() {
2333 Looper.prepare();
2334 synchronized (UnlockSim.this) {
2335 mHandler = new Handler() {
2336 @Override
2337 public void handleMessage(Message msg) {
2338 AsyncResult ar = (AsyncResult) msg.obj;
2339 switch (msg.what) {
2340 case SUPPLY_PIN_COMPLETE:
2341 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2342 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002343 mRetryCount = msg.arg1;
2344 if (ar.exception != null) {
2345 if (ar.exception instanceof CommandException &&
2346 ((CommandException)(ar.exception)).getCommandError()
2347 == CommandException.Error.PASSWORD_INCORRECT) {
2348 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002349 } //When UiccCardApp dispose,handle message and return exception
2350 else if (ar.exception instanceof CommandException &&
2351 ((CommandException) (ar.exception)).getCommandError()
2352 == CommandException.Error.ABORTED) {
2353 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002354 } else {
2355 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2356 }
2357 } else {
2358 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 mDone = true;
2361 UnlockSim.this.notifyAll();
2362 }
2363 break;
2364 }
2365 }
2366 };
2367 UnlockSim.this.notifyAll();
2368 }
2369 Looper.loop();
2370 }
2371
2372 /*
2373 * Use PIN or PUK to unlock SIM card
2374 *
2375 * If PUK is null, unlock SIM card with PIN
2376 *
2377 * If PUK is not null, unlock SIM card with PUK and set PIN code
2378 */
Wink Saville9de0f752013-10-22 19:04:03 -07002379 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380
2381 while (mHandler == null) {
2382 try {
2383 wait();
2384 } catch (InterruptedException e) {
2385 Thread.currentThread().interrupt();
2386 }
2387 }
2388 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2389
2390 if (puk == null) {
2391 mSimCard.supplyPin(pin, callback);
2392 } else {
2393 mSimCard.supplyPuk(puk, pin, callback);
2394 }
2395
2396 while (!mDone) {
2397 try {
2398 Log.d(LOG_TAG, "wait for done");
2399 wait();
2400 } catch (InterruptedException e) {
2401 // Restore the interrupted status
2402 Thread.currentThread().interrupt();
2403 }
2404 }
2405 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002406 int[] resultArray = new int[2];
2407 resultArray[0] = mResult;
2408 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002409
2410 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2411 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2412 }
2413
Wink Saville9de0f752013-10-22 19:04:03 -07002414 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 }
2416 }
2417
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002418 /**
2419 * This method has been removed due to privacy and stability concerns.
2420 */
2421 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002423 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2424 return;
Wink Saville36469e72014-06-11 15:17:00 -07002425 }
2426
Nathan Harold1f889d82020-06-04 17:05:26 -07002427 @Override
2428 public void updateServiceLocationWithPackageName(String callingPackage) {
2429 mApp.getSystemService(AppOpsManager.class)
2430 .checkPackage(Binder.getCallingUid(), callingPackage);
2431
Nathan Haroldf096d982020-11-18 17:18:06 -08002432 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002433 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2434 // Callers targeting S have no business invoking this method.
2435 return;
2436 }
2437
2438 LocationAccessPolicy.LocationPermissionResult locationResult =
2439 LocationAccessPolicy.checkLocationPermission(mApp,
2440 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2441 .setCallingPackage(callingPackage)
2442 .setCallingFeatureId(null)
2443 .setCallingPid(Binder.getCallingPid())
2444 .setCallingUid(Binder.getCallingUid())
2445 .setMethod("updateServiceLocation")
2446 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2447 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2448 .build());
2449 // Apps that lack location permission have no business calling this method;
2450 // however, because no permission was declared in the public API, denials must
2451 // all be "soft".
2452 switch (locationResult) {
2453 case DENIED_HARD: /* fall through */
2454 case DENIED_SOFT:
2455 return;
2456 }
2457
2458 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002459 final long identity = Binder.clearCallingIdentity();
2460 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002461 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002462 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002463 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464 }
2465 } finally {
2466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002470 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002471 @Override
2472 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002473 return isRadioOnWithFeature(callingPackage, null);
2474 }
2475
2476
2477 @Override
2478 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2479 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2480 callingFeatureId);
2481 }
2482
2483 @Deprecated
2484 @Override
2485 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2486 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002487 }
2488
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002489 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002490 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2491 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002493 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002494 return false;
2495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496
2497 final long identity = Binder.clearCallingIdentity();
2498 try {
2499 return isRadioOnForSubscriber(subId);
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
2502 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002503 }
2504
2505 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = getPhone(subId);
2509 if (phone != null) {
2510 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2511 } else {
2512 return false;
2513 }
2514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002516 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 }
2518
2519 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002520 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 }
Wink Saville36469e72014-06-11 15:17:00 -07002522
Wink Savilleb564aae2014-10-23 10:18:09 -07002523 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002525
2526 final long identity = Binder.clearCallingIdentity();
2527 try {
2528 final Phone phone = getPhone(subId);
2529 if (phone != null) {
2530 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2531 }
2532 } finally {
2533 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002534 }
Wink Saville36469e72014-06-11 15:17:00 -07002535 }
2536
2537 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002538 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002539 }
2540
Wink Savilleb564aae2014-10-23 10:18:09 -07002541 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 final Phone phone = getPhone(subId);
2547 if (phone == null) {
2548 return false;
2549 }
2550 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2551 toggleRadioOnOffForSubscriber(subId);
2552 }
2553 return true;
2554 } finally {
2555 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002556 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002557 }
Wink Saville36469e72014-06-11 15:17:00 -07002558
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002559 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002560 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002561 /*
2562 * If any of the Radios are available, it will need to be
2563 * shutdown. So return true if any Radio is available.
2564 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2568 Phone phone = PhoneFactory.getPhone(i);
2569 if (phone != null && phone.isRadioAvailable()) return true;
2570 }
2571 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2572 return false;
2573 } finally {
2574 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002575 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002576 }
2577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002579 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580 enforceModifyPermission();
2581
2582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2585 logv("Shutting down Phone " + i);
2586 shutdownRadioUsingPhoneId(i);
2587 }
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002590 }
2591 }
2592
2593 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002594 Phone phone = PhoneFactory.getPhone(phoneId);
2595 if (phone != null && phone.isRadioAvailable()) {
2596 phone.shutdownRadio();
2597 }
2598 }
2599
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002601 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602
2603 final long identity = Binder.clearCallingIdentity();
2604 try {
2605 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2606 if (defaultPhone != null) {
2607 defaultPhone.setRadioPower(turnOn);
2608 return true;
2609 } else {
2610 loge("There's no default phone.");
2611 return false;
2612 }
2613 } finally {
2614 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002615 }
Wink Saville36469e72014-06-11 15:17:00 -07002616 }
2617
Wink Savilleb564aae2014-10-23 10:18:09 -07002618 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620
2621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 final Phone phone = getPhone(subId);
2624 if (phone != null) {
2625 phone.setRadioPower(turnOn);
2626 return true;
2627 } else {
2628 return false;
2629 }
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002632 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 }
2634
Wink Saville36469e72014-06-11 15:17:00 -07002635 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002636 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002637 public boolean enableDataConnectivity() {
2638 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639
2640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 int subId = mSubscriptionController.getDefaultDataSubId();
2643 final Phone phone = getPhone(subId);
2644 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002645 phone.getDataEnabledSettings().setDataEnabled(
2646 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 return true;
2648 } else {
2649 return false;
2650 }
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002654 }
2655
Wink Saville36469e72014-06-11 15:17:00 -07002656 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002657 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 public boolean disableDataConnectivity() {
2659 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660
2661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 int subId = mSubscriptionController.getDefaultDataSubId();
2664 final Phone phone = getPhone(subId);
2665 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002666 phone.getDataEnabledSettings().setDataEnabled(
2667 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 return true;
2669 } else {
2670 return false;
2671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 }
2676
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002678 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 final Phone phone = getPhone(subId);
2682 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002683 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 } else {
2685 return false;
2686 }
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
2692 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002693 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002694 }
2695
pkanwarae03a6b2016-11-06 20:37:09 -08002696 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 enforceCallPermission();
2698
2699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2702 return;
2703 }
2704 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2705 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
pkanwar32d516d2016-10-14 19:37:38 -07002709 };
2710
Wink Savilleb564aae2014-10-23 10:18:09 -07002711 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713
2714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2717 return false;
2718 }
2719 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2720 } finally {
2721 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002722 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002723 }
2724
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002725 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002726 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002727 }
2728
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002729 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 final long identity = Binder.clearCallingIdentity();
2731 try {
2732 Phone phone = PhoneFactory.getPhone(slotIndex);
2733 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2734 PhoneConstantConversions.convertCallState(phone.getState());
2735 } finally {
2736 Binder.restoreCallingIdentity(identity);
2737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
2739
Sanket Padawe356d7632015-06-22 14:03:32 -07002740 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002741 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002742 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2743 }
2744
2745 @Override
2746 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002747 final long identity = Binder.clearCallingIdentity();
2748 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002749 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002750 if (phone != null) {
2751 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2752 } else {
2753 return PhoneConstantConversions.convertDataState(
2754 PhoneConstants.DataState.DISCONNECTED);
2755 }
2756 } finally {
2757 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 }
2760
Sanket Padawe356d7632015-06-22 14:03:32 -07002761 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002762 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002763 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2764 }
2765
2766 @Override
2767 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002768 final long identity = Binder.clearCallingIdentity();
2769 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002770 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 if (phone != null) {
2772 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2773 } else {
2774 return TelephonyManager.DATA_ACTIVITY_NONE;
2775 }
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002779 }
2780
2781 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002782 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002783 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002784 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002785
2786 LocationAccessPolicy.LocationPermissionResult locationResult =
2787 LocationAccessPolicy.checkLocationPermission(mApp,
2788 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2789 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002790 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002791 .setCallingPid(Binder.getCallingPid())
2792 .setCallingUid(Binder.getCallingUid())
2793 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002794 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002795 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2796 .build());
2797 switch (locationResult) {
2798 case DENIED_HARD:
2799 throw new SecurityException("Not allowed to access cell location");
2800 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002801 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2802 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002803 }
2804
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002805 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002809 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002810 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 } finally {
2812 Binder.restoreCallingIdentity(identity);
2813 }
Svetoslav64fad262015-04-14 14:35:21 -07002814 }
2815
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002817 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002818 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2819 // registered cell info, so return a NULL country instead.
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002822 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2823 // Get default phone in this case.
2824 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2825 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002826 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002828 if (phone == null) return "";
2829 ServiceStateTracker sst = phone.getServiceStateTracker();
2830 if (sst == null) return "";
2831 LocaleTracker lt = sst.getLocaleTracker();
2832 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002833 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002834 } finally {
2835 Binder.restoreCallingIdentity(identity);
2836 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002837 }
2838
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002839 /**
2840 * This method was removed due to potential issues caused by performing partial
2841 * updates of service state, and lack of a credible use case.
2842 *
2843 * This has the ability to break the telephony implementation by disabling notification of
2844 * changes in device connectivity. DO NOT USE THIS!
2845 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002846 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 public void enableLocationUpdates() {
2848 mApp.enforceCallingOrSelfPermission(
2849 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002852 /**
2853 * This method was removed due to potential issues caused by performing partial
2854 * updates of service state, and lack of a credible use case.
2855 *
2856 * This has the ability to break the telephony implementation by disabling notification of
2857 * changes in device connectivity. DO NOT USE THIS!
2858 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 @Override
2860 public void disableLocationUpdates() {
2861 mApp.enforceCallingOrSelfPermission(
2862 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002863 }
2864
2865 @Override
2866 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002867 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2868 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002869 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002870 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2871 throw new SecurityException(
2872 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2873 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002874
Jordan Liu1617b712019-07-10 15:06:26 -07002875 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2877 return null;
2878 }
Svetoslav64fad262015-04-14 14:35:21 -07002879
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002880 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002882 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002883 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002884
Nathan Haroldf180aac2018-06-01 18:43:55 -07002885 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2886 for (CellInfo ci : info) {
2887 if (ci instanceof CellInfoGsm) {
2888 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2889 } else if (ci instanceof CellInfoWcdma) {
2890 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002893 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002894 }
2895
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002896 private List<CellInfo> getCachedCellInfo() {
2897 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2898 for (Phone phone : PhoneFactory.getPhones()) {
2899 List<CellInfo> info = phone.getAllCellInfo();
2900 if (info != null) cellInfos.addAll(info);
2901 }
2902 return cellInfos;
2903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002904
2905 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002906 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002907 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002908 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002909
2910 LocationAccessPolicy.LocationPermissionResult locationResult =
2911 LocationAccessPolicy.checkLocationPermission(mApp,
2912 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2913 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002914 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002915 .setCallingPid(Binder.getCallingPid())
2916 .setCallingUid(Binder.getCallingUid())
2917 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002918 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002919 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2920 .build());
2921 switch (locationResult) {
2922 case DENIED_HARD:
2923 throw new SecurityException("Not allowed to access cell info");
2924 case DENIED_SOFT:
2925 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926 }
2927
Nathan Haroldf096d982020-11-18 17:18:06 -08002928 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002929 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2930 return getCachedCellInfo();
2931 }
2932
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002933 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002934 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2938 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002939 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002940 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002941 if (info != null) cellInfos.addAll(info);
2942 }
2943 return cellInfos;
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 }
2947 }
2948
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002949 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002950 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2951 String callingFeatureId) {
2952 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2953 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002954 }
2955
2956 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002957 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2958 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002959 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002960 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002961 }
2962
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002963 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2964 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002965 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002966 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002967
2968 LocationAccessPolicy.LocationPermissionResult locationResult =
2969 LocationAccessPolicy.checkLocationPermission(mApp,
2970 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2971 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002972 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002973 .setCallingPid(Binder.getCallingPid())
2974 .setCallingUid(Binder.getCallingUid())
2975 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002976 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2977 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002978 .build());
2979 switch (locationResult) {
2980 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002981 if (TelephonyPermissions
2982 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002983 // Safetynet logging for b/154934934
2984 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2985 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002986 throw new SecurityException("Not allowed to access cell info");
2987 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002988 if (TelephonyPermissions
2989 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002990 // Safetynet logging for b/154934934
2991 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2992 }
Nathan Harold5320c422019-05-09 10:26:08 -07002993 try {
2994 cb.onCellInfo(new ArrayList<CellInfo>());
2995 } catch (RemoteException re) {
2996 // Drop without consequences
2997 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002998 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002999 }
3000
Nathan Harolda939a962019-05-09 10:13:47 -07003001
3002 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003003 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3004
3005 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3006 }
3007
3008 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003009 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003010 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003011 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003012
3013 final long identity = Binder.clearCallingIdentity();
3014 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003015 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003016 } finally {
3017 Binder.restoreCallingIdentity(identity);
3018 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 }
3020
Shishir Agrawala9f32182016-04-12 12:00:16 -07003021 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003022 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003023 Phone phone = PhoneFactory.getPhone(slotIndex);
3024 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003025 return null;
3026 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003027 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003028 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003029 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003030 return null;
3031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 return phone.getImei();
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003039 }
3040
3041 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003042 public String getTypeAllocationCodeForSlot(int slotIndex) {
3043 Phone phone = PhoneFactory.getPhone(slotIndex);
3044 String tac = null;
3045 if (phone != null) {
3046 String imei = phone.getImei();
3047 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3048 }
3049 return tac;
3050 }
3051
3052 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003053 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003054 Phone phone = PhoneFactory.getPhone(slotIndex);
3055 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003056 return null;
3057 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003058
Jeff Davidson913390f2018-02-23 17:11:49 -08003059 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003060 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003061 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003062 return null;
3063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064
3065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 return phone.getMeid();
3068 } finally {
3069 Binder.restoreCallingIdentity(identity);
3070 }
Jack Yu2af8d712017-03-15 17:14:14 -07003071 }
3072
3073 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003074 public String getManufacturerCodeForSlot(int slotIndex) {
3075 Phone phone = PhoneFactory.getPhone(slotIndex);
3076 String manufacturerCode = null;
3077 if (phone != null) {
3078 String meid = phone.getMeid();
3079 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3080 }
3081 return manufacturerCode;
3082 }
3083
3084 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003085 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3086 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003087 Phone phone = PhoneFactory.getPhone(slotIndex);
3088 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003089 return null;
3090 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003091 int subId = phone.getSubId();
3092 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003093 mApp, subId, callingPackage, callingFeatureId,
3094 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003095 return null;
3096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003097
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 return phone.getDeviceSvn();
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003104 }
3105
fionaxu43304da2017-11-27 22:51:16 -08003106 @Override
3107 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 final Phone phone = getPhone(subId);
3111 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
3114 }
fionaxu43304da2017-11-27 22:51:16 -08003115 }
3116
3117 @Override
3118 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003119 final long identity = Binder.clearCallingIdentity();
3120 try {
3121 final Phone phone = getPhone(subId);
3122 return phone == null ? null : phone.getCarrierName();
3123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
fionaxu43304da2017-11-27 22:51:16 -08003126 }
3127
calvinpanffe225e2018-11-01 19:43:06 +08003128 @Override
chen xu0026ca62019-03-06 15:28:50 -08003129 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 final Phone phone = getPhone(subId);
3133 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003134 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003135 } finally {
3136 Binder.restoreCallingIdentity(identity);
3137 }
3138 }
3139
3140 @Override
chen xu0026ca62019-03-06 15:28:50 -08003141 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003145 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003146 } finally {
3147 Binder.restoreCallingIdentity(identity);
3148 }
3149 }
3150
chen xu651eec72018-11-11 19:03:44 -08003151 @Override
chen xu864e11c2018-12-06 22:10:03 -08003152 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3153 if (!isSubscriptionMccMnc) {
3154 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3155 }
chen xu651eec72018-11-11 19:03:44 -08003156 final Phone phone = PhoneFactory.getPhone(slotIndex);
3157 if (phone == null) {
3158 return TelephonyManager.UNKNOWN_CARRIER_ID;
3159 }
3160 final long identity = Binder.clearCallingIdentity();
3161 try {
3162 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
3166 }
3167
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003168 //
3169 // Internal helper methods.
3170 //
3171
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003172 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003173 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3174 *
3175 * @throws SecurityException if the caller does not have the required permission
3176 */
3177 private void enforceModifyPermission() {
3178 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3179 }
3180
Shuo Qiancd19c462020-01-16 20:51:11 -08003181 /**
3182 * Make sure the caller is system.
3183 *
3184 * @throws SecurityException if the caller is not system.
3185 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003186 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003187 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3188 throw new SecurityException("Caller must be system");
3189 }
3190 }
3191
Shuo Qian3b6ee772019-11-13 17:43:31 -08003192 private void enforceActiveEmergencySessionPermission() {
3193 mApp.enforceCallingOrSelfPermission(
3194 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3195 }
3196
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 /**
3198 * Make sure the caller has the CALL_PHONE permission.
3199 *
3200 * @throws SecurityException if the caller does not have the required permission
3201 */
3202 private void enforceCallPermission() {
3203 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3204 }
3205
paulhu5a773602019-08-23 19:17:33 +08003206 private void enforceSettingsPermission() {
3207 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003208 }
3209
Michele Berionne5e411512020-11-13 02:36:59 +00003210 private void enforceRebootPermission() {
3211 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3212 }
3213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003214 private String createTelUrl(String number) {
3215 if (TextUtils.isEmpty(number)) {
3216 return null;
3217 }
3218
Jake Hambye994d462014-02-03 13:10:13 -08003219 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 }
3221
Ihab Awadf9e92732013-12-05 18:02:52 -08003222 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003223 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3224 }
3225
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003226 private static void logv(String msg) {
3227 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3228 }
3229
Ihab Awadf9e92732013-12-05 18:02:52 -08003230 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003231 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3232 }
3233
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003234 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003235 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003236 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003237 }
3238
Sanket Padawe356d7632015-06-22 14:03:32 -07003239 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003240 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 final Phone phone = PhoneFactory.getPhone(slotIndex);
3244 if (phone == null) {
3245 return PhoneConstants.PHONE_TYPE_NONE;
3246 } else {
3247 return phone.getPhoneType();
3248 }
3249 } finally {
3250 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003252 }
3253
3254 /**
3255 * Returns the CDMA ERI icon index to display
3256 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003257 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003258 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3259 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3260 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003261 }
3262
Sanket Padawe356d7632015-06-22 14:03:32 -07003263 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003264 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3265 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003267 mApp, subId, callingPackage, callingFeatureId,
3268 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003269 return -1;
3270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003271
3272 final long identity = Binder.clearCallingIdentity();
3273 try {
3274 final Phone phone = getPhone(subId);
3275 if (phone != null) {
3276 return phone.getCdmaEriIconIndex();
3277 } else {
3278 return -1;
3279 }
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003283 }
3284
3285 /**
3286 * Returns the CDMA ERI icon mode,
3287 * 0 - ON
3288 * 1 - FLASHING
3289 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003290 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003291 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3292 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3293 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003294 }
3295
Sanket Padawe356d7632015-06-22 14:03:32 -07003296 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003297 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3298 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003300 mApp, subId, callingPackage, callingFeatureId,
3301 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003302 return -1;
3303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304
3305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 final Phone phone = getPhone(subId);
3308 if (phone != null) {
3309 return phone.getCdmaEriIconMode();
3310 } else {
3311 return -1;
3312 }
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003316 }
3317
3318 /**
3319 * Returns the CDMA ERI text,
3320 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003321 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003322 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3323 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3324 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003325 }
3326
Sanket Padawe356d7632015-06-22 14:03:32 -07003327 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003328 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3329 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003331 mApp, subId, callingPackage, callingFeatureId,
3332 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003333 return null;
3334 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335
3336 final long identity = Binder.clearCallingIdentity();
3337 try {
3338 final Phone phone = getPhone(subId);
3339 if (phone != null) {
3340 return phone.getCdmaEriText();
3341 } else {
3342 return null;
3343 }
3344 } finally {
3345 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003347 }
3348
3349 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003350 * Returns the CDMA MDN.
3351 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003352 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003353 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003354 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3355 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003356
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003360 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003361 return phone.getLine1Number();
3362 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003363 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003364 return null;
3365 }
3366 } finally {
3367 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003368 }
3369 }
3370
3371 /**
3372 * Returns the CDMA MIN.
3373 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003374 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003375 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3377 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 final Phone phone = getPhone(subId);
3382 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3383 return phone.getCdmaMin();
3384 } else {
3385 return null;
3386 }
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003389 }
3390 }
3391
Hall Liud892bec2018-11-30 14:51:45 -08003392 @Override
3393 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3394 INumberVerificationCallback callback, String callingPackage) {
3395 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3396 != PERMISSION_GRANTED) {
3397 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3398 }
3399 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3400
3401 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3402 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003403 throw new SecurityException("Calling package must be configured in the device config: "
3404 + "calling package: " + callingPackage
3405 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003406 }
3407
3408 if (range == null) {
3409 throw new NullPointerException("Range must be non-null");
3410 }
3411
3412 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003413 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003414
3415 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3416 }
3417
Junda Liuca05d5d2014-08-14 22:36:34 -07003418 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003419 * Returns true if CDMA provisioning needs to run.
3420 */
3421 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 final long identity = Binder.clearCallingIdentity();
3423 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003424 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003425 } finally {
3426 Binder.restoreCallingIdentity(identity);
3427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003428 }
3429
3430 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003431 * Sets the voice mail number of a given subId.
3432 */
3433 @Override
3434 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003435 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3436 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003437
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3441 new Pair<String, String>(alphaTag, number), new Integer(subId));
3442 return success;
3443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003446 }
3447
Ta-wei Yen87c49842016-05-13 21:19:52 -07003448 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003449 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3450 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003451 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3452 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003453 if (!TextUtils.equals(callingPackage, systemDialer)) {
3454 throw new SecurityException("caller must be system dialer");
3455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003456
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3460 if (phoneAccountHandle == null) {
3461 return null;
3462 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003463 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 } finally {
3465 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003466 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003467 }
3468
3469 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003470 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3471 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003474 mApp, subId, callingPackage, callingFeatureId,
3475 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003476 return null;
3477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003479 final long identity = Binder.clearCallingIdentity();
3480 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003481 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003482 } finally {
3483 Binder.restoreCallingIdentity(identity);
3484 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003485 }
3486
3487 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003488 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3489 VisualVoicemailSmsFilterSettings settings) {
3490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491
3492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003495 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003496 } finally {
3497 Binder.restoreCallingIdentity(identity);
3498 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003499 }
3500
3501 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003502 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003504
3505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003508 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003512 }
3513
3514 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003515 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3516 String callingPackage, int subId) {
3517 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003518
3519 final long identity = Binder.clearCallingIdentity();
3520 try {
3521 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003522 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003526 }
3527
3528 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003529 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003531
3532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003535 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536 } finally {
3537 Binder.restoreCallingIdentity(identity);
3538 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003539 }
3540
3541 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003542 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3543 String callingAttributionTag, int subId, String number, int port, String text,
3544 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003545 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003546 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003547 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003548 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003549 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3550 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003551 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003552
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003553 /**
fionaxu0152e512016-11-14 13:36:14 -08003554 * Sets the voice activation state of a given subId.
3555 */
3556 @Override
3557 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3559 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 if (phone != null) {
3565 phone.setVoiceActivationState(activationState);
3566 } else {
3567 loge("setVoiceActivationState fails with invalid subId: " + subId);
3568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003571 }
3572 }
3573
3574 /**
3575 * Sets the data activation state of a given subId.
3576 */
3577 @Override
3578 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3580 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581
3582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 final Phone phone = getPhone(subId);
3585 if (phone != null) {
3586 phone.setDataActivationState(activationState);
3587 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003588 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589 }
3590 } finally {
3591 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003592 }
3593 }
3594
3595 /**
3596 * Returns the voice activation state of a given subId.
3597 */
3598 @Override
3599 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601
fionaxu0152e512016-11-14 13:36:14 -08003602 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 if (phone != null) {
3606 return phone.getVoiceActivationState();
3607 } else {
3608 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3609 }
3610 } finally {
3611 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003612 }
3613 }
3614
3615 /**
3616 * Returns the data activation state of a given subId.
3617 */
3618 @Override
3619 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003620 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003621
fionaxu0152e512016-11-14 13:36:14 -08003622 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 if (phone != null) {
3626 return phone.getDataActivationState();
3627 } else {
3628 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003632 }
3633 }
3634
3635 /**
Wink Saville36469e72014-06-11 15:17:00 -07003636 * Returns the unread count of voicemails for a subId
3637 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003638 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003639 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3640 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003642 mApp, subId, callingPackage, callingFeatureId,
3643 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003644 return 0;
3645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 final Phone phone = getPhone(subId);
3649 if (phone != null) {
3650 return phone.getVoiceMessageCount();
3651 } else {
3652 return 0;
3653 }
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003657 }
3658
3659 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003660 * returns true, if the device is in a state where both voice and data
3661 * are supported simultaneously. This can change based on location or network condition.
3662 */
3663 @Override
3664 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 final Phone phone = getPhone(subId);
3668 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
3671 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003672 }
3673
3674 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003675 * Send the dialer code if called from the current default dialer or the caller has
3676 * carrier privilege.
3677 * @param inputCode The dialer code to send
3678 */
3679 @Override
3680 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003681 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003682 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003683 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3684 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003685 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003686 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003687 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689
3690 final long identity = Binder.clearCallingIdentity();
3691 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
fionaxu235cc5e2017-03-06 22:25:57 -08003696 }
3697
Pengquan Menga1bb6272018-09-06 09:59:22 -07003698 @Override
3699 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003700 TelephonyPermissions
3701 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3702 mApp, subId, "getNetworkSelectionMode");
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 if (!isActiveSubscription(subId)) {
3706 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3707 }
3708 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3709 } finally {
3710 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003711 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003712 }
3713
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003715 public boolean isInEmergencySmsMode() {
3716 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 for (Phone phone : PhoneFactory.getPhones()) {
3720 if (phone.isInEmergencySmsMode()) {
3721 return true;
3722 }
3723 }
3724 } finally {
3725 Binder.restoreCallingIdentity(identity);
3726 }
3727 return false;
3728 }
3729
shilu366312e2019-12-17 09:28:10 -08003730 /**
3731 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3732 * @param subId The subscription to use to check the configuration.
3733 * @param c The callback that will be used to send the result.
3734 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003735 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003736 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3737 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003738 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3739 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003740
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003741 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3742 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3743 "IMS not available on device.");
3744 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 final long token = Binder.clearCallingIdentity();
3746 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003747 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003748 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003750 } catch (ImsException e) {
3751 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 } finally {
3753 Binder.restoreCallingIdentity(token);
3754 }
3755 }
3756
shilu366312e2019-12-17 09:28:10 -08003757 /**
3758 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3759 * @param subId The subscription to use to check the configuration.
3760 * @param c The callback that will be used to send the result.
3761 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003763 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003764 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3765 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003766 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3767 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3768 }
Meng Wangafbc5852019-09-19 17:37:13 -07003769 final long token = Binder.clearCallingIdentity();
3770 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003771 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003772 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3773 .removeRegistrationCallbackForSubscription(c, subId);
3774 } catch (ImsException e) {
3775 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3776 + "is inactive, ignoring unregister.");
3777 // If the subscription is no longer active, just return, since the callback
3778 // will already have been removed internally.
3779 } finally {
3780 Binder.restoreCallingIdentity(token);
3781 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003782 }
3783
Brad Ebingera34a6c22019-10-22 17:36:18 -07003784 /**
3785 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3786 */
3787 @Override
3788 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3789 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3790 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3791 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3792 "IMS not available on device.");
3793 }
3794 final long token = Binder.clearCallingIdentity();
3795 try {
3796 Phone phone = getPhone(subId);
3797 if (phone == null) {
3798 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3799 + subId + "'");
3800 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3801 }
3802 phone.getImsRegistrationState(regState -> {
3803 try {
3804 consumer.accept((regState == null)
3805 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3806 } catch (RemoteException e) {
3807 // Ignore if the remote process is no longer available to call back.
3808 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3809 }
3810 });
3811 } finally {
3812 Binder.restoreCallingIdentity(token);
3813 }
3814 }
3815
3816 /**
3817 * Get the transport type for the IMS service registration state.
3818 */
3819 @Override
3820 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003821 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3822 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003823 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3824 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3825 "IMS not available on device.");
3826 }
3827 final long token = Binder.clearCallingIdentity();
3828 try {
3829 Phone phone = getPhone(subId);
3830 if (phone == null) {
3831 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3832 + subId + "'");
3833 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3834 }
3835 phone.getImsRegistrationTech(regTech -> {
3836 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3837 int regTechConverted = (regTech == null)
3838 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3839 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3840 regTechConverted);
3841 try {
3842 consumer.accept(regTechConverted);
3843 } catch (RemoteException e) {
3844 // Ignore if the remote process is no longer available to call back.
3845 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3846 }
3847 });
3848 } finally {
3849 Binder.restoreCallingIdentity(token);
3850 }
3851 }
3852
shilu366312e2019-12-17 09:28:10 -08003853 /**
3854 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3855 * @param subId The subscription to use to check the configuration.
3856 * @param c The callback that will be used to send the result.
3857 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003859 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3860 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003861 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3862 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003863 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3864 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3865 "IMS not available on device.");
3866 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3868 final long token = Binder.clearCallingIdentity();
3869 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003870 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003871 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003872 } catch (ImsException e) {
3873 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003874 } finally {
3875 Binder.restoreCallingIdentity(token);
3876 }
3877 }
3878
shilu366312e2019-12-17 09:28:10 -08003879 /**
3880 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3881 * @param subId The subscription to use to check the configuration.
3882 * @param c The callback that will be used to send the result.
3883 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003885 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003886 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3887 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3889 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3890 }
Meng Wangafbc5852019-09-19 17:37:13 -07003891
3892 final long token = Binder.clearCallingIdentity();
3893 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003894 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003895 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003896 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003897 } catch (ImsException e) {
3898 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3899 + "is inactive, ignoring unregister.");
3900 // If the subscription is no longer active, just return, since the callback
3901 // will already have been removed internally.
3902 } finally {
3903 Binder.restoreCallingIdentity(token);
3904 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 }
3906
3907 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003908 public boolean isCapable(int subId, int capability, int regTech) {
3909 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3911 final long token = Binder.clearCallingIdentity();
3912 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003913 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003915 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003916 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3917 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003918 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003919 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3920 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 } finally {
3922 Binder.restoreCallingIdentity(token);
3923 }
3924 }
3925
3926 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003927 public boolean isAvailable(int subId, int capability, int regTech) {
3928 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 final long token = Binder.clearCallingIdentity();
3930 try {
3931 Phone phone = getPhone(subId);
3932 if (phone == null) return false;
3933 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003934 } catch (com.android.ims.ImsException e) {
3935 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3936 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003937 } finally {
3938 Binder.restoreCallingIdentity(token);
3939 }
3940 }
3941
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003942 /**
3943 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3944 * subscription.
3945 * @param subId The subscription to use to check the configuration.
3946 * @param callback The callback that will be used to send the result.
3947 * @param capability The MmTelFeature capability that will be used to send the result.
3948 * @param transportType The transport type of the MmTelFeature capability.
3949 */
3950 @Override
3951 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3952 int transportType) {
3953 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3954 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3955 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3956 "IMS not available on device.");
3957 }
3958 final long token = Binder.clearCallingIdentity();
3959 try {
3960 int slotId = getSlotIndex(subId);
3961 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3962 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3963 + subId + "'");
3964 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3965 }
3966 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3967 transportType, aBoolean -> {
3968 try {
3969 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3970 } catch (RemoteException e) {
3971 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3972 + "running. Ignore");
3973 }
3974 });
3975 } finally {
3976 Binder.restoreCallingIdentity(token);
3977 }
3978 }
3979
shilu366312e2019-12-17 09:28:10 -08003980 /**
3981 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3982 * @param subId The subscription to use to check the configuration.
3983 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003984 @Override
3985 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003986 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3987 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003988
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3990 final long token = Binder.clearCallingIdentity();
3991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003992 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003994 } catch (ImsException e) {
3995 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003996 } finally {
3997 Binder.restoreCallingIdentity(token);
3998 }
3999 }
4000
4001 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004002 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004004 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 final long identity = Binder.clearCallingIdentity();
4006 try {
4007 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004008 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004010 } catch (ImsException e) {
4011 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 } finally {
4013 Binder.restoreCallingIdentity(identity);
4014 }
4015 }
4016
shilu366312e2019-12-17 09:28:10 -08004017 /**
4018 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4019 * @param subId The subscription to use to check the configuration.
4020 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004021 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004022 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004023 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4024 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 final long identity = Binder.clearCallingIdentity();
4026 try {
4027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004028 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4029 } catch (ImsException e) {
4030 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
4034 }
4035
4036 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004037 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004039 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 final long identity = Binder.clearCallingIdentity();
4041 try {
4042 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004043 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004044 } catch (ImsException e) {
4045 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
4049 }
4050
shilu366312e2019-12-17 09:28:10 -08004051 /**
4052 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4053 * @param subId The subscription to use to check the configuration.
4054 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 @Override
4056 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004057 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4058 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004062 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004064 } catch (ImsException e) {
4065 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 } finally {
4067 Binder.restoreCallingIdentity(identity);
4068 }
4069 }
4070
4071 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004072 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004074 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004078 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004079 } catch (ImsException e) {
4080 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 } finally {
4082 Binder.restoreCallingIdentity(identity);
4083 }
4084 }
4085
shilu366312e2019-12-17 09:28:10 -08004086 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004087 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4088 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4089 * @param subId The subscription to use to check the configuration.
4090 */
4091 @Override
4092 public boolean isCrossSimCallingEnabledByUser(int subId) {
4093 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4094 mApp, subId, "isCrossSimCallingEnabledByUser");
4095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4098 return ImsManager.getInstance(mApp,
4099 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4100 } catch (ImsException e) {
4101 throw new ServiceSpecificException(e.getCode());
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
4104 }
4105 }
4106
4107 /**
4108 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4109 * Requires MODIFY_PHONE_STATE permission.
4110 * @param subId The subscription to use to check the configuration.
4111 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4112 * false otherwise
4113 */
4114 @Override
4115 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4117 "setCrossSimCallingEnabled");
4118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4121 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4122 .setCrossSimCallingEnabled(isEnabled);
4123 } catch (ImsException e) {
4124 throw new ServiceSpecificException(e.getCode());
4125 } finally {
4126 Binder.restoreCallingIdentity(identity);
4127 }
4128 }
4129
4130 /**
shilu366312e2019-12-17 09:28:10 -08004131 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4132 * @param subId The subscription to use to check the configuration.
4133 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 @Override
4135 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004136 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4137 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004142 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004143 } catch (ImsException e) {
4144 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149
4150 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004151 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004153 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 final long identity = Binder.clearCallingIdentity();
4155 try {
4156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004157 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (ImsException e) {
4160 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004161 } finally {
4162 Binder.restoreCallingIdentity(identity);
4163 }
4164 }
4165
4166 @Override
4167 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4169 "setVoWiFiNonPersistent");
4170 final long identity = Binder.clearCallingIdentity();
4171 try {
4172 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004173 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004174 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004175 } catch (ImsException e) {
4176 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 } finally {
4178 Binder.restoreCallingIdentity(identity);
4179 }
4180 }
4181
shilu366312e2019-12-17 09:28:10 -08004182 /**
4183 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4184 * @param subId The subscription to use to check the configuration.
4185 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004186 @Override
4187 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004188 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4189 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004193 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004195 } catch (ImsException e) {
4196 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 } finally {
4198 Binder.restoreCallingIdentity(identity);
4199 }
4200 }
4201
4202 @Override
4203 public void setVoWiFiModeSetting(int subId, int mode) {
4204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4205 "setVoWiFiModeSetting");
4206 final long identity = Binder.clearCallingIdentity();
4207 try {
4208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004209 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004210 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004211 } catch (ImsException e) {
4212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004213 } finally {
4214 Binder.restoreCallingIdentity(identity);
4215 }
4216 }
4217
4218 @Override
4219 public int getVoWiFiRoamingModeSetting(int subId) {
4220 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4221 final long identity = Binder.clearCallingIdentity();
4222 try {
4223 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004224 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004226 } catch (ImsException e) {
4227 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
4231 }
4232
4233 @Override
4234 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4236 "setVoWiFiRoamingModeSetting");
4237 final long identity = Binder.clearCallingIdentity();
4238 try {
4239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004240 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004242 } catch (ImsException e) {
4243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
4249 @Override
4250 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4252 "setRttCapabilityEnabled");
4253 final long identity = Binder.clearCallingIdentity();
4254 try {
4255 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004256 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4257 } catch (ImsException e) {
4258 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004259 } finally {
4260 Binder.restoreCallingIdentity(identity);
4261 }
4262 }
4263
shilu366312e2019-12-17 09:28:10 -08004264 /**
4265 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4266 * @param subId The subscription to use to check the configuration.
4267 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 @Override
4269 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004270 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4271 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004272 final long identity = Binder.clearCallingIdentity();
4273 try {
4274 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004275 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004277 } catch (ImsException e) {
4278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
4282 }
4283
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004284 @Override
4285 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4286 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4287 final long identity = Binder.clearCallingIdentity();
4288 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004289 if (!isImsAvailableOnDevice()) {
4290 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4291 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004292 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004293 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004294 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004295 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004296 } catch (ImsException e) {
4297 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
4301 }
4302
4303 @Override
4304 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4305 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4306 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004307 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4308 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4309 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004310 try {
4311 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004312 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004313 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004314 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004315 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4316 + "is inactive, ignoring unregister.");
4317 // If the subscription is no longer active, just return, since the callback will already
4318 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
4322 }
4323
allenwtsu99c623b2020-01-03 18:24:23 +08004324
4325 private void checkModifyPhoneStatePermission(int subId, String message) {
4326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4327 message);
4328 }
4329
4330 private boolean isImsProvisioningRequired(int subId, int capability,
4331 boolean isMmtelCapability) {
4332 Phone phone = getPhone(subId);
4333 if (phone == null) {
4334 loge("phone instance null for subid " + subId);
4335 return false;
4336 }
4337 if (isMmtelCapability) {
4338 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4339 return false;
4340 }
4341 } else {
4342 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4343 return false;
4344 }
4345 }
4346 return true;
4347 }
4348
4349 @Override
4350 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4351 boolean isProvisioned) {
4352 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4353
4354 final long identity = Binder.clearCallingIdentity();
4355 try {
4356 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4357 if (!isImsProvisioningRequired(subId, capability, false)) {
4358 return;
4359 }
4360
4361 // this capability requires provisioning, route to the correct API.
4362 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4363 switch (capability) {
4364 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4365 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4366 ims.setEabProvisioned(isProvisioned);
4367 break;
4368 default: {
4369 throw new IllegalArgumentException("Tried to set provisioning for "
4370 + "rcs capability '" + capability + "', which does not require "
4371 + "provisioning.");
4372 }
4373 }
4374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
4377
4378 }
4379
4380
4381 @Override
4382 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4383 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4384 final long identity = Binder.clearCallingIdentity();
4385 try {
4386 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4387 if (!isImsProvisioningRequired(subId, capability, false)) {
4388 return true;
4389 }
4390
4391 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4392 switch (capability) {
4393 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4394 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4395 return ims.isEabProvisionedOnDevice();
4396
4397 default: {
4398 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4399 + "capability '" + capability + "', which does not require "
4400 + "provisioning.");
4401 }
4402 }
4403
4404 } finally {
4405 Binder.restoreCallingIdentity(identity);
4406 }
4407 }
4408
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004409 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004410 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4411 boolean isProvisioned) {
4412 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4413 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4414 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4415 }
allenwtsu99c623b2020-01-03 18:24:23 +08004416 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004417 final long identity = Binder.clearCallingIdentity();
4418 try {
4419 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004420 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004421 return;
4422 }
4423
4424 // this capability requires provisioning, route to the correct API.
4425 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4426 switch (capability) {
4427 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4428 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4429 ims.setVolteProvisioned(isProvisioned);
4430 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4431 ims.setWfcProvisioned(isProvisioned);
4432 }
4433 break;
4434 }
4435 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4436 // There is currently no difference in VT provisioning type.
4437 ims.setVtProvisioned(isProvisioned);
4438 break;
4439 }
4440 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4441 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4442 // change the capability of the feature instead if needed.
4443 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4444 == isProvisioned) {
4445 // No change in provisioning.
4446 return;
4447 }
4448 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4449 try {
4450 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004451 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004452 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4453 + ", Exception" + e.getMessage());
4454 }
4455 break;
4456 }
4457 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004458 throw new IllegalArgumentException("Tried to set provisioning for "
4459 + "MmTel capability '" + capability + "', which does not require "
4460 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004461 }
4462 }
4463
4464 } finally {
4465 Binder.restoreCallingIdentity(identity);
4466 }
4467 }
4468
4469 @Override
4470 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4471 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4472 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4473 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4474 }
4475 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4476 final long identity = Binder.clearCallingIdentity();
4477 try {
4478 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004479 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004480 return true;
4481 }
4482
4483 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4484 switch (capability) {
4485 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4486 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4487 return ims.isVolteProvisionedOnDevice();
4488 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4489 return ims.isWfcProvisionedOnDevice();
4490 }
4491 // This should never happen, since we are checking tech above to make sure it
4492 // is either LTE or IWLAN.
4493 throw new IllegalArgumentException("Invalid radio technology for voice "
4494 + "capability.");
4495 }
4496 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4497 // There is currently no difference in VT provisioning type.
4498 return ims.isVtProvisionedOnDevice();
4499 }
4500 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4501 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4502 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4503 }
4504 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004505 throw new IllegalArgumentException(
4506 "Tried to get provisioning for MmTel capability '" + capability
4507 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004508 }
4509 }
4510
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
4514 }
4515
4516 @Override
4517 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4518 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4519 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4520 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4521 }
4522 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4523 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4524 return (provisionedBits & capability) > 0;
4525 }
4526
4527 @Override
4528 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4529 boolean isProvisioned) {
4530 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4531 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4532 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4533 }
4534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4535 "setProvisioningStatusForCapability");
4536 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4537 // If the current provisioning status for capability already matches isProvisioned,
4538 // do nothing.
4539 if (((provisionedBits & capability) > 0) == isProvisioned) {
4540 return;
4541 }
4542 if (isProvisioned) {
4543 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4544 } else {
4545 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4546 }
4547 }
4548
4549 /**
4550 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4551 * technology. The bitfield should mirror the bitfield defined by
4552 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4553 */
4554 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4555 String key = getMmTelProvisioningKey(subId, tech);
4556 // Default is no capabilities are provisioned.
4557 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4558 }
4559
4560 /**
4561 * Sets the MmTel capability provisioning bitfield (defined by
4562 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4563 * technology specified.
4564 *
4565 * Note: This is a synchronous command and should not be called on UI thread.
4566 */
4567 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4568 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4569 String key = getMmTelProvisioningKey(subId, tech);
4570 editor.putInt(key, newField);
4571 editor.commit();
4572 }
4573
4574 private static String getMmTelProvisioningKey(int subId, int tech) {
4575 // resulting key is provision_ims_mmtel_{subId}_{tech}
4576 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4577 }
4578
4579 /**
4580 * Query CarrierConfig to see if the specified capability requires provisioning for the
4581 * carrier associated with the subscription id.
4582 */
4583 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4584 int capability) {
4585 CarrierConfigManager configManager = new CarrierConfigManager(context);
4586 PersistableBundle c = configManager.getConfigForSubId(subId);
4587 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004588 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004589 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4590 false);
4591 boolean requireVoiceVtProvisioning = c.getBoolean(
4592 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4593
4594 // First check to make sure that the capability requires provisioning.
4595 switch (capability) {
4596 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4597 // intentional fallthrough
4598 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4599 if (requireVoiceVtProvisioning) {
4600 // Voice and Video requires provisioning
4601 return true;
4602 }
4603 break;
4604 }
4605 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4606 if (requireUtProvisioning) {
4607 // UT requires provisioning
4608 return true;
4609 }
4610 break;
4611 }
4612 }
4613 return false;
4614 }
4615
allenwtsu99c623b2020-01-03 18:24:23 +08004616 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4617 int capability) {
4618 CarrierConfigManager configManager = new CarrierConfigManager(context);
4619 PersistableBundle c = configManager.getConfigForSubId(subId);
4620
4621 boolean requireRcsProvisioning = c.getBoolean(
4622 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4623
4624 // First check to make sure that the capability requires provisioning.
4625 switch (capability) {
4626 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4627 // intentional fallthrough
4628 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4629 if (requireRcsProvisioning) {
4630 // OPTION or PRESENCE requires provisioning
4631 return true;
4632 }
4633 break;
4634 }
4635 }
4636 return false;
4637 }
4638
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004639 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004640 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4642 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4643 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004644 enforceReadPrivilegedPermission("getImsProvisioningInt");
4645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004648 int slotId = getSlotIndex(subId);
4649 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4650 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4651 + subId + "' for key:" + key);
4652 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4653 }
calvinpanb5a34062021-02-08 19:59:36 +08004654 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004655 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004656 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4657 + subId + "' for key:" + key);
4658 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
4662 }
4663
4664 @Override
4665 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004666 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4667 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4668 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004669 enforceReadPrivilegedPermission("getImsProvisioningString");
4670 final long identity = Binder.clearCallingIdentity();
4671 try {
4672 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004673 int slotId = getSlotIndex(subId);
4674 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4675 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4676 + subId + "' for key:" + key);
4677 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4678 }
calvinpanb5a34062021-02-08 19:59:36 +08004679 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004680 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004681 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4682 + subId + "' for key:" + key);
4683 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004684 } finally {
4685 Binder.restoreCallingIdentity(identity);
4686 }
4687 }
4688
4689 @Override
4690 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4692 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4693 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4695 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004696 final long identity = Binder.clearCallingIdentity();
4697 try {
4698 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004699 int slotId = getSlotIndex(subId);
4700 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4701 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4702 + subId + "' for key:" + key);
4703 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4704 }
calvinpanb5a34062021-02-08 19:59:36 +08004705 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4706 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004707 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004708 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004709 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
4713 }
4714
4715 @Override
4716 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004717 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4718 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4719 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4721 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004722 final long identity = Binder.clearCallingIdentity();
4723 try {
4724 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004725 int slotId = getSlotIndex(subId);
4726 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4727 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4728 + subId + "' for key:" + key);
4729 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4730 }
calvinpanb5a34062021-02-08 19:59:36 +08004731 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4732 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004733 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004734 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
4739 }
4740
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004741 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004742 int slotId = SubscriptionManager.getSlotIndex(subId);
4743 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004744 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4745 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004746 }
4747 return slotId;
4748 }
4749
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004750 private int getSlotIndex(int subId) {
4751 int slotId = SubscriptionManager.getSlotIndex(subId);
4752 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4753 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4754 }
4755 return slotId;
4756 }
4757
Wink Saville36469e72014-06-11 15:17:00 -07004758 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004759 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004760 */
4761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004762 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4763 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004764 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004765 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004766 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004767 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004768 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004769 mApp, subId, callingPackage, callingFeatureId,
4770 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004771 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4772 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 final Phone phone = getPhone(subId);
4777 if (phone != null) {
4778 return phone.getServiceState().getDataNetworkType();
4779 } else {
4780 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4781 }
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004784 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004785 }
4786
4787 /**
4788 * Returns the data network type
4789 */
4790 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004791 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4792 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4793 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004794 }
4795
4796 /**
4797 * Returns the data network type for a subId
4798 */
4799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004800 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4801 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004803 mApp, subId, callingPackage, callingFeatureId,
4804 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004805 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4806 }
4807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004808 final long identity = Binder.clearCallingIdentity();
4809 try {
4810 final Phone phone = getPhone(subId);
4811 if (phone != null) {
4812 return phone.getServiceState().getDataNetworkType();
4813 } else {
4814 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4815 }
4816 } finally {
4817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004819 }
4820
4821 /**
Wink Saville36469e72014-06-11 15:17:00 -07004822 * Returns the Voice network type for a subId
4823 */
4824 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004825 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4826 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004827 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004828 mApp, subId, callingPackage, callingFeatureId,
4829 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004830 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4831 }
4832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 final long identity = Binder.clearCallingIdentity();
4834 try {
4835 final Phone phone = getPhone(subId);
4836 if (phone != null) {
4837 return phone.getServiceState().getVoiceNetworkType();
4838 } else {
4839 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4840 }
4841 } finally {
4842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004844 }
4845
4846 /**
4847 * @return true if a ICC card is present
4848 */
4849 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004850 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004851 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4852 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004853 }
4854
4855 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004856 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004857 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004858 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004859 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 final long identity = Binder.clearCallingIdentity();
4861 try {
4862 final Phone phone = PhoneFactory.getPhone(slotIndex);
4863 if (phone != null) {
4864 return phone.getIccCard().hasIccCard();
4865 } else {
4866 return false;
4867 }
4868 } finally {
4869 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004871 }
4872
4873 /**
4874 * Return if the current radio is LTE on CDMA. This
4875 * is a tri-state return value as for a period of time
4876 * the mode may be unknown.
4877 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004878 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004879 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004880 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004881 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004882 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004883 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4884 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4885 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004886 }
4887
Sanket Padawe356d7632015-06-22 14:03:32 -07004888 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004889 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4890 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004891 try {
4892 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4893 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004894 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4895 }
4896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 final long identity = Binder.clearCallingIdentity();
4898 try {
4899 final Phone phone = getPhone(subId);
4900 if (phone == null) {
4901 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4902 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004903 return TelephonyProperties.lte_on_cdma_device()
4904 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905 }
4906 } finally {
4907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004908 }
Wink Saville36469e72014-06-11 15:17:00 -07004909 }
4910
Wink Saville36469e72014-06-11 15:17:00 -07004911 /**
4912 * {@hide}
4913 * Returns Default subId, 0 in the case of single standby.
4914 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004915 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004916 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004917 }
4918
Shishir Agrawala9f32182016-04-12 12:00:16 -07004919 private int getSlotForDefaultSubscription() {
4920 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4921 }
4922
Wink Savilleb564aae2014-10-23 10:18:09 -07004923 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004924 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004925 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004926
Pengquan Menge92a50d2018-09-21 15:54:48 -07004927 private boolean isActiveSubscription(int subId) {
4928 return mSubscriptionController.isActiveSubId(subId);
4929 }
4930
Ihab Awadf2177b72013-11-25 13:33:23 -08004931 /**
4932 * @see android.telephony.TelephonyManager.WifiCallingChoices
4933 */
4934 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 final long identity = Binder.clearCallingIdentity();
4936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004937 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4939 getWhenToMakeWifiCallsDefaultPreference());
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004943 }
4944
4945 /**
4946 * @see android.telephony.TelephonyManager.WifiCallingChoices
4947 */
4948 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 final long identity = Binder.clearCallingIdentity();
4950 try {
4951 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004952 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4954 } finally {
4955 Binder.restoreCallingIdentity(identity);
4956 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004957 }
4958
Sailesh Nepald1e68152013-12-12 19:08:02 -08004959 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004960 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004961 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004962 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004963
Jordan Liu4c733742019-02-28 12:03:40 -08004964 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4965 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4966 if (phoneId == -1) {
4967 throw new IllegalArgumentException("Given slot index: " + slotIndex
4968 + " does not correspond to an active phone");
4969 }
4970 return PhoneFactory.getPhone(phoneId);
4971 }
4972
Shishir Agrawal566b7612013-10-28 14:41:00 -07004973 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004974 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4975 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4977 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004979 if (DBG) {
4980 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4981 }
4982 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4983 p2);
4984 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004985
Jordan Liu4c733742019-02-28 12:03:40 -08004986
4987 @Override
4988 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4989 int slotIndex, String callingPackage, String aid, int p2) {
4990 enforceModifyPermission();
4991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4992 if (DBG) {
4993 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4994 }
4995 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4996 callingPackage, aid, p2);
4997 }
4998
4999 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5000 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 final long identity = Binder.clearCallingIdentity();
5002 try {
5003 if (TextUtils.equals(ISDR_AID, aid)) {
5004 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005005 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5006 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 if (bestComponent == null
5008 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5009 loge("The calling package is not allowed to access ISD-R.");
5010 throw new SecurityException(
5011 "The calling package is not allowed to access ISD-R.");
5012 }
Derek Tan740e1672017-06-27 14:56:27 -07005013 }
Derek Tan740e1672017-06-27 14:56:27 -07005014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005016 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5017 null /* workSource */);
5018 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019 return response;
5020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005023 }
5024
5025 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005026 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5028 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005029 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5030 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5031 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005032
Jordan Liu4c733742019-02-28 12:03:40 -08005033 @Override
5034 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5035 enforceModifyPermission();
5036 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5037 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5038 channel);
5039 }
5040
5041 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 final long identity = Binder.clearCallingIdentity();
5043 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 if (channel < 0) {
5045 return false;
5046 }
Jordan Liu4c733742019-02-28 12:03:40 -08005047 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5048 null /* workSource */);
5049 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 return success;
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005053 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005054 }
5055
5056 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005057 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005058 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5060 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005061 if (DBG) {
5062 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5063 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5064 + p3 + " data=" + data);
5065 }
5066 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5067 command, p1, p2, p3, data);
5068 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005069
Jordan Liu4c733742019-02-28 12:03:40 -08005070 @Override
5071 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5072 int command, int p1, int p2, int p3, String data) {
5073 enforceModifyPermission();
5074 if (DBG) {
5075 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5076 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5077 + p3 + " data=" + data);
5078 }
5079 return iccTransmitApduLogicalChannelWithPermission(
5080 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5081 data);
5082 }
5083
5084 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5085 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 final long identity = Binder.clearCallingIdentity();
5087 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005088 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 return "";
5090 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005093 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5094 null /* workSource */);
5095 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005097 // Append the returned status code to the end of the response payload.
5098 String s = Integer.toHexString(
5099 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5100 if (response.payload != null) {
5101 s = IccUtils.bytesToHexString(response.payload) + s;
5102 }
5103 return s;
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005106 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005107 }
Jake Hambye994d462014-02-03 13:10:13 -08005108
Evan Charltonc66da362014-05-16 14:06:40 -07005109 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005110 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5111 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5113 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005115 if (DBG) {
5116 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5117 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5118 }
5119 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5120 cla, command, p1, p2, p3, data);
5121 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005122
Jordan Liu4c733742019-02-28 12:03:40 -08005123 @Override
5124 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5125 int command, int p1, int p2, int p3, String data) {
5126 enforceModifyPermission();
5127 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5128 if (DBG) {
5129 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5130 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5131 + " data=" + data);
5132 }
5133
5134 return iccTransmitApduBasicChannelWithPermission(
5135 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5136 p2, p3, data);
5137 }
5138
5139 // open APDU basic channel assuming the caller has sufficient permissions
5140 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5141 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5145 && TextUtils.equals(ISDR_AID, data)) {
5146 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005147 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5148 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 if (bestComponent == null
5150 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5151 loge("The calling package is not allowed to select ISD-R.");
5152 throw new SecurityException(
5153 "The calling package is not allowed to select ISD-R.");
5154 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005155 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005158 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5159 null /* workSource */);
5160 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 // Append the returned status code to the end of the response payload.
5163 String s = Integer.toHexString(
5164 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5165 if (response.payload != null) {
5166 s = IccUtils.bytesToHexString(response.payload) + s;
5167 }
5168 return s;
5169 } finally {
5170 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005171 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005172 }
5173
5174 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005175 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005176 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5178 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005180 final long identity = Binder.clearCallingIdentity();
5181 try {
5182 if (DBG) {
5183 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5184 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5185 }
5186
5187 IccIoResult response =
5188 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5189 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5190 subId);
5191
5192 if (DBG) {
5193 log("Exchange SIM_IO [R]" + response);
5194 }
5195
5196 byte[] result = null;
5197 int length = 2;
5198 if (response.payload != null) {
5199 length = 2 + response.payload.length;
5200 result = new byte[length];
5201 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5202 } else {
5203 result = new byte[length];
5204 }
5205
5206 result[length - 1] = (byte) response.sw2;
5207 result[length - 2] = (byte) response.sw1;
5208 return result;
5209 } finally {
5210 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005211 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005212 }
5213
Nathan Haroldb3014052017-01-25 15:57:32 -08005214 /**
5215 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5216 * on a particular subscription
5217 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005218 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5219 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005221 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005222 return null;
5223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224
5225 final long identity = Binder.clearCallingIdentity();
5226 try {
5227 if (appType != TelephonyManager.APPTYPE_USIM
5228 && appType != TelephonyManager.APPTYPE_SIM) {
5229 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5230 return null;
5231 }
5232 Object response = sendRequest(
5233 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5234 if (response instanceof String[]) {
5235 return (String[]) response;
5236 }
yincheng zhao2737e882019-09-06 17:06:54 -07005237 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005239 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005240 } finally {
5241 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005242 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005243 }
5244
yincheng zhao2737e882019-09-06 17:06:54 -07005245 /**
5246 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5247 * subscription.
5248 *
5249 * @param subId the id of the subscription.
5250 * @param appType the uicc app type, must be USIM or SIM.
5251 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5252 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005253 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005254 * @return number of fplmns that is successfully written to the SIM.
5255 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005256 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5257 String callingFeatureId) {
5258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5259 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005260 if (DBG) logv("no permissions for setForbiddenplmns");
5261 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5262 }
5263 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5264 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5265 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5266 }
5267 if (fplmns == null) {
5268 throw new IllegalArgumentException("Fplmn List provided is null");
5269 }
5270 for (String fplmn : fplmns) {
5271 if (!CellIdentity.isValidPlmn(fplmn)) {
5272 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5273 }
5274 }
5275 final long identity = Binder.clearCallingIdentity();
5276 try {
5277 Object response = sendRequest(
5278 CMD_SET_FORBIDDEN_PLMNS,
5279 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5280 subId);
5281 return (int) response;
5282 } finally {
5283 Binder.restoreCallingIdentity(identity);
5284 }
5285 }
5286
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005287 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005288 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5290 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 final long identity = Binder.clearCallingIdentity();
5293 try {
5294 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5295 if (response.payload == null) {
5296 return "";
5297 }
Evan Charltonc66da362014-05-16 14:06:40 -07005298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 // Append the returned status code to the end of the response payload.
5300 String s = Integer.toHexString(
5301 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5302 s = IccUtils.bytesToHexString(response.payload) + s;
5303 return s;
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
5306 }
Evan Charltonc66da362014-05-16 14:06:40 -07005307 }
5308
Jake Hambye994d462014-02-03 13:10:13 -08005309 /**
5310 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5311 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5312 *
5313 * @param itemID the ID of the item to read
5314 * @return the NV item as a String, or null on error.
5315 */
5316 @Override
5317 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5320 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321
5322 final long identity = Binder.clearCallingIdentity();
5323 try {
5324 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005325 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5327 return value;
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
Jake Hambye994d462014-02-03 13:10:13 -08005331 }
5332
5333 /**
5334 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5335 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5336 *
5337 * @param itemID the ID of the item to read
5338 * @param itemValue the value to write, as a String
5339 * @return true on success; false on any failure
5340 */
5341 @Override
5342 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005343 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5345 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346
5347 final long identity = Binder.clearCallingIdentity();
5348 try {
5349 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5350 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005351 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5353 return success;
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
5356 }
Jake Hambye994d462014-02-03 13:10:13 -08005357 }
5358
5359 /**
5360 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5361 * Used for device configuration by some CDMA operators.
5362 *
5363 * @param preferredRoamingList byte array containing the new PRL
5364 * @return true on success; false on any failure
5365 */
5366 @Override
5367 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5369 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370
5371 final long identity = Binder.clearCallingIdentity();
5372 try {
5373 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5374 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5375 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5376 return success;
5377 } finally {
5378 Binder.restoreCallingIdentity(identity);
5379 }
Jake Hambye994d462014-02-03 13:10:13 -08005380 }
5381
5382 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005383 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005384 * Used for device configuration by some CDMA operators.
5385 *
chen xu6dac5ab2018-10-26 17:39:23 -07005386 * @param slotIndex - device slot.
5387 *
Jake Hambye994d462014-02-03 13:10:13 -08005388 * @return true on success; false on any failure
5389 */
5390 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005391 public boolean resetModemConfig(int slotIndex) {
5392 Phone phone = PhoneFactory.getPhone(slotIndex);
5393 if (phone != null) {
5394 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5395 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396
chen xu6dac5ab2018-10-26 17:39:23 -07005397 final long identity = Binder.clearCallingIdentity();
5398 try {
5399 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5400 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5401 return success;
5402 } finally {
5403 Binder.restoreCallingIdentity(identity);
5404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 }
chen xu6dac5ab2018-10-26 17:39:23 -07005406 return false;
5407 }
5408
5409 /**
5410 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5411 *
5412 * @param slotIndex - device slot.
5413 *
5414 * @return true on success; false on any failure
5415 */
5416 @Override
5417 public boolean rebootModem(int slotIndex) {
5418 Phone phone = PhoneFactory.getPhone(slotIndex);
5419 if (phone != null) {
5420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5421 mApp, phone.getSubId(), "rebootModem");
5422
5423 final long identity = Binder.clearCallingIdentity();
5424 try {
5425 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5426 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5427 return success;
5428 } finally {
5429 Binder.restoreCallingIdentity(identity);
5430 }
5431 }
5432 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005433 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005434
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005435 public String[] getPcscfAddress(String apnType, String callingPackage,
5436 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005437 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5439 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005440 return new String[0];
5441 }
5442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443 final long identity = Binder.clearCallingIdentity();
5444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005445 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 } finally {
5447 Binder.restoreCallingIdentity(identity);
5448 }
Wink Saville36469e72014-06-11 15:17:00 -07005449 }
5450
Brad Ebinger51f743a2017-01-23 13:50:20 -08005451 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005452 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5453 * {@link #disableIms(int)}.
5454 * @param slotIndex device slot.
5455 */
5456 public void resetIms(int slotIndex) {
5457 enforceModifyPermission();
5458
5459 final long identity = Binder.clearCallingIdentity();
5460 try {
5461 if (mImsResolver == null) {
5462 // may happen if the does not support IMS.
5463 return;
5464 }
5465 mImsResolver.disableIms(slotIndex);
5466 mImsResolver.enableIms(slotIndex);
5467 } finally {
5468 Binder.restoreCallingIdentity(identity);
5469 }
5470 }
5471
5472 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005473 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5474 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005475 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005476 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478
5479 final long identity = Binder.clearCallingIdentity();
5480 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005481 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005482 // may happen if the device does not support IMS.
5483 return;
5484 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005485 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 } finally {
5487 Binder.restoreCallingIdentity(identity);
5488 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005489 }
5490
5491 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005492 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5493 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005494 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005495 public void disableIms(int slotId) {
5496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497
5498 final long identity = Binder.clearCallingIdentity();
5499 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005500 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005501 // may happen if the device does not support IMS.
5502 return;
5503 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005504 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005505 } finally {
5506 Binder.restoreCallingIdentity(identity);
5507 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005508 }
5509
5510 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005511 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5512 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005513 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005514 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005515 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005516 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517
5518 final long identity = Binder.clearCallingIdentity();
5519 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005520 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005521 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5522 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005523 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005524 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005528 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005529 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005530 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5531 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005532 @Override
5533 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005534 enforceModifyPermission();
5535
5536 final long identity = Binder.clearCallingIdentity();
5537 try {
5538 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005539 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005540 } finally {
5541 Binder.restoreCallingIdentity(identity);
5542 }
5543 }
5544
5545 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005546 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005547 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005548 */
5549 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551
5552 final long identity = Binder.clearCallingIdentity();
5553 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005554 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005555 // may happen if the device does not support IMS.
5556 return null;
5557 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005558 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 } finally {
5560 Binder.restoreCallingIdentity(identity);
5561 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005562 }
5563
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005564 /**
5565 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005566 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005567 */
5568 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570
5571 final long identity = Binder.clearCallingIdentity();
5572 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005573 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005574 // may happen if the device does not support IMS.
5575 return null;
5576 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005577 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 } finally {
5579 Binder.restoreCallingIdentity(identity);
5580 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005581 }
5582
Brad Ebinger884c07b2018-02-15 16:17:40 -08005583 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005584 * Sets the ImsService Package Name that Telephony will bind to.
5585 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005586 * @param slotIndex the slot ID that the ImsService should bind for.
5587 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005588 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005589 * @param featureTypes An integer array of feature types associated with a packageName.
5590 * @param packageName The name of the package that the current configuration will be replaced
5591 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005592 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005593 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005594 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5595 int[] featureTypes, String packageName) {
5596 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5597 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5599 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005600 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005601
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 final long identity = Binder.clearCallingIdentity();
5603 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005604 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005605 // may happen if the device does not support IMS.
5606 return false;
5607 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005608 Map<Integer, String> featureConfig = new HashMap<>();
5609 for (int featureType : featureTypes) {
5610 featureConfig.put(featureType, packageName);
5611 }
5612 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5613 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 } finally {
5615 Binder.restoreCallingIdentity(identity);
5616 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005617 }
5618
5619 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005620 * Clears any carrier ImsService overrides for the slot index specified that were previously
5621 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5622 *
5623 * This should only be used for testing.
5624 *
5625 * @param slotIndex the slot ID that the ImsService should bind for.
5626 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5627 */
5628 @Override
5629 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5630 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5631 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5632 "clearCarrierImsServiceOverride");
5633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5634 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5635 "clearCarrierImsServiceOverride");
5636
5637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 if (mImsResolver == null) {
5640 // may happen if the device does not support IMS.
5641 return false;
5642 }
5643 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5644 } finally {
5645 Binder.restoreCallingIdentity(identity);
5646 }
5647 }
5648
5649 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005650 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005651 *
5652 * @param slotId The slot that the ImsService is associated with.
5653 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5654 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005655 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005656 * @return the package name of the ImsService configuration.
5657 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005658 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5659 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005660 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005661 TelephonyPermissions
5662 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5663 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5664 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005665
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 final long identity = Binder.clearCallingIdentity();
5667 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005668 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005669 // may happen if the device does not support IMS.
5670 return "";
5671 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005672 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005673 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5674 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005678 }
5679
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005680 /**
5681 * Get the MmTelFeature state associated with the requested subscription id.
5682 * @param subId The subscription that the MmTelFeature is associated with.
5683 * @param callback A callback with an integer containing the
5684 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5685 */
5686 @Override
5687 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5688 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5689 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5690 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5691 "IMS not available on device.");
5692 }
5693 final long token = Binder.clearCallingIdentity();
5694 try {
5695 int slotId = getSlotIndex(subId);
5696 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5697 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5698 + subId + "'");
5699 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5700 }
5701 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5702 try {
5703 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5704 } catch (RemoteException e) {
5705 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5706 + "Ignore");
5707 }
5708 });
5709 } finally {
5710 Binder.restoreCallingIdentity(token);
5711 }
5712 }
5713
Daniel Brightbb5840b2021-01-12 15:48:18 -08005714 /**
5715 * Sets the ims registration state on all valid {@link Phone}s.
5716 */
5717 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005718 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005719
5720 final long identity = Binder.clearCallingIdentity();
5721 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005722 // NOTE: Before S, this method only set the default phone.
5723 for (final Phone phone : PhoneFactory.getPhones()) {
5724 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5725 phone.setImsRegistrationState(registered);
5726 }
5727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 } finally {
5729 Binder.restoreCallingIdentity(identity);
5730 }
Wink Saville36469e72014-06-11 15:17:00 -07005731 }
5732
5733 /**
Stuart Scott54788802015-03-30 13:18:01 -07005734 * Set the network selection mode to automatic.
5735 *
5736 */
5737 @Override
5738 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5740 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741
5742 final long identity = Binder.clearCallingIdentity();
5743 try {
shilufc958392020-01-20 11:36:01 -08005744 if (!isActiveSubscription(subId)) {
5745 return;
5746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005748 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5749 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 } finally {
5751 Binder.restoreCallingIdentity(identity);
5752 }
Stuart Scott54788802015-03-30 13:18:01 -07005753 }
5754
Jack Yud10cdd42020-09-28 20:28:01 -07005755 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005756 * Ask the radio to connect to the input network and change selection mode to manual.
5757 *
5758 * @param subId the id of the subscription.
5759 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5760 * the operator to attach to.
5761 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5762 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5763 * normal network selection next time.
5764 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005765 */
5766 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005767 public boolean setNetworkSelectionModeManual(
5768 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5770 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005771
5772 if (!isActiveSubscription(subId)) {
5773 return false;
5774 }
5775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 final long identity = Binder.clearCallingIdentity();
5777 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005778 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005780 if (DBG) {
5781 log("setNetworkSelectionModeManual: subId: " + subId
5782 + " operator: " + operatorInfo);
5783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5785 } finally {
5786 Binder.restoreCallingIdentity(identity);
5787 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005788 }
shilu84f6e8b2019-12-19 13:58:01 -08005789 /**
5790 * Get the manual network selection
5791 *
5792 * @param subId the id of the subscription.
5793 *
5794 * @return the previously saved user selected PLMN
5795 */
5796 @Override
5797 public String getManualNetworkSelectionPlmn(int subId) {
5798 TelephonyPermissions
5799 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5800 mApp, subId, "getManualNetworkSelectionPlmn");
5801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
5804 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005805 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005806 }
5807
5808 final Phone phone = getPhone(subId);
5809 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005810 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005811 }
5812 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5813 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5814 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
5817 }
5818 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005819
5820 /**
5821 * Scans for available networks.
5822 */
5823 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005824 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5825 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5827 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005828 LocationAccessPolicy.LocationPermissionResult locationResult =
5829 LocationAccessPolicy.checkLocationPermission(mApp,
5830 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5831 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005832 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005833 .setCallingPid(Binder.getCallingPid())
5834 .setCallingUid(Binder.getCallingUid())
5835 .setMethod("getCellNetworkScanResults")
5836 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005837 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5838 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005839 .build());
5840 switch (locationResult) {
5841 case DENIED_HARD:
5842 throw new SecurityException("Not allowed to access scan results -- location");
5843 case DENIED_SOFT:
5844 return null;
5845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846
Pengquan Menga1bb6272018-09-06 09:59:22 -07005847 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 try {
5849 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005850 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005852 } finally {
5853 Binder.restoreCallingIdentity(identity);
5854 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005855 }
5856
5857 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005858 * Get the call forwarding info, given the call forwarding reason.
5859 */
5860 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005861 public void getCallForwarding(int subId, int callForwardingReason,
5862 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005863 enforceReadPrivilegedPermission("getCallForwarding");
5864 long identity = Binder.clearCallingIdentity();
5865 try {
5866 if (DBG) {
5867 log("getCallForwarding: subId " + subId
5868 + " callForwardingReason" + callForwardingReason);
5869 }
Hall Liu27d24262020-09-18 19:04:59 -07005870
5871 Phone phone = getPhone(subId);
5872 if (phone == null) {
5873 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005874 callback.onError(
5875 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005876 } catch (RemoteException e) {
5877 // ignore
5878 }
5879 return;
5880 }
5881
5882 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5883 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5884 @Override
5885 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5886 try {
5887 callback.onCallForwardingInfoAvailable(info);
5888 } catch (RemoteException e) {
5889 // ignore
5890 }
5891 }
5892
5893 @Override
5894 public void onError(int error) {
5895 try {
5896 callback.onError(error);
5897 } catch (RemoteException e) {
5898 // ignore
5899 }
5900 }
5901 });
5902 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
5906 }
5907
5908 /**
5909 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5910 * reason, the number to forward, and the timeout before the forwarding is attempted.
5911 */
5912 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005913 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5914 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005915 enforceModifyPermission();
5916 long identity = Binder.clearCallingIdentity();
5917 try {
5918 if (DBG) {
5919 log("setCallForwarding: subId " + subId
5920 + " callForwardingInfo" + callForwardingInfo);
5921 }
Hall Liu27d24262020-09-18 19:04:59 -07005922
5923 Phone phone = getPhone(subId);
5924 if (phone == null) {
5925 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005926 callback.accept(
5927 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005928 } catch (RemoteException e) {
5929 // ignore
5930 }
5931 return;
5932 }
5933
5934 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5935 FunctionalUtils.ignoreRemoteException(callback::accept));
5936
5937 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005938 } finally {
5939 Binder.restoreCallingIdentity(identity);
5940 }
5941 }
5942
5943 /**
Hall Liu27d24262020-09-18 19:04:59 -07005944 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005945 */
5946 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005947 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005948 enforceReadPrivilegedPermission("getCallForwarding");
5949 long identity = Binder.clearCallingIdentity();
5950 try {
Hall Liu27d24262020-09-18 19:04:59 -07005951
5952 Phone phone = getPhone(subId);
5953 if (phone == null) {
5954 try {
5955 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5956 } catch (RemoteException e) {
5957 // ignore
5958 }
5959 return;
5960 }
5961
5962 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5963
Shuo Qian4a594052020-01-23 11:59:30 -08005964 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005965 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005966 } finally {
5967 Binder.restoreCallingIdentity(identity);
5968 }
5969 }
5970
5971 /**
Hall Liu27d24262020-09-18 19:04:59 -07005972 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005973 */
5974 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005975 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005976 enforceModifyPermission();
5977 long identity = Binder.clearCallingIdentity();
5978 try {
Hall Liu27d24262020-09-18 19:04:59 -07005979 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5980
5981 Phone phone = getPhone(subId);
5982 if (phone == null) {
5983 try {
5984 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5985 } catch (RemoteException e) {
5986 // ignore
5987 }
5988 return;
5989 }
5990
5991 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5992 FunctionalUtils.ignoreRemoteException(callback::accept));
5993
5994 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005995 } finally {
5996 Binder.restoreCallingIdentity(identity);
5997 }
5998 }
5999
6000 /**
yinxub1bed742017-04-17 11:45:04 -07006001 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006002 *
yinxub1bed742017-04-17 11:45:04 -07006003 * @param subId id of the subscription
6004 * @param request contains the radio access networks with bands/channels to scan
6005 * @param messenger callback messenger for scan results or errors
6006 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006007 * @return the id of the requested scan which can be used to stop the scan.
6008 */
6009 @Override
6010 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006011 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6013 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006014 LocationAccessPolicy.LocationPermissionResult locationResult =
6015 LocationAccessPolicy.checkLocationPermission(mApp,
6016 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6017 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006018 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006019 .setCallingPid(Binder.getCallingPid())
6020 .setCallingUid(Binder.getCallingUid())
6021 .setMethod("requestNetworkScan")
6022 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006023 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6024 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006025 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006026 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006027 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6028 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006029 if (e != null) {
6030 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6031 throw e;
6032 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006033 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006034 return TelephonyScanManager.INVALID_SCAN_ID;
6035 }
6036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 }
Hall Liu912dfd32019-04-25 14:02:26 -07006038 int callingUid = Binder.getCallingUid();
6039 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006040 final long identity = Binder.clearCallingIdentity();
6041 try {
6042 return mNetworkScanRequestTracker.startNetworkScan(
6043 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006044 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006045 } finally {
6046 Binder.restoreCallingIdentity(identity);
6047 }
yinxu504e1392017-04-12 16:03:22 -07006048 }
6049
Hall Liub2ac8ef2019-02-28 15:56:23 -08006050 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006051 NetworkScanRequest request, int subId, String callingPackage) {
6052 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006053 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6054 boolean hasNetworkScanPermission =
6055 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6056 == PERMISSION_GRANTED;
6057
6058 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6059 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6060 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006061 }
6062
6063 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6064 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006065 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6066 return new SecurityException("Specific channels must not be"
6067 + " scanned without location access.");
6068 }
6069 }
6070 }
6071
Hall Liub2ac8ef2019-02-28 15:56:23 -08006072 return null;
6073 }
6074
yinxu504e1392017-04-12 16:03:22 -07006075 /**
6076 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006077 *
6078 * @param subId id of the subscription
6079 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006080 */
6081 @Override
6082 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6084 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085
Hall Liu912dfd32019-04-25 14:02:26 -07006086 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 final long identity = Binder.clearCallingIdentity();
6088 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006089 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
yinxu504e1392017-04-12 16:03:22 -07006093 }
6094
6095 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006096 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006097 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006098 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006099 */
6100 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006101 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006102 TelephonyPermissions
6103 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006104 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006105
6106 final long identity = Binder.clearCallingIdentity();
6107 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006108 if (DBG) log("getAllowedNetworkTypesBitmask");
6109 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6110 int networkTypesBitmask = (result != null ? result[0] : -1);
6111 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6112 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 } finally {
6114 Binder.restoreCallingIdentity(identity);
6115 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006116 }
6117
6118 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006119 * Get the allowed network types for certain reason.
6120 *
6121 * @param subId the id of the subscription.
6122 * @param reason the reason the allowed network type change is taking place
6123 * @return the allowed network types.
6124 */
6125 @Override
6126 public long getAllowedNetworkTypesForReason(int subId,
6127 @TelephonyManager.AllowedNetworkTypesReason int reason) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006128 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6129 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006130 final long identity = Binder.clearCallingIdentity();
6131 try {
6132 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6133 } finally {
6134 Binder.restoreCallingIdentity(identity);
6135 }
6136 }
6137
6138 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006139 * Enable/Disable E-UTRA-NR Dual Connectivity
6140 * @param subId subscription id of the sim card
6141 * @param nrDualConnectivityState expected NR dual connectivity state
6142 * This can be passed following states
6143 * <ol>
6144 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6145 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6146 * <li>Disable NR dual connectivity and force secondary cell to be released
6147 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6148 * </ol>
6149 * @return operation result.
6150 */
6151 @Override
6152 public int setNrDualConnectivityState(int subId,
6153 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6155 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006156 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006157 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6158 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6159 }
6160
Sooraj Sasindran37444802020-08-11 10:40:43 -07006161 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6162 final long identity = Binder.clearCallingIdentity();
6163 try {
6164 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6165 nrDualConnectivityState, subId,
6166 workSource);
6167 if (DBG) log("enableNRDualConnectivity result: " + result);
6168 return result;
6169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171 }
6172 }
6173
6174 /**
6175 * Is E-UTRA-NR Dual Connectivity enabled
6176 * @return true if dual connectivity is enabled else false
6177 */
6178 @Override
6179 public boolean isNrDualConnectivityEnabled(int subId) {
6180 TelephonyPermissions
6181 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6182 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006183 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006184 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6185 return false;
6186 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006187 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6191 null, subId, workSource);
6192 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6193 return isEnabled;
6194 } finally {
6195 Binder.restoreCallingIdentity(identity);
6196 }
6197 }
6198
6199 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006200 * Set the allowed network types of the device and
6201 * provide the reason triggering the allowed network change.
6202 *
6203 * @param subId the id of the subscription.
6204 * @param reason the reason the allowed network type change is taking place
6205 * @param allowedNetworkTypes the allowed network types.
6206 * @return true on success; false on any failure.
6207 */
6208 @Override
6209 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006210 @TelephonyManager.AllowedNetworkTypesReason int reason,
6211 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6213 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006214 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6215 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6216 return false;
6217 }
6218
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006219 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6220 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6221
6222
6223 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6224 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6225 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006226 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006227
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006228 final long identity = Binder.clearCallingIdentity();
6229 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006230 Boolean success = (Boolean) sendRequest(
6231 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6232 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6233
6234 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6235 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006236 } finally {
6237 Binder.restoreCallingIdentity(identity);
6238 }
6239 }
6240
6241 /**
Miaoa84611c2019-03-15 09:21:10 +08006242 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006243 *
Miaoa84611c2019-03-15 09:21:10 +08006244 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006245 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006246 * @hide
6247 */
6248 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006249 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006250 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006252 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 try {
Miaoa84611c2019-03-15 09:21:10 +08006254 if (phone != null) {
6255 return phone.hasMatchedTetherApnSetting();
6256 } else {
6257 return false;
6258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 } finally {
6260 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006261 }
Junda Liu475951f2014-11-07 16:45:03 -08006262 }
6263
6264 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006265 * Enable or disable always reporting signal strength changes from radio.
6266 *
6267 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6268 */
6269 @Override
6270 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6271 enforceModifyPermission();
6272 enforceSystemCaller();
6273
6274 final long identity = Binder.clearCallingIdentity();
6275 final Phone phone = getPhone(subId);
6276 try {
6277 if (phone != null) {
6278 if (DBG) {
6279 log("setAlwaysReportSignalStrength: subId=" + subId
6280 + " isEnable=" + isEnable);
6281 }
6282 phone.setAlwaysReportSignalStrength(isEnable);
6283 } else {
6284 loge("setAlwaysReportSignalStrength: no phone found for subId="
6285 + subId);
6286 }
6287 } finally {
6288 Binder.restoreCallingIdentity(identity);
6289 }
6290 }
6291
6292 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006293 * Get the user enabled state of Mobile Data.
6294 *
6295 * TODO: remove and use isUserDataEnabled.
6296 * This can't be removed now because some vendor codes
6297 * calls through ITelephony directly while they should
6298 * use TelephonyManager.
6299 *
6300 * @return true on enabled
6301 */
6302 @Override
6303 public boolean getDataEnabled(int subId) {
6304 return isUserDataEnabled(subId);
6305 }
6306
6307 /**
6308 * Get whether mobile data is enabled per user setting.
6309 *
6310 * There are other factors deciding whether mobile data is actually enabled, but they are
6311 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006312 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006313 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006314 *
6315 * @return {@code true} if data is enabled else {@code false}
6316 */
6317 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006318 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006319 try {
6320 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6321 null);
6322 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6324 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006326
6327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 int phoneId = mSubscriptionController.getPhoneId(subId);
6330 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6331 Phone phone = PhoneFactory.getPhone(phoneId);
6332 if (phone != null) {
6333 boolean retVal = phone.isUserDataEnabled();
6334 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6335 return retVal;
6336 } else {
6337 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6338 return false;
6339 }
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006342 }
6343 }
6344
6345 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006346 * Checks if the device is capable of mobile data by considering whether whether the
6347 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6348 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006349 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006350 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006351 */
6352 @Override
6353 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006354 try {
6355 try {
6356 mApp.enforceCallingOrSelfPermission(
6357 android.Manifest.permission.ACCESS_NETWORK_STATE,
6358 null);
6359 } catch (Exception e) {
6360 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6361 "isDataEnabled");
6362 }
6363 } catch (Exception e) {
6364 enforceReadPrivilegedPermission("isDataEnabled");
6365 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006366
6367 final long identity = Binder.clearCallingIdentity();
6368 try {
6369 int phoneId = mSubscriptionController.getPhoneId(subId);
6370 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6371 Phone phone = PhoneFactory.getPhone(phoneId);
6372 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006373 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6375 return retVal;
6376 } else {
6377 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6378 return false;
6379 }
6380 } finally {
6381 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006382 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006383 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006384
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006385 /**
6386 * Check if data is enabled for a specific reason
6387 * @param subId Subscription index
6388 * @param reason the reason the data enable change is taking place
6389 * @return {@code true} if the overall data is enabled; {@code false} if not.
6390 */
6391 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006392 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006393 @TelephonyManager.DataEnabledReason int reason) {
6394 try {
6395 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6396 null);
6397 } catch (Exception e) {
6398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006399 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006400 }
6401
6402
6403 final long identity = Binder.clearCallingIdentity();
6404 try {
6405 int phoneId = mSubscriptionController.getPhoneId(subId);
6406 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006407 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006408 + " reason=" + reason);
6409 }
6410 Phone phone = PhoneFactory.getPhone(phoneId);
6411 if (phone != null) {
6412 boolean retVal;
6413 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6414 retVal = phone.isUserDataEnabled();
6415 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006416 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006417 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006418 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006419 return retVal;
6420 } else {
6421 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006422 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006423 + subId + " retVal=false");
6424 }
6425 return false;
6426 }
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
6430 }
6431
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006432 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006433 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006434 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6435 // Skip the check if it's one of these special uids
6436 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6437 }
6438
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006439 //load access rules from carrier configs, and check those as well: b/139133814
6440 SubscriptionController subController = SubscriptionController.getInstance();
6441 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6442 || subController == null) return privilegeFromSim;
6443
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006444 PackageManager pkgMgr = phone.getContext().getPackageManager();
6445 String[] packages = pkgMgr.getPackagesForUid(uid);
6446
6447 final long identity = Binder.clearCallingIdentity();
6448 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006449 int subId = phone.getSubId();
6450 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6451 // A test override is in place for the privileges for this subId, so don't try to
6452 // read the subscription privileges.
6453 return privilegeFromSim;
6454 }
6455 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006456 SubscriptionManager subManager = (SubscriptionManager)
6457 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6458 for (String pkg : packages) {
6459 if (subManager.canManageSubscription(subInfo, pkg)) {
6460 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6461 }
6462 }
6463 return privilegeFromSim;
6464 } finally {
6465 Binder.restoreCallingIdentity(identity);
6466 }
6467 }
6468
6469 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6470 String pkgName) {
6471 //load access rules from carrier configs, and check those as well: b/139133814
6472 SubscriptionController subController = SubscriptionController.getInstance();
6473 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6474 || subController == null) return privilegeFromSim;
6475
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006478 int subId = phone.getSubId();
6479 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6480 // A test override is in place for the privileges for this subId, so don't try to
6481 // read the subscription privileges.
6482 return privilegeFromSim;
6483 }
6484 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006485 SubscriptionManager subManager = (SubscriptionManager)
6486 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6487 return subManager.canManageSubscription(subInfo, pkgName)
6488 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
6492 }
6493
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006494 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006495 public int getCarrierPrivilegeStatus(int subId) {
6496 final Phone phone = getPhone(subId);
6497 if (phone == null) {
6498 loge("getCarrierPrivilegeStatus: Invalid subId");
6499 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6500 }
6501 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006502 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006503 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006504 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6505 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006506
6507 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6508 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006509 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006510 }
Junda Liu29340342014-07-10 15:23:27 -07006511
6512 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006513 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006514 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006515 final Phone phone = getPhone(subId);
6516 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006517 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006518 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6519 }
6520 UiccProfile profile =
6521 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6522 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006523 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006524 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6525 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006526 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006527 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006528 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006529 }
6530
6531 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006532 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6533 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006534 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006535 }
6536
6537 int phoneId = SubscriptionManager.getPhoneId(subId);
6538 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006539 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006540 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006541 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6542 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006543 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6544 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6545 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006546 }
6547
6548 @Override
6549 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006550 if (TextUtils.isEmpty(pkgName))
6551 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006552 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6553 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6554 UiccCard card = UiccController.getInstance().getUiccCard(i);
6555 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006556 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006557 continue;
6558 }
6559
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006560 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6561 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6562 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006563 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6564 break;
6565 }
6566 }
6567
6568 return result;
Junda Liu29340342014-07-10 15:23:27 -07006569 }
Derek Tan89e89d42014-07-08 17:00:10 -07006570
6571 @Override
Junda Liue64de782015-04-16 17:19:16 -07006572 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6573 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6574 loge("phoneId " + phoneId + " is not valid.");
6575 return null;
6576 }
6577 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006578 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006579 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006580 return null ;
6581 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006582 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006583 }
6584
Amith Yamasani6e118872016-02-19 12:53:51 -08006585 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006586 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006587 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006588 List<String> privilegedPackages = new ArrayList<>();
6589 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006590 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6591 // has UICC in that slot.
6592 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006593 if (card.hasCarrierPrivilegeRules()) {
6594 if (packages == null) {
6595 // Only check packages in user 0 for now
6596 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006597 PackageManager.MATCH_DISABLED_COMPONENTS
6598 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006599 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006600 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006601 }
6602 for (int p = packages.size() - 1; p >= 0; p--) {
6603 PackageInfo pkgInfo = packages.get(p);
6604 if (pkgInfo != null && pkgInfo.packageName != null
6605 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006606 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006607 privilegedPackages.add(pkgInfo.packageName);
6608 }
6609 }
6610 }
6611 }
6612 return privilegedPackages;
6613 }
6614
chen xuf7e9fe82019-05-09 19:31:02 -07006615 @Override
6616 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006617 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6618
6619 final long identity = Binder.clearCallingIdentity();
6620
chen xuf7e9fe82019-05-09 19:31:02 -07006621 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006622 try {
6623 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6624 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6625 }
6626 } finally {
6627 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006628 }
6629 return privilegedPackages;
6630 }
6631
Wink Savilleb564aae2014-10-23 10:18:09 -07006632 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006633 final Phone phone = getPhone(subId);
6634 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006635 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006636 return null;
6637 }
6638 String iccId = card.getIccId();
6639 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006640 return null;
6641 }
6642 return iccId;
6643 }
6644
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006645 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006646 public void setCallComposerStatus(int subId, int status) {
6647 enforceModifyPermission();
6648
6649 final long identity = Binder.clearCallingIdentity();
6650 try {
6651 Phone phone = getPhone(subId);
6652 if (phone != null) {
6653 Phone defaultPhone = phone.getImsPhone();
6654 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6655 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6656 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006657 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6658 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006659 }
6660 }
Shuo Qian284ae752020-12-22 19:10:14 -08006661 } catch (ImsException e) {
6662 throw new ServiceSpecificException(e.getCode());
6663 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006664 Binder.restoreCallingIdentity(identity);
6665 }
6666 }
6667
6668 @Override
6669 public int getCallComposerStatus(int subId) {
6670 enforceReadPrivilegedPermission("getCallComposerStatus");
6671
6672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 Phone phone = getPhone(subId);
6675 if (phone != null) {
6676 Phone defaultPhone = phone.getImsPhone();
6677 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6678 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6679 return imsPhone.getCallComposerStatus();
6680 }
6681 }
6682 } finally {
6683 Binder.restoreCallingIdentity(identity);
6684 }
6685 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6686 }
6687
6688 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006689 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6690 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006691 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006692 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 final String iccId = getIccId(subId);
6697 final Phone phone = getPhone(subId);
6698 if (phone == null) {
6699 return false;
6700 }
6701 final String subscriberId = phone.getSubscriberId();
6702
6703 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006704 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 + subscriberId + " to " + number);
6706 }
6707
6708 if (TextUtils.isEmpty(iccId)) {
6709 return false;
6710 }
6711
6712 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6713
6714 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6715 if (alphaTag == null) {
6716 editor.remove(alphaTagPrefKey);
6717 } else {
6718 editor.putString(alphaTagPrefKey, alphaTag);
6719 }
6720
6721 // Record both the line number and IMSI for this ICCID, since we need to
6722 // track all merged IMSIs based on line number
6723 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6724 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6725 if (number == null) {
6726 editor.remove(numberPrefKey);
6727 editor.remove(subscriberPrefKey);
6728 } else {
6729 editor.putString(numberPrefKey, number);
6730 editor.putString(subscriberPrefKey, subscriberId);
6731 }
6732
6733 editor.commit();
6734 return true;
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006737 }
Derek Tan7226c842014-07-02 17:42:23 -07006738 }
6739
6740 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006741 public String getLine1NumberForDisplay(int subId, String callingPackage,
6742 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006743 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006744 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006745 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006746 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006747 return null;
6748 }
Derek Tan97ebb422014-09-05 16:55:38 -07006749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 final long identity = Binder.clearCallingIdentity();
6751 try {
6752 String iccId = getIccId(subId);
6753 if (iccId != null) {
6754 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6755 if (DBG_MERGE) {
6756 log("getLine1NumberForDisplay returning "
6757 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6758 }
6759 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6762 return null;
6763 } finally {
6764 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006765 }
Derek Tan7226c842014-07-02 17:42:23 -07006766 }
6767
6768 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006769 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6770 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006772 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006773 return null;
6774 }
Derek Tan97ebb422014-09-05 16:55:38 -07006775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776 final long identity = Binder.clearCallingIdentity();
6777 try {
6778 String iccId = getIccId(subId);
6779 if (iccId != null) {
6780 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6781 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6782 }
6783 return null;
6784 } finally {
6785 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006786 }
Derek Tan7226c842014-07-02 17:42:23 -07006787 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006788
6789 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006790 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6791 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006792 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6793 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006795 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006796 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006797 return null;
6798 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006799
Jordan Liub49b04b2019-05-06 14:45:15 -07006800 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6801 // the process, where TelephonyManager was instantiated.
6802 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006803 final long identity = Binder.clearCallingIdentity();
6804 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006805 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 final TelephonyManager tele = TelephonyManager.from(context);
6807 final SubscriptionManager sub = SubscriptionManager.from(context);
6808
6809 // Figure out what subscribers are currently active
6810 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811
Jordan Liub49b04b2019-05-06 14:45:15 -07006812 // Only consider subs which match the current subId
6813 // This logic can be simplified. See b/131189269 for progress.
6814 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006815 activeSubscriberIds.add(tele.getSubscriberId(subId));
6816 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817
6818 // First pass, find a number override for an active subscriber
6819 String mergeNumber = null;
6820 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6821 for (String key : prefs.keySet()) {
6822 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6823 final String subscriberId = (String) prefs.get(key);
6824 if (activeSubscriberIds.contains(subscriberId)) {
6825 final String iccId = key.substring(
6826 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6827 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6828 mergeNumber = (String) prefs.get(numberKey);
6829 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006830 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006831 + " for active subscriber " + subscriberId);
6832 }
6833 if (!TextUtils.isEmpty(mergeNumber)) {
6834 break;
6835 }
6836 }
6837 }
6838 }
6839
6840 // Shortcut when no active merged subscribers
6841 if (TextUtils.isEmpty(mergeNumber)) {
6842 return null;
6843 }
6844
6845 // Second pass, find all subscribers under that line override
6846 final ArraySet<String> result = new ArraySet<>();
6847 for (String key : prefs.keySet()) {
6848 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6849 final String number = (String) prefs.get(key);
6850 if (mergeNumber.equals(number)) {
6851 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6852 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6853 final String subscriberId = (String) prefs.get(subscriberKey);
6854 if (!TextUtils.isEmpty(subscriberId)) {
6855 result.add(subscriberId);
6856 }
6857 }
6858 }
6859 }
6860
6861 final String[] resultArray = result.toArray(new String[result.size()]);
6862 Arrays.sort(resultArray);
6863 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006864 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6866 }
6867 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006868 } finally {
6869 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006870 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006871 }
6872
6873 @Override
zoey chen38003472019-12-13 17:16:31 +08006874 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6875 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006876
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
6879 final TelephonyManager telephonyManager = mApp.getSystemService(
6880 TelephonyManager.class);
6881 String subscriberId = telephonyManager.getSubscriberId(subId);
6882 if (subscriberId == null) {
6883 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006884 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006885 + subId);
6886 }
6887 return null;
6888 }
6889
6890 final SubscriptionInfo info = SubscriptionController.getInstance()
6891 .getSubscriptionInfo(subId);
6892 final ParcelUuid groupUuid = info.getGroupUuid();
6893 // If it doesn't belong to any group, return just subscriberId of itself.
6894 if (groupUuid == null) {
6895 return new String[]{subscriberId};
6896 }
6897
6898 // Get all subscriberIds from the group.
6899 final List<String> mergedSubscriberIds = new ArrayList<>();
6900 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006901 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006902 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006903 for (SubscriptionInfo subInfo : groupInfos) {
6904 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6905 if (subscriberId != null) {
6906 mergedSubscriberIds.add(subscriberId);
6907 }
6908 }
6909
6910 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6911 } finally {
6912 Binder.restoreCallingIdentity(identity);
6913
6914 }
6915 }
6916
6917 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006918 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006919 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006920 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 final Phone phone = getPhone(subId);
6925 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6926 } finally {
6927 Binder.restoreCallingIdentity(identity);
6928 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006929 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006930
6931 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006932 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006933 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6934 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006935 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6936 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937
6938 final long identity = Binder.clearCallingIdentity();
6939 try {
6940 final Phone phone = getPhone(subId);
6941 if (phone == null) {
6942 return false;
6943 }
6944 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6945 cdmaNonRoamingList);
6946 } finally {
6947 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006948 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006949 }
6950
6951 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006952 @Deprecated
6953 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6954 enforceModifyPermission();
6955
6956 int returnValue = 0;
6957 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006958 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006959 if(result.exception == null) {
6960 if (result.result != null) {
6961 byte[] responseData = (byte[])(result.result);
6962 if(responseData.length > oemResp.length) {
6963 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6964 responseData.length + "bytes. Buffer Size is " +
6965 oemResp.length + "bytes.");
6966 }
6967 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6968 returnValue = responseData.length;
6969 }
6970 } else {
6971 CommandException ex = (CommandException) result.exception;
6972 returnValue = ex.getCommandError().ordinal();
6973 if(returnValue > 0) returnValue *= -1;
6974 }
6975 } catch (RuntimeException e) {
6976 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6977 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6978 if(returnValue > 0) returnValue *= -1;
6979 }
6980
6981 return returnValue;
6982 }
6983
6984 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006985 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006986 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006987 try {
6988 TelephonyPermissions
6989 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6990 mApp, phone.getSubId(), "getRadioAccessFamily");
6991 } catch (SecurityException e) {
6992 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6993 throw e;
6994 }
chen xub97461a2018-10-26 14:17:57 -07006995 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006996 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006997 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 final long identity = Binder.clearCallingIdentity();
7000 try {
chen xub97461a2018-10-26 14:17:57 -07007001 TelephonyPermissions
7002 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7003 mApp, phone.getSubId(), "getRadioAccessFamily");
7004 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
chen xub97461a2018-10-26 14:17:57 -07007008 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007009 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007010
7011 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007012 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007013 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007014 try {
7015 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7016 Binder.getCallingUid())) {
7017 throw new SecurityException("Package uid and package name do not match: "
7018 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7019 }
7020 } catch (PackageManager.NameNotFoundException e) {
7021 throw new SecurityException("Package name invalid:" + callingPackage);
7022 }
7023 RoleManager rm = mApp.getSystemService(RoleManager.class);
7024 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7025 if (!dialerRoleHolders.contains(callingPackage)) {
7026 throw new SecurityException("App must be the dialer role holder to"
7027 + " upload a call composer pic");
7028 }
7029
7030 Executors.newSingleThreadExecutor().execute(() -> {
7031 ByteArrayOutputStream output = new ByteArrayOutputStream(
7032 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7033 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7034 boolean readUntilEnd = false;
7035 int totalBytesRead = 0;
7036 byte[] buffer = new byte[16 * 1024];
7037 while (true) {
7038 int numRead;
7039 try {
7040 numRead = input.read(buffer);
7041 } catch (IOException e) {
7042 try {
7043 fd.checkError();
7044 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7045 null);
7046 } catch (IOException e1) {
7047 // This means that the other side closed explicitly with an error. If this
7048 // happens, log and ignore.
7049 loge("Remote end of call composer picture pipe closed: " + e1);
7050 }
7051 break;
7052 }
7053 if (numRead == -1) {
7054 readUntilEnd = true;
7055 break;
7056 }
7057 totalBytesRead += numRead;
7058 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7059 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7060 try {
7061 input.close();
7062 } catch (IOException e) {
7063 // ignore
7064 }
7065 break;
7066 }
7067 output.write(buffer, 0, numRead);
7068 }
7069 // Generally, the remote end will close the file descriptors. The only case where we
7070 // close is above, where the picture size is too big.
7071
7072 try {
7073 fd.checkError();
7074 } catch (IOException e) {
7075 loge("Remote end for call composer closed with an error: " + e);
7076 return;
7077 }
7078
Hall Liuaa4211e2021-01-20 15:43:39 -08007079 if (!readUntilEnd) {
7080 loge("Did not finish reading entire image; aborting");
7081 return;
7082 }
Hall Liu82694d52020-12-11 18:22:04 -08007083
Hall Liuaa4211e2021-01-20 15:43:39 -08007084 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7085 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7086 new CallComposerPictureTransfer.Factory() {},
7087 imageData,
7088 (result) -> {
7089 if (result.first != null) {
7090 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7091 Bundle outputResult = new Bundle();
7092 outputResult.putParcelable(
7093 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7094 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7095 outputResult);
7096 } else {
7097 callback.send(result.second, null);
7098 }
7099 }
7100 );
Hall Liu82694d52020-12-11 18:22:04 -08007101 });
7102 }
7103
7104 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007105 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007106 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007107 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108
7109 final long identity = Binder.clearCallingIdentity();
7110 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007111 ImsManager.getInstance(defaultPhone.getContext(),
7112 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113 } finally {
7114 Binder.restoreCallingIdentity(identity);
7115 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007116 }
7117
7118 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007119 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007120 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7122 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007123 return false;
7124 }
Svet Ganovb320e182015-04-16 12:30:10 -07007125
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 final long identity = Binder.clearCallingIdentity();
7127 try {
7128 // Check the user preference and the system-level IMS setting. Even if the user has
7129 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7130 // In the long run, we may instead need to check if there exists a connection service
7131 // which can support video calling.
7132 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007133 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 return imsManager.isVtEnabledByPlatform()
7135 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7136 && imsManager.isVtEnabledByUser();
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007140 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007141
Andrew Leea1239f22015-03-02 17:44:07 -08007142 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007143 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7144 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007145 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007146 mApp, subId, callingPackage, callingFeatureId,
7147 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148 return false;
7149 }
7150
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 CarrierConfigManager configManager =
7154 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007155 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
7159 }
Andrew Leea1239f22015-03-02 17:44:07 -08007160 }
7161
7162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007163 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007165 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 return false;
7167 }
7168
7169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 CarrierConfigManager configManager =
7172 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007173 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7175 } finally {
7176 Binder.restoreCallingIdentity(identity);
7177 }
Andrew Leea1239f22015-03-02 17:44:07 -08007178 }
7179
Andrew Lee9431b832015-03-09 18:46:45 -07007180 @Override
7181 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007182 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007183 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007184 }
7185
7186 @Override
7187 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188 final long identity = Binder.clearCallingIdentity();
7189 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007190 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 } finally {
7192 Binder.restoreCallingIdentity(identity);
7193 }
Andrew Lee9431b832015-03-09 18:46:45 -07007194 }
7195
Hall Liuf6668912018-10-31 17:05:23 -07007196 /**
7197 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7198 * support for the feature and device firmware support.
7199 *
7200 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7201 */
7202 @Override
7203 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007205 final Phone phone = getPhone(subscriptionId);
7206 if (phone == null) {
7207 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7208 return false;
7209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007211 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7213 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007214 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215 return isCarrierSupported && isDeviceSupported;
7216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
Hall Liu98187582018-01-22 19:15:32 -08007219 }
7220
Hall Liuf6668912018-10-31 17:05:23 -07007221 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007222 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7223 * RTT setting, will return true if the device and carrier both support RTT.
7224 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007225 */
7226 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 final long identity = Binder.clearCallingIdentity();
7228 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007229 boolean isRttSupported = isRttSupported(subscriptionId);
7230 boolean isUserRttSettingOn = Settings.Secure.getInt(
7231 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7232 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7233 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7234 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007238 }
7239
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007240 @Deprecated
7241 @Override
7242 public String getDeviceId(String callingPackage) {
7243 return getDeviceIdWithFeature(callingPackage, null);
7244 }
7245
Sanket Padawe7310cc72015-01-14 09:53:20 -08007246 /**
7247 * Returns the unique device ID of phone, for example, the IMEI for
7248 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7249 *
7250 * <p>Requires Permission:
7251 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7252 */
7253 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007254 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007255 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007256 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007257 return null;
7258 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007259 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007260 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007261 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007262 return null;
7263 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264
7265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 return phone.getDeviceId();
7268 } finally {
7269 Binder.restoreCallingIdentity(identity);
7270 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007271 }
7272
Ping Sunc67b7c22016-03-02 19:16:45 +08007273 /**
7274 * {@hide}
7275 * Returns the IMS Registration Status on a particular subid
7276 *
7277 * @param subId
7278 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007279 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007280 Phone phone = getPhone(subId);
7281 if (phone != null) {
7282 return phone.isImsRegistered();
7283 } else {
7284 return false;
7285 }
7286 }
7287
Santos Cordon7a1885b2015-02-03 11:15:19 -08007288 @Override
7289 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7293 } finally {
7294 Binder.restoreCallingIdentity(identity);
7295 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007296 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007297
Tyler Gunnf70ed162019-04-03 15:28:53 -07007298 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007299 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007300 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007302 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007303 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7304 }
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7308 } finally {
7309 Binder.restoreCallingIdentity(identity);
7310 }
7311 }
7312
7313 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007314 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007315 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7316 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007317 final long identity = Binder.clearCallingIdentity();
7318 try {
7319 Phone phone = getPhone(subscriptionId);
7320 if (phone == null) {
7321 return null;
7322 }
7323 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
7326 }
7327 }
7328
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007329 /**
7330 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007331 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007332 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 Phone phone = getPhone(subId);
7336 if (phone != null) {
7337 return phone.isWifiCallingEnabled();
7338 } else {
7339 return false;
7340 }
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007343 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007344 }
7345
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007346 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007347 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007348 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007349 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 final long identity = Binder.clearCallingIdentity();
7351 try {
7352 Phone phone = getPhone(subId);
7353 if (phone != null) {
7354 return phone.isVideoEnabled();
7355 } else {
7356 return false;
7357 }
7358 } finally {
7359 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007360 }
7361 }
7362
7363 /**
7364 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7365 * defined in {@link ImsRegistrationImplBase}.
7366 */
7367 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 final long identity = Binder.clearCallingIdentity();
7369 try {
7370 Phone phone = getPhone(subId);
7371 if (phone != null) {
7372 return phone.getImsRegistrationTech();
7373 } else {
7374 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7375 }
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007378 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007379 }
7380
Stuart Scott8eef64f2015-04-08 15:13:54 -07007381 @Override
7382 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007383 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007384 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7385 return;
7386 }
7387
Svet Ganovcc087f82015-05-12 20:35:54 -07007388 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007389
Svet Ganovcc087f82015-05-12 20:35:54 -07007390 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007391 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7392 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007393 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007394 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007395 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007396 Phone phone = getPhone(subId);
7397 if (phone != null) {
7398 SubscriptionManager.setSubscriptionProperty(subId,
7399 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7400 "user=" + RadioAccessFamily.getRafFromNetworkType(
7401 RILConstants.PREFERRED_NETWORK_MODE));
7402 phone.loadAllowedNetworksFromSubscriptionDatabase();
7403 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007404 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7405 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007406 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007407 // There has been issues when Sms raw table somehow stores orphan
7408 // fragments. They lead to garbled message when new fragments come
7409 // in and combined with those stale ones. In case this happens again,
7410 // user can reset all network settings which will clean up this table.
7411 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007412 // Clean up IMS settings as well here.
7413 int slotId = getSlotIndex(subId);
7414 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7415 ImsManager.getInstance(mApp, slotId).factoryReset();
7416 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007417
7418 // Erase modem config if erase modem on network setting is enabled.
7419 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7420 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7421 if (configValue != null && Boolean.parseBoolean(configValue)) {
7422 sendEraseModemConfig(getDefaultPhone());
7423 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007424 } finally {
7425 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007426 }
7427 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007428
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007429 private void cleanUpSmsRawTable(Context context) {
7430 ContentResolver resolver = context.getContentResolver();
7431 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7432 resolver.delete(uri, null, null);
7433 }
7434
Narayan Kamath1c496c22015-04-16 14:40:19 +01007435 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007436 public String getSimLocaleForSubscriber(int subId) {
7437 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7438 final Phone phone = getPhone(subId);
7439 if (phone == null) {
7440 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007441 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 final long identity = Binder.clearCallingIdentity();
7444 try {
chen xu5d3637b2019-01-21 23:31:38 -08007445 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007446 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007447 if (info == null) {
7448 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7449 return null;
7450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007451 // Try and fetch the locale from the carrier properties or from the SIM language
7452 // preferences (EF-PL and EF-LI)...
7453 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007455 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7456 if (localeFromDefaultSim != null) {
7457 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7458 if (DBG) log("Using locale from subId: " + subId + " locale: "
7459 + localeFromDefaultSim);
7460 return localeFromDefaultSim.toLanguageTag();
7461 } else {
7462 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 }
7464 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007466 // The SIM language preferences only store a language (e.g. fr = French), not an
7467 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7468 // the SIM and carrier preferences does not include a country we add the country
7469 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007470 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007472 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007473 return mccLocale.toLanguageTag();
7474 }
7475
7476 if (DBG) log("No locale found - returning null");
7477 return null;
7478 } finally {
7479 Binder.restoreCallingIdentity(identity);
7480 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007481 }
7482
7483 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007484 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007485 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007486 }
7487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 /**
7489 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7490 */
7491 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007492 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007493 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007494 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007495
Chenjie Yu1ba97252018-01-11 18:16:20 -08007496 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007497 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007498
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007499 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007500 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7501 * representing the state of the modem.
7502 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007503 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7504 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007505 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007506 */
7507 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007508 public void requestModemActivityInfo(ResultReceiver result) {
7509 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007510 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511
7512 final long identity = Binder.clearCallingIdentity();
7513 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007514 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 } finally {
7516 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007517 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007518 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007519
Siddharth Rayb8114062018-06-17 15:02:38 -07007520 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7521 // less than total activity duration.
7522 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7523 if (info == null) {
7524 return false;
7525 }
7526 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007527 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7528 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7529
Siddharth Rayb8114062018-06-17 15:02:38 -07007530 return (info.isValid()
7531 && (info.getSleepTimeMillis() <= activityDurationMs)
7532 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007533 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007534 && (totalTxTimeMs <= activityDurationMs));
7535 }
7536
Jack Yu85bd38a2015-11-09 11:34:32 -08007537 /**
7538 * {@hide}
7539 * Returns the service state information on specified subscription.
7540 */
7541 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007542 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7543 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007544 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007545 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007546 return null;
7547 }
7548
Hall Liuf19c44f2018-11-27 14:38:17 -08007549 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7550 LocationAccessPolicy.checkLocationPermission(mApp,
7551 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7552 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007553 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007554 .setCallingPid(Binder.getCallingPid())
7555 .setCallingUid(Binder.getCallingUid())
7556 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007557 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007558 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007559 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7560 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007561 .build());
7562
7563 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7564 LocationAccessPolicy.checkLocationPermission(mApp,
7565 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7566 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007567 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007568 .setCallingPid(Binder.getCallingPid())
7569 .setCallingUid(Binder.getCallingUid())
7570 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007571 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007572 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007573 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7574 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007575 .build());
7576 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7577 boolean hasFinePermission =
7578 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7579 boolean hasCoarsePermission =
7580 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7581
Jack Yu479f40e2020-10-27 21:29:25 -07007582 final Phone phone = getPhone(subId);
7583 if (phone == null) {
7584 return null;
7585 }
7586
Jordan Liu0f2bc442020-11-18 16:47:37 -08007587 final long identity = Binder.clearCallingIdentity();
7588
Jack Yu479f40e2020-10-27 21:29:25 -07007589 boolean isCallingPackageDataService = phone.getDataServicePackages()
7590 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007592 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7593 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7594 Rlog.d(LOG_TAG,
7595 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7596 return null;
7597 }
7598
Hall Liuf19c44f2018-11-27 14:38:17 -08007599 ServiceState ss = phone.getServiceState();
7600
7601 // Scrub out the location info in ServiceState depending on what level of access
7602 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007603 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007604 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7605 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606 } finally {
7607 Binder.restoreCallingIdentity(identity);
7608 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007609 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007610
7611 /**
7612 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7613 *
7614 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7615 * voicemail ringtone.
7616 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7617 * PhoneAccount.
7618 */
7619 @Override
7620 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 final long identity = Binder.clearCallingIdentity();
7622 try {
7623 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7624 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007625 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007626 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007628 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7629 } finally {
7630 Binder.restoreCallingIdentity(identity);
7631 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007632 }
7633
7634 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007635 * Sets the per-account voicemail ringtone.
7636 *
7637 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7638 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7639 *
7640 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7641 * voicemail ringtone.
7642 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7643 * PhoneAccount.
7644 */
7645 @Override
7646 public void setVoicemailRingtoneUri(String callingPackage,
7647 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007648 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007649 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007650 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7651 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7653 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7654 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656
7657 final long identity = Binder.clearCallingIdentity();
7658 try {
7659 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7660 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007661 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662 }
7663 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7664 } finally {
7665 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007666 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007667 }
7668
7669 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007670 * Returns whether vibration is set for voicemail notification in Phone settings.
7671 *
7672 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7673 * voicemail vibration setting.
7674 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7675 */
7676 @Override
7677 public boolean isVoicemailVibrationEnabled(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.isVibrationEnabled(phone.getContext());
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
7688 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007689 }
7690
Youhan Wange64578a2016-05-02 15:32:42 -07007691 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007692 * Sets the per-account voicemail vibration.
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 vibration setting.
7699 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7700 * specific PhoneAccount.
7701 */
7702 @Override
7703 public void setVoicemailVibrationEnabled(String callingPackage,
7704 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
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 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007712 }
7713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007714 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.setVibrationEnabled(phone.getContext(), enabled);
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 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007727 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7728 *
7729 * @throws SecurityException if the caller does not have the required permission
7730 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007731 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007732 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007733 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007734 }
7735
7736 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007737 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7738 * permission.
7739 *
7740 * @throws SecurityException if the caller does not have the required permission
7741 */
7742 private void enforceSendSmsPermission() {
7743 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7744 }
7745
7746 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007747 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007748 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007749 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007750 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007751 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752 final long identity = Binder.clearCallingIdentity();
7753 try {
7754 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007755 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756 if (componentName == null) {
7757 throw new SecurityException(
7758 "Caller not current active visual voicemail package[null]");
7759 }
7760 String vvmPackage = componentName.getPackageName();
7761 if (!callingPackage.equals(vvmPackage)) {
7762 throw new SecurityException("Caller not current active visual voicemail package["
7763 + vvmPackage + "]");
7764 }
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007767 }
7768 }
7769
7770 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007771 * Return the application ID for the app type.
7772 *
7773 * @param subId the subscription ID that this request applies to.
7774 * @param appType the uicc app type.
7775 * @return Application ID for specificied app type, or null if no uicc.
7776 */
7777 @Override
7778 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007779 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007780 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007781
7782 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007783 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 if (phone == null) {
7785 return null;
7786 }
7787 String aid = null;
7788 try {
7789 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7790 .getApplicationByType(appType).getAid();
7791 } catch (Exception e) {
7792 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7793 }
7794 return aid;
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007797 }
Youhan Wange64578a2016-05-02 15:32:42 -07007798 }
7799
Youhan Wang4001d252016-05-11 10:29:41 -07007800 /**
7801 * Return the Electronic Serial Number.
7802 *
7803 * @param subId the subscription ID that this request applies to.
7804 * @return ESN or null if error.
7805 */
7806 @Override
7807 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007808 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007809 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810
7811 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007812 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813 if (phone == null) {
7814 return null;
7815 }
7816 String esn = null;
7817 try {
7818 esn = phone.getEsn();
7819 } catch (Exception e) {
7820 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7821 }
7822 return esn;
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007825 }
Youhan Wang4001d252016-05-11 10:29:41 -07007826 }
7827
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007828 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007829 * Return the Preferred Roaming List Version.
7830 *
7831 * @param subId the subscription ID that this request applies to.
7832 * @return PRLVersion or null if error.
7833 */
7834 @Override
7835 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007836 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007837 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007838
7839 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007840 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007841 if (phone == null) {
7842 return null;
7843 }
7844 String cdmaPrlVersion = null;
7845 try {
7846 cdmaPrlVersion = phone.getCdmaPrlVersion();
7847 } catch (Exception e) {
7848 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7849 }
7850 return cdmaPrlVersion;
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007853 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007854 }
7855
7856 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007857 * Get snapshot of Telephony histograms
7858 * @return List of Telephony histograms
7859 * @hide
7860 */
7861 @Override
7862 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7864 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865
7866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 return RIL.getTelephonyRILTimingHistograms();
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
7871 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007872 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007873
7874 /**
7875 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007876 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7877 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007878 * Require system privileges. In the future we may add this to carrier APIs.
7879 *
Michele Berionne482f8202018-11-27 18:57:59 -08007880 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007881 */
7882 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007883 @TelephonyManager.SetCarrierRestrictionResult
7884 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007885 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007886 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007887
Michele Berionne482f8202018-11-27 18:57:59 -08007888 if (carrierRestrictionRules == null) {
7889 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007890 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007892 final long identity = Binder.clearCallingIdentity();
7893 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007894 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007895 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896 } finally {
7897 Binder.restoreCallingIdentity(identity);
7898 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007899 }
7900
7901 /**
7902 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007903 * Get the allowed carrier list and the excluded carrier list, including the priority between
7904 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007905 * Require system privileges. In the future we may add this to carrier APIs.
7906 *
Michele Berionne482f8202018-11-27 18:57:59 -08007907 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007908 */
7909 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007910 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007911 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007912 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007913
7914 final long identity = Binder.clearCallingIdentity();
7915 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007916 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7917 if (response instanceof CarrierRestrictionRules) {
7918 return (CarrierRestrictionRules) response;
7919 }
7920 // Response is an Exception of some kind,
7921 // which is signalled to the user as a NULL retval
7922 return null;
7923 } catch (Exception e) {
7924 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7925 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 } finally {
7927 Binder.restoreCallingIdentity(identity);
7928 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007929 }
7930
fionaxu59545b42016-05-25 15:53:37 -07007931 /**
fionaxu59545b42016-05-25 15:53:37 -07007932 * Action set from carrier signalling broadcast receivers to enable/disable radio
7933 * @param subId the subscription ID that this action applies to.
7934 * @param enabled control enable or disable radio.
7935 * {@hide}
7936 */
7937 @Override
7938 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7939 enforceModifyPermission();
7940 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941
7942 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007943 if (phone == null) {
7944 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7945 return;
7946 }
7947 try {
7948 phone.carrierActionSetRadioEnabled(enabled);
7949 } catch (Exception e) {
7950 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 } finally {
7952 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007953 }
7954 }
7955
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007956 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007957 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7958 * network status based on which carrier apps could apply actions accordingly,
7959 * enable/disable default url handler for example.
7960 *
7961 * @param subId the subscription ID that this action applies to.
7962 * @param report control start/stop reporting the default network status.
7963 * {@hide}
7964 */
7965 @Override
7966 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7967 enforceModifyPermission();
7968 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969
7970 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007971 if (phone == null) {
7972 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7973 return;
7974 }
7975 try {
7976 phone.carrierActionReportDefaultNetworkStatus(report);
7977 } catch (Exception e) {
7978 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007979 } finally {
7980 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007981 }
7982 }
7983
7984 /**
fionaxud9622282017-07-17 17:51:30 -07007985 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7986 * @param subId the subscription ID that this action applies to.
7987 * {@hide}
7988 */
7989 @Override
7990 public void carrierActionResetAll(int subId) {
7991 enforceModifyPermission();
7992 final Phone phone = getPhone(subId);
7993 if (phone == null) {
7994 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7995 return;
7996 }
7997 try {
7998 phone.carrierActionResetAll();
7999 } catch (Exception e) {
8000 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8001 }
8002 }
8003
8004 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008005 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8006 * bug report is being generated.
8007 */
8008 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008009 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008010 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8011 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008012 writer.println("Permission Denial: can't dump Phone from pid="
8013 + Binder.getCallingPid()
8014 + ", uid=" + Binder.getCallingUid()
8015 + "without permission "
8016 + android.Manifest.permission.DUMP);
8017 return;
8018 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008019 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008020 }
Jack Yueb89b242016-06-22 13:27:47 -07008021
Brad Ebingerdac2f002018-04-03 15:17:52 -07008022 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008023 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8024 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8025 @NonNull String[] args) {
8026 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8027 this, in.getFileDescriptor(), out.getFileDescriptor(),
8028 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008029 }
8030
Jack Yueb89b242016-06-22 13:27:47 -07008031 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008032 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008033 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008034 * @param reason the reason the data enable change is taking place
8035 * @param enabled True if enabling the data, otherwise disabling.
8036 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008037 */
8038 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008039 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008040 boolean enabled) {
8041 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8042 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8043 try {
8044 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008045 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008046 } catch (SecurityException se) {
8047 enforceModifyPermission();
8048 }
8049 } else {
8050 enforceModifyPermission();
8051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052
8053 final long identity = Binder.clearCallingIdentity();
8054 try {
8055 Phone phone = getPhone(subId);
8056 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008057 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8058 phone.carrierActionSetMeteredApnsEnabled(enabled);
8059 } else {
8060 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008062 }
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008065 }
8066 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008067
8068 /**
8069 * Get Client request stats
8070 * @return List of Client Request Stats
8071 * @hide
8072 */
8073 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008074 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8075 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008076 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008077 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008078 return null;
8079 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008080 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008082 final long identity = Binder.clearCallingIdentity();
8083 try {
8084 if (phone != null) {
8085 return phone.getClientRequestStats();
8086 }
8087
8088 return null;
8089 } finally {
8090 Binder.restoreCallingIdentity(identity);
8091 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008092 }
8093
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008094 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008095 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008096 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008097 }
Jack Yueb4124c2017-02-16 15:32:43 -08008098
8099 /**
Grace Chen70990072017-03-24 17:21:30 -07008100 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008101 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008102 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008103 * @param state State of SIM (power down, power up, pass through)
8104 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8105 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8106 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008107 *
8108 **/
8109 @Override
Grace Chen70990072017-03-24 17:21:30 -07008110 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008111 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008112 Phone phone = PhoneFactory.getPhone(slotIndex);
8113
vagdeviaf9a5b92018-08-15 16:01:53 -07008114 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8115
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008116 final long identity = Binder.clearCallingIdentity();
8117 try {
8118 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008119 phone.setSimPowerState(state, null, workSource);
8120 }
8121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
8124 }
8125
8126 /**
8127 * Set SIM card power state.
8128 *
8129 * @param slotIndex SIM slot id.
8130 * @param state State of SIM (power down, power up, pass through)
8131 * @param callback callback to trigger after success or failure
8132 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8133 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8134 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8135 *
8136 **/
8137 @Override
8138 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8139 IIntegerConsumer callback) {
8140 enforceModifyPermission();
8141 Phone phone = PhoneFactory.getPhone(slotIndex);
8142
8143 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8144
8145 final long identity = Binder.clearCallingIdentity();
8146 try {
8147 if (phone != null) {
8148 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8149 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008150 }
8151 } finally {
8152 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008153 }
8154 }
Shuo Qiandd210312017-04-12 22:11:33 +00008155
Tyler Gunn65d45c22017-06-05 11:22:26 -07008156 private boolean isUssdApiAllowed(int subId) {
8157 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008158 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008159 if (configManager == null) {
8160 return false;
8161 }
8162 PersistableBundle pb = configManager.getConfigForSubId(subId);
8163 if (pb == null) {
8164 return false;
8165 }
8166 return pb.getBoolean(
8167 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8168 }
8169
Shuo Qiandd210312017-04-12 22:11:33 +00008170 /**
8171 * Check if phone is in emergency callback mode
8172 * @return true if phone is in emergency callback mode
8173 * @param subId sub id
8174 */
goneil9c5f4872017-12-05 14:07:56 -08008175 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008176 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008177 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008178 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008179
8180 final long identity = Binder.clearCallingIdentity();
8181 try {
8182 if (phone != null) {
8183 return phone.isInEcm();
8184 } else {
8185 return false;
8186 }
8187 } finally {
8188 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008189 }
8190 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008191
8192 /**
8193 * Get the current signal strength information for the given subscription.
8194 * Because this information is not updated when the device is in a low power state
8195 * it should not be relied-upon to be current.
8196 * @param subId Subscription index
8197 * @return the most recent cached signal strength info from the modem
8198 */
8199 @Override
8200 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008201 final long identity = Binder.clearCallingIdentity();
8202 try {
8203 Phone p = getPhone(subId);
8204 if (p == null) {
8205 return null;
8206 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 return p.getSignalStrength();
8209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008212 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008213
Pengquan Meng77b7f132018-08-22 14:49:57 -07008214 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008215 * Get the current modem radio state for the given slot.
8216 * @param slotIndex slot index.
8217 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008218 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008219 * @return the current radio power state from the modem
8220 */
8221 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008222 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008223 Phone phone = PhoneFactory.getPhone(slotIndex);
8224 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8226 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008227 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8228 }
8229
8230 final long identity = Binder.clearCallingIdentity();
8231 try {
8232 return phone.getRadioPowerState();
8233 } finally {
8234 Binder.restoreCallingIdentity(identity);
8235 }
8236 }
8237 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8238 }
8239
8240 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008241 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8242 *
8243 * <p>Requires one of the following permissions:
8244 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8245 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8246 * privileges.
8247 *
8248 * @param subId subscription id
8249 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8250 * {@code false}.
8251 */
8252 @Override
8253 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008254 try {
8255 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8256 null);
8257 } catch (Exception e) {
8258 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8259 mApp, subId, "isDataRoamingEnabled");
8260 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008261
Pengquan Menga1bb6272018-09-06 09:59:22 -07008262 boolean isEnabled = false;
8263 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008264 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008265 Phone phone = getPhone(subId);
8266 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008267 } finally {
8268 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008269 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008270 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008271 }
8272
8273
8274 /**
8275 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8276 *
8277 * <p> Requires permission:
8278 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8279 * privileges.
8280 *
8281 * @param subId subscription id
8282 * @param isEnabled {@code true} means enable, {@code false} means disable.
8283 */
8284 @Override
8285 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8287 mApp, subId, "setDataRoamingEnabled");
8288
Pengquan Menga1bb6272018-09-06 09:59:22 -07008289 final long identity = Binder.clearCallingIdentity();
8290 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008291 Phone phone = getPhone(subId);
8292 if (phone != null) {
8293 phone.setDataRoamingEnabled(isEnabled);
8294 }
8295 } finally {
8296 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008297 }
8298 }
8299
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008300 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008301 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008302 TelephonyPermissions
8303 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008304 mApp, subId, "isManualNetworkSelectionAllowed");
8305
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008306 boolean isAllowed = true;
8307 final long identity = Binder.clearCallingIdentity();
8308 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008309 Phone phone = getPhone(subId);
8310 if (phone != null) {
8311 isAllowed = phone.isCspPlmnEnabled();
8312 }
8313 } finally {
8314 Binder.restoreCallingIdentity(identity);
8315 }
8316 return isAllowed;
8317 }
8318
8319 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008320 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008321 // Verify that tha callingPackage belongs to the calling UID
8322 mApp.getSystemService(AppOpsManager.class)
8323 .checkPackage(Binder.getCallingUid(), callingPackage);
8324
Jordan Liu1e142fc2019-04-22 15:10:43 -07008325 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008326 try {
8327 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008328 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008329 } catch (SecurityException e) {
8330 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8331 // has carrier privileges on an active UICC
8332 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8333 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008334 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008335 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008336 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008337
8338 final long identity = Binder.clearCallingIdentity();
8339 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008340 UiccController uiccController = UiccController.getInstance();
8341 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008342 if (hasReadPermission) {
8343 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008344 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008345
8346 // Remove private info if the caller doesn't have access
8347 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8348 for (UiccCardInfo cardInfo : cardInfos) {
8349 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8350 // is available
8351 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8352 if (card == null || card.getUiccProfile() == null) {
8353 // assume no access if the card or profile is unavailable
8354 filteredInfos.add(cardInfo.getUnprivileged());
8355 continue;
8356 }
8357 UiccProfile profile = card.getUiccProfile();
8358 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8359 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8360 filteredInfos.add(cardInfo);
8361 } else {
8362 filteredInfos.add(cardInfo.getUnprivileged());
8363 }
8364 }
8365 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008366 } finally {
8367 Binder.restoreCallingIdentity(identity);
8368 }
8369 }
8370
8371 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008372 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008373 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375 final long identity = Binder.clearCallingIdentity();
8376 try {
8377 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8378 if (slots == null) {
8379 Rlog.i(LOG_TAG, "slots is null.");
8380 return null;
8381 }
8382
8383 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8384 for (int i = 0; i < slots.length; i++) {
8385 UiccSlot slot = slots[i];
8386 if (slot == null) {
8387 continue;
8388 }
8389
Jordan Liu7be7e652019-05-06 18:55:02 +00008390 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 UiccCard card = slot.getUiccCard();
8392 if (card != null) {
8393 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008394 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008395 cardId = slot.getEid();
8396 if (TextUtils.isEmpty(cardId)) {
8397 cardId = slot.getIccId();
8398 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008399 }
8400
Jordan Liu857451f2019-05-09 16:35:35 -07008401 if (cardId != null) {
8402 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8403 // if cardId is an EID, it's all digits so this is fine
8404 cardId = IccUtils.stripTrailingFs(cardId);
8405 }
8406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008407 int cardState = 0;
8408 switch (slot.getCardState()) {
8409 case CARDSTATE_ABSENT:
8410 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8411 break;
8412 case CARDSTATE_PRESENT:
8413 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8414 break;
8415 case CARDSTATE_ERROR:
8416 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8417 break;
8418 case CARDSTATE_RESTRICTED:
8419 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8420 break;
8421 default:
8422 break;
8423
8424 }
8425
8426 infos[i] = new UiccSlotInfo(
8427 slot.isActive(),
8428 slot.isEuicc(),
8429 cardId,
8430 cardState,
8431 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008432 slot.isExtendedApduSupported(),
8433 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008434 }
8435 return infos;
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008438 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008439 }
8440
8441 @Override
8442 public boolean switchSlots(int[] physicalSlots) {
8443 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444
8445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8448 } finally {
8449 Binder.restoreCallingIdentity(identity);
8450 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008451 }
Jack Yu4c988042018-02-27 15:30:01 -08008452
8453 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008454 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008455 final long identity = Binder.clearCallingIdentity();
8456 try {
8457 return UiccController.getInstance().getCardIdForDefaultEuicc();
8458 } finally {
8459 Binder.restoreCallingIdentity(identity);
8460 }
8461 }
8462
Pengquan Meng85728fb2018-03-12 16:31:21 -07008463 /**
goneil47ffb6e2018-04-06 15:40:58 -07008464 * A test API to reload the UICC profile.
8465 *
8466 * <p>Requires that the calling app has permission
8467 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8468 * @hide
8469 */
8470 @Override
8471 public void refreshUiccProfile(int subId) {
8472 enforceModifyPermission();
8473
8474 final long identity = Binder.clearCallingIdentity();
8475 try {
8476 Phone phone = getPhone(subId);
8477 if (phone == null) {
8478 return;
8479 }
8480 UiccCard uiccCard = phone.getUiccCard();
8481 if (uiccCard == null) {
8482 return;
8483 }
8484 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8485 if (uiccProfile == null) {
8486 return;
8487 }
8488 uiccProfile.refresh();
8489 } finally {
8490 Binder.restoreCallingIdentity(identity);
8491 }
8492 }
8493
8494 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008495 * Returns false if the mobile data is disabled by default, otherwise return true.
8496 */
8497 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008498 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008499 }
8500
8501 /**
8502 * Returns true if the data roaming is enabled by default, i.e the system property
8503 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8504 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8505 */
8506 private boolean getDefaultDataRoamingEnabled(int subId) {
8507 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008508 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008509 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008510 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8511 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8512 return isDataRoamingEnabled;
8513 }
8514
8515 /**
8516 * Returns the default network type for the given {@code subId}, if the default network type is
8517 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8518 */
8519 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008520 List<Integer> list = TelephonyProperties.default_network();
8521 int phoneId = mSubscriptionController.getPhoneId(subId);
8522 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8523 return list.get(phoneId);
8524 }
8525 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008526 }
fionaxua13278b2018-03-21 00:08:13 -07008527
8528 @Override
8529 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008530 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008532
8533 final long identity = Binder.clearCallingIdentity();
8534 try {
8535 final Phone phone = getPhone(subId);
8536 if (phone == null) {
8537 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8538 return;
8539 }
chen xueaba88a2019-03-15 13:15:10 -07008540 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8541 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008542 if (carrierPrivilegeRules == null) {
8543 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8544 } else {
8545 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8546 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008547 } finally {
8548 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008549 }
fionaxua13278b2018-03-21 00:08:13 -07008550 }
8551
8552 @Override
8553 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008554 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008555
8556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 final Phone phone = getPhone(subId);
8559 if (phone == null) {
8560 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8561 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8562 }
8563 return phone.getCarrierIdListVersion();
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008566 }
fionaxua13278b2018-03-21 00:08:13 -07008567 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008568
8569 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008570 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8571 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008572 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008573 mApp, subId, callingPackage, callingFeatureId,
8574 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008575 return -1;
8576 }
8577
8578 final long identity = Binder.clearCallingIdentity();
8579 try {
8580 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
8584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008585
8586 @Override
8587 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008588 TelephonyPermissions
8589 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008590 mApp, subId, "getCdmaRoamingMode");
8591
8592 final long identity = Binder.clearCallingIdentity();
8593 try {
8594 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8595 } finally {
8596 Binder.restoreCallingIdentity(identity);
8597 }
8598 }
8599
8600 @Override
8601 public boolean setCdmaRoamingMode(int subId, int mode) {
8602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8603 mApp, subId, "setCdmaRoamingMode");
8604
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
8611 }
8612
8613 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008614 public int getCdmaSubscriptionMode(int subId) {
8615 TelephonyPermissions
8616 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8617 mApp, subId, "getCdmaSubscriptionMode");
8618
8619 final long identity = Binder.clearCallingIdentity();
8620 try {
8621 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8622 } finally {
8623 Binder.restoreCallingIdentity(identity);
8624 }
8625 }
8626
8627 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008628 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8629 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8630 mApp, subId, "setCdmaSubscriptionMode");
8631
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8635 } finally {
8636 Binder.restoreCallingIdentity(identity);
8637 }
8638 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008639
sqianc5eccab2018-10-19 18:46:41 -07008640 @Override
sqian8c685422019-02-22 15:55:18 -08008641 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008642 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008643 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008644 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8645 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008646 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8647 }
8648 final long identity = Binder.clearCallingIdentity();
8649 try {
sqian854d44b2018-12-12 16:48:18 -08008650 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8651 for (Phone phone: PhoneFactory.getPhones()) {
8652 if (phone.getEmergencyNumberTracker() != null
8653 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8654 emergencyNumberListInternal.put(
8655 phone.getSubId(),
8656 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8657 }
sqian11b7a0e2018-12-05 18:48:28 -08008658 }
sqian854d44b2018-12-12 16:48:18 -08008659 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008660 } finally {
8661 Binder.restoreCallingIdentity(identity);
8662 }
sqianc5eccab2018-10-19 18:46:41 -07008663 }
8664
8665 @Override
sqian8c685422019-02-22 15:55:18 -08008666 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008667 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008668 if (!exactMatch) {
8669 TelephonyPermissions
8670 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008671 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008672 }
8673 final long identity = Binder.clearCallingIdentity();
8674 try {
sqian854d44b2018-12-12 16:48:18 -08008675 for (Phone phone: PhoneFactory.getPhones()) {
8676 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008677 && phone.getEmergencyNumberTracker()
8678 .isEmergencyNumber(number, exactMatch)) {
8679 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008680 }
sqian11b7a0e2018-12-05 18:48:28 -08008681 }
8682 return false;
8683 } finally {
8684 Binder.restoreCallingIdentity(identity);
8685 }
8686 }
8687
sqianf4ca7ed2019-01-15 18:32:07 -08008688 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008689 * Start emergency callback mode for GsmCdmaPhone for testing.
8690 */
8691 @Override
8692 public void startEmergencyCallbackMode() {
8693 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8694 "startEmergencyCallbackMode");
8695 enforceModifyPermission();
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
8698 for (Phone phone : PhoneFactory.getPhones()) {
8699 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8700 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8701 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8702 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8703 gsmCdmaPhone.obtainMessage(
8704 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8705 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8706 }
8707 }
8708 } finally {
8709 Binder.restoreCallingIdentity(identity);
8710 }
8711 }
8712
8713 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008714 * Update emergency number list for test mode.
8715 */
8716 @Override
8717 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8718 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8719 "updateEmergencyNumberListTestMode");
8720
8721 final long identity = Binder.clearCallingIdentity();
8722 try {
8723 for (Phone phone: PhoneFactory.getPhones()) {
8724 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8725 if (tracker != null) {
8726 tracker.executeEmergencyNumberTestModeCommand(action, num);
8727 }
8728 }
8729 } finally {
8730 Binder.restoreCallingIdentity(identity);
8731 }
8732 }
8733
8734 /**
8735 * Get the full emergency number list for test mode.
8736 */
8737 @Override
8738 public List<String> getEmergencyNumberListTestMode() {
8739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8740 "getEmergencyNumberListTestMode");
8741
8742 final long identity = Binder.clearCallingIdentity();
8743 try {
8744 Set<String> emergencyNumbers = new HashSet<>();
8745 for (Phone phone: PhoneFactory.getPhones()) {
8746 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8747 if (tracker != null) {
8748 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8749 emergencyNumbers.add(num.getNumber());
8750 }
8751 }
8752 }
8753 return new ArrayList<>(emergencyNumbers);
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
8758
chen xud6b45bd2018-10-30 22:27:10 -07008759 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008760 public int getEmergencyNumberDbVersion(int subId) {
8761 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8762
8763 final long identity = Binder.clearCallingIdentity();
8764 try {
8765 final Phone phone = getPhone(subId);
8766 if (phone == null) {
8767 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8768 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8769 }
8770 return phone.getEmergencyNumberDbVersion();
8771 } finally {
8772 Binder.restoreCallingIdentity(identity);
8773 }
8774 }
8775
8776 @Override
8777 public void notifyOtaEmergencyNumberDbInstalled() {
8778 enforceModifyPermission();
8779
8780 final long identity = Binder.clearCallingIdentity();
8781 try {
8782 for (Phone phone: PhoneFactory.getPhones()) {
8783 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8784 if (tracker != null) {
8785 tracker.updateOtaEmergencyNumberDatabase();
8786 }
8787 }
8788 } finally {
8789 Binder.restoreCallingIdentity(identity);
8790 }
8791 }
8792
8793 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008794 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008795 enforceActiveEmergencySessionPermission();
8796
8797 final long identity = Binder.clearCallingIdentity();
8798 try {
8799 for (Phone phone: PhoneFactory.getPhones()) {
8800 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8801 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008802 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8803 }
8804 }
8805 } finally {
8806 Binder.restoreCallingIdentity(identity);
8807 }
8808 }
8809
8810 @Override
8811 public void resetOtaEmergencyNumberDbFilePath() {
8812 enforceActiveEmergencySessionPermission();
8813
8814 final long identity = Binder.clearCallingIdentity();
8815 try {
8816 for (Phone phone: PhoneFactory.getPhones()) {
8817 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8818 if (tracker != null) {
8819 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008820 }
8821 }
8822 } finally {
8823 Binder.restoreCallingIdentity(identity);
8824 }
8825 }
8826
8827 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008828 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8829 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8830 Phone phone = getPhone(subId);
8831 if (phone == null) {
8832 return null;
8833 }
8834 final long identity = Binder.clearCallingIdentity();
8835 try {
8836 UiccProfile profile = UiccController.getInstance()
8837 .getUiccProfileForPhone(phone.getPhoneId());
8838 if (profile != null) {
8839 return profile.getCertsFromCarrierPrivilegeAccessRules();
8840 }
8841 } finally {
8842 Binder.restoreCallingIdentity(identity);
8843 }
8844 return null;
8845 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008846
8847 /**
8848 * Enable or disable a modem stack.
8849 */
8850 @Override
8851 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8852 enforceModifyPermission();
8853
8854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 Phone phone = PhoneFactory.getPhone(slotIndex);
8857 if (phone == null) {
8858 return false;
8859 } else {
8860 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8861 }
8862 } finally {
8863 Binder.restoreCallingIdentity(identity);
8864 }
8865 }
Michelecea4cf22018-12-21 15:00:11 -08008866
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008867 /**
8868 * Whether a modem stack is enabled or not.
8869 */
8870 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008871 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8872 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008873 Phone phone = PhoneFactory.getPhone(slotIndex);
8874 if (phone == null) return false;
8875
8876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008877 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8878 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008879 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8880 }
8881
8882 final long identity = Binder.clearCallingIdentity();
8883 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008884 try {
8885 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8886 } catch (NoSuchElementException ex) {
8887 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8888 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008889 } finally {
8890 Binder.restoreCallingIdentity(identity);
8891 }
8892 }
8893
Michelecea4cf22018-12-21 15:00:11 -08008894 @Override
Michele0ea7d782019-03-19 14:58:42 -07008895 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008896 enforceModifyPermission();
8897
8898 final long identity = Binder.clearCallingIdentity();
8899 try {
8900 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008901 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008902 .commit();
8903 } finally {
8904 Binder.restoreCallingIdentity(identity);
8905 }
8906 }
8907
8908 @Override
Michele0ea7d782019-03-19 14:58:42 -07008909 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008910 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008911 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008912 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8913 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008914 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008915 }
Michelecea4cf22018-12-21 15:00:11 -08008916
8917 final long identity = Binder.clearCallingIdentity();
8918 try {
Michele0ea7d782019-03-19 14:58:42 -07008919 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008920 } finally {
8921 Binder.restoreCallingIdentity(identity);
8922 }
8923 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008924
Michele0ea7d782019-03-19 14:58:42 -07008925 @TelephonyManager.IsMultiSimSupportedResult
8926 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008927 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8928 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8929 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008930 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8931 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008932 }
8933 // Check if the hardware supports multisim functionality. If usage of multisim is not
8934 // supported by the modem, indicate that it is restricted.
8935 PhoneCapability staticCapability =
8936 mPhoneConfigurationManager.getStaticPhoneCapability();
8937 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008938 loge("isMultiSimSupportedInternal: no static configuration available");
8939 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008940 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008941 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008942 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8943 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008944 }
8945 // Check if support of multiple SIMs is restricted by carrier
8946 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008947 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008948 }
8949
Michele0ea7d782019-03-19 14:58:42 -07008950 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008951 }
8952
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008953 /**
8954 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008955 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8956 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8957 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008958 * @param numOfSims number of active sims we want to switch to
8959 */
8960 @Override
8961 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008962 if (numOfSims == 1) {
8963 enforceModifyPermission();
8964 } else {
8965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8966 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8967 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008968 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008969
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008970 try {
Michele30b57b22019-03-01 12:01:14 -08008971 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008972 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008973 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8974 return;
8975 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008976 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8977 } finally {
8978 Binder.restoreCallingIdentity(identity);
8979 }
8980 }
8981
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008982 @Override
8983 public boolean isApplicationOnUicc(int subId, int appType) {
8984 enforceReadPrivilegedPermission("isApplicationOnUicc");
8985 Phone phone = getPhone(subId);
8986 if (phone == null) {
8987 return false;
8988 }
8989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 UiccCard uiccCard = phone.getUiccCard();
8992 if (uiccCard == null) {
8993 return false;
8994 }
8995 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8996 if (uiccProfile == null) {
8997 return false;
8998 }
8999 if (TelephonyManager.APPTYPE_SIM <= appType
9000 && appType <= TelephonyManager.APPTYPE_ISIM) {
9001 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9002 }
9003 return false;
9004 } finally {
9005 Binder.restoreCallingIdentity(identity);
9006 }
9007 }
9008
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009009 /**
chen xub4baa772019-04-03 10:23:41 -07009010 * Get whether making changes to modem configurations will trigger reboot.
9011 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009012 */
9013 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009014 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9015 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009017 mApp, subId, callingPackage, callingFeatureId,
9018 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009019 return false;
9020 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009021 final long identity = Binder.clearCallingIdentity();
9022 try {
9023 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9024 } finally {
9025 Binder.restoreCallingIdentity(identity);
9026 }
9027 }
9028
Nathan Harold29f5f052019-02-15 13:41:57 -08009029 private void updateModemStateMetrics() {
9030 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9031 // TODO: check the state for each modem if the api is ready.
9032 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9033 }
9034
Pengquan Meng3889a572019-01-23 11:16:29 -08009035 @Override
9036 public int[] getSlotsMapping() {
9037 enforceReadPrivilegedPermission("getSlotsMapping");
9038
9039 final long identity = Binder.clearCallingIdentity();
9040 try {
9041 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9042 // All logical slots should have a mapping to a physical slot.
9043 int[] logicalSlotsMapping = new int[phoneCount];
9044 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9045 for (int i = 0; i < slotInfos.length; i++) {
9046 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9047 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9048 }
9049 }
9050 return logicalSlotsMapping;
9051 } finally {
9052 Binder.restoreCallingIdentity(identity);
9053 }
9054 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009055
9056 /**
9057 * Get the IRadio HAL Version
9058 */
9059 @Override
9060 public int getRadioHalVersion() {
9061 Phone phone = getDefaultPhone();
9062 if (phone == null) return -1;
9063 HalVersion hv = phone.getHalVersion();
9064 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9065 return hv.major * 100 + hv.minor;
9066 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009067
9068 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009069 * Get the current calling package name.
9070 * @return the current calling package name
9071 */
9072 @Override
9073 public String getCurrentPackageName() {
9074 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9075 }
9076
9077 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009078 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9079 * corresponding network requests on a subId.
9080 *
9081 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009082 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009083 * 2) APN is un-metered for this subscription, or
9084 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009085 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009086 *
9087 * @return whether data is allowed for a apn type.
9088 *
9089 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009090 */
9091 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009092 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009093 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9094 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009095
9096 // Now that all security checks passes, perform the operation as ourselves.
9097 final long identity = Binder.clearCallingIdentity();
9098 try {
9099 Phone phone = getPhone(subId);
9100 if (phone == null) return false;
9101
Jack Yu41407ee2019-05-13 16:54:09 -07009102 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009103 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9104 } finally {
9105 Binder.restoreCallingIdentity(identity);
9106 }
9107 }
9108
9109 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009110 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009111 enforceReadPrivilegedPermission("isApnMetered");
9112
9113 // Now that all security checks passes, perform the operation as ourselves.
9114 final long identity = Binder.clearCallingIdentity();
9115 try {
9116 Phone phone = getPhone(subId);
9117 if (phone == null) return true; // By default return true.
9118
Jack Yu41407ee2019-05-13 16:54:09 -07009119 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009120 } finally {
9121 Binder.restoreCallingIdentity(identity);
9122 }
9123 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009124
9125 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009126 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9127 int subscriptionId, IBooleanConsumer resultCallback) {
9128 enforceModifyPermission();
9129 long token = Binder.clearCallingIdentity();
9130 try {
9131 Phone phone = getPhone(subscriptionId);
9132 if (phone == null) {
9133 try {
9134 if (resultCallback != null) {
9135 resultCallback.accept(false);
9136 }
9137 } catch (RemoteException e) {
9138 // ignore
9139 }
9140 return;
9141 }
9142 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9143 Pair.create(specifiers, (x) -> {
9144 try {
9145 if (resultCallback != null) {
9146 resultCallback.accept(x);
9147 }
9148 } catch (RemoteException e) {
9149 // ignore
9150 }
9151 });
9152 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9153 } finally {
9154 Binder.restoreCallingIdentity(token);
9155 }
9156 }
9157
9158 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009159 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9160 TelephonyPermissions
9161 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9162 mApp, subId, "getSystemSelectionChannels");
9163 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9164 final long identity = Binder.clearCallingIdentity();
9165 try {
9166 List<RadioAccessSpecifier> specifiers =
9167 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9168 null, subId, workSource);
9169 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9170 return specifiers;
9171 } finally {
9172 Binder.restoreCallingIdentity(identity);
9173 }
9174 }
9175
9176 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009177 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009178 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009179 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9180 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9181 if (iccRecords == null) {
9182 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9183 return false;
9184 }
9185 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9186 }
9187
9188 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009189 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9190 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009191 if (callingPackage == null) {
9192 callingPackage = getCurrentPackageName();
9193 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009194 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9195 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009196 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9197 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009198 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9199 }
9200 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9201 Intent intent = new Intent();
9202 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9203 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9204 // Bring up choose default SMS subscription dialog right now
9205 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9206 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9207 mApp.startActivity(intent);
9208 }
chen xud5ca2d52019-05-28 15:20:57 -07009209
9210 @Override
9211 public String getMmsUAProfUrl(int subId) {
9212 //TODO investigate if this API should require proper permission check in R b/133791609
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009215 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9216 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9217 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9218 return carrierUAProfUrl;
9219 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009220 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9221 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009222 } finally {
9223 Binder.restoreCallingIdentity(identity);
9224 }
9225 }
9226
9227 @Override
9228 public String getMmsUserAgent(int subId) {
9229 //TODO investigate if this API should require proper permission check in R b/133791609
9230 final long identity = Binder.clearCallingIdentity();
9231 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009232 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9233 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9234 if (!TextUtils.isEmpty(carrierUserAgent)) {
9235 return carrierUserAgent;
9236 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009237 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9238 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009239 } finally {
9240 Binder.restoreCallingIdentity(identity);
9241 }
9242 }
Jack Yub07d4972019-05-28 16:12:25 -07009243
9244 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009245 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9246 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009247
Jack Yub07d4972019-05-28 16:12:25 -07009248 final long identity = Binder.clearCallingIdentity();
9249 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009250 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009251 if (phone == null) return false;
9252
Hall Liua62f5da2020-09-25 10:42:19 -07009253 switch (policy) {
9254 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9255 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9256 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9257 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9258 default:
9259 throw new IllegalArgumentException(policy + " is not a valid policy");
9260 }
Jack Yub07d4972019-05-28 16:12:25 -07009261 } finally {
9262 Binder.restoreCallingIdentity(identity);
9263 }
9264 }
9265
9266 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009267 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009268 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009269 enforceModifyPermission();
9270
changbettyd5c246e2019-12-24 15:40:37 +08009271 final long identity = Binder.clearCallingIdentity();
9272 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009273 Phone phone = getPhone(subscriptionId);
9274 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009275
Hall Liua62f5da2020-09-25 10:42:19 -07009276 switch (policy) {
9277 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9278 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9279 break;
9280 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9281 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9282 break;
9283 default:
9284 throw new IllegalArgumentException(policy + " is not a valid policy");
9285 }
changbettyd5c246e2019-12-24 15:40:37 +08009286 } finally {
9287 Binder.restoreCallingIdentity(identity);
9288 }
9289 }
9290
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009291 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009292 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009293 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9294 * otherwise.
9295 */
9296 @Override
9297 public void setCepEnabled(boolean isCepEnabled) {
9298 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9299
9300 final long identity = Binder.clearCallingIdentity();
9301 try {
9302 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9303 for (Phone phone : PhoneFactory.getPhones()) {
9304 Phone defaultPhone = phone.getImsPhone();
9305 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9306 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9307 ImsPhoneCallTracker imsPhoneCallTracker =
9308 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9309 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9310 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9311 + imsPhone.getMsisdn());
9312 }
9313 }
9314 } finally {
9315 Binder.restoreCallingIdentity(identity);
9316 }
9317 }
allenwtsu46dcc572020-01-08 18:24:03 +08009318
9319 /**
9320 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9321 *
9322 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9323 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9324 * before being read.
9325 */
9326 @Override
9327 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9328 isCompressed) {
9329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9330 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009331 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9332 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9333 }
9334 if (!isImsAvailableOnDevice()) {
9335 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9336 "IMS not available on device.");
9337 }
9338
9339 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009340 try {
Hui Wang761a6682020-10-31 05:12:53 +00009341 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9342 } finally {
9343 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009344 }
9345 }
zoey chene02881a2019-12-30 16:11:23 +08009346
9347 @Override
9348 public boolean isIccLockEnabled(int subId) {
9349 enforceReadPrivilegedPermission("isIccLockEnabled");
9350
9351 // Now that all security checks passes, perform the operation as ourselves.
9352 final long identity = Binder.clearCallingIdentity();
9353 try {
9354 Phone phone = getPhone(subId);
9355 if (phone != null && phone.getIccCard() != null) {
9356 return phone.getIccCard().getIccLockEnabled();
9357 } else {
9358 return false;
9359 }
9360 } finally {
9361 Binder.restoreCallingIdentity(identity);
9362 }
9363 }
9364
9365 /**
9366 * Set the ICC pin lock enabled or disabled.
9367 *
9368 * @return an integer representing the status of IccLock enabled or disabled in the following
9369 * three cases:
9370 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9371 * successfully.
9372 * - Positive number and zero for remaining password attempts.
9373 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9374 *
9375 */
9376 @Override
9377 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9378 enforceModifyPermission();
9379
9380 Phone phone = getPhone(subId);
9381 if (phone == null) {
9382 return 0;
9383 }
9384 // Now that all security checks passes, perform the operation as ourselves.
9385 final long identity = Binder.clearCallingIdentity();
9386 try {
9387 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9388 new Pair<Boolean, String>(enabled, password), phone, null);
9389 return attemptsRemaining;
9390
9391 } catch (Exception e) {
9392 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9393 } finally {
9394 Binder.restoreCallingIdentity(identity);
9395 }
9396 return 0;
9397 }
9398
9399 /**
9400 * Change the ICC password used in ICC pin lock.
9401 *
9402 * @return an integer representing the status of IccLock changed in the following three cases:
9403 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9404 * - Positive number and zero for remaining password attempts.
9405 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9406 *
9407 */
9408 @Override
9409 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9410 enforceModifyPermission();
9411
9412 Phone phone = getPhone(subId);
9413 if (phone == null) {
9414 return 0;
9415 }
9416 // Now that all security checks passes, perform the operation as ourselves.
9417 final long identity = Binder.clearCallingIdentity();
9418 try {
9419 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9420 new Pair<String, String>(oldPassword, newPassword), phone, null);
9421 return attemptsRemaining;
9422
9423 } catch (Exception e) {
9424 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9425 } finally {
9426 Binder.restoreCallingIdentity(identity);
9427 }
9428 return 0;
9429 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009430
9431 /**
9432 * Request for receiving user activity notification
9433 */
9434 @Override
9435 public void requestUserActivityNotification() {
9436 if (!mNotifyUserActivity.get()
9437 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9438 mNotifyUserActivity.set(true);
9439 }
9440 }
9441
9442 /**
9443 * Called when userActivity is signalled in the power manager.
9444 * This is safe to call from any thread, with any window manager locks held or not.
9445 */
9446 @Override
9447 public void userActivity() {
9448 // ***************************************
9449 // * Inherited from PhoneWindowManager *
9450 // ***************************************
9451 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9452 // WITH ITS LOCKS HELD.
9453 //
9454 // This code must be VERY careful about the locks
9455 // it acquires.
9456 // In fact, the current code acquires way too many,
9457 // and probably has lurking deadlocks.
9458
9459 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9460 throw new SecurityException("Only the OS may call notifyUserActivity()");
9461 }
9462
9463 if (mNotifyUserActivity.getAndSet(false)) {
9464 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9465 USER_ACTIVITY_NOTIFICATION_DELAY);
9466 }
9467 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009468
9469 @Override
9470 public boolean canConnectTo5GInDsdsMode() {
9471 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9472 }
Jack Yud10cdd42020-09-28 20:28:01 -07009473
9474 @Override
9475 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9476 String callingFeatureId) {
9477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9478 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9479 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9480 }
9481
9482 Phone phone = getPhone(subId);
9483 if (phone == null) {
9484 throw new RuntimeException("phone is not available");
9485 }
9486 // Now that all security checks passes, perform the operation as ourselves.
9487 final long identity = Binder.clearCallingIdentity();
9488 try {
9489 return phone.getEquivalentHomePlmns();
9490 } finally {
9491 Binder.restoreCallingIdentity(identity);
9492 }
9493 }
Daniel Bright59e67312020-11-13 11:49:37 -08009494
9495 @Override
9496 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009497 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9498 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009499 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009500 if (radioInterfaceCapabilities == null) {
9501 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009502 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009503 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009504 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009505
Hui Wang641e81c2020-10-12 12:14:23 -07009506 @Override
9507 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9508 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009509 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9510 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9511 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9512 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9513 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009514 if (DBG) {
9515 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9516 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9517 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9518 }
9519
9520 if (!SubscriptionManager.isValidSubscriptionId(subId)
9521 || appType < TelephonyManager.APPTYPE_UNKNOWN
9522 || appType > TelephonyManager.APPTYPE_ISIM
9523 || nafUrl == null || securityProtocol == null || callback == null) {
9524 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9525 if (callback != null) {
9526 try {
9527 callback.onAuthenticationFailure(
9528 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9529 } catch (RemoteException exception) {
9530 log("Fail to notify onAuthenticationFailure due to " + exception);
9531 }
9532 return;
9533 }
9534 }
9535
9536 final long token = Binder.clearCallingIdentity();
9537 try {
9538 getGbaManager(subId).bootstrapAuthenticationRequest(
9539 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9540 forceBootStrapping, callback));
9541 } finally {
9542 Binder.restoreCallingIdentity(token);
9543 }
9544 }
9545
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009546 /**
9547 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9548 * requested radio power state will actually be set. See {@link
9549 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9550 *
9551 * @param subId the subscription ID of the phone requesting to set the radio power state.
9552 * @param enable {@code true} if trying to turn radio on.
9553 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9554 * false}.
9555 */
9556 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9557 Phone phone = getPhone(subId);
9558 if (phone != null) {
9559 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9560 return true;
9561 }
9562 return false;
9563 }
9564
9565 private int handleDataThrottlingRequest(int subId,
9566 DataThrottlingRequest dataThrottlingRequest) {
9567 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9568 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9569 if (!setRadioPowerForThermal(subId, true)) {
9570 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9571 }
9572
9573 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9574
9575 int thermalMitigationResult =
9576 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9577 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9578 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9579 }
9580 return thermalMitigationResult;
9581 }
9582
9583 /**
9584 * Thermal mitigation request to control functionalities at modem.
9585 *
9586 * @param subId the id of the subscription.
9587 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9588 *
9589 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9590 */
9591 @Override
9592 @ThermalMitigationResult
9593 public int sendThermalMitigationRequest(
9594 int subId,
9595 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9596 enforceModifyPermission();
9597
9598 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9599 final long identity = Binder.clearCallingIdentity();
9600
9601 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9602 try {
9603 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9604 switch (thermalMitigationAction) {
9605 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9606 thermalMitigationResult =
9607 handleDataThrottlingRequest(subId,
9608 thermalMitigationRequest.getDataThrottlingRequest());
9609 break;
9610 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9611 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9612 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9613 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9614 }
9615
9616 // Ensure that radio is on. If not able to power on due to phone being
9617 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9618 if (!setRadioPowerForThermal(subId, true)) {
9619 thermalMitigationResult =
9620 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9621 break;
9622 }
9623
9624 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9625 false);
9626 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9627 break;
9628 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9629 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9630 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9631 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9632 }
9633
9634 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9635 if (registry != null) {
9636 TelephonyConnectionService service =
9637 registry.getTelephonyConnectionService();
9638 Phone phone = getPhone(subId);
9639 if (phone == null) {
9640 thermalMitigationResult =
9641 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9642 break;
9643 }
9644
9645 if (PhoneConstantConversions.convertCallState(phone.getState())
9646 != TelephonyManager.CALL_STATE_IDLE
9647 || phone.isInEmergencySmsMode() || phone.isInEcm()
9648 || (service != null && service.isEmergencyCallPending())) {
9649 String errorMessage = "Phone state is not valid. call state = "
9650 + PhoneConstantConversions.convertCallState(phone.getState())
9651 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9652 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9653 errorMessage += service == null
9654 ? " TelephonyConnectionService is null"
9655 : " isEmergencyCallPending = "
9656 + service.isEmergencyCallPending();
9657 Log.e(LOG_TAG, errorMessage);
9658 thermalMitigationResult =
9659 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9660 break;
9661 }
9662 } else {
9663 thermalMitigationResult =
9664 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9665 break;
9666 }
9667
9668 // Turn radio off. If not able to power off due to phone being unavailable,
9669 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9670 if (!setRadioPowerForThermal(subId, false)) {
9671 thermalMitigationResult =
9672 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9673 break;
9674 }
9675 thermalMitigationResult =
9676 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9677 break;
9678 default:
9679 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9680 + "not exist. Requested action: " + thermalMitigationAction);
9681 }
9682 } catch (IllegalArgumentException e) {
9683 throw e;
9684 } catch (Exception e) {
9685 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9686 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9687 } finally {
9688 Binder.restoreCallingIdentity(identity);
9689 }
9690
9691 if (DBG) {
9692 log("thermalMitigationRequest returning with thermalMitigationResult: "
9693 + thermalMitigationResult);
9694 }
9695
9696 return thermalMitigationResult;
9697 }
Hui Wang641e81c2020-10-12 12:14:23 -07009698
9699 /**
9700 * Set the GbaService Package Name that Telephony will bind to.
9701 *
9702 * @param subId The sim that the GbaService is associated with.
9703 * @param packageName The name of the package to be replaced with.
9704 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9705 */
9706 @Override
9707 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9708 enforceModifyPermission();
9709
9710 final long identity = Binder.clearCallingIdentity();
9711 try {
9712 return getGbaManager(subId).overrideServicePackage(packageName);
9713 } finally {
9714 Binder.restoreCallingIdentity(identity);
9715 }
9716 }
9717
9718 /**
9719 * Return the package name of the currently bound GbaService.
9720 *
9721 * @param subId The sim that the GbaService is associated with.
9722 * @return the package name of the GbaService configuration, null if GBA is not supported.
9723 */
9724 @Override
9725 public String getBoundGbaService(int subId) {
9726 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9727
9728 final long identity = Binder.clearCallingIdentity();
9729 try {
9730 return getGbaManager(subId).getServicePackage();
9731 } finally {
9732 Binder.restoreCallingIdentity(identity);
9733 }
9734 }
9735
9736 /**
9737 * Set the release time for telephony to unbind GbaService.
9738 *
9739 * @param subId The sim that the GbaService is associated with.
9740 * @param interval The release time to unbind GbaService by millisecond.
9741 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9742 */
9743 @Override
9744 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9745 enforceModifyPermission();
9746
9747 final long identity = Binder.clearCallingIdentity();
9748 try {
9749 return getGbaManager(subId).overrideReleaseTime(interval);
9750 } finally {
9751 Binder.restoreCallingIdentity(identity);
9752 }
9753 }
9754
9755 /**
9756 * Return the release time for telephony to unbind GbaService.
9757 *
9758 * @param subId The sim that the GbaService is associated with.
9759 * @return The release time to unbind GbaService by millisecond.
9760 */
9761 @Override
9762 public int getGbaReleaseTime(int subId) {
9763 enforceReadPrivilegedPermission("getGbaReleaseTime");
9764
9765 final long identity = Binder.clearCallingIdentity();
9766 try {
9767 return getGbaManager(subId).getReleaseTime();
9768 } finally {
9769 Binder.restoreCallingIdentity(identity);
9770 }
9771 }
9772
9773 private GbaManager getGbaManager(int subId) {
9774 GbaManager instance = GbaManager.getInstance(subId);
9775 if (instance == null) {
9776 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9777 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9778 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9779 }
9780 return instance;
9781 }
Hui Wang761a6682020-10-31 05:12:53 +00009782
9783 /**
9784 * indicate whether the device and the carrier can support
9785 * RCS VoLTE single registration.
9786 */
9787 @Override
9788 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009789 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9790 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9791 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9792 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009793
9794 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9795 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9796 }
9797
9798 final long identity = Binder.clearCallingIdentity();
9799 try {
9800 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9801 if (rpm != null) {
9802 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9803 }
9804 return false;
9805 } finally {
9806 Binder.restoreCallingIdentity(identity);
9807 }
9808 }
9809
9810 /**
9811 * Register RCS provisioning callback.
9812 */
9813 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009814 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009815 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009816 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009817 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009818 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9819 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009820
9821 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9822 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9823 }
9824 if (!isImsAvailableOnDevice()) {
9825 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9826 "IMS not available on device.");
9827 }
9828
9829 final long identity = Binder.clearCallingIdentity();
9830 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009831 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009832 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -08009833 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9834 "Service not available for the subscription.");
9835 }
Hui Wang761a6682020-10-31 05:12:53 +00009836 } finally {
9837 Binder.restoreCallingIdentity(identity);
9838 }
9839 }
9840
9841 /**
9842 * Unregister RCS provisioning callback.
9843 */
9844 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009845 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009846 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009847 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009848 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009849 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9850 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009851
9852 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9853 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9854 }
9855 if (!isImsAvailableOnDevice()) {
9856 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9857 "IMS not available on device.");
9858 }
9859
9860 final long identity = Binder.clearCallingIdentity();
9861 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009862 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009863 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009864 } finally {
9865 Binder.restoreCallingIdentity(identity);
9866 }
9867 }
9868
9869 /**
9870 * trigger RCS reconfiguration.
9871 */
9872 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009873 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9874 "triggerRcsReconfiguration",
9875 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009876
9877 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9878 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9879 }
9880 if (!isImsAvailableOnDevice()) {
9881 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9882 "IMS not available on device.");
9883 }
9884
9885 final long identity = Binder.clearCallingIdentity();
9886 try {
9887 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9888 } finally {
9889 Binder.restoreCallingIdentity(identity);
9890 }
9891 }
9892
9893 /**
9894 * Provide the client configuration parameters of the RCS application.
9895 */
9896 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009897 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9898 "setRcsClientConfiguration",
9899 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009900
9901 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9902 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9903 }
9904 if (!isImsAvailableOnDevice()) {
9905 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9906 "IMS not available on device.");
9907 }
9908
9909 final long identity = Binder.clearCallingIdentity();
9910
9911 try {
9912 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9913 if (configBinder == null) {
9914 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9915 } else {
9916 configBinder.setRcsClientConfiguration(rcc);
9917 }
9918 } catch (RemoteException e) {
9919 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9920 } finally {
9921 Binder.restoreCallingIdentity(identity);
9922 }
9923 }
9924
9925 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -08009926 * Enables or disables the test mode for RCS VoLTE single registration.
9927 */
9928 @Override
9929 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9930 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9931 "setRcsSingleRegistrationTestModeEnabled");
9932
9933 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9934 }
9935
9936 /**
9937 * Gets the test mode for RCS VoLTE single registration.
9938 */
9939 @Override
9940 public boolean getRcsSingleRegistrationTestModeEnabled() {
9941 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9942 "getRcsSingleRegistrationTestModeEnabled");
9943
9944 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9945 }
9946
9947 /**
Hui Wang761a6682020-10-31 05:12:53 +00009948 * Overrides the config of RCS VoLTE single registration enabled for the device.
9949 */
9950 @Override
9951 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9952 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9953 "setDeviceSingleRegistrationEnabledOverride");
9954 enforceModifyPermission();
9955
9956 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9957 : Boolean.parseBoolean(enabledStr);
9958 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009959 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +00009960 }
9961
9962 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009963 * Sends a device to device communication message. Only usable via shell.
9964 * @param message message to send.
9965 * @param value message value.
9966 */
9967 @Override
9968 public void sendDeviceToDeviceMessage(int message, int value) {
9969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -08009970 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -08009971 enforceModifyPermission();
9972
9973 final long identity = Binder.clearCallingIdentity();
9974 try {
9975 TelephonyConnectionService service =
9976 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9977 if (service == null) {
9978 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9979 return;
9980 }
9981 service.sendTestDeviceToDeviceMessage(message, value);
9982 } finally {
9983 Binder.restoreCallingIdentity(identity);
9984 }
9985 }
9986
Tyler Gunnbabbda02021-02-10 11:05:02 -08009987 /**
9988 * Sets the specified device to device transport active.
9989 * @param transport The transport to set active.
9990 */
9991 @Override
9992 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
9993 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9994 "setActiveDeviceToDeviceTransport");
9995 enforceModifyPermission();
9996
9997 final long identity = Binder.clearCallingIdentity();
9998 try {
9999 TelephonyConnectionService service =
10000 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10001 if (service == null) {
10002 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10003 return;
10004 }
10005 service.setActiveDeviceToDeviceTransport(transport);
10006 } finally {
10007 Binder.restoreCallingIdentity(identity);
10008 }
10009 }
Tyler Gunn92479152021-01-20 16:30:10 -080010010
10011 /**
Hui Wang761a6682020-10-31 05:12:53 +000010012 * Gets the config of RCS VoLTE single registration enabled for the device.
10013 */
10014 @Override
10015 public boolean getDeviceSingleRegistrationEnabled() {
10016 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10017 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10018 }
10019
10020 /**
10021 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10022 */
10023 @Override
10024 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10025 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10026 "setCarrierSingleRegistrationEnabledOverride");
10027 enforceModifyPermission();
10028
10029 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10030 : Boolean.parseBoolean(enabledStr);
10031 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10032 subId, enabled);
10033 }
10034
10035 /**
10036 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10037 */
10038 @Override
10039 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10040 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10041 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10042 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010043
10044 /**
10045 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10046 * their mobile plan.
10047 */
10048 @Override
10049 public String getMobileProvisioningUrl() {
10050 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10051 final long identity = Binder.clearCallingIdentity();
10052 try {
10053 return getDefaultPhone().getMobileProvisioningUrl();
10054 } finally {
10055 Binder.restoreCallingIdentity(identity);
10056 }
10057 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010058
James.cf Linbcdf8b32021-01-14 16:44:13 +080010059 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010060 * Get the EAB contact from the EAB database.
10061 */
10062 @Override
10063 public String getContactFromEab(String contact) {
10064 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10065 enforceModifyPermission();
10066 final long identity = Binder.clearCallingIdentity();
10067 try {
10068 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10069 } finally {
10070 Binder.restoreCallingIdentity(identity);
10071 }
10072 }
10073
10074 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010075 * Remove the EAB contacts from the EAB database.
10076 */
10077 @Override
10078 public int removeContactFromEab(int subId, String contacts) {
10079 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10080 enforceModifyPermission();
10081 final long identity = Binder.clearCallingIdentity();
10082 try {
10083 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10084 } finally {
10085 Binder.restoreCallingIdentity(identity);
10086 }
10087 }
10088
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010089 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010090 public boolean getDeviceUceEnabled() {
10091 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10092 final long identity = Binder.clearCallingIdentity();
10093 try {
10094 return mApp.getDeviceUceEnabled();
10095 } finally {
10096 Binder.restoreCallingIdentity(identity);
10097 }
10098 }
10099
10100 @Override
10101 public void setDeviceUceEnabled(boolean isEnabled) {
10102 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10103 final long identity = Binder.clearCallingIdentity();
10104 try {
10105 mApp.setDeviceUceEnabled(isEnabled);
10106 } finally {
10107 Binder.restoreCallingIdentity(identity);
10108 }
10109 }
10110
Brad Ebinger14d467f2021-02-12 06:18:28 +000010111 /**
10112 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10113 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10114 */
10115 // Used for SHELL command only right now.
10116 @Override
10117 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10118 List<String> featureTags) {
10119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10120 "addUceRegistrationOverrideShell");
10121 final long identity = Binder.clearCallingIdentity();
10122 try {
10123 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10124 new ArraySet<>(featureTags));
10125 } catch (ImsException e) {
10126 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10127 } finally {
10128 Binder.restoreCallingIdentity(identity);
10129 }
10130 }
10131
10132 /**
10133 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10134 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10135 */
10136 // Used for SHELL command only right now.
10137 @Override
10138 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10139 List<String> featureTags) {
10140 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10141 "removeUceRegistrationOverrideShell");
10142 final long identity = Binder.clearCallingIdentity();
10143 try {
10144 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10145 new ArraySet<>(featureTags));
10146 } catch (ImsException e) {
10147 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10148 } finally {
10149 Binder.restoreCallingIdentity(identity);
10150 }
10151 }
10152
10153 /**
10154 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10155 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10156 */
10157 // Used for SHELL command only right now.
10158 @Override
10159 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10160 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10161 "clearUceRegistrationOverrideShell");
10162 final long identity = Binder.clearCallingIdentity();
10163 try {
10164 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10165 } catch (ImsException e) {
10166 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10167 } finally {
10168 Binder.restoreCallingIdentity(identity);
10169 }
10170 }
10171
10172 /**
10173 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10174 */
10175 // Used for SHELL command only right now.
10176 @Override
10177 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10178 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10179 "getLatestRcsContactUceCapabilityShell");
10180 final long identity = Binder.clearCallingIdentity();
10181 try {
10182 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10183 } catch (ImsException e) {
10184 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10185 } finally {
10186 Binder.restoreCallingIdentity(identity);
10187 }
10188 }
10189
10190 /**
10191 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10192 * device does not have an active PUBLISH.
10193 */
10194 // Used for SHELL command only right now.
10195 @Override
10196 public String getLastUcePidfXmlShell(int subId) {
10197 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10198 final long identity = Binder.clearCallingIdentity();
10199 try {
10200 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10201 } catch (ImsException e) {
10202 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10203 } finally {
10204 Binder.restoreCallingIdentity(identity);
10205 }
10206 }
10207
10208
James.cf Lin4b784aa2021-01-31 03:25:15 +080010209 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010210 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10211 String callingPackage) {
10212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10213 mApp, subId, "setSignalStrengthUpdateRequest");
10214
10215 final int callingUid = Binder.getCallingUid();
10216 // Verify that tha callingPackage belongs to the calling UID
10217 mApp.getSystemService(AppOpsManager.class)
10218 .checkPackage(callingUid, callingPackage);
10219
10220 validateSignalStrengthUpdateRequest(request, callingUid);
10221
10222 final long identity = Binder.clearCallingIdentity();
10223 try {
10224 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10225 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10226
10227 if (result instanceof IllegalStateException) {
10228 throw (IllegalStateException) result;
10229 }
10230 } finally {
10231 Binder.restoreCallingIdentity(identity);
10232 }
10233 }
10234
10235 @Override
10236 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10237 String callingPackage) {
10238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10239 mApp, subId, "clearSignalStrengthUpdateRequest");
10240
10241 final int callingUid = Binder.getCallingUid();
10242 // Verify that tha callingPackage belongs to the calling UID
10243 mApp.getSystemService(AppOpsManager.class)
10244 .checkPackage(callingUid, callingPackage);
10245
10246 final long identity = Binder.clearCallingIdentity();
10247 try {
10248 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10249 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10250
10251 if (result instanceof IllegalStateException) {
10252 throw (IllegalStateException) result;
10253 }
10254 } finally {
10255 Binder.restoreCallingIdentity(identity);
10256 }
10257 }
10258
10259 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10260 int callingUid) {
10261 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10262 // phone/system process do not have further restriction on request
10263 return;
10264 }
10265
10266 // Applications has restrictions on how to use the request:
10267 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10268 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10269 // This is not system caller which has been checked above
10270 throw new IllegalArgumentException(
10271 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10272 }
10273
10274 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10275 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10276 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10277 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10278 || info.isEnabled()) {
10279 throw new IllegalArgumentException(
10280 "Only system can set hide fields in SignalThresholdInfo");
10281 }
10282
10283 // Thresholds length for each RAN need in range. This has been validated in
10284 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10285 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10286 final int[] thresholds = info.getThresholds();
10287 Objects.requireNonNull(thresholds);
10288 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10289 || thresholds.length
10290 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10291 throw new IllegalArgumentException(
10292 "thresholds length is out of range: " + thresholds.length);
10293 }
10294 }
10295 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010296
10297 /**
10298 * Gets the current phone capability.
10299 *
10300 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10301 * @return the PhoneCapability which describes the data connection capability of modem.
10302 * It's used to evaluate possible phone config change, for example from single
10303 * SIM device to multi-SIM device.
10304 */
10305 @Override
10306 public PhoneCapability getPhoneCapability() {
10307 enforceReadPrivilegedPermission("getPhoneCapability");
10308 final long identity = Binder.clearCallingIdentity();
10309 try {
10310 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10311 } finally {
10312 Binder.restoreCallingIdentity(identity);
10313 }
10314 }
Michele Berionne5e411512020-11-13 02:36:59 +000010315
10316 /**
10317 * Prepare TelephonyManager for an unattended reboot. The reboot is
10318 * required to be done shortly after the API is invoked.
10319 */
10320 @Override
10321 @TelephonyManager.PrepareUnattendedRebootResult
10322 public int prepareForUnattendedReboot() {
10323 enforceRebootPermission();
10324
10325 final long identity = Binder.clearCallingIdentity();
10326 try {
10327 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10328 } finally {
10329 Binder.restoreCallingIdentity(identity);
10330 }
10331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010332}