blob: fea8b694eccf22411ce2e3d9a7309acbff2143c2 [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;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070073import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
111import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700112import android.telephony.gba.GbaAuthRequest;
113import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700114import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000116import android.telephony.ims.RcsClientConfiguration;
Brad 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");
6156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6157 final long identity = Binder.clearCallingIdentity();
6158 try {
6159 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6160 nrDualConnectivityState, subId,
6161 workSource);
6162 if (DBG) log("enableNRDualConnectivity result: " + result);
6163 return result;
6164 } finally {
6165 Binder.restoreCallingIdentity(identity);
6166 }
6167 }
6168
6169 /**
6170 * Is E-UTRA-NR Dual Connectivity enabled
6171 * @return true if dual connectivity is enabled else false
6172 */
6173 @Override
6174 public boolean isNrDualConnectivityEnabled(int subId) {
6175 TelephonyPermissions
6176 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6177 mApp, subId, "isNRDualConnectivityEnabled");
6178 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6179 final long identity = Binder.clearCallingIdentity();
6180 try {
6181 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6182 null, subId, workSource);
6183 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6184 return isEnabled;
6185 } finally {
6186 Binder.restoreCallingIdentity(identity);
6187 }
6188 }
6189
6190 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006191 * get carrier bandwidth per primary and secondary carrier
6192 * @param subId subscription id of the sim card
6193 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6194 */
6195 @Override
6196 public CarrierBandwidth getCarrierBandwidth(int subId) {
6197 TelephonyPermissions
6198 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6199 mApp, subId, "isNRDualConnectivityEnabled");
6200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 CarrierBandwidth carrierBandwidth =
6204 getPhoneFromSubId(subId).getCarrierBandwidth();
6205 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6206 return carrierBandwidth;
6207 } finally {
6208 Binder.restoreCallingIdentity(identity);
6209 }
6210 }
6211
6212 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006213 * Set the allowed network types of the device and
6214 * provide the reason triggering the allowed network change.
6215 *
6216 * @param subId the id of the subscription.
6217 * @param reason the reason the allowed network type change is taking place
6218 * @param allowedNetworkTypes the allowed network types.
6219 * @return true on success; false on any failure.
6220 */
6221 @Override
6222 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006223 @TelephonyManager.AllowedNetworkTypesReason int reason,
6224 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006225 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6226 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006227 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6228 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6229 return false;
6230 }
6231
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006232 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6233 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6234
6235
6236 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6237 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6238 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006239 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006240
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006241 final long identity = Binder.clearCallingIdentity();
6242 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006243 Boolean success = (Boolean) sendRequest(
6244 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6245 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6246
6247 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6248 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006249 } finally {
6250 Binder.restoreCallingIdentity(identity);
6251 }
6252 }
6253
6254 /**
Miaoa84611c2019-03-15 09:21:10 +08006255 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006256 *
Miaoa84611c2019-03-15 09:21:10 +08006257 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006258 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006259 * @hide
6260 */
6261 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006262 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006263 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006265 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 try {
Miaoa84611c2019-03-15 09:21:10 +08006267 if (phone != null) {
6268 return phone.hasMatchedTetherApnSetting();
6269 } else {
6270 return false;
6271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006272 } finally {
6273 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006274 }
Junda Liu475951f2014-11-07 16:45:03 -08006275 }
6276
6277 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006278 * Enable or disable always reporting signal strength changes from radio.
6279 *
6280 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6281 */
6282 @Override
6283 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6284 enforceModifyPermission();
6285 enforceSystemCaller();
6286
6287 final long identity = Binder.clearCallingIdentity();
6288 final Phone phone = getPhone(subId);
6289 try {
6290 if (phone != null) {
6291 if (DBG) {
6292 log("setAlwaysReportSignalStrength: subId=" + subId
6293 + " isEnable=" + isEnable);
6294 }
6295 phone.setAlwaysReportSignalStrength(isEnable);
6296 } else {
6297 loge("setAlwaysReportSignalStrength: no phone found for subId="
6298 + subId);
6299 }
6300 } finally {
6301 Binder.restoreCallingIdentity(identity);
6302 }
6303 }
6304
6305 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006306 * Get the user enabled state of Mobile Data.
6307 *
6308 * TODO: remove and use isUserDataEnabled.
6309 * This can't be removed now because some vendor codes
6310 * calls through ITelephony directly while they should
6311 * use TelephonyManager.
6312 *
6313 * @return true on enabled
6314 */
6315 @Override
6316 public boolean getDataEnabled(int subId) {
6317 return isUserDataEnabled(subId);
6318 }
6319
6320 /**
6321 * Get whether mobile data is enabled per user setting.
6322 *
6323 * There are other factors deciding whether mobile data is actually enabled, but they are
6324 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006325 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006326 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006327 *
6328 * @return {@code true} if data is enabled else {@code false}
6329 */
6330 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006331 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006332 try {
6333 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6334 null);
6335 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006338 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339
6340 final long identity = Binder.clearCallingIdentity();
6341 try {
6342 int phoneId = mSubscriptionController.getPhoneId(subId);
6343 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6344 Phone phone = PhoneFactory.getPhone(phoneId);
6345 if (phone != null) {
6346 boolean retVal = phone.isUserDataEnabled();
6347 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6348 return retVal;
6349 } else {
6350 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6351 return false;
6352 }
6353 } finally {
6354 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006355 }
6356 }
6357
6358 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006359 * Checks if the device is capable of mobile data by considering whether whether the
6360 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6361 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006362 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006363 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006364 */
6365 @Override
6366 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006367 try {
6368 try {
6369 mApp.enforceCallingOrSelfPermission(
6370 android.Manifest.permission.ACCESS_NETWORK_STATE,
6371 null);
6372 } catch (Exception e) {
6373 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6374 "isDataEnabled");
6375 }
6376 } catch (Exception e) {
6377 enforceReadPrivilegedPermission("isDataEnabled");
6378 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379
6380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 int phoneId = mSubscriptionController.getPhoneId(subId);
6383 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6384 Phone phone = PhoneFactory.getPhone(phoneId);
6385 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006386 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6388 return retVal;
6389 } else {
6390 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6391 return false;
6392 }
6393 } finally {
6394 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006395 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006396 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006397
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006398 /**
6399 * Check if data is enabled for a specific reason
6400 * @param subId Subscription index
6401 * @param reason the reason the data enable change is taking place
6402 * @return {@code true} if the overall data is enabled; {@code false} if not.
6403 */
6404 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006405 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006406 @TelephonyManager.DataEnabledReason int reason) {
6407 try {
6408 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6409 null);
6410 } catch (Exception e) {
6411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006412 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006413 }
6414
6415
6416 final long identity = Binder.clearCallingIdentity();
6417 try {
6418 int phoneId = mSubscriptionController.getPhoneId(subId);
6419 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006420 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006421 + " reason=" + reason);
6422 }
6423 Phone phone = PhoneFactory.getPhone(phoneId);
6424 if (phone != null) {
6425 boolean retVal;
6426 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6427 retVal = phone.isUserDataEnabled();
6428 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006429 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006430 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006431 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006432 return retVal;
6433 } else {
6434 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006435 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006436 + subId + " retVal=false");
6437 }
6438 return false;
6439 }
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
6443 }
6444
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006445 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006446 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006447 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6448 // Skip the check if it's one of these special uids
6449 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6450 }
6451
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006452 //load access rules from carrier configs, and check those as well: b/139133814
6453 SubscriptionController subController = SubscriptionController.getInstance();
6454 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6455 || subController == null) return privilegeFromSim;
6456
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006457 PackageManager pkgMgr = phone.getContext().getPackageManager();
6458 String[] packages = pkgMgr.getPackagesForUid(uid);
6459
6460 final long identity = Binder.clearCallingIdentity();
6461 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006462 int subId = phone.getSubId();
6463 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6464 // A test override is in place for the privileges for this subId, so don't try to
6465 // read the subscription privileges.
6466 return privilegeFromSim;
6467 }
6468 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006469 SubscriptionManager subManager = (SubscriptionManager)
6470 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6471 for (String pkg : packages) {
6472 if (subManager.canManageSubscription(subInfo, pkg)) {
6473 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6474 }
6475 }
6476 return privilegeFromSim;
6477 } finally {
6478 Binder.restoreCallingIdentity(identity);
6479 }
6480 }
6481
6482 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6483 String pkgName) {
6484 //load access rules from carrier configs, and check those as well: b/139133814
6485 SubscriptionController subController = SubscriptionController.getInstance();
6486 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6487 || subController == null) return privilegeFromSim;
6488
6489 final long identity = Binder.clearCallingIdentity();
6490 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006491 int subId = phone.getSubId();
6492 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6493 // A test override is in place for the privileges for this subId, so don't try to
6494 // read the subscription privileges.
6495 return privilegeFromSim;
6496 }
6497 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006498 SubscriptionManager subManager = (SubscriptionManager)
6499 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6500 return subManager.canManageSubscription(subInfo, pkgName)
6501 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6502 } finally {
6503 Binder.restoreCallingIdentity(identity);
6504 }
6505 }
6506
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006507 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006508 public int getCarrierPrivilegeStatus(int subId) {
6509 final Phone phone = getPhone(subId);
6510 if (phone == null) {
6511 loge("getCarrierPrivilegeStatus: Invalid subId");
6512 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6513 }
6514 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006515 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006516 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006517 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6518 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006519
6520 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6521 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006522 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006523 }
Junda Liu29340342014-07-10 15:23:27 -07006524
6525 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006526 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006527 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006528 final Phone phone = getPhone(subId);
6529 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006530 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006531 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6532 }
6533 UiccProfile profile =
6534 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6535 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006536 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006537 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6538 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006539 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006540 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006541 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006542 }
6543
6544 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006545 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6546 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006547 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006548 }
6549
6550 int phoneId = SubscriptionManager.getPhoneId(subId);
6551 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006552 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006553 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006554 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6555 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006556 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6557 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6558 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006559 }
6560
6561 @Override
6562 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006563 if (TextUtils.isEmpty(pkgName))
6564 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006565 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6566 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6567 UiccCard card = UiccController.getInstance().getUiccCard(i);
6568 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006569 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006570 continue;
6571 }
6572
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006573 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6574 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6575 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006576 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6577 break;
6578 }
6579 }
6580
6581 return result;
Junda Liu29340342014-07-10 15:23:27 -07006582 }
Derek Tan89e89d42014-07-08 17:00:10 -07006583
6584 @Override
Junda Liue64de782015-04-16 17:19:16 -07006585 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6586 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6587 loge("phoneId " + phoneId + " is not valid.");
6588 return null;
6589 }
6590 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006591 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006592 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006593 return null ;
6594 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006595 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006596 }
6597
Amith Yamasani6e118872016-02-19 12:53:51 -08006598 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006599 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006600 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006601 List<String> privilegedPackages = new ArrayList<>();
6602 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006603 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6604 // has UICC in that slot.
6605 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006606 if (card.hasCarrierPrivilegeRules()) {
6607 if (packages == null) {
6608 // Only check packages in user 0 for now
6609 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006610 PackageManager.MATCH_DISABLED_COMPONENTS
6611 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006612 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006613 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006614 }
6615 for (int p = packages.size() - 1; p >= 0; p--) {
6616 PackageInfo pkgInfo = packages.get(p);
6617 if (pkgInfo != null && pkgInfo.packageName != null
6618 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006619 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006620 privilegedPackages.add(pkgInfo.packageName);
6621 }
6622 }
6623 }
6624 }
6625 return privilegedPackages;
6626 }
6627
chen xuf7e9fe82019-05-09 19:31:02 -07006628 @Override
6629 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006630 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6631
6632 final long identity = Binder.clearCallingIdentity();
6633
chen xuf7e9fe82019-05-09 19:31:02 -07006634 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006635 try {
6636 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6637 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6638 }
6639 } finally {
6640 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006641 }
6642 return privilegedPackages;
6643 }
6644
Wink Savilleb564aae2014-10-23 10:18:09 -07006645 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006646 final Phone phone = getPhone(subId);
6647 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006648 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006649 return null;
6650 }
6651 String iccId = card.getIccId();
6652 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006653 return null;
6654 }
6655 return iccId;
6656 }
6657
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006658 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006659 public void setCallComposerStatus(int subId, int status) {
6660 enforceModifyPermission();
6661
6662 final long identity = Binder.clearCallingIdentity();
6663 try {
6664 Phone phone = getPhone(subId);
6665 if (phone != null) {
6666 Phone defaultPhone = phone.getImsPhone();
6667 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6668 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6669 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006670 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6671 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006672 }
6673 }
Shuo Qian284ae752020-12-22 19:10:14 -08006674 } catch (ImsException e) {
6675 throw new ServiceSpecificException(e.getCode());
6676 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006677 Binder.restoreCallingIdentity(identity);
6678 }
6679 }
6680
6681 @Override
6682 public int getCallComposerStatus(int subId) {
6683 enforceReadPrivilegedPermission("getCallComposerStatus");
6684
6685 final long identity = Binder.clearCallingIdentity();
6686 try {
6687 Phone phone = getPhone(subId);
6688 if (phone != null) {
6689 Phone defaultPhone = phone.getImsPhone();
6690 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6691 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6692 return imsPhone.getCallComposerStatus();
6693 }
6694 }
6695 } finally {
6696 Binder.restoreCallingIdentity(identity);
6697 }
6698 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6699 }
6700
6701 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006702 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6703 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006704 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006705 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 final long identity = Binder.clearCallingIdentity();
6708 try {
6709 final String iccId = getIccId(subId);
6710 final Phone phone = getPhone(subId);
6711 if (phone == null) {
6712 return false;
6713 }
6714 final String subscriberId = phone.getSubscriberId();
6715
6716 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006717 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 + subscriberId + " to " + number);
6719 }
6720
6721 if (TextUtils.isEmpty(iccId)) {
6722 return false;
6723 }
6724
6725 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6726
6727 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6728 if (alphaTag == null) {
6729 editor.remove(alphaTagPrefKey);
6730 } else {
6731 editor.putString(alphaTagPrefKey, alphaTag);
6732 }
6733
6734 // Record both the line number and IMSI for this ICCID, since we need to
6735 // track all merged IMSIs based on line number
6736 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6737 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6738 if (number == null) {
6739 editor.remove(numberPrefKey);
6740 editor.remove(subscriberPrefKey);
6741 } else {
6742 editor.putString(numberPrefKey, number);
6743 editor.putString(subscriberPrefKey, subscriberId);
6744 }
6745
6746 editor.commit();
6747 return true;
6748 } finally {
6749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006750 }
Derek Tan7226c842014-07-02 17:42:23 -07006751 }
6752
6753 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006754 public String getLine1NumberForDisplay(int subId, String callingPackage,
6755 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006756 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006758 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006759 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006760 return null;
6761 }
Derek Tan97ebb422014-09-05 16:55:38 -07006762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006763 final long identity = Binder.clearCallingIdentity();
6764 try {
6765 String iccId = getIccId(subId);
6766 if (iccId != null) {
6767 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6768 if (DBG_MERGE) {
6769 log("getLine1NumberForDisplay returning "
6770 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6771 }
6772 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6775 return null;
6776 } finally {
6777 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006778 }
Derek Tan7226c842014-07-02 17:42:23 -07006779 }
6780
6781 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006782 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6783 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006785 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006786 return null;
6787 }
Derek Tan97ebb422014-09-05 16:55:38 -07006788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 final long identity = Binder.clearCallingIdentity();
6790 try {
6791 String iccId = getIccId(subId);
6792 if (iccId != null) {
6793 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6794 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6795 }
6796 return null;
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006799 }
Derek Tan7226c842014-07-02 17:42:23 -07006800 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006801
6802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006803 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6804 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006805 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6806 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006808 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006809 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006810 return null;
6811 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006812
Jordan Liub49b04b2019-05-06 14:45:15 -07006813 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6814 // the process, where TelephonyManager was instantiated.
6815 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006816 final long identity = Binder.clearCallingIdentity();
6817 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006818 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819 final TelephonyManager tele = TelephonyManager.from(context);
6820 final SubscriptionManager sub = SubscriptionManager.from(context);
6821
6822 // Figure out what subscribers are currently active
6823 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824
Jordan Liub49b04b2019-05-06 14:45:15 -07006825 // Only consider subs which match the current subId
6826 // This logic can be simplified. See b/131189269 for progress.
6827 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006828 activeSubscriberIds.add(tele.getSubscriberId(subId));
6829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006830
6831 // First pass, find a number override for an active subscriber
6832 String mergeNumber = null;
6833 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6834 for (String key : prefs.keySet()) {
6835 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6836 final String subscriberId = (String) prefs.get(key);
6837 if (activeSubscriberIds.contains(subscriberId)) {
6838 final String iccId = key.substring(
6839 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6840 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6841 mergeNumber = (String) prefs.get(numberKey);
6842 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006843 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844 + " for active subscriber " + subscriberId);
6845 }
6846 if (!TextUtils.isEmpty(mergeNumber)) {
6847 break;
6848 }
6849 }
6850 }
6851 }
6852
6853 // Shortcut when no active merged subscribers
6854 if (TextUtils.isEmpty(mergeNumber)) {
6855 return null;
6856 }
6857
6858 // Second pass, find all subscribers under that line override
6859 final ArraySet<String> result = new ArraySet<>();
6860 for (String key : prefs.keySet()) {
6861 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6862 final String number = (String) prefs.get(key);
6863 if (mergeNumber.equals(number)) {
6864 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6865 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6866 final String subscriberId = (String) prefs.get(subscriberKey);
6867 if (!TextUtils.isEmpty(subscriberId)) {
6868 result.add(subscriberId);
6869 }
6870 }
6871 }
6872 }
6873
6874 final String[] resultArray = result.toArray(new String[result.size()]);
6875 Arrays.sort(resultArray);
6876 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006877 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6879 }
6880 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006881 } finally {
6882 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006883 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006884 }
6885
6886 @Override
zoey chen38003472019-12-13 17:16:31 +08006887 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6888 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006889
6890 final long identity = Binder.clearCallingIdentity();
6891 try {
6892 final TelephonyManager telephonyManager = mApp.getSystemService(
6893 TelephonyManager.class);
6894 String subscriberId = telephonyManager.getSubscriberId(subId);
6895 if (subscriberId == null) {
6896 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006897 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006898 + subId);
6899 }
6900 return null;
6901 }
6902
6903 final SubscriptionInfo info = SubscriptionController.getInstance()
6904 .getSubscriptionInfo(subId);
6905 final ParcelUuid groupUuid = info.getGroupUuid();
6906 // If it doesn't belong to any group, return just subscriberId of itself.
6907 if (groupUuid == null) {
6908 return new String[]{subscriberId};
6909 }
6910
6911 // Get all subscriberIds from the group.
6912 final List<String> mergedSubscriberIds = new ArrayList<>();
6913 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006914 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006915 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006916 for (SubscriptionInfo subInfo : groupInfos) {
6917 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6918 if (subscriberId != null) {
6919 mergedSubscriberIds.add(subscriberId);
6920 }
6921 }
6922
6923 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926
6927 }
6928 }
6929
6930 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006931 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006932 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006933 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934
6935 final long identity = Binder.clearCallingIdentity();
6936 try {
6937 final Phone phone = getPhone(subId);
6938 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6939 } finally {
6940 Binder.restoreCallingIdentity(identity);
6941 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006942 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006943
6944 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006945 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006946 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6947 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006948 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6949 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
6953 final Phone phone = getPhone(subId);
6954 if (phone == null) {
6955 return false;
6956 }
6957 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6958 cdmaNonRoamingList);
6959 } finally {
6960 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006961 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006962 }
6963
6964 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006965 @Deprecated
6966 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6967 enforceModifyPermission();
6968
6969 int returnValue = 0;
6970 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006971 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006972 if(result.exception == null) {
6973 if (result.result != null) {
6974 byte[] responseData = (byte[])(result.result);
6975 if(responseData.length > oemResp.length) {
6976 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6977 responseData.length + "bytes. Buffer Size is " +
6978 oemResp.length + "bytes.");
6979 }
6980 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6981 returnValue = responseData.length;
6982 }
6983 } else {
6984 CommandException ex = (CommandException) result.exception;
6985 returnValue = ex.getCommandError().ordinal();
6986 if(returnValue > 0) returnValue *= -1;
6987 }
6988 } catch (RuntimeException e) {
6989 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6990 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6991 if(returnValue > 0) returnValue *= -1;
6992 }
6993
6994 return returnValue;
6995 }
6996
6997 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006998 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006999 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007000 try {
7001 TelephonyPermissions
7002 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7003 mApp, phone.getSubId(), "getRadioAccessFamily");
7004 } catch (SecurityException e) {
7005 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7006 throw e;
7007 }
chen xub97461a2018-10-26 14:17:57 -07007008 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007009 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007010 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 final long identity = Binder.clearCallingIdentity();
7013 try {
chen xub97461a2018-10-26 14:17:57 -07007014 TelephonyPermissions
7015 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7016 mApp, phone.getSubId(), "getRadioAccessFamily");
7017 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007018 } finally {
7019 Binder.restoreCallingIdentity(identity);
7020 }
chen xub97461a2018-10-26 14:17:57 -07007021 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007022 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007023
7024 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007025 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007026 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007027 try {
7028 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7029 Binder.getCallingUid())) {
7030 throw new SecurityException("Package uid and package name do not match: "
7031 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7032 }
7033 } catch (PackageManager.NameNotFoundException e) {
7034 throw new SecurityException("Package name invalid:" + callingPackage);
7035 }
7036 RoleManager rm = mApp.getSystemService(RoleManager.class);
7037 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7038 if (!dialerRoleHolders.contains(callingPackage)) {
7039 throw new SecurityException("App must be the dialer role holder to"
7040 + " upload a call composer pic");
7041 }
7042
7043 Executors.newSingleThreadExecutor().execute(() -> {
7044 ByteArrayOutputStream output = new ByteArrayOutputStream(
7045 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7046 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7047 boolean readUntilEnd = false;
7048 int totalBytesRead = 0;
7049 byte[] buffer = new byte[16 * 1024];
7050 while (true) {
7051 int numRead;
7052 try {
7053 numRead = input.read(buffer);
7054 } catch (IOException e) {
7055 try {
7056 fd.checkError();
7057 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7058 null);
7059 } catch (IOException e1) {
7060 // This means that the other side closed explicitly with an error. If this
7061 // happens, log and ignore.
7062 loge("Remote end of call composer picture pipe closed: " + e1);
7063 }
7064 break;
7065 }
7066 if (numRead == -1) {
7067 readUntilEnd = true;
7068 break;
7069 }
7070 totalBytesRead += numRead;
7071 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7072 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7073 try {
7074 input.close();
7075 } catch (IOException e) {
7076 // ignore
7077 }
7078 break;
7079 }
7080 output.write(buffer, 0, numRead);
7081 }
7082 // Generally, the remote end will close the file descriptors. The only case where we
7083 // close is above, where the picture size is too big.
7084
7085 try {
7086 fd.checkError();
7087 } catch (IOException e) {
7088 loge("Remote end for call composer closed with an error: " + e);
7089 return;
7090 }
7091
Hall Liuaa4211e2021-01-20 15:43:39 -08007092 if (!readUntilEnd) {
7093 loge("Did not finish reading entire image; aborting");
7094 return;
7095 }
Hall Liu82694d52020-12-11 18:22:04 -08007096
Hall Liuaa4211e2021-01-20 15:43:39 -08007097 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7098 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7099 new CallComposerPictureTransfer.Factory() {},
7100 imageData,
7101 (result) -> {
7102 if (result.first != null) {
7103 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7104 Bundle outputResult = new Bundle();
7105 outputResult.putParcelable(
7106 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7107 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7108 outputResult);
7109 } else {
7110 callback.send(result.second, null);
7111 }
7112 }
7113 );
Hall Liu82694d52020-12-11 18:22:04 -08007114 });
7115 }
7116
7117 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007118 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007119 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121
7122 final long identity = Binder.clearCallingIdentity();
7123 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007124 ImsManager.getInstance(defaultPhone.getContext(),
7125 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 } finally {
7127 Binder.restoreCallingIdentity(identity);
7128 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007129 }
7130
7131 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007132 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007133 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7135 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007136 return false;
7137 }
Svet Ganovb320e182015-04-16 12:30:10 -07007138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 // Check the user preference and the system-level IMS setting. Even if the user has
7142 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7143 // In the long run, we may instead need to check if there exists a connection service
7144 // which can support video calling.
7145 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007146 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147 return imsManager.isVtEnabledByPlatform()
7148 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7149 && imsManager.isVtEnabledByUser();
7150 } finally {
7151 Binder.restoreCallingIdentity(identity);
7152 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007153 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007154
Andrew Leea1239f22015-03-02 17:44:07 -08007155 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007156 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7157 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007159 mApp, subId, callingPackage, callingFeatureId,
7160 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 return false;
7162 }
7163
7164 final long identity = Binder.clearCallingIdentity();
7165 try {
7166 CarrierConfigManager configManager =
7167 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007168 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172 }
Andrew Leea1239f22015-03-02 17:44:07 -08007173 }
7174
7175 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007176 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007178 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 return false;
7180 }
7181
7182 final long identity = Binder.clearCallingIdentity();
7183 try {
7184 CarrierConfigManager configManager =
7185 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007186 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7188 } finally {
7189 Binder.restoreCallingIdentity(identity);
7190 }
Andrew Leea1239f22015-03-02 17:44:07 -08007191 }
7192
Andrew Lee9431b832015-03-09 18:46:45 -07007193 @Override
7194 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007195 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007196 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007197 }
7198
7199 @Override
7200 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201 final long identity = Binder.clearCallingIdentity();
7202 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007203 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 } finally {
7205 Binder.restoreCallingIdentity(identity);
7206 }
Andrew Lee9431b832015-03-09 18:46:45 -07007207 }
7208
Hall Liuf6668912018-10-31 17:05:23 -07007209 /**
7210 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7211 * support for the feature and device firmware support.
7212 *
7213 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7214 */
7215 @Override
7216 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007218 final Phone phone = getPhone(subscriptionId);
7219 if (phone == null) {
7220 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7221 return false;
7222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007223 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007224 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007225 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7226 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007227 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 return isCarrierSupported && isDeviceSupported;
7229 } finally {
7230 Binder.restoreCallingIdentity(identity);
7231 }
Hall Liu98187582018-01-22 19:15:32 -08007232 }
7233
Hall Liuf6668912018-10-31 17:05:23 -07007234 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007235 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7236 * RTT setting, will return true if the device and carrier both support RTT.
7237 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007238 */
7239 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 final long identity = Binder.clearCallingIdentity();
7241 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007242 boolean isRttSupported = isRttSupported(subscriptionId);
7243 boolean isUserRttSettingOn = Settings.Secure.getInt(
7244 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7245 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7246 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7247 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007248 } finally {
7249 Binder.restoreCallingIdentity(identity);
7250 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007251 }
7252
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007253 @Deprecated
7254 @Override
7255 public String getDeviceId(String callingPackage) {
7256 return getDeviceIdWithFeature(callingPackage, null);
7257 }
7258
Sanket Padawe7310cc72015-01-14 09:53:20 -08007259 /**
7260 * Returns the unique device ID of phone, for example, the IMEI for
7261 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7262 *
7263 * <p>Requires Permission:
7264 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7265 */
7266 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007267 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007268 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007269 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007270 return null;
7271 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007272 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007273 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007274 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007275 return null;
7276 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007277
7278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 return phone.getDeviceId();
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007284 }
7285
Ping Sunc67b7c22016-03-02 19:16:45 +08007286 /**
7287 * {@hide}
7288 * Returns the IMS Registration Status on a particular subid
7289 *
7290 * @param subId
7291 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007292 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007293 Phone phone = getPhone(subId);
7294 if (phone != null) {
7295 return phone.isImsRegistered();
7296 } else {
7297 return false;
7298 }
7299 }
7300
Santos Cordon7a1885b2015-02-03 11:15:19 -08007301 @Override
7302 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007303 final long identity = Binder.clearCallingIdentity();
7304 try {
7305 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7306 } finally {
7307 Binder.restoreCallingIdentity(identity);
7308 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007309 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007310
Tyler Gunnf70ed162019-04-03 15:28:53 -07007311 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007312 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007313 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007315 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007316 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7317 }
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
7324 }
7325
7326 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007327 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007328 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7329 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007330 final long identity = Binder.clearCallingIdentity();
7331 try {
7332 Phone phone = getPhone(subscriptionId);
7333 if (phone == null) {
7334 return null;
7335 }
7336 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7337 } finally {
7338 Binder.restoreCallingIdentity(identity);
7339 }
7340 }
7341
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007342 /**
7343 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007344 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007345 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007346 final long identity = Binder.clearCallingIdentity();
7347 try {
7348 Phone phone = getPhone(subId);
7349 if (phone != null) {
7350 return phone.isWifiCallingEnabled();
7351 } else {
7352 return false;
7353 }
7354 } finally {
7355 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007356 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007357 }
7358
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007359 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007360 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007361 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007362 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 final long identity = Binder.clearCallingIdentity();
7364 try {
7365 Phone phone = getPhone(subId);
7366 if (phone != null) {
7367 return phone.isVideoEnabled();
7368 } else {
7369 return false;
7370 }
7371 } finally {
7372 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007373 }
7374 }
7375
7376 /**
7377 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7378 * defined in {@link ImsRegistrationImplBase}.
7379 */
7380 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 final long identity = Binder.clearCallingIdentity();
7382 try {
7383 Phone phone = getPhone(subId);
7384 if (phone != null) {
7385 return phone.getImsRegistrationTech();
7386 } else {
7387 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7388 }
7389 } finally {
7390 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007391 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007392 }
7393
Stuart Scott8eef64f2015-04-08 15:13:54 -07007394 @Override
7395 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007396 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007397 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7398 return;
7399 }
7400
Svet Ganovcc087f82015-05-12 20:35:54 -07007401 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007402
Svet Ganovcc087f82015-05-12 20:35:54 -07007403 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007404 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7405 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007406 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007407 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007408 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007409 Phone phone = getPhone(subId);
7410 if (phone != null) {
7411 SubscriptionManager.setSubscriptionProperty(subId,
7412 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7413 "user=" + RadioAccessFamily.getRafFromNetworkType(
7414 RILConstants.PREFERRED_NETWORK_MODE));
7415 phone.loadAllowedNetworksFromSubscriptionDatabase();
7416 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007417 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7418 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007419 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007420 // There has been issues when Sms raw table somehow stores orphan
7421 // fragments. They lead to garbled message when new fragments come
7422 // in and combined with those stale ones. In case this happens again,
7423 // user can reset all network settings which will clean up this table.
7424 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007425 // Clean up IMS settings as well here.
7426 int slotId = getSlotIndex(subId);
7427 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7428 ImsManager.getInstance(mApp, slotId).factoryReset();
7429 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007430
7431 // Erase modem config if erase modem on network setting is enabled.
7432 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7433 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7434 if (configValue != null && Boolean.parseBoolean(configValue)) {
7435 sendEraseModemConfig(getDefaultPhone());
7436 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007437 } finally {
7438 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007439 }
7440 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007441
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007442 private void cleanUpSmsRawTable(Context context) {
7443 ContentResolver resolver = context.getContentResolver();
7444 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7445 resolver.delete(uri, null, null);
7446 }
7447
Narayan Kamath1c496c22015-04-16 14:40:19 +01007448 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007449 public String getSimLocaleForSubscriber(int subId) {
7450 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7451 final Phone phone = getPhone(subId);
7452 if (phone == null) {
7453 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007454 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 final long identity = Binder.clearCallingIdentity();
7457 try {
chen xu5d3637b2019-01-21 23:31:38 -08007458 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007459 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007460 if (info == null) {
7461 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7462 return null;
7463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 // Try and fetch the locale from the carrier properties or from the SIM language
7465 // preferences (EF-PL and EF-LI)...
7466 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007468 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7469 if (localeFromDefaultSim != null) {
7470 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7471 if (DBG) log("Using locale from subId: " + subId + " locale: "
7472 + localeFromDefaultSim);
7473 return localeFromDefaultSim.toLanguageTag();
7474 } else {
7475 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 }
7477 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 // The SIM language preferences only store a language (e.g. fr = French), not an
7480 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7481 // the SIM and carrier preferences does not include a country we add the country
7482 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007483 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007484 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007485 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007486 return mccLocale.toLanguageTag();
7487 }
7488
7489 if (DBG) log("No locale found - returning null");
7490 return null;
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007494 }
7495
7496 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007497 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007498 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007499 }
7500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 /**
7502 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7503 */
7504 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007505 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007506 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007507 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007508
Chenjie Yu1ba97252018-01-11 18:16:20 -08007509 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007510 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007511
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007512 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007513 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7514 * representing the state of the modem.
7515 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007516 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7517 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007518 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007519 */
7520 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007521 public void requestModemActivityInfo(ResultReceiver result) {
7522 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007523 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524
7525 final long identity = Binder.clearCallingIdentity();
7526 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007527 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 } finally {
7529 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007530 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007531 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007532
Siddharth Rayb8114062018-06-17 15:02:38 -07007533 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7534 // less than total activity duration.
7535 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7536 if (info == null) {
7537 return false;
7538 }
7539 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007540 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7541 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7542
Siddharth Rayb8114062018-06-17 15:02:38 -07007543 return (info.isValid()
7544 && (info.getSleepTimeMillis() <= activityDurationMs)
7545 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007546 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007547 && (totalTxTimeMs <= activityDurationMs));
7548 }
7549
Jack Yu85bd38a2015-11-09 11:34:32 -08007550 /**
7551 * {@hide}
7552 * Returns the service state information on specified subscription.
7553 */
7554 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007555 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7556 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007557 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007558 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007559 return null;
7560 }
7561
Hall Liuf19c44f2018-11-27 14:38:17 -08007562 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7563 LocationAccessPolicy.checkLocationPermission(mApp,
7564 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7565 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007566 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007567 .setCallingPid(Binder.getCallingPid())
7568 .setCallingUid(Binder.getCallingUid())
7569 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007570 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007571 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007572 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7573 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007574 .build());
7575
7576 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7577 LocationAccessPolicy.checkLocationPermission(mApp,
7578 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7579 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007580 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007581 .setCallingPid(Binder.getCallingPid())
7582 .setCallingUid(Binder.getCallingUid())
7583 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007584 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007585 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007586 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7587 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007588 .build());
7589 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7590 boolean hasFinePermission =
7591 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7592 boolean hasCoarsePermission =
7593 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7594
Jack Yu479f40e2020-10-27 21:29:25 -07007595 final Phone phone = getPhone(subId);
7596 if (phone == null) {
7597 return null;
7598 }
7599
Jordan Liu0f2bc442020-11-18 16:47:37 -08007600 final long identity = Binder.clearCallingIdentity();
7601
Jack Yu479f40e2020-10-27 21:29:25 -07007602 boolean isCallingPackageDataService = phone.getDataServicePackages()
7603 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007605 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7606 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7607 Rlog.d(LOG_TAG,
7608 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7609 return null;
7610 }
7611
Hall Liuf19c44f2018-11-27 14:38:17 -08007612 ServiceState ss = phone.getServiceState();
7613
7614 // Scrub out the location info in ServiceState depending on what level of access
7615 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007616 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007617 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7618 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007622 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007623
7624 /**
7625 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7626 *
7627 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7628 * voicemail ringtone.
7629 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7630 * PhoneAccount.
7631 */
7632 @Override
7633 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634 final long identity = Binder.clearCallingIdentity();
7635 try {
7636 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7637 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007638 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007641 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7642 } finally {
7643 Binder.restoreCallingIdentity(identity);
7644 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007645 }
7646
7647 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007648 * Sets the per-account voicemail ringtone.
7649 *
7650 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7651 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7652 *
7653 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7654 * voicemail ringtone.
7655 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7656 * PhoneAccount.
7657 */
7658 @Override
7659 public void setVoicemailRingtoneUri(String callingPackage,
7660 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007661 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007662 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007663 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7664 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7666 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7667 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007668 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669
7670 final long identity = Binder.clearCallingIdentity();
7671 try {
7672 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7673 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007674 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675 }
7676 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7677 } finally {
7678 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007679 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007680 }
7681
7682 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007683 * Returns whether vibration is set for voicemail notification in Phone settings.
7684 *
7685 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7686 * voicemail vibration setting.
7687 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7688 */
7689 @Override
7690 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7694 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007695 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007696 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
7701 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007702 }
7703
Youhan Wange64578a2016-05-02 15:32:42 -07007704 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007705 * Sets the per-account voicemail vibration.
7706 *
7707 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7708 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7709 *
7710 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7711 * voicemail vibration setting.
7712 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7713 * specific PhoneAccount.
7714 */
7715 @Override
7716 public void setVoicemailVibrationEnabled(String callingPackage,
7717 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007718 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007719 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007720 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7721 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7723 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7724 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007725 }
7726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 final long identity = Binder.clearCallingIdentity();
7728 try {
7729 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7730 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007731 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007732 }
7733 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7734 } finally {
7735 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007736 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007737 }
7738
7739 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007740 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7741 *
7742 * @throws SecurityException if the caller does not have the required permission
7743 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007744 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007745 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007746 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007747 }
7748
7749 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007750 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7751 * permission.
7752 *
7753 * @throws SecurityException if the caller does not have the required permission
7754 */
7755 private void enforceSendSmsPermission() {
7756 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7757 }
7758
7759 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007760 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007761 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007762 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007763 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007764 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 final long identity = Binder.clearCallingIdentity();
7766 try {
7767 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007768 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 if (componentName == null) {
7770 throw new SecurityException(
7771 "Caller not current active visual voicemail package[null]");
7772 }
7773 String vvmPackage = componentName.getPackageName();
7774 if (!callingPackage.equals(vvmPackage)) {
7775 throw new SecurityException("Caller not current active visual voicemail package["
7776 + vvmPackage + "]");
7777 }
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007780 }
7781 }
7782
7783 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007784 * Return the application ID for the app type.
7785 *
7786 * @param subId the subscription ID that this request applies to.
7787 * @param appType the uicc app type.
7788 * @return Application ID for specificied app type, or null if no uicc.
7789 */
7790 @Override
7791 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007792 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007793 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794
7795 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007796 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 if (phone == null) {
7798 return null;
7799 }
7800 String aid = null;
7801 try {
7802 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7803 .getApplicationByType(appType).getAid();
7804 } catch (Exception e) {
7805 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7806 }
7807 return aid;
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007810 }
Youhan Wange64578a2016-05-02 15:32:42 -07007811 }
7812
Youhan Wang4001d252016-05-11 10:29:41 -07007813 /**
7814 * Return the Electronic Serial Number.
7815 *
7816 * @param subId the subscription ID that this request applies to.
7817 * @return ESN or null if error.
7818 */
7819 @Override
7820 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007821 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007822 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823
7824 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007825 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826 if (phone == null) {
7827 return null;
7828 }
7829 String esn = null;
7830 try {
7831 esn = phone.getEsn();
7832 } catch (Exception e) {
7833 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7834 }
7835 return esn;
7836 } finally {
7837 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007838 }
Youhan Wang4001d252016-05-11 10:29:41 -07007839 }
7840
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007841 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007842 * Return the Preferred Roaming List Version.
7843 *
7844 * @param subId the subscription ID that this request applies to.
7845 * @return PRLVersion or null if error.
7846 */
7847 @Override
7848 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007849 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007850 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007851
7852 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007853 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007854 if (phone == null) {
7855 return null;
7856 }
7857 String cdmaPrlVersion = null;
7858 try {
7859 cdmaPrlVersion = phone.getCdmaPrlVersion();
7860 } catch (Exception e) {
7861 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7862 }
7863 return cdmaPrlVersion;
7864 } finally {
7865 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007866 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007867 }
7868
7869 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007870 * Get snapshot of Telephony histograms
7871 * @return List of Telephony histograms
7872 * @hide
7873 */
7874 @Override
7875 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7877 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878
7879 final long identity = Binder.clearCallingIdentity();
7880 try {
7881 return RIL.getTelephonyRILTimingHistograms();
7882 } finally {
7883 Binder.restoreCallingIdentity(identity);
7884 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007885 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007886
7887 /**
7888 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007889 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7890 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007891 * Require system privileges. In the future we may add this to carrier APIs.
7892 *
Michele Berionne482f8202018-11-27 18:57:59 -08007893 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007894 */
7895 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007896 @TelephonyManager.SetCarrierRestrictionResult
7897 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007898 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007899 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007900
Michele Berionne482f8202018-11-27 18:57:59 -08007901 if (carrierRestrictionRules == null) {
7902 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007903 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007904
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 final long identity = Binder.clearCallingIdentity();
7906 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007907 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007908 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007909 } finally {
7910 Binder.restoreCallingIdentity(identity);
7911 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007912 }
7913
7914 /**
7915 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007916 * Get the allowed carrier list and the excluded carrier list, including the priority between
7917 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007918 * Require system privileges. In the future we may add this to carrier APIs.
7919 *
Michele Berionne482f8202018-11-27 18:57:59 -08007920 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007921 */
7922 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007923 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007924 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926
7927 final long identity = Binder.clearCallingIdentity();
7928 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007929 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7930 if (response instanceof CarrierRestrictionRules) {
7931 return (CarrierRestrictionRules) response;
7932 }
7933 // Response is an Exception of some kind,
7934 // which is signalled to the user as a NULL retval
7935 return null;
7936 } catch (Exception e) {
7937 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7938 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007942 }
7943
fionaxu59545b42016-05-25 15:53:37 -07007944 /**
fionaxu59545b42016-05-25 15:53:37 -07007945 * Action set from carrier signalling broadcast receivers to enable/disable radio
7946 * @param subId the subscription ID that this action applies to.
7947 * @param enabled control enable or disable radio.
7948 * {@hide}
7949 */
7950 @Override
7951 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7952 enforceModifyPermission();
7953 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007954
7955 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007956 if (phone == null) {
7957 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7958 return;
7959 }
7960 try {
7961 phone.carrierActionSetRadioEnabled(enabled);
7962 } catch (Exception e) {
7963 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007964 } finally {
7965 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007966 }
7967 }
7968
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007969 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007970 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7971 * network status based on which carrier apps could apply actions accordingly,
7972 * enable/disable default url handler for example.
7973 *
7974 * @param subId the subscription ID that this action applies to.
7975 * @param report control start/stop reporting the default network status.
7976 * {@hide}
7977 */
7978 @Override
7979 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7980 enforceModifyPermission();
7981 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007982
7983 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007984 if (phone == null) {
7985 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7986 return;
7987 }
7988 try {
7989 phone.carrierActionReportDefaultNetworkStatus(report);
7990 } catch (Exception e) {
7991 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007992 } finally {
7993 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007994 }
7995 }
7996
7997 /**
fionaxud9622282017-07-17 17:51:30 -07007998 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7999 * @param subId the subscription ID that this action applies to.
8000 * {@hide}
8001 */
8002 @Override
8003 public void carrierActionResetAll(int subId) {
8004 enforceModifyPermission();
8005 final Phone phone = getPhone(subId);
8006 if (phone == null) {
8007 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8008 return;
8009 }
8010 try {
8011 phone.carrierActionResetAll();
8012 } catch (Exception e) {
8013 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8014 }
8015 }
8016
8017 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008018 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8019 * bug report is being generated.
8020 */
8021 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008022 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008023 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8024 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008025 writer.println("Permission Denial: can't dump Phone from pid="
8026 + Binder.getCallingPid()
8027 + ", uid=" + Binder.getCallingUid()
8028 + "without permission "
8029 + android.Manifest.permission.DUMP);
8030 return;
8031 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008032 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008033 }
Jack Yueb89b242016-06-22 13:27:47 -07008034
Brad Ebingerdac2f002018-04-03 15:17:52 -07008035 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008036 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8037 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8038 @NonNull String[] args) {
8039 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8040 this, in.getFileDescriptor(), out.getFileDescriptor(),
8041 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008042 }
8043
Jack Yueb89b242016-06-22 13:27:47 -07008044 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008045 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008046 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008047 * @param reason the reason the data enable change is taking place
8048 * @param enabled True if enabling the data, otherwise disabling.
8049 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008050 */
8051 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008052 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008053 boolean enabled) {
8054 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8055 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8056 try {
8057 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008058 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008059 } catch (SecurityException se) {
8060 enforceModifyPermission();
8061 }
8062 } else {
8063 enforceModifyPermission();
8064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008065
8066 final long identity = Binder.clearCallingIdentity();
8067 try {
8068 Phone phone = getPhone(subId);
8069 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008070 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8071 phone.carrierActionSetMeteredApnsEnabled(enabled);
8072 } else {
8073 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075 }
8076 } finally {
8077 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008078 }
8079 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008080
8081 /**
8082 * Get Client request stats
8083 * @return List of Client Request Stats
8084 * @hide
8085 */
8086 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008087 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8088 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008089 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008090 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008091 return null;
8092 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008093 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008094
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008095 final long identity = Binder.clearCallingIdentity();
8096 try {
8097 if (phone != null) {
8098 return phone.getClientRequestStats();
8099 }
8100
8101 return null;
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
8104 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008105 }
8106
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008107 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008108 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008109 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008110 }
Jack Yueb4124c2017-02-16 15:32:43 -08008111
8112 /**
Grace Chen70990072017-03-24 17:21:30 -07008113 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008114 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008115 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008116 * @param state State of SIM (power down, power up, pass through)
8117 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8118 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8119 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008120 *
8121 **/
8122 @Override
Grace Chen70990072017-03-24 17:21:30 -07008123 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008124 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008125 Phone phone = PhoneFactory.getPhone(slotIndex);
8126
vagdeviaf9a5b92018-08-15 16:01:53 -07008127 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008129 final long identity = Binder.clearCallingIdentity();
8130 try {
8131 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008132 phone.setSimPowerState(state, null, workSource);
8133 }
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
8136 }
8137 }
8138
8139 /**
8140 * Set SIM card power state.
8141 *
8142 * @param slotIndex SIM slot id.
8143 * @param state State of SIM (power down, power up, pass through)
8144 * @param callback callback to trigger after success or failure
8145 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8146 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8147 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8148 *
8149 **/
8150 @Override
8151 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8152 IIntegerConsumer callback) {
8153 enforceModifyPermission();
8154 Phone phone = PhoneFactory.getPhone(slotIndex);
8155
8156 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8157
8158 final long identity = Binder.clearCallingIdentity();
8159 try {
8160 if (phone != null) {
8161 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8162 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008163 }
8164 } finally {
8165 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008166 }
8167 }
Shuo Qiandd210312017-04-12 22:11:33 +00008168
Tyler Gunn65d45c22017-06-05 11:22:26 -07008169 private boolean isUssdApiAllowed(int subId) {
8170 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008171 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008172 if (configManager == null) {
8173 return false;
8174 }
8175 PersistableBundle pb = configManager.getConfigForSubId(subId);
8176 if (pb == null) {
8177 return false;
8178 }
8179 return pb.getBoolean(
8180 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8181 }
8182
Shuo Qiandd210312017-04-12 22:11:33 +00008183 /**
8184 * Check if phone is in emergency callback mode
8185 * @return true if phone is in emergency callback mode
8186 * @param subId sub id
8187 */
goneil9c5f4872017-12-05 14:07:56 -08008188 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008189 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008190 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008191 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008192
8193 final long identity = Binder.clearCallingIdentity();
8194 try {
8195 if (phone != null) {
8196 return phone.isInEcm();
8197 } else {
8198 return false;
8199 }
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008202 }
8203 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008204
8205 /**
8206 * Get the current signal strength information for the given subscription.
8207 * Because this information is not updated when the device is in a low power state
8208 * it should not be relied-upon to be current.
8209 * @param subId Subscription index
8210 * @return the most recent cached signal strength info from the modem
8211 */
8212 @Override
8213 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 Phone p = getPhone(subId);
8217 if (p == null) {
8218 return null;
8219 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008221 return p.getSignalStrength();
8222 } finally {
8223 Binder.restoreCallingIdentity(identity);
8224 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008225 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008226
Pengquan Meng77b7f132018-08-22 14:49:57 -07008227 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008228 * Get the current modem radio state for the given slot.
8229 * @param slotIndex slot index.
8230 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008231 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008232 * @return the current radio power state from the modem
8233 */
8234 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008235 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008236 Phone phone = PhoneFactory.getPhone(slotIndex);
8237 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8239 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008240 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8241 }
8242
8243 final long identity = Binder.clearCallingIdentity();
8244 try {
8245 return phone.getRadioPowerState();
8246 } finally {
8247 Binder.restoreCallingIdentity(identity);
8248 }
8249 }
8250 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8251 }
8252
8253 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008254 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8255 *
8256 * <p>Requires one of the following permissions:
8257 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8258 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8259 * privileges.
8260 *
8261 * @param subId subscription id
8262 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8263 * {@code false}.
8264 */
8265 @Override
8266 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008267 try {
8268 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8269 null);
8270 } catch (Exception e) {
8271 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8272 mApp, subId, "isDataRoamingEnabled");
8273 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008274
Pengquan Menga1bb6272018-09-06 09:59:22 -07008275 boolean isEnabled = false;
8276 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008277 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008278 Phone phone = getPhone(subId);
8279 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008280 } finally {
8281 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008282 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008283 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008284 }
8285
8286
8287 /**
8288 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8289 *
8290 * <p> Requires permission:
8291 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8292 * privileges.
8293 *
8294 * @param subId subscription id
8295 * @param isEnabled {@code true} means enable, {@code false} means disable.
8296 */
8297 @Override
8298 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8300 mApp, subId, "setDataRoamingEnabled");
8301
Pengquan Menga1bb6272018-09-06 09:59:22 -07008302 final long identity = Binder.clearCallingIdentity();
8303 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008304 Phone phone = getPhone(subId);
8305 if (phone != null) {
8306 phone.setDataRoamingEnabled(isEnabled);
8307 }
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008310 }
8311 }
8312
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008313 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008314 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008315 TelephonyPermissions
8316 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008317 mApp, subId, "isManualNetworkSelectionAllowed");
8318
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008319 boolean isAllowed = true;
8320 final long identity = Binder.clearCallingIdentity();
8321 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008322 Phone phone = getPhone(subId);
8323 if (phone != null) {
8324 isAllowed = phone.isCspPlmnEnabled();
8325 }
8326 } finally {
8327 Binder.restoreCallingIdentity(identity);
8328 }
8329 return isAllowed;
8330 }
8331
8332 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008333 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008334 // Verify that tha callingPackage belongs to the calling UID
8335 mApp.getSystemService(AppOpsManager.class)
8336 .checkPackage(Binder.getCallingUid(), callingPackage);
8337
Jordan Liu1e142fc2019-04-22 15:10:43 -07008338 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008339 try {
8340 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008341 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008342 } catch (SecurityException e) {
8343 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8344 // has carrier privileges on an active UICC
8345 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8346 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008347 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008348 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008349 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008350
8351 final long identity = Binder.clearCallingIdentity();
8352 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008353 UiccController uiccController = UiccController.getInstance();
8354 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008355 if (hasReadPermission) {
8356 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008357 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008358
8359 // Remove private info if the caller doesn't have access
8360 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8361 for (UiccCardInfo cardInfo : cardInfos) {
8362 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8363 // is available
8364 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8365 if (card == null || card.getUiccProfile() == null) {
8366 // assume no access if the card or profile is unavailable
8367 filteredInfos.add(cardInfo.getUnprivileged());
8368 continue;
8369 }
8370 UiccProfile profile = card.getUiccProfile();
8371 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8372 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8373 filteredInfos.add(cardInfo);
8374 } else {
8375 filteredInfos.add(cardInfo.getUnprivileged());
8376 }
8377 }
8378 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008379 } finally {
8380 Binder.restoreCallingIdentity(identity);
8381 }
8382 }
8383
8384 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008385 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008386 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388 final long identity = Binder.clearCallingIdentity();
8389 try {
8390 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8391 if (slots == null) {
8392 Rlog.i(LOG_TAG, "slots is null.");
8393 return null;
8394 }
8395
8396 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8397 for (int i = 0; i < slots.length; i++) {
8398 UiccSlot slot = slots[i];
8399 if (slot == null) {
8400 continue;
8401 }
8402
Jordan Liu7be7e652019-05-06 18:55:02 +00008403 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008404 UiccCard card = slot.getUiccCard();
8405 if (card != null) {
8406 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008407 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008408 cardId = slot.getEid();
8409 if (TextUtils.isEmpty(cardId)) {
8410 cardId = slot.getIccId();
8411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008412 }
8413
Jordan Liu857451f2019-05-09 16:35:35 -07008414 if (cardId != null) {
8415 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8416 // if cardId is an EID, it's all digits so this is fine
8417 cardId = IccUtils.stripTrailingFs(cardId);
8418 }
8419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008420 int cardState = 0;
8421 switch (slot.getCardState()) {
8422 case CARDSTATE_ABSENT:
8423 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8424 break;
8425 case CARDSTATE_PRESENT:
8426 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8427 break;
8428 case CARDSTATE_ERROR:
8429 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8430 break;
8431 case CARDSTATE_RESTRICTED:
8432 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8433 break;
8434 default:
8435 break;
8436
8437 }
8438
8439 infos[i] = new UiccSlotInfo(
8440 slot.isActive(),
8441 slot.isEuicc(),
8442 cardId,
8443 cardState,
8444 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008445 slot.isExtendedApduSupported(),
8446 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008447 }
8448 return infos;
8449 } finally {
8450 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008451 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008452 }
8453
8454 @Override
8455 public boolean switchSlots(int[] physicalSlots) {
8456 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008457
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008464 }
Jack Yu4c988042018-02-27 15:30:01 -08008465
8466 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008467 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008468 final long identity = Binder.clearCallingIdentity();
8469 try {
8470 return UiccController.getInstance().getCardIdForDefaultEuicc();
8471 } finally {
8472 Binder.restoreCallingIdentity(identity);
8473 }
8474 }
8475
Pengquan Meng85728fb2018-03-12 16:31:21 -07008476 /**
goneil47ffb6e2018-04-06 15:40:58 -07008477 * A test API to reload the UICC profile.
8478 *
8479 * <p>Requires that the calling app has permission
8480 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8481 * @hide
8482 */
8483 @Override
8484 public void refreshUiccProfile(int subId) {
8485 enforceModifyPermission();
8486
8487 final long identity = Binder.clearCallingIdentity();
8488 try {
8489 Phone phone = getPhone(subId);
8490 if (phone == null) {
8491 return;
8492 }
8493 UiccCard uiccCard = phone.getUiccCard();
8494 if (uiccCard == null) {
8495 return;
8496 }
8497 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8498 if (uiccProfile == null) {
8499 return;
8500 }
8501 uiccProfile.refresh();
8502 } finally {
8503 Binder.restoreCallingIdentity(identity);
8504 }
8505 }
8506
8507 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008508 * Returns false if the mobile data is disabled by default, otherwise return true.
8509 */
8510 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008511 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008512 }
8513
8514 /**
8515 * Returns true if the data roaming is enabled by default, i.e the system property
8516 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8517 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8518 */
8519 private boolean getDefaultDataRoamingEnabled(int subId) {
8520 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008521 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008522 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008523 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8524 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8525 return isDataRoamingEnabled;
8526 }
8527
8528 /**
8529 * Returns the default network type for the given {@code subId}, if the default network type is
8530 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8531 */
8532 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008533 List<Integer> list = TelephonyProperties.default_network();
8534 int phoneId = mSubscriptionController.getPhoneId(subId);
8535 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8536 return list.get(phoneId);
8537 }
8538 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008539 }
fionaxua13278b2018-03-21 00:08:13 -07008540
8541 @Override
8542 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008543 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008545
8546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 final Phone phone = getPhone(subId);
8549 if (phone == null) {
8550 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8551 return;
8552 }
chen xueaba88a2019-03-15 13:15:10 -07008553 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8554 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008555 if (carrierPrivilegeRules == null) {
8556 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8557 } else {
8558 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8559 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008560 } finally {
8561 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008562 }
fionaxua13278b2018-03-21 00:08:13 -07008563 }
8564
8565 @Override
8566 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008567 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008568
8569 final long identity = Binder.clearCallingIdentity();
8570 try {
8571 final Phone phone = getPhone(subId);
8572 if (phone == null) {
8573 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8574 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8575 }
8576 return phone.getCarrierIdListVersion();
8577 } finally {
8578 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008579 }
fionaxua13278b2018-03-21 00:08:13 -07008580 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008581
8582 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008583 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8584 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008585 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008586 mApp, subId, callingPackage, callingFeatureId,
8587 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008588 return -1;
8589 }
8590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8594 } finally {
8595 Binder.restoreCallingIdentity(identity);
8596 }
8597 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008598
8599 @Override
8600 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008601 TelephonyPermissions
8602 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008603 mApp, subId, "getCdmaRoamingMode");
8604
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
8611 }
8612
8613 @Override
8614 public boolean setCdmaRoamingMode(int subId, int mode) {
8615 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8616 mApp, subId, "setCdmaRoamingMode");
8617
8618 final long identity = Binder.clearCallingIdentity();
8619 try {
8620 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8621 } finally {
8622 Binder.restoreCallingIdentity(identity);
8623 }
8624 }
8625
8626 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008627 public int getCdmaSubscriptionMode(int subId) {
8628 TelephonyPermissions
8629 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8630 mApp, subId, "getCdmaSubscriptionMode");
8631
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8635 } finally {
8636 Binder.restoreCallingIdentity(identity);
8637 }
8638 }
8639
8640 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008641 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8643 mApp, subId, "setCdmaSubscriptionMode");
8644
8645 final long identity = Binder.clearCallingIdentity();
8646 try {
8647 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8648 } finally {
8649 Binder.restoreCallingIdentity(identity);
8650 }
8651 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008652
sqianc5eccab2018-10-19 18:46:41 -07008653 @Override
sqian8c685422019-02-22 15:55:18 -08008654 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008655 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008656 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008657 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8658 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008659 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8660 }
8661 final long identity = Binder.clearCallingIdentity();
8662 try {
sqian854d44b2018-12-12 16:48:18 -08008663 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8664 for (Phone phone: PhoneFactory.getPhones()) {
8665 if (phone.getEmergencyNumberTracker() != null
8666 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8667 emergencyNumberListInternal.put(
8668 phone.getSubId(),
8669 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8670 }
sqian11b7a0e2018-12-05 18:48:28 -08008671 }
sqian854d44b2018-12-12 16:48:18 -08008672 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008673 } finally {
8674 Binder.restoreCallingIdentity(identity);
8675 }
sqianc5eccab2018-10-19 18:46:41 -07008676 }
8677
8678 @Override
sqian8c685422019-02-22 15:55:18 -08008679 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008680 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008681 if (!exactMatch) {
8682 TelephonyPermissions
8683 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008684 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008685 }
8686 final long identity = Binder.clearCallingIdentity();
8687 try {
sqian854d44b2018-12-12 16:48:18 -08008688 for (Phone phone: PhoneFactory.getPhones()) {
8689 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008690 && phone.getEmergencyNumberTracker()
8691 .isEmergencyNumber(number, exactMatch)) {
8692 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008693 }
sqian11b7a0e2018-12-05 18:48:28 -08008694 }
8695 return false;
8696 } finally {
8697 Binder.restoreCallingIdentity(identity);
8698 }
8699 }
8700
sqianf4ca7ed2019-01-15 18:32:07 -08008701 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008702 * Start emergency callback mode for GsmCdmaPhone for testing.
8703 */
8704 @Override
8705 public void startEmergencyCallbackMode() {
8706 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8707 "startEmergencyCallbackMode");
8708 enforceModifyPermission();
8709 final long identity = Binder.clearCallingIdentity();
8710 try {
8711 for (Phone phone : PhoneFactory.getPhones()) {
8712 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8713 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8714 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8715 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8716 gsmCdmaPhone.obtainMessage(
8717 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8718 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8719 }
8720 }
8721 } finally {
8722 Binder.restoreCallingIdentity(identity);
8723 }
8724 }
8725
8726 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008727 * Update emergency number list for test mode.
8728 */
8729 @Override
8730 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8731 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8732 "updateEmergencyNumberListTestMode");
8733
8734 final long identity = Binder.clearCallingIdentity();
8735 try {
8736 for (Phone phone: PhoneFactory.getPhones()) {
8737 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8738 if (tracker != null) {
8739 tracker.executeEmergencyNumberTestModeCommand(action, num);
8740 }
8741 }
8742 } finally {
8743 Binder.restoreCallingIdentity(identity);
8744 }
8745 }
8746
8747 /**
8748 * Get the full emergency number list for test mode.
8749 */
8750 @Override
8751 public List<String> getEmergencyNumberListTestMode() {
8752 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8753 "getEmergencyNumberListTestMode");
8754
8755 final long identity = Binder.clearCallingIdentity();
8756 try {
8757 Set<String> emergencyNumbers = new HashSet<>();
8758 for (Phone phone: PhoneFactory.getPhones()) {
8759 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8760 if (tracker != null) {
8761 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8762 emergencyNumbers.add(num.getNumber());
8763 }
8764 }
8765 }
8766 return new ArrayList<>(emergencyNumbers);
8767 } finally {
8768 Binder.restoreCallingIdentity(identity);
8769 }
8770 }
8771
chen xud6b45bd2018-10-30 22:27:10 -07008772 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008773 public int getEmergencyNumberDbVersion(int subId) {
8774 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8775
8776 final long identity = Binder.clearCallingIdentity();
8777 try {
8778 final Phone phone = getPhone(subId);
8779 if (phone == null) {
8780 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8781 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8782 }
8783 return phone.getEmergencyNumberDbVersion();
8784 } finally {
8785 Binder.restoreCallingIdentity(identity);
8786 }
8787 }
8788
8789 @Override
8790 public void notifyOtaEmergencyNumberDbInstalled() {
8791 enforceModifyPermission();
8792
8793 final long identity = Binder.clearCallingIdentity();
8794 try {
8795 for (Phone phone: PhoneFactory.getPhones()) {
8796 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8797 if (tracker != null) {
8798 tracker.updateOtaEmergencyNumberDatabase();
8799 }
8800 }
8801 } finally {
8802 Binder.restoreCallingIdentity(identity);
8803 }
8804 }
8805
8806 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008807 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008808 enforceActiveEmergencySessionPermission();
8809
8810 final long identity = Binder.clearCallingIdentity();
8811 try {
8812 for (Phone phone: PhoneFactory.getPhones()) {
8813 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8814 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008815 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8816 }
8817 }
8818 } finally {
8819 Binder.restoreCallingIdentity(identity);
8820 }
8821 }
8822
8823 @Override
8824 public void resetOtaEmergencyNumberDbFilePath() {
8825 enforceActiveEmergencySessionPermission();
8826
8827 final long identity = Binder.clearCallingIdentity();
8828 try {
8829 for (Phone phone: PhoneFactory.getPhones()) {
8830 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8831 if (tracker != null) {
8832 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008833 }
8834 }
8835 } finally {
8836 Binder.restoreCallingIdentity(identity);
8837 }
8838 }
8839
8840 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008841 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8842 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8843 Phone phone = getPhone(subId);
8844 if (phone == null) {
8845 return null;
8846 }
8847 final long identity = Binder.clearCallingIdentity();
8848 try {
8849 UiccProfile profile = UiccController.getInstance()
8850 .getUiccProfileForPhone(phone.getPhoneId());
8851 if (profile != null) {
8852 return profile.getCertsFromCarrierPrivilegeAccessRules();
8853 }
8854 } finally {
8855 Binder.restoreCallingIdentity(identity);
8856 }
8857 return null;
8858 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008859
8860 /**
8861 * Enable or disable a modem stack.
8862 */
8863 @Override
8864 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8865 enforceModifyPermission();
8866
8867 final long identity = Binder.clearCallingIdentity();
8868 try {
8869 Phone phone = PhoneFactory.getPhone(slotIndex);
8870 if (phone == null) {
8871 return false;
8872 } else {
8873 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8874 }
8875 } finally {
8876 Binder.restoreCallingIdentity(identity);
8877 }
8878 }
Michelecea4cf22018-12-21 15:00:11 -08008879
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008880 /**
8881 * Whether a modem stack is enabled or not.
8882 */
8883 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008884 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8885 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008886 Phone phone = PhoneFactory.getPhone(slotIndex);
8887 if (phone == null) return false;
8888
8889 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008890 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8891 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008892 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8893 }
8894
8895 final long identity = Binder.clearCallingIdentity();
8896 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008897 try {
8898 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8899 } catch (NoSuchElementException ex) {
8900 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8901 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008902 } finally {
8903 Binder.restoreCallingIdentity(identity);
8904 }
8905 }
8906
Michelecea4cf22018-12-21 15:00:11 -08008907 @Override
Michele0ea7d782019-03-19 14:58:42 -07008908 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008909 enforceModifyPermission();
8910
8911 final long identity = Binder.clearCallingIdentity();
8912 try {
8913 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008914 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008915 .commit();
8916 } finally {
8917 Binder.restoreCallingIdentity(identity);
8918 }
8919 }
8920
8921 @Override
Michele0ea7d782019-03-19 14:58:42 -07008922 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008923 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008925 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8926 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008927 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008928 }
Michelecea4cf22018-12-21 15:00:11 -08008929
8930 final long identity = Binder.clearCallingIdentity();
8931 try {
Michele0ea7d782019-03-19 14:58:42 -07008932 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008933 } finally {
8934 Binder.restoreCallingIdentity(identity);
8935 }
8936 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008937
Michele0ea7d782019-03-19 14:58:42 -07008938 @TelephonyManager.IsMultiSimSupportedResult
8939 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008940 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8941 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8942 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008943 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8944 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008945 }
8946 // Check if the hardware supports multisim functionality. If usage of multisim is not
8947 // supported by the modem, indicate that it is restricted.
8948 PhoneCapability staticCapability =
8949 mPhoneConfigurationManager.getStaticPhoneCapability();
8950 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008951 loge("isMultiSimSupportedInternal: no static configuration available");
8952 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008953 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008954 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008955 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8956 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008957 }
8958 // Check if support of multiple SIMs is restricted by carrier
8959 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008960 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008961 }
8962
Michele0ea7d782019-03-19 14:58:42 -07008963 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008964 }
8965
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008966 /**
8967 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008968 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8969 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8970 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008971 * @param numOfSims number of active sims we want to switch to
8972 */
8973 @Override
8974 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008975 if (numOfSims == 1) {
8976 enforceModifyPermission();
8977 } else {
8978 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8979 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8980 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008981 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008982
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008983 try {
Michele30b57b22019-03-01 12:01:14 -08008984 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008985 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008986 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8987 return;
8988 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008989 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8990 } finally {
8991 Binder.restoreCallingIdentity(identity);
8992 }
8993 }
8994
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008995 @Override
8996 public boolean isApplicationOnUicc(int subId, int appType) {
8997 enforceReadPrivilegedPermission("isApplicationOnUicc");
8998 Phone phone = getPhone(subId);
8999 if (phone == null) {
9000 return false;
9001 }
9002 final long identity = Binder.clearCallingIdentity();
9003 try {
9004 UiccCard uiccCard = phone.getUiccCard();
9005 if (uiccCard == null) {
9006 return false;
9007 }
9008 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9009 if (uiccProfile == null) {
9010 return false;
9011 }
9012 if (TelephonyManager.APPTYPE_SIM <= appType
9013 && appType <= TelephonyManager.APPTYPE_ISIM) {
9014 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9015 }
9016 return false;
9017 } finally {
9018 Binder.restoreCallingIdentity(identity);
9019 }
9020 }
9021
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009022 /**
chen xub4baa772019-04-03 10:23:41 -07009023 * Get whether making changes to modem configurations will trigger reboot.
9024 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009025 */
9026 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009027 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9028 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009029 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009030 mApp, subId, callingPackage, callingFeatureId,
9031 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009032 return false;
9033 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009034 final long identity = Binder.clearCallingIdentity();
9035 try {
9036 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9037 } finally {
9038 Binder.restoreCallingIdentity(identity);
9039 }
9040 }
9041
Nathan Harold29f5f052019-02-15 13:41:57 -08009042 private void updateModemStateMetrics() {
9043 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9044 // TODO: check the state for each modem if the api is ready.
9045 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9046 }
9047
Pengquan Meng3889a572019-01-23 11:16:29 -08009048 @Override
9049 public int[] getSlotsMapping() {
9050 enforceReadPrivilegedPermission("getSlotsMapping");
9051
9052 final long identity = Binder.clearCallingIdentity();
9053 try {
9054 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9055 // All logical slots should have a mapping to a physical slot.
9056 int[] logicalSlotsMapping = new int[phoneCount];
9057 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9058 for (int i = 0; i < slotInfos.length; i++) {
9059 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9060 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9061 }
9062 }
9063 return logicalSlotsMapping;
9064 } finally {
9065 Binder.restoreCallingIdentity(identity);
9066 }
9067 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009068
9069 /**
9070 * Get the IRadio HAL Version
9071 */
9072 @Override
9073 public int getRadioHalVersion() {
9074 Phone phone = getDefaultPhone();
9075 if (phone == null) return -1;
9076 HalVersion hv = phone.getHalVersion();
9077 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9078 return hv.major * 100 + hv.minor;
9079 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009080
9081 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009082 * Get the current calling package name.
9083 * @return the current calling package name
9084 */
9085 @Override
9086 public String getCurrentPackageName() {
9087 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9088 }
9089
9090 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009091 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9092 * corresponding network requests on a subId.
9093 *
9094 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009095 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009096 * 2) APN is un-metered for this subscription, or
9097 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009098 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009099 *
9100 * @return whether data is allowed for a apn type.
9101 *
9102 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009103 */
9104 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009105 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009106 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9107 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009108
9109 // Now that all security checks passes, perform the operation as ourselves.
9110 final long identity = Binder.clearCallingIdentity();
9111 try {
9112 Phone phone = getPhone(subId);
9113 if (phone == null) return false;
9114
Jack Yu41407ee2019-05-13 16:54:09 -07009115 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009116 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9117 } finally {
9118 Binder.restoreCallingIdentity(identity);
9119 }
9120 }
9121
9122 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009123 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009124 enforceReadPrivilegedPermission("isApnMetered");
9125
9126 // Now that all security checks passes, perform the operation as ourselves.
9127 final long identity = Binder.clearCallingIdentity();
9128 try {
9129 Phone phone = getPhone(subId);
9130 if (phone == null) return true; // By default return true.
9131
Jack Yu41407ee2019-05-13 16:54:09 -07009132 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009133 } finally {
9134 Binder.restoreCallingIdentity(identity);
9135 }
9136 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009137
9138 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009139 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9140 int subscriptionId, IBooleanConsumer resultCallback) {
9141 enforceModifyPermission();
9142 long token = Binder.clearCallingIdentity();
9143 try {
9144 Phone phone = getPhone(subscriptionId);
9145 if (phone == null) {
9146 try {
9147 if (resultCallback != null) {
9148 resultCallback.accept(false);
9149 }
9150 } catch (RemoteException e) {
9151 // ignore
9152 }
9153 return;
9154 }
9155 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9156 Pair.create(specifiers, (x) -> {
9157 try {
9158 if (resultCallback != null) {
9159 resultCallback.accept(x);
9160 }
9161 } catch (RemoteException e) {
9162 // ignore
9163 }
9164 });
9165 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9166 } finally {
9167 Binder.restoreCallingIdentity(token);
9168 }
9169 }
9170
9171 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009172 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9173 TelephonyPermissions
9174 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9175 mApp, subId, "getSystemSelectionChannels");
9176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9177 final long identity = Binder.clearCallingIdentity();
9178 try {
9179 List<RadioAccessSpecifier> specifiers =
9180 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9181 null, subId, workSource);
9182 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9183 return specifiers;
9184 } finally {
9185 Binder.restoreCallingIdentity(identity);
9186 }
9187 }
9188
9189 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009190 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009191 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009192 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9193 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9194 if (iccRecords == null) {
9195 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9196 return false;
9197 }
9198 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9199 }
9200
9201 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009202 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9203 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009204 if (callingPackage == null) {
9205 callingPackage = getCurrentPackageName();
9206 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009207 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9208 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009209 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9210 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009211 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9212 }
9213 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9214 Intent intent = new Intent();
9215 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9216 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9217 // Bring up choose default SMS subscription dialog right now
9218 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9219 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9220 mApp.startActivity(intent);
9221 }
chen xud5ca2d52019-05-28 15:20:57 -07009222
9223 @Override
9224 public String getMmsUAProfUrl(int subId) {
9225 //TODO investigate if this API should require proper permission check in R b/133791609
9226 final long identity = Binder.clearCallingIdentity();
9227 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009228 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9229 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9230 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9231 return carrierUAProfUrl;
9232 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009233 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9234 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 }
9239
9240 @Override
9241 public String getMmsUserAgent(int subId) {
9242 //TODO investigate if this API should require proper permission check in R b/133791609
9243 final long identity = Binder.clearCallingIdentity();
9244 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009245 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9246 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9247 if (!TextUtils.isEmpty(carrierUserAgent)) {
9248 return carrierUserAgent;
9249 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009250 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9251 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009252 } finally {
9253 Binder.restoreCallingIdentity(identity);
9254 }
9255 }
Jack Yub07d4972019-05-28 16:12:25 -07009256
9257 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009258 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9259 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009260
Jack Yub07d4972019-05-28 16:12:25 -07009261 final long identity = Binder.clearCallingIdentity();
9262 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009263 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009264 if (phone == null) return false;
9265
Hall Liua62f5da2020-09-25 10:42:19 -07009266 switch (policy) {
9267 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9268 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9269 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9270 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9271 default:
9272 throw new IllegalArgumentException(policy + " is not a valid policy");
9273 }
Jack Yub07d4972019-05-28 16:12:25 -07009274 } finally {
9275 Binder.restoreCallingIdentity(identity);
9276 }
9277 }
9278
9279 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009280 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009281 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009282 enforceModifyPermission();
9283
changbettyd5c246e2019-12-24 15:40:37 +08009284 final long identity = Binder.clearCallingIdentity();
9285 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009286 Phone phone = getPhone(subscriptionId);
9287 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009288
Hall Liua62f5da2020-09-25 10:42:19 -07009289 switch (policy) {
9290 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9291 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9292 break;
9293 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9294 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9295 break;
9296 default:
9297 throw new IllegalArgumentException(policy + " is not a valid policy");
9298 }
changbettyd5c246e2019-12-24 15:40:37 +08009299 } finally {
9300 Binder.restoreCallingIdentity(identity);
9301 }
9302 }
9303
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009304 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009305 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009306 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9307 * otherwise.
9308 */
9309 @Override
9310 public void setCepEnabled(boolean isCepEnabled) {
9311 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9312
9313 final long identity = Binder.clearCallingIdentity();
9314 try {
9315 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9316 for (Phone phone : PhoneFactory.getPhones()) {
9317 Phone defaultPhone = phone.getImsPhone();
9318 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9319 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9320 ImsPhoneCallTracker imsPhoneCallTracker =
9321 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9322 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9323 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9324 + imsPhone.getMsisdn());
9325 }
9326 }
9327 } finally {
9328 Binder.restoreCallingIdentity(identity);
9329 }
9330 }
allenwtsu46dcc572020-01-08 18:24:03 +08009331
9332 /**
9333 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9334 *
9335 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9336 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9337 * before being read.
9338 */
9339 @Override
9340 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9341 isCompressed) {
9342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9343 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009344 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9345 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9346 }
9347 if (!isImsAvailableOnDevice()) {
9348 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9349 "IMS not available on device.");
9350 }
9351
9352 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009353 try {
Hui Wang761a6682020-10-31 05:12:53 +00009354 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9355 } finally {
9356 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009357 }
9358 }
zoey chene02881a2019-12-30 16:11:23 +08009359
9360 @Override
9361 public boolean isIccLockEnabled(int subId) {
9362 enforceReadPrivilegedPermission("isIccLockEnabled");
9363
9364 // Now that all security checks passes, perform the operation as ourselves.
9365 final long identity = Binder.clearCallingIdentity();
9366 try {
9367 Phone phone = getPhone(subId);
9368 if (phone != null && phone.getIccCard() != null) {
9369 return phone.getIccCard().getIccLockEnabled();
9370 } else {
9371 return false;
9372 }
9373 } finally {
9374 Binder.restoreCallingIdentity(identity);
9375 }
9376 }
9377
9378 /**
9379 * Set the ICC pin lock enabled or disabled.
9380 *
9381 * @return an integer representing the status of IccLock enabled or disabled in the following
9382 * three cases:
9383 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9384 * successfully.
9385 * - Positive number and zero for remaining password attempts.
9386 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9387 *
9388 */
9389 @Override
9390 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9391 enforceModifyPermission();
9392
9393 Phone phone = getPhone(subId);
9394 if (phone == null) {
9395 return 0;
9396 }
9397 // Now that all security checks passes, perform the operation as ourselves.
9398 final long identity = Binder.clearCallingIdentity();
9399 try {
9400 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9401 new Pair<Boolean, String>(enabled, password), phone, null);
9402 return attemptsRemaining;
9403
9404 } catch (Exception e) {
9405 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9406 } finally {
9407 Binder.restoreCallingIdentity(identity);
9408 }
9409 return 0;
9410 }
9411
9412 /**
9413 * Change the ICC password used in ICC pin lock.
9414 *
9415 * @return an integer representing the status of IccLock changed in the following three cases:
9416 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9417 * - Positive number and zero for remaining password attempts.
9418 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9419 *
9420 */
9421 @Override
9422 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9423 enforceModifyPermission();
9424
9425 Phone phone = getPhone(subId);
9426 if (phone == null) {
9427 return 0;
9428 }
9429 // Now that all security checks passes, perform the operation as ourselves.
9430 final long identity = Binder.clearCallingIdentity();
9431 try {
9432 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9433 new Pair<String, String>(oldPassword, newPassword), phone, null);
9434 return attemptsRemaining;
9435
9436 } catch (Exception e) {
9437 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
9441 return 0;
9442 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009443
9444 /**
9445 * Request for receiving user activity notification
9446 */
9447 @Override
9448 public void requestUserActivityNotification() {
9449 if (!mNotifyUserActivity.get()
9450 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9451 mNotifyUserActivity.set(true);
9452 }
9453 }
9454
9455 /**
9456 * Called when userActivity is signalled in the power manager.
9457 * This is safe to call from any thread, with any window manager locks held or not.
9458 */
9459 @Override
9460 public void userActivity() {
9461 // ***************************************
9462 // * Inherited from PhoneWindowManager *
9463 // ***************************************
9464 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9465 // WITH ITS LOCKS HELD.
9466 //
9467 // This code must be VERY careful about the locks
9468 // it acquires.
9469 // In fact, the current code acquires way too many,
9470 // and probably has lurking deadlocks.
9471
9472 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9473 throw new SecurityException("Only the OS may call notifyUserActivity()");
9474 }
9475
9476 if (mNotifyUserActivity.getAndSet(false)) {
9477 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9478 USER_ACTIVITY_NOTIFICATION_DELAY);
9479 }
9480 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009481
9482 @Override
9483 public boolean canConnectTo5GInDsdsMode() {
9484 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9485 }
Jack Yud10cdd42020-09-28 20:28:01 -07009486
9487 @Override
9488 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9489 String callingFeatureId) {
9490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9491 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9492 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9493 }
9494
9495 Phone phone = getPhone(subId);
9496 if (phone == null) {
9497 throw new RuntimeException("phone is not available");
9498 }
9499 // Now that all security checks passes, perform the operation as ourselves.
9500 final long identity = Binder.clearCallingIdentity();
9501 try {
9502 return phone.getEquivalentHomePlmns();
9503 } finally {
9504 Binder.restoreCallingIdentity(identity);
9505 }
9506 }
Daniel Bright59e67312020-11-13 11:49:37 -08009507
9508 @Override
9509 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009510 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9511 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009512 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009513 if (radioInterfaceCapabilities == null) {
9514 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009515 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009516 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009517 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009518
Hui Wang641e81c2020-10-12 12:14:23 -07009519 @Override
9520 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9521 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009522 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9523 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9524 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9525 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9526 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009527 if (DBG) {
9528 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9529 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9530 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9531 }
9532
9533 if (!SubscriptionManager.isValidSubscriptionId(subId)
9534 || appType < TelephonyManager.APPTYPE_UNKNOWN
9535 || appType > TelephonyManager.APPTYPE_ISIM
9536 || nafUrl == null || securityProtocol == null || callback == null) {
9537 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9538 if (callback != null) {
9539 try {
9540 callback.onAuthenticationFailure(
9541 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9542 } catch (RemoteException exception) {
9543 log("Fail to notify onAuthenticationFailure due to " + exception);
9544 }
9545 return;
9546 }
9547 }
9548
9549 final long token = Binder.clearCallingIdentity();
9550 try {
9551 getGbaManager(subId).bootstrapAuthenticationRequest(
9552 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9553 forceBootStrapping, callback));
9554 } finally {
9555 Binder.restoreCallingIdentity(token);
9556 }
9557 }
9558
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009559 /**
9560 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9561 * requested radio power state will actually be set. See {@link
9562 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9563 *
9564 * @param subId the subscription ID of the phone requesting to set the radio power state.
9565 * @param enable {@code true} if trying to turn radio on.
9566 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9567 * false}.
9568 */
9569 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9570 Phone phone = getPhone(subId);
9571 if (phone != null) {
9572 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9573 return true;
9574 }
9575 return false;
9576 }
9577
9578 private int handleDataThrottlingRequest(int subId,
9579 DataThrottlingRequest dataThrottlingRequest) {
9580 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9581 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9582 if (!setRadioPowerForThermal(subId, true)) {
9583 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9584 }
9585
9586 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9587
9588 int thermalMitigationResult =
9589 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9590 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9591 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9592 }
9593 return thermalMitigationResult;
9594 }
9595
9596 /**
9597 * Thermal mitigation request to control functionalities at modem.
9598 *
9599 * @param subId the id of the subscription.
9600 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9601 *
9602 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9603 */
9604 @Override
9605 @ThermalMitigationResult
9606 public int sendThermalMitigationRequest(
9607 int subId,
9608 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9609 enforceModifyPermission();
9610
9611 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9612 final long identity = Binder.clearCallingIdentity();
9613
9614 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9615 try {
9616 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9617 switch (thermalMitigationAction) {
9618 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9619 thermalMitigationResult =
9620 handleDataThrottlingRequest(subId,
9621 thermalMitigationRequest.getDataThrottlingRequest());
9622 break;
9623 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9624 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9625 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9626 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9627 }
9628
9629 // Ensure that radio is on. If not able to power on due to phone being
9630 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9631 if (!setRadioPowerForThermal(subId, true)) {
9632 thermalMitigationResult =
9633 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9634 break;
9635 }
9636
9637 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9638 false);
9639 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9640 break;
9641 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9642 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9643 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9644 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9645 }
9646
9647 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9648 if (registry != null) {
9649 TelephonyConnectionService service =
9650 registry.getTelephonyConnectionService();
9651 Phone phone = getPhone(subId);
9652 if (phone == null) {
9653 thermalMitigationResult =
9654 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9655 break;
9656 }
9657
9658 if (PhoneConstantConversions.convertCallState(phone.getState())
9659 != TelephonyManager.CALL_STATE_IDLE
9660 || phone.isInEmergencySmsMode() || phone.isInEcm()
9661 || (service != null && service.isEmergencyCallPending())) {
9662 String errorMessage = "Phone state is not valid. call state = "
9663 + PhoneConstantConversions.convertCallState(phone.getState())
9664 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9665 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9666 errorMessage += service == null
9667 ? " TelephonyConnectionService is null"
9668 : " isEmergencyCallPending = "
9669 + service.isEmergencyCallPending();
9670 Log.e(LOG_TAG, errorMessage);
9671 thermalMitigationResult =
9672 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9673 break;
9674 }
9675 } else {
9676 thermalMitigationResult =
9677 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9678 break;
9679 }
9680
9681 // Turn radio off. If not able to power off due to phone being unavailable,
9682 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9683 if (!setRadioPowerForThermal(subId, false)) {
9684 thermalMitigationResult =
9685 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9686 break;
9687 }
9688 thermalMitigationResult =
9689 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9690 break;
9691 default:
9692 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9693 + "not exist. Requested action: " + thermalMitigationAction);
9694 }
9695 } catch (IllegalArgumentException e) {
9696 throw e;
9697 } catch (Exception e) {
9698 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9699 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9700 } finally {
9701 Binder.restoreCallingIdentity(identity);
9702 }
9703
9704 if (DBG) {
9705 log("thermalMitigationRequest returning with thermalMitigationResult: "
9706 + thermalMitigationResult);
9707 }
9708
9709 return thermalMitigationResult;
9710 }
Hui Wang641e81c2020-10-12 12:14:23 -07009711
9712 /**
9713 * Set the GbaService Package Name that Telephony will bind to.
9714 *
9715 * @param subId The sim that the GbaService is associated with.
9716 * @param packageName The name of the package to be replaced with.
9717 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9718 */
9719 @Override
9720 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9721 enforceModifyPermission();
9722
9723 final long identity = Binder.clearCallingIdentity();
9724 try {
9725 return getGbaManager(subId).overrideServicePackage(packageName);
9726 } finally {
9727 Binder.restoreCallingIdentity(identity);
9728 }
9729 }
9730
9731 /**
9732 * Return the package name of the currently bound GbaService.
9733 *
9734 * @param subId The sim that the GbaService is associated with.
9735 * @return the package name of the GbaService configuration, null if GBA is not supported.
9736 */
9737 @Override
9738 public String getBoundGbaService(int subId) {
9739 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9740
9741 final long identity = Binder.clearCallingIdentity();
9742 try {
9743 return getGbaManager(subId).getServicePackage();
9744 } finally {
9745 Binder.restoreCallingIdentity(identity);
9746 }
9747 }
9748
9749 /**
9750 * Set the release time for telephony to unbind GbaService.
9751 *
9752 * @param subId The sim that the GbaService is associated with.
9753 * @param interval The release time to unbind GbaService by millisecond.
9754 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9755 */
9756 @Override
9757 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9758 enforceModifyPermission();
9759
9760 final long identity = Binder.clearCallingIdentity();
9761 try {
9762 return getGbaManager(subId).overrideReleaseTime(interval);
9763 } finally {
9764 Binder.restoreCallingIdentity(identity);
9765 }
9766 }
9767
9768 /**
9769 * Return the release time for telephony to unbind GbaService.
9770 *
9771 * @param subId The sim that the GbaService is associated with.
9772 * @return The release time to unbind GbaService by millisecond.
9773 */
9774 @Override
9775 public int getGbaReleaseTime(int subId) {
9776 enforceReadPrivilegedPermission("getGbaReleaseTime");
9777
9778 final long identity = Binder.clearCallingIdentity();
9779 try {
9780 return getGbaManager(subId).getReleaseTime();
9781 } finally {
9782 Binder.restoreCallingIdentity(identity);
9783 }
9784 }
9785
9786 private GbaManager getGbaManager(int subId) {
9787 GbaManager instance = GbaManager.getInstance(subId);
9788 if (instance == null) {
9789 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9790 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9791 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9792 }
9793 return instance;
9794 }
Hui Wang761a6682020-10-31 05:12:53 +00009795
9796 /**
9797 * indicate whether the device and the carrier can support
9798 * RCS VoLTE single registration.
9799 */
9800 @Override
9801 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009802 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9803 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9804 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9805 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009806
9807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9808 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9809 }
9810
9811 final long identity = Binder.clearCallingIdentity();
9812 try {
9813 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9814 if (rpm != null) {
9815 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9816 }
9817 return false;
9818 } finally {
9819 Binder.restoreCallingIdentity(identity);
9820 }
9821 }
9822
9823 /**
9824 * Register RCS provisioning callback.
9825 */
9826 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009827 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009828 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009829 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009830 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009831 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9832 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009833
9834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9835 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9836 }
9837 if (!isImsAvailableOnDevice()) {
9838 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9839 "IMS not available on device.");
9840 }
9841
9842 final long identity = Binder.clearCallingIdentity();
9843 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009844 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009845 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -08009846 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9847 "Service not available for the subscription.");
9848 }
Hui Wang761a6682020-10-31 05:12:53 +00009849 } finally {
9850 Binder.restoreCallingIdentity(identity);
9851 }
9852 }
9853
9854 /**
9855 * Unregister RCS provisioning callback.
9856 */
9857 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009858 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009859 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009860 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009861 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009862 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9863 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009864
9865 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9866 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9867 }
9868 if (!isImsAvailableOnDevice()) {
9869 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9870 "IMS not available on device.");
9871 }
9872
9873 final long identity = Binder.clearCallingIdentity();
9874 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009875 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009876 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009877 } finally {
9878 Binder.restoreCallingIdentity(identity);
9879 }
9880 }
9881
9882 /**
9883 * trigger RCS reconfiguration.
9884 */
9885 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009886 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9887 "triggerRcsReconfiguration",
9888 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009889
9890 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9891 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9892 }
9893 if (!isImsAvailableOnDevice()) {
9894 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9895 "IMS not available on device.");
9896 }
9897
9898 final long identity = Binder.clearCallingIdentity();
9899 try {
9900 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9901 } finally {
9902 Binder.restoreCallingIdentity(identity);
9903 }
9904 }
9905
9906 /**
9907 * Provide the client configuration parameters of the RCS application.
9908 */
9909 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009910 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9911 "setRcsClientConfiguration",
9912 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009913
9914 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9915 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9916 }
9917 if (!isImsAvailableOnDevice()) {
9918 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9919 "IMS not available on device.");
9920 }
9921
9922 final long identity = Binder.clearCallingIdentity();
9923
9924 try {
9925 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9926 if (configBinder == null) {
9927 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9928 } else {
9929 configBinder.setRcsClientConfiguration(rcc);
9930 }
9931 } catch (RemoteException e) {
9932 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9933 } finally {
9934 Binder.restoreCallingIdentity(identity);
9935 }
9936 }
9937
9938 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -08009939 * Enables or disables the test mode for RCS VoLTE single registration.
9940 */
9941 @Override
9942 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9944 "setRcsSingleRegistrationTestModeEnabled");
9945
9946 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9947 }
9948
9949 /**
9950 * Gets the test mode for RCS VoLTE single registration.
9951 */
9952 @Override
9953 public boolean getRcsSingleRegistrationTestModeEnabled() {
9954 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9955 "getRcsSingleRegistrationTestModeEnabled");
9956
9957 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9958 }
9959
9960 /**
Hui Wang761a6682020-10-31 05:12:53 +00009961 * Overrides the config of RCS VoLTE single registration enabled for the device.
9962 */
9963 @Override
9964 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9965 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9966 "setDeviceSingleRegistrationEnabledOverride");
9967 enforceModifyPermission();
9968
9969 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9970 : Boolean.parseBoolean(enabledStr);
9971 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009972 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +00009973 }
9974
9975 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009976 * Sends a device to device communication message. Only usable via shell.
9977 * @param message message to send.
9978 * @param value message value.
9979 */
9980 @Override
9981 public void sendDeviceToDeviceMessage(int message, int value) {
9982 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -08009983 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -08009984 enforceModifyPermission();
9985
9986 final long identity = Binder.clearCallingIdentity();
9987 try {
9988 TelephonyConnectionService service =
9989 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9990 if (service == null) {
9991 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9992 return;
9993 }
9994 service.sendTestDeviceToDeviceMessage(message, value);
9995 } finally {
9996 Binder.restoreCallingIdentity(identity);
9997 }
9998 }
9999
Tyler Gunnbabbda02021-02-10 11:05:02 -080010000 /**
10001 * Sets the specified device to device transport active.
10002 * @param transport The transport to set active.
10003 */
10004 @Override
10005 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10006 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10007 "setActiveDeviceToDeviceTransport");
10008 enforceModifyPermission();
10009
10010 final long identity = Binder.clearCallingIdentity();
10011 try {
10012 TelephonyConnectionService service =
10013 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10014 if (service == null) {
10015 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10016 return;
10017 }
10018 service.setActiveDeviceToDeviceTransport(transport);
10019 } finally {
10020 Binder.restoreCallingIdentity(identity);
10021 }
10022 }
Tyler Gunn92479152021-01-20 16:30:10 -080010023
10024 /**
Hui Wang761a6682020-10-31 05:12:53 +000010025 * Gets the config of RCS VoLTE single registration enabled for the device.
10026 */
10027 @Override
10028 public boolean getDeviceSingleRegistrationEnabled() {
10029 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10030 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10031 }
10032
10033 /**
10034 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10035 */
10036 @Override
10037 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10038 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10039 "setCarrierSingleRegistrationEnabledOverride");
10040 enforceModifyPermission();
10041
10042 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10043 : Boolean.parseBoolean(enabledStr);
10044 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10045 subId, enabled);
10046 }
10047
10048 /**
10049 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10050 */
10051 @Override
10052 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10053 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10054 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10055 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010056
10057 /**
10058 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10059 * their mobile plan.
10060 */
10061 @Override
10062 public String getMobileProvisioningUrl() {
10063 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10064 final long identity = Binder.clearCallingIdentity();
10065 try {
10066 return getDefaultPhone().getMobileProvisioningUrl();
10067 } finally {
10068 Binder.restoreCallingIdentity(identity);
10069 }
10070 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010071
James.cf Linbcdf8b32021-01-14 16:44:13 +080010072 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010073 * Get the EAB contact from the EAB database.
10074 */
10075 @Override
10076 public String getContactFromEab(String contact) {
10077 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10078 enforceModifyPermission();
10079 final long identity = Binder.clearCallingIdentity();
10080 try {
10081 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10082 } finally {
10083 Binder.restoreCallingIdentity(identity);
10084 }
10085 }
10086
10087 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010088 * Remove the EAB contacts from the EAB database.
10089 */
10090 @Override
10091 public int removeContactFromEab(int subId, String contacts) {
10092 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10093 enforceModifyPermission();
10094 final long identity = Binder.clearCallingIdentity();
10095 try {
10096 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10097 } finally {
10098 Binder.restoreCallingIdentity(identity);
10099 }
10100 }
10101
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010102 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010103 public boolean getDeviceUceEnabled() {
10104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10105 final long identity = Binder.clearCallingIdentity();
10106 try {
10107 return mApp.getDeviceUceEnabled();
10108 } finally {
10109 Binder.restoreCallingIdentity(identity);
10110 }
10111 }
10112
10113 @Override
10114 public void setDeviceUceEnabled(boolean isEnabled) {
10115 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10116 final long identity = Binder.clearCallingIdentity();
10117 try {
10118 mApp.setDeviceUceEnabled(isEnabled);
10119 } finally {
10120 Binder.restoreCallingIdentity(identity);
10121 }
10122 }
10123
10124 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010125 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10126 String callingPackage) {
10127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10128 mApp, subId, "setSignalStrengthUpdateRequest");
10129
10130 final int callingUid = Binder.getCallingUid();
10131 // Verify that tha callingPackage belongs to the calling UID
10132 mApp.getSystemService(AppOpsManager.class)
10133 .checkPackage(callingUid, callingPackage);
10134
10135 validateSignalStrengthUpdateRequest(request, callingUid);
10136
10137 final long identity = Binder.clearCallingIdentity();
10138 try {
10139 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10140 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10141
10142 if (result instanceof IllegalStateException) {
10143 throw (IllegalStateException) result;
10144 }
10145 } finally {
10146 Binder.restoreCallingIdentity(identity);
10147 }
10148 }
10149
10150 @Override
10151 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10152 String callingPackage) {
10153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10154 mApp, subId, "clearSignalStrengthUpdateRequest");
10155
10156 final int callingUid = Binder.getCallingUid();
10157 // Verify that tha callingPackage belongs to the calling UID
10158 mApp.getSystemService(AppOpsManager.class)
10159 .checkPackage(callingUid, callingPackage);
10160
10161 final long identity = Binder.clearCallingIdentity();
10162 try {
10163 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10164 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10165
10166 if (result instanceof IllegalStateException) {
10167 throw (IllegalStateException) result;
10168 }
10169 } finally {
10170 Binder.restoreCallingIdentity(identity);
10171 }
10172 }
10173
10174 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10175 int callingUid) {
10176 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10177 // phone/system process do not have further restriction on request
10178 return;
10179 }
10180
10181 // Applications has restrictions on how to use the request:
10182 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10183 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10184 // This is not system caller which has been checked above
10185 throw new IllegalArgumentException(
10186 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10187 }
10188
10189 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10190 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10191 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10192 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10193 || info.isEnabled()) {
10194 throw new IllegalArgumentException(
10195 "Only system can set hide fields in SignalThresholdInfo");
10196 }
10197
10198 // Thresholds length for each RAN need in range. This has been validated in
10199 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10200 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10201 final int[] thresholds = info.getThresholds();
10202 Objects.requireNonNull(thresholds);
10203 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10204 || thresholds.length
10205 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10206 throw new IllegalArgumentException(
10207 "thresholds length is out of range: " + thresholds.length);
10208 }
10209 }
10210 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010211
10212 /**
10213 * Gets the current phone capability.
10214 *
10215 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10216 * @return the PhoneCapability which describes the data connection capability of modem.
10217 * It's used to evaluate possible phone config change, for example from single
10218 * SIM device to multi-SIM device.
10219 */
10220 @Override
10221 public PhoneCapability getPhoneCapability() {
10222 enforceReadPrivilegedPermission("getPhoneCapability");
10223 final long identity = Binder.clearCallingIdentity();
10224 try {
10225 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10226 } finally {
10227 Binder.restoreCallingIdentity(identity);
10228 }
10229 }
Michele Berionne5e411512020-11-13 02:36:59 +000010230
10231 /**
10232 * Prepare TelephonyManager for an unattended reboot. The reboot is
10233 * required to be done shortly after the API is invoked.
10234 */
10235 @Override
10236 @TelephonyManager.PrepareUnattendedRebootResult
10237 public int prepareForUnattendedReboot() {
10238 enforceRebootPermission();
10239
10240 final long identity = Binder.clearCallingIdentity();
10241 try {
10242 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10243 } finally {
10244 Binder.restoreCallingIdentity(identity);
10245 }
10246 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010247}