blob: 798d4295a4a55bcfa6f76a2aba2cd5a85dbf5a67 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Shuo Qianccbaf742021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Brad Ebinger34c09a52021-02-17 23:23:21 +000026import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080028import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070029import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080031import android.app.PendingIntent;
Hall Liu82694d52020-12-11 18:22:04 -080032import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070033import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070034import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.content.Context;
36import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070037import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070038import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080039import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070040import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.net.Uri;
42import android.os.AsyncResult;
43import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080044import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Bundle;
46import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.Looper;
49import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070050import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080051import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070052import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070053import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080054import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080055import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070056import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070057import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080058import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070059import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070060import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070061import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070062import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070063import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080064import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070065import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090066import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080067import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080068import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070069import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070070import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080071import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080072import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070073import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080074import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070075import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080076import android.telephony.CellIdentityCdma;
77import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070079import android.telephony.CellInfoGsm;
80import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070081import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080082import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070083import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070084import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070085import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080086import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070087import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080088import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070089import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080090import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080091import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070092import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080095import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080096import android.telephony.SignalStrengthUpdateRequest;
97import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080098import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080099import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800100import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700101import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700102import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800103import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800104import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800105import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000106import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700107import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700108import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800109import android.telephony.data.ApnSetting;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800110import android.telephony.data.SlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800111import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700112import android.telephony.gba.GbaAuthRequest;
113import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700114import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000116import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000117import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700118import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800120import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700121import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800122import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700123import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000124import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700125import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800126import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800127import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800128import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800129import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800131import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700132import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800134import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800135
Andrew Lee312e8172014-10-23 17:01:36 -0700136import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800137import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800138import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800139import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700141import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700142import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800143import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700144import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800146import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700147import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700148import com.android.internal.telephony.GbaManager;
Shuo Qianccbaf742021-02-22 18:32:21 -0800149import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800150import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800151import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700152import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800154import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800156import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700157import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700158import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700159import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700161import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800162import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700163import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700164import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700165import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700166import com.android.internal.telephony.RIL;
SongFerngWang8c6e82e2021-03-02 22:09:29 +0800167import com.android.internal.telephony.RILConstants;
Daniel Bright94f43662021-03-01 14:43:40 -0800168import com.android.internal.telephony.RadioInterfaceCapabilityController;
Jack Yu5f7092c2018-04-13 14:05:37 -0700169import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700170import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800172import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800173import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800174import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700175import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700177import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800178import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700179import com.android.internal.telephony.imsphone.ImsPhone;
180import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800181import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700182import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800184import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700187import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700189import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800190import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000191import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800192import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700193import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700194import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800195import com.android.internal.util.HexDump;
Hall Liuaa4211e2021-01-20 15:43:39 -0800196import com.android.phone.callcomposer.CallComposerPictureManager;
197import com.android.phone.callcomposer.CallComposerPictureTransfer;
198import com.android.phone.callcomposer.ImageData;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700199import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700200import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800201import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700202import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700203import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800204import com.android.services.telephony.TelecomAccountRegistry;
205import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800206import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800207
Hall Liu82694d52020-12-11 18:22:04 -0800208import java.io.ByteArrayOutputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700209import java.io.FileDescriptor;
Hall Liu82694d52020-12-11 18:22:04 -0800210import java.io.IOException;
211import java.io.InputStream;
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700212import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800214import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800215import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800216import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800217import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100218import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800219import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700220import java.util.NoSuchElementException;
Hall Liu82694d52020-12-11 18:22:04 -0800221import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800222import java.util.Set;
Hall Liu82694d52020-12-11 18:22:04 -0800223import java.util.concurrent.Executors;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800224import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800225import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700226
227/**
228 * Implementation of the ITelephony interface.
229 */
Santos Cordon117fee72014-05-16 17:56:12 -0700230public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700231 private static final String LOG_TAG = "PhoneInterfaceManager";
232 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
233 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800234 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700235
236 // Message codes used with mMainThreadHandler
237 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700238 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
239 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700240 private static final int CMD_OPEN_CHANNEL = 9;
241 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
242 private static final int CMD_CLOSE_CHANNEL = 11;
243 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800244 private static final int CMD_NV_READ_ITEM = 13;
245 private static final int EVENT_NV_READ_ITEM_DONE = 14;
246 private static final int CMD_NV_WRITE_ITEM = 15;
247 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
248 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
249 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700250 private static final int CMD_RESET_MODEM_CONFIG = 19;
251 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800252 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
253 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800254 private static final int CMD_SEND_ENVELOPE = 25;
255 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000256 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
257 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700258 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
259 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
260 private static final int CMD_EXCHANGE_SIM_IO = 31;
261 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800262 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
263 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700264 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
265 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700266 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
267 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700268 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
269 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
270 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
271 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700272 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
273 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
274 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
275 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700276 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800277 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
278 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000279 private static final int CMD_SWITCH_SLOTS = 50;
280 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700281 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
282 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
283 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
284 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
285 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
286 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
287 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
288 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700289 private static final int CMD_GET_ALL_CELL_INFO = 60;
290 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
291 private static final int CMD_GET_CELL_LOCATION = 62;
292 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700293 private static final int CMD_MODEM_REBOOT = 64;
294 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700295 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
296 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800297 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
298 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700299 private static final int CMD_GET_MODEM_STATUS = 70;
300 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700301 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
302 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700303 private static final int CMD_ERASE_MODEM_CONFIG = 74;
304 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800305 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
306 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
307 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
308 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800309 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
310 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800311 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800312 private static final int CMD_GET_CALL_FORWARDING = 83;
313 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
314 private static final int CMD_SET_CALL_FORWARDING = 85;
315 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
316 private static final int CMD_GET_CALL_WAITING = 87;
317 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
318 private static final int CMD_SET_CALL_WAITING = 89;
319 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700320 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
321 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
322 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
323 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700324 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
325 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800326 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
327 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800328 private static final int CMD_SET_DATA_THROTTLING = 99;
329 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800330 private static final int CMD_SET_SIM_POWER = 101;
331 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800332 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
333 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
334 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
335 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800336 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
337 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionne5e411512020-11-13 02:36:59 +0000338 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800339 private static final int CMD_GET_SLICING_CONFIG = 110;
340 private static final int EVENT_GET_SLICING_CONFIG_DONE = 111;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800342 // Parameters of select command.
343 private static final int SELECT_COMMAND = 0xA4;
344 private static final int SELECT_P1 = 0x04;
345 private static final int SELECT_P2 = 0;
346 private static final int SELECT_P3 = 0x10;
347
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 /** The singleton instance. */
349 private static PhoneInterfaceManager sInstance;
350
Wink Saville3ab207e2014-11-20 13:07:20 -0800351 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800352 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800353 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700354 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800355 private AppOpsManager mAppOps;
356 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800357 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800358 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700359 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800360 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361
Peter Wangdafb9ac2020-01-15 14:13:38 -0800362 /** User Activity */
363 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800364 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
365
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700366 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
367
Derek Tan97ebb422014-09-05 16:55:38 -0700368 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
369 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800370 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800371 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700372
Michelecea4cf22018-12-21 15:00:11 -0800373 // String to store multi SIM allowed
374 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
375
Derek Tan740e1672017-06-27 14:56:27 -0700376 // The AID of ISD-R.
377 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
378
yinxub1bed742017-04-17 11:45:04 -0700379 private NetworkScanRequestTracker mNetworkScanRequestTracker;
380
David Kelly5e06a7f2018-03-12 14:10:59 +0000381 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
382 private static final int MANUFACTURER_CODE_LENGTH = 8;
383
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800384 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
385
Derek Tan89e89d42014-07-08 17:00:10 -0700386 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700387 * Experiment flag to enable erase modem config on reset network, default value is false
388 */
389 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
390 "reset_network_erase_modem_config_enabled";
391
Rambo Wang0f050d82021-02-12 11:43:36 -0800392 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
393
Naina Nallurid63128d2019-09-17 14:10:30 -0700394 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700395 * A request object to use for transmitting data to an ICC.
396 */
397 private static final class IccAPDUArgument {
398 public int channel, cla, command, p1, p2, p3;
399 public String data;
400
401 public IccAPDUArgument(int channel, int cla, int command,
402 int p1, int p2, int p3, String data) {
403 this.channel = channel;
404 this.cla = cla;
405 this.command = command;
406 this.p1 = p1;
407 this.p2 = p2;
408 this.p3 = p3;
409 this.data = data;
410 }
411 }
412
413 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700414 * A request object to use for transmitting data to an ICC.
415 */
416 private static final class ManualNetworkSelectionArgument {
417 public OperatorInfo operatorInfo;
418 public boolean persistSelection;
419
420 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
421 this.operatorInfo = operatorInfo;
422 this.persistSelection = persistSelection;
423 }
424 }
425
426 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
428 * request after sending. The main thread will notify the request when it is complete.
429 */
430 private static final class MainThreadRequest {
431 /** The argument to use for the request */
432 public Object argument;
433 /** The result of the request that is run on the main thread */
434 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800435 // The subscriber id that this request applies to. Defaults to
436 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
437 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438
Nathan Harold92bed182018-10-12 18:16:49 -0700439 // In cases where subId is unavailable, the caller needs to specify the phone.
440 public Phone phone;
441
vagdeviaf9a5b92018-08-15 16:01:53 -0700442 public WorkSource workSource;
443
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 public MainThreadRequest(Object argument) {
445 this.argument = argument;
446 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800447
Nathan Harold92bed182018-10-12 18:16:49 -0700448 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
449 this.argument = argument;
450 if (phone != null) {
451 this.phone = phone;
452 }
453 this.workSource = workSource;
454 }
455
vagdeviaf9a5b92018-08-15 16:01:53 -0700456 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800457 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800458 if (subId != null) {
459 this.subId = subId;
460 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700461 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700463 }
464
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800465 private static final class IncomingThirdPartyCallArgs {
466 public final ComponentName component;
467 public final String callId;
468 public final String callerDisplayName;
469
470 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
471 String callerDisplayName) {
472 this.component = component;
473 this.callId = callId;
474 this.callerDisplayName = callerDisplayName;
475 }
476 }
477
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 /**
479 * A handler that processes messages on the main thread in the phone process. Since many
480 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
481 * inbound binder threads to the main thread in the phone process. The Binder thread
482 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
483 * on, which will be notified when the operation completes and will contain the result of the
484 * request.
485 *
486 * <p>If a MainThreadRequest object is provided in the msg.obj field,
487 * note that request.result must be set to something non-null for the calling thread to
488 * unblock.
489 */
490 private final class MainThreadHandler extends Handler {
491 @Override
492 public void handleMessage(Message msg) {
493 MainThreadRequest request;
494 Message onCompleted;
495 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800496 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800498 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700499
500 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700501 case CMD_HANDLE_USSD_REQUEST: {
502 request = (MainThreadRequest) msg.obj;
503 final Phone phone = getPhoneFromRequest(request);
504 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
505 String ussdRequest = ussdObject.first;
506 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700507
Pengquan Menga1bb6272018-09-06 09:59:22 -0700508 if (!isUssdApiAllowed(request.subId)) {
509 // Carrier does not support use of this API, return failure.
510 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
511 UssdResponse response = new UssdResponse(ussdRequest, null);
512 Bundle returnData = new Bundle();
513 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
514 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700515
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 request.result = true;
517 notifyRequester(request);
518 return;
519 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700520
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 try {
522 request.result = phone != null
523 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
524 } catch (CallStateException cse) {
525 request.result = false;
526 }
527 // Wake up the requesting thread
528 notifyRequester(request);
529 break;
pkanwar32d516d2016-10-14 19:37:38 -0700530 }
531
Yorke Lee716f67e2015-06-17 15:39:16 -0700532 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700533 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700534 final Phone phone = getPhoneFromRequest(request);
535 request.result = phone != null ?
536 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
537 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700538 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800546 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700547 if (uiccCard == null) {
548 loge("iccTransmitApduLogicalChannel: No UICC");
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700550 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
553 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 iccArgument.channel, iccArgument.cla, iccArgument.command,
556 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700557 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 break;
560
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 ar = (AsyncResult) msg.obj;
563 request = (MainThreadRequest) ar.userObj;
564 if (ar.exception == null && ar.result != null) {
565 request.result = ar.result;
566 } else {
567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
568 if (ar.result == null) {
569 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800570 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800572 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 } else {
574 loge("iccTransmitApduLogicalChannel: Unknown exception");
575 }
576 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 break;
579
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
581 request = (MainThreadRequest) msg.obj;
582 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800583 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 if (uiccCard == null) {
585 loge("iccTransmitApduBasicChannel: No UICC");
586 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
590 request);
591 uiccCard.iccTransmitApduBasicChannel(
592 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
593 iccArgument.p3, iccArgument.data, onCompleted);
594 }
595 break;
596
597 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
598 ar = (AsyncResult) msg.obj;
599 request = (MainThreadRequest) ar.userObj;
600 if (ar.exception == null && ar.result != null) {
601 request.result = ar.result;
602 } else {
603 request.result = new IccIoResult(0x6F, 0, (byte[])null);
604 if (ar.result == null) {
605 loge("iccTransmitApduBasicChannel: Empty response");
606 } else if (ar.exception instanceof CommandException) {
607 loge("iccTransmitApduBasicChannel: CommandException: " +
608 ar.exception);
609 } else {
610 loge("iccTransmitApduBasicChannel: Unknown exception");
611 }
612 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 break;
615
616 case CMD_EXCHANGE_SIM_IO:
617 request = (MainThreadRequest) msg.obj;
618 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800619 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 if (uiccCard == null) {
621 loge("iccExchangeSimIO: No UICC");
622 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 } else {
625 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
626 request);
627 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
628 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
629 iccArgument.data, onCompleted);
630 }
631 break;
632
633 case EVENT_EXCHANGE_SIM_IO_DONE:
634 ar = (AsyncResult) msg.obj;
635 request = (MainThreadRequest) ar.userObj;
636 if (ar.exception == null && ar.result != null) {
637 request.result = ar.result;
638 } else {
639 request.result = new IccIoResult(0x6f, 0, (byte[])null);
640 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700641 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 break;
643
Derek Tan4d5e5c12014-02-04 11:54:58 -0800644 case CMD_SEND_ENVELOPE:
645 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800646 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700647 if (uiccCard == null) {
648 loge("sendEnvelopeWithStatus: No UICC");
649 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700650 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 } else {
652 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
653 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
654 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 break;
656
657 case EVENT_SEND_ENVELOPE_DONE:
658 ar = (AsyncResult) msg.obj;
659 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700660 if (ar.exception == null && ar.result != null) {
661 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800662 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700663 request.result = new IccIoResult(0x6F, 0, (byte[])null);
664 if (ar.result == null) {
665 loge("sendEnvelopeWithStatus: Empty response");
666 } else if (ar.exception instanceof CommandException) {
667 loge("sendEnvelopeWithStatus: CommandException: " +
668 ar.exception);
669 } else {
670 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
671 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800672 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700673 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 break;
675
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 case CMD_OPEN_CHANNEL:
677 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800678 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800679 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 if (uiccCard == null) {
681 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800682 request.result = new IccOpenLogicalChannelResponse(-1,
683 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700684 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700685 } else {
686 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800687 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
688 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
692 case EVENT_OPEN_CHANNEL_DONE:
693 ar = (AsyncResult) msg.obj;
694 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 int[] result = (int[]) ar.result;
698 int channelId = result[0];
699 byte[] selectResponse = null;
700 if (result.length > 1) {
701 selectResponse = new byte[result.length - 1];
702 for (int i = 1; i < result.length; ++i) {
703 selectResponse[i - 1] = (byte) result[i];
704 }
705 }
706 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700707 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 if (ar.result == null) {
710 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700712 if (ar.exception != null) {
713 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
714 }
715
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700716 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700717 if (ar.exception instanceof CommandException) {
718 CommandException.Error error =
719 ((CommandException) (ar.exception)).getCommandError();
720 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700721 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700722 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700723 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700724 }
725 }
726 openChannelResp = new IccOpenLogicalChannelResponse(
727 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700728 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700729 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700730 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700731 break;
732
733 case CMD_CLOSE_CHANNEL:
734 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800735 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700736 if (uiccCard == null) {
737 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900738 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700739 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700740 } else {
741 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
742 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
743 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 break;
745
746 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800747 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
748 break;
749
750 case CMD_NV_READ_ITEM:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800753 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
754 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800755 break;
756
757 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700758 ar = (AsyncResult) msg.obj;
759 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800760 if (ar.exception == null && ar.result != null) {
761 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700762 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800763 request.result = "";
764 if (ar.result == null) {
765 loge("nvReadItem: Empty response");
766 } else if (ar.exception instanceof CommandException) {
767 loge("nvReadItem: CommandException: " +
768 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700769 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800770 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700771 }
772 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700773 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 break;
775
Jake Hambye994d462014-02-03 13:10:13 -0800776 case CMD_NV_WRITE_ITEM:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
779 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800780 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700781 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800782 break;
783
784 case EVENT_NV_WRITE_ITEM_DONE:
785 handleNullReturnEvent(msg, "nvWriteItem");
786 break;
787
788 case CMD_NV_WRITE_CDMA_PRL:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800792 break;
793
794 case EVENT_NV_WRITE_CDMA_PRL_DONE:
795 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
796 break;
797
chen xu6dac5ab2018-10-26 17:39:23 -0700798 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800799 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700800 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800801 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800802 break;
803
chen xu6dac5ab2018-10-26 17:39:23 -0700804 case EVENT_RESET_MODEM_CONFIG_DONE:
805 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800806 break;
807
Sooraj Sasindran37444802020-08-11 10:40:43 -0700808 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
809 request = (MainThreadRequest) msg.obj;
810 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
811 request);
812 Phone phone = getPhoneFromRequest(request);
813 if (phone != null) {
814 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
815 } else {
816 loge("isNRDualConnectivityEnabled: No phone object");
817 request.result = false;
818 notifyRequester(request);
819 }
820 break;
821 }
822
823 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
824 ar = (AsyncResult) msg.obj;
825 request = (MainThreadRequest) ar.userObj;
826 if (ar.exception == null && ar.result != null) {
827 request.result = ar.result;
828 } else {
829 // request.result must be set to something non-null
830 // for the calling thread to unblock
831 if (request.result != null) {
832 request.result = ar.result;
833 } else {
834 request.result = false;
835 }
836 if (ar.result == null) {
837 loge("isNRDualConnectivityEnabled: Empty response");
838 } else if (ar.exception instanceof CommandException) {
839 loge("isNRDualConnectivityEnabled: CommandException: "
840 + ar.exception);
841 } else {
842 loge("isNRDualConnectivityEnabled: Unknown exception");
843 }
844 }
845 notifyRequester(request);
846 break;
847
848 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
849 request = (MainThreadRequest) msg.obj;
850 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
851 Phone phone = getPhoneFromRequest(request);
852 if (phone != null) {
853 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
854 request.workSource);
855 } else {
856 loge("enableNrDualConnectivity: No phone object");
857 request.result =
858 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
859 notifyRequester(request);
860 }
861 break;
862 }
863
864 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
867 if (ar.exception == null) {
868 request.result =
869 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
870 } else {
871 request.result =
872 TelephonyManager
873 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
874 if (ar.exception instanceof CommandException) {
875 CommandException.Error error =
876 ((CommandException) (ar.exception)).getCommandError();
877 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
878 request.result =
879 TelephonyManager
880 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000881 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
882 request.result =
883 TelephonyManager
884 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700885 }
886 loge("enableNrDualConnectivity" + ": CommandException: "
887 + ar.exception);
888 } else {
889 loge("enableNrDualConnectivity" + ": Unknown exception");
890 }
891 }
892 notifyRequester(request);
893 break;
894 }
895
SongFerngWang3ef3e072020-12-21 16:41:52 +0800896 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800898 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
899 request);
900 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 break;
902
SongFerngWang3ef3e072020-12-21 16:41:52 +0800903 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 ar = (AsyncResult) msg.obj;
905 request = (MainThreadRequest) ar.userObj;
906 if (ar.exception == null && ar.result != null) {
907 request.result = ar.result; // Integer
908 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530909 // request.result must be set to something non-null
910 // for the calling thread to unblock
911 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800912 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800913 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800914 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800915 loge("getAllowedNetworkTypesBitmask: CommandException: "
916 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800918 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 }
920 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700921 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800922 break;
923
SongFerngWang3ef3e072020-12-21 16:41:52 +0800924 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800925 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800926 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
927 request);
928 Pair<Integer, Long> reasonWithNetworkTypes =
929 (Pair<Integer, Long>) request.argument;
930 getPhoneFromRequest(request).setAllowedNetworkTypes(
931 reasonWithNetworkTypes.first,
932 reasonWithNetworkTypes.second,
933 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800934 break;
935
SongFerngWang3ef3e072020-12-21 16:41:52 +0800936 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
937 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800938 break;
939
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000940 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
941 request = (MainThreadRequest)msg.obj;
942 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800943 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000944 break;
945
946 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
947 ar = (AsyncResult)msg.obj;
948 request = (MainThreadRequest)ar.userObj;
949 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700950 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000951 break;
952
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800953 case CMD_SET_VOICEMAIL_NUMBER:
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
956 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800957 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
958 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800959 break;
960
961 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
962 handleNullReturnEvent(msg, "setVoicemailNumber");
963 break;
964
Stuart Scott54788802015-03-30 13:18:01 -0700965 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
968 request);
969 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
970 break;
971
972 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
973 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
974 break;
975
Shishir Agrawal302c8692015-06-19 13:49:39 -0700976 case CMD_PERFORM_NETWORK_SCAN:
977 request = (MainThreadRequest) msg.obj;
978 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
979 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
980 break;
981
Hall Liu27d24262020-09-18 19:04:59 -0700982 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800983 request = (MainThreadRequest) msg.obj;
984 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700985 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
986 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
987 request.argument;
988 int callForwardingReason = args.first;
989 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800990 break;
Hall Liu27d24262020-09-18 19:04:59 -0700991 }
992 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700995 TelephonyManager.CallForwardingInfoCallback callback =
996 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
997 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800998 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700999 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001000 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1001 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1002 // Service Class is a bit mask per 3gpp 27.007. Search for
1003 // any service for voice call.
1004 if ((callForwardInfo.serviceClass
1005 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001006 callForwardingInfo = new CallForwardingInfo(true,
1007 callForwardInfo.reason,
1008 callForwardInfo.number,
1009 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001010 break;
1011 }
1012 }
1013 // Didn't find a call forward info for voice call.
1014 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001015 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1016 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001017 }
Hall Liu27d24262020-09-18 19:04:59 -07001018 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001019 } else {
1020 if (ar.result == null) {
1021 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1022 }
1023 if (ar.exception != null) {
1024 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1025 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001026 int errorCode = TelephonyManager
1027 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001028 if (ar.exception instanceof CommandException) {
1029 CommandException.Error error =
1030 ((CommandException) (ar.exception)).getCommandError();
1031 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001032 errorCode = TelephonyManager
1033 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001034 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001035 errorCode = TelephonyManager
1036 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001037 }
1038 }
Hall Liu27d24262020-09-18 19:04:59 -07001039 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001040 }
Shuo Qian4a594052020-01-23 11:59:30 -08001041 break;
Hall Liu27d24262020-09-18 19:04:59 -07001042 }
Shuo Qian4a594052020-01-23 11:59:30 -08001043
Hall Liu27d24262020-09-18 19:04:59 -07001044 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001045 request = (MainThreadRequest) msg.obj;
1046 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001047 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001048 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001049 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1050 request.argument).first;
1051 request.phone.setCallForwardingOption(
1052 callForwardingInfoToSet.isEnabled()
1053 ? CommandsInterface.CF_ACTION_ENABLE
1054 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001055 callForwardingInfoToSet.getReason(),
1056 callForwardingInfoToSet.getNumber(),
1057 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1058 break;
Hall Liu27d24262020-09-18 19:04:59 -07001059 }
Shuo Qian4a594052020-01-23 11:59:30 -08001060
Hall Liu27d24262020-09-18 19:04:59 -07001061 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001062 ar = (AsyncResult) msg.obj;
1063 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001064 Consumer<Integer> callback =
1065 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1066 request.argument).second;
1067 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001068 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001069 int errorCode = TelephonyManager.CallForwardingInfoCallback
1070 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001071 if (ar.exception instanceof CommandException) {
1072 CommandException.Error error =
1073 ((CommandException) (ar.exception)).getCommandError();
1074 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001075 errorCode = TelephonyManager.CallForwardingInfoCallback
1076 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001077 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001078 errorCode = TelephonyManager.CallForwardingInfoCallback
1079 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001080 }
1081 }
1082 callback.accept(errorCode);
1083 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001084 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001085 }
Shuo Qian4a594052020-01-23 11:59:30 -08001086 break;
Hall Liu27d24262020-09-18 19:04:59 -07001087 }
Shuo Qian4a594052020-01-23 11:59:30 -08001088
Hall Liu27d24262020-09-18 19:04:59 -07001089 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001090 request = (MainThreadRequest) msg.obj;
1091 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1092 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1093 break;
Hall Liu27d24262020-09-18 19:04:59 -07001094 }
Shuo Qian4a594052020-01-23 11:59:30 -08001095
Hall Liu27d24262020-09-18 19:04:59 -07001096 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001099 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001100 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1101 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001102 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001103 // Service Class is a bit mask per 3gpp 27.007.
1104 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001105 if (callForwardResults.length > 1
1106 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001107 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001108 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001109 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1110 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001111 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001112 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001113 }
1114 } else {
1115 if (ar.result == null) {
1116 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1117 }
1118 if (ar.exception != null) {
1119 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1120 }
1121 if (ar.exception instanceof CommandException) {
1122 CommandException.Error error =
1123 ((CommandException) (ar.exception)).getCommandError();
1124 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1125 callForwardingStatus =
1126 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1127 }
1128 }
1129 }
Hall Liu27d24262020-09-18 19:04:59 -07001130 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001131 break;
Hall Liu27d24262020-09-18 19:04:59 -07001132 }
Shuo Qian4a594052020-01-23 11:59:30 -08001133
Hall Liu27d24262020-09-18 19:04:59 -07001134 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001135 request = (MainThreadRequest) msg.obj;
1136 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001137 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1138 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001139 break;
Hall Liu27d24262020-09-18 19:04:59 -07001140 }
Shuo Qian4a594052020-01-23 11:59:30 -08001141
Hall Liu27d24262020-09-18 19:04:59 -07001142 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001143 ar = (AsyncResult) msg.obj;
1144 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001145 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1146 Consumer<Integer> callback =
1147 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1148 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001149 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001150 if (ar.exception instanceof CommandException) {
1151 CommandException.Error error =
1152 ((CommandException) (ar.exception)).getCommandError();
1153 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1154 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1155 } else {
1156 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1157 }
1158 } else {
1159 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1160 }
1161 } else {
1162 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1163 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001164 }
Shuo Qian4a594052020-01-23 11:59:30 -08001165 break;
Hall Liu27d24262020-09-18 19:04:59 -07001166 }
Shuo Qian4a594052020-01-23 11:59:30 -08001167
Shishir Agrawal302c8692015-06-19 13:49:39 -07001168 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1169 ar = (AsyncResult) msg.obj;
1170 request = (MainThreadRequest) ar.userObj;
1171 CellNetworkScanResult cellScanResult;
1172 if (ar.exception == null && ar.result != null) {
1173 cellScanResult = new CellNetworkScanResult(
1174 CellNetworkScanResult.STATUS_SUCCESS,
1175 (List<OperatorInfo>) ar.result);
1176 } else {
1177 if (ar.result == null) {
1178 loge("getCellNetworkScanResults: Empty response");
1179 }
1180 if (ar.exception != null) {
1181 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1182 }
1183 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1184 if (ar.exception instanceof CommandException) {
1185 CommandException.Error error =
1186 ((CommandException) (ar.exception)).getCommandError();
1187 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1188 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1189 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1190 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1191 }
1192 }
1193 cellScanResult = new CellNetworkScanResult(errorCode, null);
1194 }
1195 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001196 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001197 break;
1198
1199 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1200 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001201 ManualNetworkSelectionArgument selArg =
1202 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001203 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1204 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001205 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1206 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001207 break;
1208
1209 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001210 ar = (AsyncResult) msg.obj;
1211 request = (MainThreadRequest) ar.userObj;
1212 if (ar.exception == null) {
1213 request.result = true;
1214 } else {
1215 request.result = false;
1216 loge("setNetworkSelectionModeManual " + ar.exception);
1217 }
1218 notifyRequester(request);
1219 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001220 break;
1221
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001222 case CMD_GET_MODEM_ACTIVITY_INFO:
1223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001225 if (defaultPhone != null) {
1226 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001227 } else {
1228 ResultReceiver result = (ResultReceiver) request.argument;
1229 Bundle bundle = new Bundle();
1230 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001231 new ModemActivityInfo(0, 0, 0,
1232 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001233 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001234 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001235 break;
1236
Hall Liud0f208c2020-10-14 16:54:44 -07001237 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001240 ResultReceiver result = (ResultReceiver) request.argument;
1241
Hall Liud0f208c2020-10-14 16:54:44 -07001242 ModemActivityInfo ret = null;
1243 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001244 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001245 // Update the last modem activity info and the result of the request.
1246 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1247 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001248 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001249 int[] txTimeMs = info.getTransmitTimeMillis();
1250 int[] lastModemTxTimeMs = mLastModemActivityInfo
1251 .getTransmitTimeMillis();
1252 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1253 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1254 }
Hall Liu49656c02020-10-09 19:00:11 -07001255 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001256 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1257 + mLastModemActivityInfo.getSleepTimeMillis());
1258 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1259 + mLastModemActivityInfo.getIdleTimeMillis());
1260 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1261 mLastModemActivityInfo.setReceiveTimeMillis(
1262 info.getReceiveTimeMillis()
1263 + mLastModemActivityInfo.getReceiveTimeMillis());
1264 }
Hall Liu49656c02020-10-09 19:00:11 -07001265 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001266 mLastModemActivityInfo.getSleepTimeMillis(),
1267 mLastModemActivityInfo.getIdleTimeMillis(),
1268 mLastModemActivityInfo.getTransmitTimeMillis(),
1269 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001270 } else {
1271 if (ar.result == null) {
1272 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001273 error = TelephonyManager.ModemActivityInfoException
1274 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001275 } else if (ar.exception instanceof CommandException) {
1276 loge("queryModemActivityInfo: CommandException: " +
1277 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001278 error = TelephonyManager.ModemActivityInfoException
1279 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001280 } else {
1281 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001282 error = TelephonyManager.ModemActivityInfoException
1283 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001284 }
1285 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001286 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001287 if (ret != null) {
1288 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1289 } else {
1290 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1291 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001292 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001293 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001294 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001295 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001296
Meng Wang1a7c35a2016-05-05 20:56:15 -07001297 case CMD_SET_ALLOWED_CARRIERS:
1298 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001299 CarrierRestrictionRules argument =
1300 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001301 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001302 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 break;
1304
1305 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1306 ar = (AsyncResult) msg.obj;
1307 request = (MainThreadRequest) ar.userObj;
1308 if (ar.exception == null && ar.result != null) {
1309 request.result = ar.result;
1310 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001311 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1312 if (ar.exception instanceof CommandException) {
1313 loge("setAllowedCarriers: CommandException: " + ar.exception);
1314 CommandException.Error error =
1315 ((CommandException) (ar.exception)).getCommandError();
1316 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1317 request.result =
1318 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1319 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001320 } else {
1321 loge("setAllowedCarriers: Unknown exception");
1322 }
1323 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001324 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001325 break;
1326
1327 case CMD_GET_ALLOWED_CARRIERS:
1328 request = (MainThreadRequest) msg.obj;
1329 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001330 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001331 break;
1332
1333 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1334 ar = (AsyncResult) msg.obj;
1335 request = (MainThreadRequest) ar.userObj;
1336 if (ar.exception == null && ar.result != null) {
1337 request.result = ar.result;
1338 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001339 request.result = new IllegalStateException(
1340 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001341 if (ar.result == null) {
1342 loge("getAllowedCarriers: Empty response");
1343 } else if (ar.exception instanceof CommandException) {
1344 loge("getAllowedCarriers: CommandException: " +
1345 ar.exception);
1346 } else {
1347 loge("getAllowedCarriers: Unknown exception");
1348 }
1349 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001350 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001351 break;
1352
Nathan Haroldb3014052017-01-25 15:57:32 -08001353 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1354 ar = (AsyncResult) msg.obj;
1355 request = (MainThreadRequest) ar.userObj;
1356 if (ar.exception == null && ar.result != null) {
1357 request.result = ar.result;
1358 } else {
1359 request.result = new IllegalArgumentException(
1360 "Failed to retrieve Forbidden Plmns");
1361 if (ar.result == null) {
1362 loge("getForbiddenPlmns: Empty response");
1363 } else {
1364 loge("getForbiddenPlmns: Unknown exception");
1365 }
1366 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001367 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001368 break;
1369
1370 case CMD_GET_FORBIDDEN_PLMNS:
1371 request = (MainThreadRequest) msg.obj;
1372 uiccCard = getUiccCardFromRequest(request);
1373 if (uiccCard == null) {
1374 loge("getForbiddenPlmns() UiccCard is null");
1375 request.result = new IllegalArgumentException(
1376 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001377 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001378 break;
1379 }
1380 Integer appType = (Integer) request.argument;
1381 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1382 if (uiccApp == null) {
1383 loge("getForbiddenPlmns() no app with specified type -- "
1384 + appType);
1385 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001386 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001387 break;
1388 } else {
1389 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1390 + " specified type -- " + appType);
1391 }
1392 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1393 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1394 onCompleted);
1395 break;
1396
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001397 case CMD_SWITCH_SLOTS:
1398 request = (MainThreadRequest) msg.obj;
1399 int[] physicalSlots = (int[]) request.argument;
1400 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1401 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1402 break;
1403
1404 case EVENT_SWITCH_SLOTS_DONE:
1405 ar = (AsyncResult) msg.obj;
1406 request = (MainThreadRequest) ar.userObj;
1407 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001408 notifyRequester(request);
1409 break;
1410 case CMD_GET_NETWORK_SELECTION_MODE:
1411 request = (MainThreadRequest) msg.obj;
1412 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1413 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1414 break;
1415
1416 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1417 ar = (AsyncResult) msg.obj;
1418 request = (MainThreadRequest) ar.userObj;
1419 if (ar.exception != null) {
1420 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1421 } else {
1422 int mode = ((int[]) ar.result)[0];
1423 if (mode == 0) {
1424 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1425 } else {
1426 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1427 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001428 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001429 notifyRequester(request);
1430 break;
1431 case CMD_GET_CDMA_ROAMING_MODE:
1432 request = (MainThreadRequest) msg.obj;
1433 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1434 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1435 break;
1436 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1437 ar = (AsyncResult) msg.obj;
1438 request = (MainThreadRequest) ar.userObj;
1439 if (ar.exception != null) {
1440 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1441 } else {
1442 request.result = ((int[]) ar.result)[0];
1443 }
1444 notifyRequester(request);
1445 break;
1446 case CMD_SET_CDMA_ROAMING_MODE:
1447 request = (MainThreadRequest) msg.obj;
1448 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1449 int mode = (int) request.argument;
1450 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1451 break;
1452 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1453 ar = (AsyncResult) msg.obj;
1454 request = (MainThreadRequest) ar.userObj;
1455 request.result = ar.exception == null;
1456 notifyRequester(request);
1457 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001458 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1459 request = (MainThreadRequest) msg.obj;
1460 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1461 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1462 break;
1463 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1464 ar = (AsyncResult) msg.obj;
1465 request = (MainThreadRequest) ar.userObj;
1466 if (ar.exception != null) {
1467 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1468 } else {
1469 request.result = ((int[]) ar.result)[0];
1470 }
1471 notifyRequester(request);
1472 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001473 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1474 request = (MainThreadRequest) msg.obj;
1475 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1476 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001477 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1478 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001479 break;
1480 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1481 ar = (AsyncResult) msg.obj;
1482 request = (MainThreadRequest) ar.userObj;
1483 request.result = ar.exception == null;
1484 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001485 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001486 case CMD_GET_ALL_CELL_INFO:
1487 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001488 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001489 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 case EVENT_GET_ALL_CELL_INFO_DONE:
1492 ar = (AsyncResult) msg.obj;
1493 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001494 // If a timeout occurs, the response will be null
1495 request.result = (ar.exception == null && ar.result != null)
1496 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001497 synchronized (request) {
1498 request.notifyAll();
1499 }
1500 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001501 case CMD_REQUEST_CELL_INFO_UPDATE:
1502 request = (MainThreadRequest) msg.obj;
1503 request.phone.requestCellInfoUpdate(request.workSource,
1504 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1505 break;
1506 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1507 ar = (AsyncResult) msg.obj;
1508 request = (MainThreadRequest) ar.userObj;
1509 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1510 try {
1511 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001512 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001513 cb.onError(
1514 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1515 ar.exception.getClass().getName(),
1516 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001517 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001518 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001519 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001520 } else {
1521 // use the result as returned
1522 cb.onCellInfo((List<CellInfo>) ar.result);
1523 }
1524 } catch (RemoteException re) {
1525 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1526 }
1527 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001528 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001529 request = (MainThreadRequest) msg.obj;
1530 WorkSource ws = (WorkSource) request.argument;
1531 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001532 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001533 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001534 }
1535 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001536 ar = (AsyncResult) msg.obj;
1537 request = (MainThreadRequest) ar.userObj;
1538 if (ar.exception == null) {
1539 request.result = ar.result;
1540 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001541 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001542 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001543 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001544 }
1545
1546 synchronized (request) {
1547 request.notifyAll();
1548 }
1549 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001550 }
chen xu6dac5ab2018-10-26 17:39:23 -07001551 case CMD_MODEM_REBOOT:
1552 request = (MainThreadRequest) msg.obj;
1553 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001554 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001555 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001556 case EVENT_CMD_MODEM_REBOOT_DONE:
1557 handleNullReturnEvent(msg, "rebootModem");
1558 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001559 case CMD_REQUEST_ENABLE_MODEM:
1560 request = (MainThreadRequest) msg.obj;
1561 boolean enable = (boolean) request.argument;
1562 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001563 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001564 PhoneConfigurationManager.getInstance()
1565 .enablePhone(request.phone, enable, onCompleted);
1566 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001567 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001568 ar = (AsyncResult) msg.obj;
1569 request = (MainThreadRequest) ar.userObj;
1570 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001571 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001572 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001573 if ((boolean) request.result) {
1574 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1575 updateModemStateMetrics();
1576 } else {
1577 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1578 + ar.exception);
1579 }
1580 notifyRequester(request);
1581 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001582 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001583 case CMD_GET_MODEM_STATUS:
1584 request = (MainThreadRequest) msg.obj;
1585 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1586 PhoneConfigurationManager.getInstance()
1587 .getPhoneStatusFromModem(request.phone, onCompleted);
1588 break;
1589 case EVENT_GET_MODEM_STATUS_DONE:
1590 ar = (AsyncResult) msg.obj;
1591 request = (MainThreadRequest) ar.userObj;
1592 int id = request.phone.getPhoneId();
1593 if (ar.exception == null && ar.result != null) {
1594 request.result = ar.result;
1595 //update the cache as modem status has changed
1596 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1597 (boolean) request.result);
1598 } else {
1599 // Return true if modem status cannot be retrieved. For most cases,
1600 // modem status is on. And for older version modems, GET_MODEM_STATUS
1601 // and disable modem are not supported. Modem is always on.
1602 // TODO: this should be fixed in R to support a third
1603 // status UNKNOWN b/131631629
1604 request.result = true;
1605 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1606 + ar.exception);
1607 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001608 notifyRequester(request);
1609 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001610 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1611 request = (MainThreadRequest) msg.obj;
1612 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1613 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1614 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1615 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1616 break;
1617 }
1618 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1619 ar = (AsyncResult) msg.obj;
1620 request = (MainThreadRequest) ar.userObj;
1621 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1622 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1623 args.second.accept(ar.exception == null);
1624 notifyRequester(request);
1625 break;
1626 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001627 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1628 request = (MainThreadRequest) msg.obj;
1629 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1630 Phone phone = getPhoneFromRequest(request);
1631 if (phone != null) {
1632 phone.getSystemSelectionChannels(onCompleted);
1633 } else {
1634 loge("getSystemSelectionChannels: No phone object");
1635 request.result = new ArrayList<RadioAccessSpecifier>();
1636 notifyRequester(request);
1637 }
1638 break;
1639 }
1640 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1641 ar = (AsyncResult) msg.obj;
1642 request = (MainThreadRequest) ar.userObj;
1643 if (ar.exception == null && ar.result != null) {
1644 request.result = ar.result;
1645 } else {
1646 request.result = new IllegalArgumentException(
1647 "Failed to retrieve system selection channels");
1648 if (ar.result == null) {
1649 loge("getSystemSelectionChannels: Empty response");
1650 } else {
1651 loge("getSystemSelectionChannels: Unknown exception");
1652 }
1653 }
1654 notifyRequester(request);
1655 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001656 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1657 ar = (AsyncResult) msg.obj;
1658 request = (MainThreadRequest) ar.userObj;
1659 if (ar.exception == null && ar.result != null) {
1660 request.result = ar.result;
1661 } else {
1662 request.result = -1;
1663 loge("Failed to set Forbidden Plmns");
1664 if (ar.result == null) {
1665 loge("setForbidenPlmns: Empty response");
1666 } else if (ar.exception != null) {
1667 loge("setForbiddenPlmns: Exception: " + ar.exception);
1668 request.result = -1;
1669 } else {
1670 loge("setForbiddenPlmns: Unknown exception");
1671 }
1672 }
1673 notifyRequester(request);
1674 break;
1675 case CMD_SET_FORBIDDEN_PLMNS:
1676 request = (MainThreadRequest) msg.obj;
1677 uiccCard = getUiccCardFromRequest(request);
1678 if (uiccCard == null) {
1679 loge("setForbiddenPlmns: UiccCard is null");
1680 request.result = -1;
1681 notifyRequester(request);
1682 break;
1683 }
1684 Pair<Integer, List<String>> setFplmnsArgs =
1685 (Pair<Integer, List<String>>) request.argument;
1686 appType = setFplmnsArgs.first;
1687 List<String> fplmns = setFplmnsArgs.second;
1688 uiccApp = uiccCard.getApplicationByType(appType);
1689 if (uiccApp == null) {
1690 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1691 request.result = -1;
1692 loge("Failed to get UICC App");
1693 notifyRequester(request);
1694 } else {
1695 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1696 ((SIMRecords) uiccApp.getIccRecords())
1697 .setForbiddenPlmns(onCompleted, fplmns);
1698 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001699 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001700 case CMD_ERASE_MODEM_CONFIG:
1701 request = (MainThreadRequest) msg.obj;
1702 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1703 defaultPhone.eraseModemConfig(onCompleted);
1704 break;
1705 case EVENT_ERASE_MODEM_CONFIG_DONE:
1706 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001707 break;
zoey chene02881a2019-12-30 16:11:23 +08001708
1709 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1710 request = (MainThreadRequest) msg.obj;
1711 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1712 Pair<String, String> changed = (Pair<String, String>) request.argument;
1713 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1714 changed.first, changed.second, onCompleted);
1715 break;
1716 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1717 ar = (AsyncResult) msg.obj;
1718 request = (MainThreadRequest) ar.userObj;
1719 if (ar.exception == null) {
1720 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001721 // If the operation is successful, update the PIN storage
1722 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1723 int phoneId = getPhoneFromRequest(request).getPhoneId();
1724 UiccController.getInstance().getPinStorage()
1725 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001726 } else {
1727 request.result = msg.arg1;
1728 }
1729 notifyRequester(request);
1730 break;
1731
Michele Berionne5e411512020-11-13 02:36:59 +00001732 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001733 request = (MainThreadRequest) msg.obj;
1734 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1735 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1736 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1737 enabled.first, enabled.second, onCompleted);
1738 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001739 }
zoey chene02881a2019-12-30 16:11:23 +08001740 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1741 ar = (AsyncResult) msg.obj;
1742 request = (MainThreadRequest) ar.userObj;
1743 if (ar.exception == null) {
1744 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001745 // If the operation is successful, update the PIN storage
1746 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1747 int phoneId = getPhoneFromRequest(request).getPhoneId();
1748 if (enabled.first) {
1749 UiccController.getInstance().getPinStorage()
1750 .storePin(enabled.second, phoneId);
1751 } else {
1752 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1753 }
zoey chene02881a2019-12-30 16:11:23 +08001754 } else {
1755 request.result = msg.arg1;
1756 }
Michele Berionne5e411512020-11-13 02:36:59 +00001757
1758
zoey chene02881a2019-12-30 16:11:23 +08001759 notifyRequester(request);
1760 break;
1761
Peter Wangdafb9ac2020-01-15 14:13:38 -08001762 case MSG_NOTIFY_USER_ACTIVITY:
1763 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001764 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001765 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1766 getDefaultPhone().getContext().sendBroadcastAsUser(
1767 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1768 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001769
1770 case CMD_SET_DATA_THROTTLING: {
1771 request = (MainThreadRequest) msg.obj;
1772 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1773 DataThrottlingRequest dataThrottlingRequest =
1774 (DataThrottlingRequest) request.argument;
1775 Phone phone = getPhoneFromRequest(request);
1776 if (phone != null) {
1777 phone.setDataThrottling(onCompleted,
1778 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1779 dataThrottlingRequest.getCompletionDurationMillis());
1780 } else {
1781 loge("setDataThrottling: No phone object");
1782 request.result =
1783 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1784 notifyRequester(request);
1785 }
1786
1787 break;
1788 }
1789 case EVENT_SET_DATA_THROTTLING_DONE:
1790 ar = (AsyncResult) msg.obj;
1791 request = (MainThreadRequest) ar.userObj;
1792
1793 if (ar.exception == null) {
1794 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1795 } else if (ar.exception instanceof CommandException) {
1796 loge("setDataThrottling: CommandException: " + ar.exception);
1797 CommandException.Error error =
1798 ((CommandException) (ar.exception)).getCommandError();
1799
1800 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1801 request.result = TelephonyManager
1802 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1803 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1804 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1805 } else {
1806 request.result =
1807 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1808 }
1809 } else {
1810 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1811 }
1812 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1813 notifyRequester(request);
1814 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001815
1816 case CMD_SET_SIM_POWER: {
1817 request = (MainThreadRequest) msg.obj;
1818 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1819 request = (MainThreadRequest) msg.obj;
1820 int stateToSet =
1821 ((Pair<Integer, IIntegerConsumer>)
1822 request.argument).first;
1823 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1824 break;
1825 }
1826 case EVENT_SET_SIM_POWER_DONE: {
1827 ar = (AsyncResult) msg.obj;
1828 request = (MainThreadRequest) ar.userObj;
1829 IIntegerConsumer callback =
1830 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1831 if (ar.exception != null) {
1832 loge("setSimPower exception: " + ar.exception);
1833 int errorCode = TelephonyManager.CallForwardingInfoCallback
1834 .RESULT_ERROR_UNKNOWN;
1835 if (ar.exception instanceof CommandException) {
1836 CommandException.Error error =
1837 ((CommandException) (ar.exception)).getCommandError();
1838 if (error == CommandException.Error.SIM_ERR) {
1839 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1840 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1841 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1842 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1843 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1844 } else {
1845 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1846 }
1847 }
1848 try {
1849 callback.accept(errorCode);
1850 } catch (RemoteException e) {
1851 // Ignore if the remote process is no longer available to call back.
1852 Log.w(LOG_TAG, "setSimPower: callback not available.");
1853 }
1854 } else {
1855 try {
1856 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1857 } catch (RemoteException e) {
1858 // Ignore if the remote process is no longer available to call back.
1859 Log.w(LOG_TAG, "setSimPower: callback not available.");
1860 }
1861 }
1862 break;
1863 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001864 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1865 request = (MainThreadRequest) msg.obj;
1866
1867 final Phone phone = getPhoneFromRequest(request);
1868 if (phone == null || phone.getServiceStateTracker() == null) {
1869 request.result = new IllegalStateException("Phone or SST is null");
1870 notifyRequester(request);
1871 break;
1872 }
1873
1874 Pair<Integer, SignalStrengthUpdateRequest> pair =
1875 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1876 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1877 request);
1878 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1879 request.subId, pair.first /*callingUid*/,
1880 pair.second /*request*/, onCompleted);
1881 break;
1882 }
1883 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1884 ar = (AsyncResult) msg.obj;
1885 request = (MainThreadRequest) ar.userObj;
1886 // request.result will be the exception of ar if present, true otherwise.
1887 // Be cautious not to leave result null which will wait() forever
1888 request.result = ar.exception != null ? ar.exception : true;
1889 notifyRequester(request);
1890 break;
1891 }
1892 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1893 request = (MainThreadRequest) msg.obj;
1894
1895 Phone phone = getPhoneFromRequest(request);
1896 if (phone == null || phone.getServiceStateTracker() == null) {
1897 request.result = new IllegalStateException("Phone or SST is null");
1898 notifyRequester(request);
1899 break;
1900 }
1901
1902 Pair<Integer, SignalStrengthUpdateRequest> pair =
1903 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1904 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1905 request);
1906 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1907 request.subId, pair.first /*callingUid*/,
1908 pair.second /*request*/, onCompleted);
1909 break;
1910 }
1911 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1912 ar = (AsyncResult) msg.obj;
1913 request = (MainThreadRequest) ar.userObj;
1914 request.result = ar.exception != null ? ar.exception : true;
1915 notifyRequester(request);
1916 break;
1917 }
Jordan Liu109698e2020-11-24 14:50:34 -08001918
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001919 case CMD_GET_SLICING_CONFIG: {
1920 request = (MainThreadRequest) msg.obj;
1921 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1922 request.phone.getSlicingConfig(onCompleted);
1923 break;
1924 }
1925 case EVENT_GET_SLICING_CONFIG_DONE: {
1926 ar = (AsyncResult) msg.obj;
1927 request = (MainThreadRequest) ar.userObj;
1928 ResultReceiver result = (ResultReceiver) request.argument;
1929
1930 SlicingConfig slicingConfig = null;
1931 Bundle bundle = new Bundle();
1932 int resultCode = 0;
1933 if (ar.exception != null) {
1934 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1935 + ar.exception);
1936 resultCode = TelephonyManager.SlicingException.ERROR_MODEM_ERROR;
1937 } else if (ar.result == null) {
1938 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
1939 resultCode = TelephonyManager.SlicingException.ERROR_TIMEOUT;
1940 } else {
1941 // use the result as returned
1942 resultCode = TelephonyManager.SlicingException.SUCCESS;
1943 slicingConfig = (SlicingConfig) ar.result;
1944 }
1945
1946 if (slicingConfig == null) {
1947 slicingConfig = new SlicingConfig();
1948 }
1949 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1950 result.send(resultCode, bundle);
1951 notifyRequester(request);
1952 break;
1953 }
1954
Michele Berionne5e411512020-11-13 02:36:59 +00001955 case CMD_PREPARE_UNATTENDED_REBOOT:
1956 request = (MainThreadRequest) msg.obj;
1957 request.result =
1958 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1959 notifyRequester(request);
1960 break;
1961
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 default:
1963 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1964 break;
1965 }
1966 }
Jake Hambye994d462014-02-03 13:10:13 -08001967
Pengquan Menga1bb6272018-09-06 09:59:22 -07001968 private void notifyRequester(MainThreadRequest request) {
1969 synchronized (request) {
1970 request.notifyAll();
1971 }
1972 }
1973
Jake Hambye994d462014-02-03 13:10:13 -08001974 private void handleNullReturnEvent(Message msg, String command) {
1975 AsyncResult ar = (AsyncResult) msg.obj;
1976 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1977 if (ar.exception == null) {
1978 request.result = true;
1979 } else {
1980 request.result = false;
1981 if (ar.exception instanceof CommandException) {
1982 loge(command + ": CommandException: " + ar.exception);
1983 } else {
1984 loge(command + ": Unknown exception");
1985 }
1986 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001987 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
1991 /**
1992 * Posts the specified command to be executed on the main thread,
1993 * waits for the request to complete, and returns the result.
1994 * @see #sendRequestAsync
1995 */
1996 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001997 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1998 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -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, WorkSource workSource) {
2007 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002008 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002009 }
2010
2011 /**
2012 * Posts the specified command to be executed on the main thread,
2013 * waits for the request to complete, and returns the result.
2014 * @see #sendRequestAsync
2015 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002016 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002017 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2018 }
2019
2020 /**
2021 * Posts the specified command to be executed on the main thread,
2022 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2023 * if not timeout or null otherwise.
2024 * @see #sendRequestAsync
2025 */
2026 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2027 long timeoutInMs) {
2028 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002029 }
2030
2031 /**
2032 * Posts the specified command to be executed on the main thread,
2033 * waits for the request to complete, and returns the result.
2034 * @see #sendRequestAsync
2035 */
Nathan Harold92bed182018-10-12 18:16:49 -07002036 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002037 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002038 }
2039
2040 /**
2041 * Posts the specified command to be executed on the main thread,
2042 * waits for the request to complete, and returns the result.
2043 * @see #sendRequestAsync
2044 */
2045 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002046 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2047 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002048 }
2049
2050 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002051 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2052 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2053 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002054 * @see #sendRequestAsync
2055 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002056 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2057 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2059 throw new RuntimeException("This method will deadlock if called from the main thread.");
2060 }
2061
Nathan Harold92bed182018-10-12 18:16:49 -07002062 MainThreadRequest request = null;
2063 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2064 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2065 } else if (phone != null) {
2066 request = new MainThreadRequest(argument, phone, workSource);
2067 } else {
2068 request = new MainThreadRequest(argument, subId, workSource);
2069 }
2070
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 Message msg = mMainThreadHandler.obtainMessage(command, request);
2072 msg.sendToTarget();
2073
Rambo Wang0f050d82021-02-12 11:43:36 -08002074
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002076 if (timeoutInMs >= 0) {
2077 // Wait for at least timeoutInMs before returning null request result
2078 long now = SystemClock.elapsedRealtime();
2079 long deadline = now + timeoutInMs;
2080 while (request == null && now < deadline) {
2081 try {
2082 request.wait(deadline - now);
2083 } catch (InterruptedException e) {
2084 // Do nothing, go back and check if request is completed or timeout
2085 } finally {
2086 now = SystemClock.elapsedRealtime();
2087 }
2088 }
2089 } else {
2090 // Wait for the request to complete
2091 while (request.result == null) {
2092 try {
2093 request.wait();
2094 } catch (InterruptedException e) {
2095 // Do nothing, go back and wait until the request is complete
2096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 }
2098 }
2099 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002100 if (request.result == null) {
2101 Log.wtf(LOG_TAG,
2102 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 return request.result;
2105 }
2106
2107 /**
2108 * Asynchronous ("fire and forget") version of sendRequest():
2109 * Posts the specified command to be executed on the main thread, and
2110 * returns immediately.
2111 * @see #sendRequest
2112 */
2113 private void sendRequestAsync(int command) {
2114 mMainThreadHandler.sendEmptyMessage(command);
2115 }
2116
2117 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002118 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002119 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002120 */
2121 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002122 sendRequestAsync(command, argument, null, null);
2123 }
2124
2125 /**
2126 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2127 * @see {@link #sendRequest(int,Object)}
2128 */
2129 private void sendRequestAsync(
2130 int command, Object argument, Phone phone, WorkSource workSource) {
2131 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002132 Message msg = mMainThreadHandler.obtainMessage(command, request);
2133 msg.sendToTarget();
2134 }
2135
2136 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 * Initialize the singleton PhoneInterfaceManager instance.
2138 * This is only done once, at startup, from PhoneApp.onCreate().
2139 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002140 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 synchronized (PhoneInterfaceManager.class) {
2142 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002143 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 } else {
2145 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2146 }
2147 return sInstance;
2148 }
2149 }
2150
2151 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002152 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002155 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002156 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2158 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002159 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002160 mTelephonySharedPreferences =
2161 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002162 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002163 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002164 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002165 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002166
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 publish();
2168 }
2169
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002170 private Phone getDefaultPhone() {
2171 Phone thePhone = getPhone(getDefaultSubscription());
2172 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2173 }
2174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 private void publish() {
2176 if (DBG) log("publish: " + this);
2177
Peter Wangc035ce42020-01-08 21:00:22 -08002178 TelephonyFrameworkInitializer
2179 .getTelephonyServiceManager()
2180 .getTelephonyServiceRegisterer()
2181 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
2183
Stuart Scott584921c2015-01-15 17:10:34 -08002184 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002185 if (request.phone != null) {
2186 return request.phone;
2187 } else {
2188 return getPhoneFromSubId(request.subId);
2189 }
2190 }
2191
2192 private Phone getPhoneFromSubId(int subId) {
2193 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2194 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002195 }
2196
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002197 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2198 Phone phone = getPhoneFromRequest(request);
2199 return phone == null ? null :
2200 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2201 }
2202
Wink Saville36469e72014-06-11 15:17:00 -07002203 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002204 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002205 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002206 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207
Naina Nallurid63128d2019-09-17 14:10:30 -07002208 private void sendEraseModemConfig(Phone phone) {
2209 if (phone != null) {
2210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2211 mApp, phone.getSubId(), "eraseModemConfig");
2212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2215 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2216 } finally {
2217 Binder.restoreCallingIdentity(identity);
2218 }
2219 }
2220 }
2221
Peter Wang44b186e2020-01-13 23:33:09 -08002222 private boolean isImsAvailableOnDevice() {
2223 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2224 if (pm == null) {
2225 // For some reason package manger is not available.. This will fail internally anyway,
2226 // so do not throw error and allow.
2227 return true;
2228 }
2229 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2230 }
2231
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002233 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002234 }
2235
Wink Savilleb564aae2014-10-23 10:18:09 -07002236 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 if (DBG) log("dial: " + number);
2238 // No permission check needed here: This is just a wrapper around the
2239 // ACTION_DIAL intent, which is available to any app since it puts up
2240 // the UI before it does anything.
2241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 String url = createTelUrl(number);
2245 if (url == null) {
2246 return;
2247 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249 // PENDING: should we just silently fail if phone is offhook or ringing?
2250 PhoneConstants.State state = mCM.getState(subId);
2251 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2252 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2253 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2254 mApp.startActivity(intent);
2255 }
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259 }
2260
2261 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002262 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002263 }
2264
Wink Savilleb564aae2014-10-23 10:18:09 -07002265 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 if (DBG) log("call: " + number);
2267
2268 // This is just a wrapper around the ACTION_CALL intent, but we still
2269 // need to do a permission check since we're calling startActivity()
2270 // from the context of the phone app.
2271 enforceCallPermission();
2272
Jordan Liu1617b712019-07-10 15:06:26 -07002273 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002274 != AppOpsManager.MODE_ALLOWED) {
2275 return;
2276 }
2277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278 final long identity = Binder.clearCallingIdentity();
2279 try {
2280 String url = createTelUrl(number);
2281 if (url == null) {
2282 return;
2283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285 boolean isValid = false;
2286 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2287 if (slist != null) {
2288 for (SubscriptionInfo subInfoRecord : slist) {
2289 if (subInfoRecord.getSubscriptionId() == subId) {
2290 isValid = true;
2291 break;
2292 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002293 }
Wink Saville08874612014-08-31 19:19:58 -07002294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 if (!isValid) {
2296 return;
2297 }
Wink Saville08874612014-08-31 19:19:58 -07002298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2300 intent.putExtra(SUBSCRIPTION_KEY, subId);
2301 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2302 mApp.startActivity(intent);
2303 } finally {
2304 Binder.restoreCallingIdentity(identity);
2305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
Wink Savilleb564aae2014-10-23 10:18:09 -07002308 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002309 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002310 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2311 }
2312
Wink Savilleb564aae2014-10-23 10:18:09 -07002313 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002314 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002315 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2316 }
2317
Wink Savilleb564aae2014-10-23 10:18:09 -07002318 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002320
2321 final long identity = Binder.clearCallingIdentity();
2322 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002323 Phone phone = getPhone(subId);
2324 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325 checkSimPin.start();
2326 return checkSimPin.unlockSim(null, pin);
2327 } finally {
2328 Binder.restoreCallingIdentity(identity);
2329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 }
2331
Wink Savilleb564aae2014-10-23 10:18:09 -07002332 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334
2335 final long identity = Binder.clearCallingIdentity();
2336 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002337 Phone phone = getPhone(subId);
2338 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339 checkSimPuk.start();
2340 return checkSimPuk.unlockSim(puk, pin);
2341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 }
2345
2346 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002347 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 * a synchronous one.
2349 */
2350 private static class UnlockSim extends Thread {
2351
2352 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002353 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354
2355 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002356 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2357 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358
2359 // For replies from SimCard interface
2360 private Handler mHandler;
2361
2362 // For async handler to identify request type
2363 private static final int SUPPLY_PIN_COMPLETE = 100;
2364
Michele Berionne5e411512020-11-13 02:36:59 +00002365 UnlockSim(int phoneId, IccCard simCard) {
2366 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 mSimCard = simCard;
2368 }
2369
2370 @Override
2371 public void run() {
2372 Looper.prepare();
2373 synchronized (UnlockSim.this) {
2374 mHandler = new Handler() {
2375 @Override
2376 public void handleMessage(Message msg) {
2377 AsyncResult ar = (AsyncResult) msg.obj;
2378 switch (msg.what) {
2379 case SUPPLY_PIN_COMPLETE:
2380 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2381 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002382 mRetryCount = msg.arg1;
2383 if (ar.exception != null) {
2384 if (ar.exception instanceof CommandException &&
2385 ((CommandException)(ar.exception)).getCommandError()
2386 == CommandException.Error.PASSWORD_INCORRECT) {
2387 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002388 } //When UiccCardApp dispose,handle message and return exception
2389 else if (ar.exception instanceof CommandException &&
2390 ((CommandException) (ar.exception)).getCommandError()
2391 == CommandException.Error.ABORTED) {
2392 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002393 } else {
2394 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2395 }
2396 } else {
2397 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 mDone = true;
2400 UnlockSim.this.notifyAll();
2401 }
2402 break;
2403 }
2404 }
2405 };
2406 UnlockSim.this.notifyAll();
2407 }
2408 Looper.loop();
2409 }
2410
2411 /*
2412 * Use PIN or PUK to unlock SIM card
2413 *
2414 * If PUK is null, unlock SIM card with PIN
2415 *
2416 * If PUK is not null, unlock SIM card with PUK and set PIN code
2417 */
Wink Saville9de0f752013-10-22 19:04:03 -07002418 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419
2420 while (mHandler == null) {
2421 try {
2422 wait();
2423 } catch (InterruptedException e) {
2424 Thread.currentThread().interrupt();
2425 }
2426 }
2427 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2428
2429 if (puk == null) {
2430 mSimCard.supplyPin(pin, callback);
2431 } else {
2432 mSimCard.supplyPuk(puk, pin, callback);
2433 }
2434
2435 while (!mDone) {
2436 try {
2437 Log.d(LOG_TAG, "wait for done");
2438 wait();
2439 } catch (InterruptedException e) {
2440 // Restore the interrupted status
2441 Thread.currentThread().interrupt();
2442 }
2443 }
2444 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002445 int[] resultArray = new int[2];
2446 resultArray[0] = mResult;
2447 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002448
2449 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2450 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2451 }
2452
Wink Saville9de0f752013-10-22 19:04:03 -07002453 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 }
2455 }
2456
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002457 /**
2458 * This method has been removed due to privacy and stability concerns.
2459 */
2460 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002462 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2463 return;
Wink Saville36469e72014-06-11 15:17:00 -07002464 }
2465
Nathan Harold1f889d82020-06-04 17:05:26 -07002466 @Override
2467 public void updateServiceLocationWithPackageName(String callingPackage) {
2468 mApp.getSystemService(AppOpsManager.class)
2469 .checkPackage(Binder.getCallingUid(), callingPackage);
2470
Nathan Haroldf096d982020-11-18 17:18:06 -08002471 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002472 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2473 // Callers targeting S have no business invoking this method.
2474 return;
2475 }
2476
2477 LocationAccessPolicy.LocationPermissionResult locationResult =
2478 LocationAccessPolicy.checkLocationPermission(mApp,
2479 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2480 .setCallingPackage(callingPackage)
2481 .setCallingFeatureId(null)
2482 .setCallingPid(Binder.getCallingPid())
2483 .setCallingUid(Binder.getCallingUid())
2484 .setMethod("updateServiceLocation")
2485 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2486 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2487 .build());
2488 // Apps that lack location permission have no business calling this method;
2489 // however, because no permission was declared in the public API, denials must
2490 // all be "soft".
2491 switch (locationResult) {
2492 case DENIED_HARD: /* fall through */
2493 case DENIED_SOFT:
2494 return;
2495 }
2496
2497 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 final long identity = Binder.clearCallingIdentity();
2499 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002500 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002502 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503 }
2504 } finally {
2505 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002507 }
2508
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002509 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002510 @Override
2511 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002512 return isRadioOnWithFeature(callingPackage, null);
2513 }
2514
2515
2516 @Override
2517 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2518 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2519 callingFeatureId);
2520 }
2521
2522 @Deprecated
2523 @Override
2524 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2525 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002526 }
2527
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002528 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002529 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2530 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002532 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002533 return false;
2534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535
2536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 return isRadioOnForSubscriber(subId);
2539 } finally {
2540 Binder.restoreCallingIdentity(identity);
2541 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002542 }
2543
2544 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 final Phone phone = getPhone(subId);
2548 if (phone != null) {
2549 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2550 } else {
2551 return false;
2552 }
2553 } finally {
2554 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 }
2557
2558 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002559 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 }
Wink Saville36469e72014-06-11 15:17:00 -07002561
Wink Savilleb564aae2014-10-23 10:18:09 -07002562 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 final Phone phone = getPhone(subId);
2568 if (phone != null) {
2569 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2570 }
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002573 }
Wink Saville36469e72014-06-11 15:17:00 -07002574 }
2575
2576 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002577 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002578 }
2579
Wink Savilleb564aae2014-10-23 10:18:09 -07002580 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002581 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 final Phone phone = getPhone(subId);
2586 if (phone == null) {
2587 return false;
2588 }
2589 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2590 toggleRadioOnOffForSubscriber(subId);
2591 }
2592 return true;
2593 } finally {
2594 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002596 }
Wink Saville36469e72014-06-11 15:17:00 -07002597
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002598 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002599 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002600 /*
2601 * If any of the Radios are available, it will need to be
2602 * shutdown. So return true if any Radio is available.
2603 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002604 final long identity = Binder.clearCallingIdentity();
2605 try {
2606 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2607 Phone phone = PhoneFactory.getPhone(i);
2608 if (phone != null && phone.isRadioAvailable()) return true;
2609 }
2610 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2611 return false;
2612 } finally {
2613 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002614 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002615 }
2616
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002617 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002618 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 enforceModifyPermission();
2620
2621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2624 logv("Shutting down Phone " + i);
2625 shutdownRadioUsingPhoneId(i);
2626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002629 }
2630 }
2631
2632 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002633 Phone phone = PhoneFactory.getPhone(phoneId);
2634 if (phone != null && phone.isRadioAvailable()) {
2635 phone.shutdownRadio();
2636 }
2637 }
2638
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002640 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2645 if (defaultPhone != null) {
2646 defaultPhone.setRadioPower(turnOn);
2647 return true;
2648 } else {
2649 loge("There's no default phone.");
2650 return false;
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002654 }
Wink Saville36469e72014-06-11 15:17:00 -07002655 }
2656
Wink Savilleb564aae2014-10-23 10:18:09 -07002657 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659
2660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(subId);
2663 if (phone != null) {
2664 phone.setRadioPower(turnOn);
2665 return true;
2666 } else {
2667 return false;
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002672 }
2673
Wink Saville36469e72014-06-11 15:17:00 -07002674 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 public boolean enableDataConnectivity() {
2677 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678
2679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 int subId = mSubscriptionController.getDefaultDataSubId();
2682 final Phone phone = getPhone(subId);
2683 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002684 phone.getDataEnabledSettings().setDataEnabled(
2685 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 return true;
2687 } else {
2688 return false;
2689 }
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 }
2694
Wink Saville36469e72014-06-11 15:17:00 -07002695 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002696 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 public boolean disableDataConnectivity() {
2698 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699
2700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 int subId = mSubscriptionController.getDefaultDataSubId();
2703 final Phone phone = getPhone(subId);
2704 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002705 phone.getDataEnabledSettings().setDataEnabled(
2706 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002707 return true;
2708 } else {
2709 return false;
2710 }
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002717 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002722 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 } else {
2724 return false;
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 }
2730
2731 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002732 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002733 }
2734
pkanwarae03a6b2016-11-06 20:37:09 -08002735 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 enforceCallPermission();
2737
2738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2741 return;
2742 }
2743 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2744 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
pkanwar32d516d2016-10-14 19:37:38 -07002748 };
2749
Wink Savilleb564aae2014-10-23 10:18:09 -07002750 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002752
2753 final long identity = Binder.clearCallingIdentity();
2754 try {
2755 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2756 return false;
2757 }
2758 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2759 } finally {
2760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002761 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 }
2763
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002765 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002766 }
2767
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002768 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 final long identity = Binder.clearCallingIdentity();
2770 try {
2771 Phone phone = PhoneFactory.getPhone(slotIndex);
2772 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2773 PhoneConstantConversions.convertCallState(phone.getState());
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
2776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
2778
Sanket Padawe356d7632015-06-22 14:03:32 -07002779 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002780 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002781 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2782 }
2783
2784 @Override
2785 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002788 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 if (phone != null) {
2790 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2791 } else {
2792 return PhoneConstantConversions.convertDataState(
2793 PhoneConstants.DataState.DISCONNECTED);
2794 }
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 }
2799
Sanket Padawe356d7632015-06-22 14:03:32 -07002800 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002801 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002802 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2803 }
2804
2805 @Override
2806 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807 final long identity = Binder.clearCallingIdentity();
2808 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002809 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 if (phone != null) {
2811 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2812 } else {
2813 return TelephonyManager.DATA_ACTIVITY_NONE;
2814 }
2815 } finally {
2816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
2819
2820 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002821 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002822 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002823 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002824
2825 LocationAccessPolicy.LocationPermissionResult locationResult =
2826 LocationAccessPolicy.checkLocationPermission(mApp,
2827 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2828 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002829 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002830 .setCallingPid(Binder.getCallingPid())
2831 .setCallingUid(Binder.getCallingUid())
2832 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002833 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002834 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2835 .build());
2836 switch (locationResult) {
2837 case DENIED_HARD:
2838 throw new SecurityException("Not allowed to access cell location");
2839 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002840 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2841 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002842 }
2843
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002844 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002845 final long identity = Binder.clearCallingIdentity();
2846 try {
2847 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002848 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002849 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 } finally {
2851 Binder.restoreCallingIdentity(identity);
2852 }
Svetoslav64fad262015-04-14 14:35:21 -07002853 }
2854
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002856 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002857 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2858 // registered cell info, so return a NULL country instead.
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002861 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2862 // Get default phone in this case.
2863 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2864 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002865 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002867 if (phone == null) return "";
2868 ServiceStateTracker sst = phone.getServiceStateTracker();
2869 if (sst == null) return "";
2870 LocaleTracker lt = sst.getLocaleTracker();
2871 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002872 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002873 } finally {
2874 Binder.restoreCallingIdentity(identity);
2875 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002876 }
2877
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002878 /**
2879 * This method was removed due to potential issues caused by performing partial
2880 * updates of service state, and lack of a credible use case.
2881 *
2882 * This has the ability to break the telephony implementation by disabling notification of
2883 * changes in device connectivity. DO NOT USE THIS!
2884 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002885 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002886 public void enableLocationUpdates() {
2887 mApp.enforceCallingOrSelfPermission(
2888 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 }
2890
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002891 /**
2892 * This method was removed due to potential issues caused by performing partial
2893 * updates of service state, and lack of a credible use case.
2894 *
2895 * This has the ability to break the telephony implementation by disabling notification of
2896 * changes in device connectivity. DO NOT USE THIS!
2897 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002898 @Override
2899 public void disableLocationUpdates() {
2900 mApp.enforceCallingOrSelfPermission(
2901 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 }
2903
2904 @Override
2905 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002906 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2907 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002908 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002909 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2910 throw new SecurityException(
2911 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2912 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002913
Jordan Liu1617b712019-07-10 15:06:26 -07002914 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002915 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2916 return null;
2917 }
Svetoslav64fad262015-04-14 14:35:21 -07002918
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002919 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002921 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002922 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923
Nathan Haroldf180aac2018-06-01 18:43:55 -07002924 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2925 for (CellInfo ci : info) {
2926 if (ci instanceof CellInfoGsm) {
2927 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2928 } else if (ci instanceof CellInfoWcdma) {
2929 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002931 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002932 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002933 }
2934
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002935 private List<CellInfo> getCachedCellInfo() {
2936 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2937 for (Phone phone : PhoneFactory.getPhones()) {
2938 List<CellInfo> info = phone.getAllCellInfo();
2939 if (info != null) cellInfos.addAll(info);
2940 }
2941 return cellInfos;
2942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002943
2944 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002945 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002946 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002947 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002948
2949 LocationAccessPolicy.LocationPermissionResult locationResult =
2950 LocationAccessPolicy.checkLocationPermission(mApp,
2951 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2952 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002953 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002954 .setCallingPid(Binder.getCallingPid())
2955 .setCallingUid(Binder.getCallingUid())
2956 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002957 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002958 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2959 .build());
2960 switch (locationResult) {
2961 case DENIED_HARD:
2962 throw new SecurityException("Not allowed to access cell info");
2963 case DENIED_SOFT:
2964 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002965 }
2966
Nathan Haroldf096d982020-11-18 17:18:06 -08002967 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002968 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2969 return getCachedCellInfo();
2970 }
2971
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002972 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2977 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002978 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002979 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980 if (info != null) cellInfos.addAll(info);
2981 }
2982 return cellInfos;
2983 } finally {
2984 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002985 }
2986 }
2987
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002988 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002989 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2990 String callingFeatureId) {
2991 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2992 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002993 }
2994
2995 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002996 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2997 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002998 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002999 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003000 }
3001
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003002 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3003 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003005 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003006
3007 LocationAccessPolicy.LocationPermissionResult locationResult =
3008 LocationAccessPolicy.checkLocationPermission(mApp,
3009 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3010 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003011 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003012 .setCallingPid(Binder.getCallingPid())
3013 .setCallingUid(Binder.getCallingUid())
3014 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003015 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3016 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003017 .build());
3018 switch (locationResult) {
3019 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003020 if (TelephonyPermissions
3021 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003022 // Safetynet logging for b/154934934
3023 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3024 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003025 throw new SecurityException("Not allowed to access cell info");
3026 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003027 if (TelephonyPermissions
3028 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003029 // Safetynet logging for b/154934934
3030 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3031 }
Nathan Harold5320c422019-05-09 10:26:08 -07003032 try {
3033 cb.onCellInfo(new ArrayList<CellInfo>());
3034 } catch (RemoteException re) {
3035 // Drop without consequences
3036 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003037 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003038 }
3039
Nathan Harolda939a962019-05-09 10:13:47 -07003040
3041 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003042 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3043
3044 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3045 }
3046
3047 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003049 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003050 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003051
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003054 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003058 }
3059
Shishir Agrawala9f32182016-04-12 12:00:16 -07003060 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003061 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003062 Phone phone = PhoneFactory.getPhone(slotIndex);
3063 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003064 return null;
3065 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003066 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003067 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003068 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003069 return null;
3070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071
3072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 return phone.getImei();
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003078 }
3079
3080 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003081 public String getTypeAllocationCodeForSlot(int slotIndex) {
3082 Phone phone = PhoneFactory.getPhone(slotIndex);
3083 String tac = null;
3084 if (phone != null) {
3085 String imei = phone.getImei();
3086 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3087 }
3088 return tac;
3089 }
3090
3091 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003092 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003093 Phone phone = PhoneFactory.getPhone(slotIndex);
3094 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003095 return null;
3096 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003097
Jeff Davidson913390f2018-02-23 17:11:49 -08003098 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003099 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003100 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003101 return null;
3102 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103
3104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 return phone.getMeid();
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
Jack Yu2af8d712017-03-15 17:14:14 -07003110 }
3111
3112 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003113 public String getManufacturerCodeForSlot(int slotIndex) {
3114 Phone phone = PhoneFactory.getPhone(slotIndex);
3115 String manufacturerCode = null;
3116 if (phone != null) {
3117 String meid = phone.getMeid();
3118 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3119 }
3120 return manufacturerCode;
3121 }
3122
3123 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003124 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3125 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003126 Phone phone = PhoneFactory.getPhone(slotIndex);
3127 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003128 return null;
3129 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003130 int subId = phone.getSubId();
3131 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003132 mApp, subId, callingPackage, callingFeatureId,
3133 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003134 return null;
3135 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003136
3137 final long identity = Binder.clearCallingIdentity();
3138 try {
3139 return phone.getDeviceSvn();
3140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003143 }
3144
fionaxu43304da2017-11-27 22:51:16 -08003145 @Override
3146 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 final Phone phone = getPhone(subId);
3150 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3151 } finally {
3152 Binder.restoreCallingIdentity(identity);
3153 }
fionaxu43304da2017-11-27 22:51:16 -08003154 }
3155
3156 @Override
3157 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003158 final long identity = Binder.clearCallingIdentity();
3159 try {
3160 final Phone phone = getPhone(subId);
3161 return phone == null ? null : phone.getCarrierName();
3162 } finally {
3163 Binder.restoreCallingIdentity(identity);
3164 }
fionaxu43304da2017-11-27 22:51:16 -08003165 }
3166
calvinpanffe225e2018-11-01 19:43:06 +08003167 @Override
chen xu0026ca62019-03-06 15:28:50 -08003168 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 final Phone phone = getPhone(subId);
3172 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003173 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003174 } finally {
3175 Binder.restoreCallingIdentity(identity);
3176 }
3177 }
3178
3179 @Override
chen xu0026ca62019-03-06 15:28:50 -08003180 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003184 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
3188 }
3189
chen xu651eec72018-11-11 19:03:44 -08003190 @Override
chen xu864e11c2018-12-06 22:10:03 -08003191 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3192 if (!isSubscriptionMccMnc) {
3193 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3194 }
chen xu651eec72018-11-11 19:03:44 -08003195 final Phone phone = PhoneFactory.getPhone(slotIndex);
3196 if (phone == null) {
3197 return TelephonyManager.UNKNOWN_CARRIER_ID;
3198 }
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3202 } finally {
3203 Binder.restoreCallingIdentity(identity);
3204 }
3205 }
3206
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003207 //
3208 // Internal helper methods.
3209 //
3210
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003211 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003212 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3213 *
3214 * @throws SecurityException if the caller does not have the required permission
3215 */
3216 private void enforceModifyPermission() {
3217 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3218 }
3219
Shuo Qiancd19c462020-01-16 20:51:11 -08003220 /**
3221 * Make sure the caller is system.
3222 *
3223 * @throws SecurityException if the caller is not system.
3224 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003225 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003226 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3227 throw new SecurityException("Caller must be system");
3228 }
3229 }
3230
Shuo Qian3b6ee772019-11-13 17:43:31 -08003231 private void enforceActiveEmergencySessionPermission() {
3232 mApp.enforceCallingOrSelfPermission(
3233 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3234 }
3235
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003236 /**
3237 * Make sure the caller has the CALL_PHONE permission.
3238 *
3239 * @throws SecurityException if the caller does not have the required permission
3240 */
3241 private void enforceCallPermission() {
3242 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3243 }
3244
paulhu5a773602019-08-23 19:17:33 +08003245 private void enforceSettingsPermission() {
3246 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003247 }
3248
Michele Berionne5e411512020-11-13 02:36:59 +00003249 private void enforceRebootPermission() {
3250 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3251 }
3252
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 private String createTelUrl(String number) {
3254 if (TextUtils.isEmpty(number)) {
3255 return null;
3256 }
3257
Jake Hambye994d462014-02-03 13:10:13 -08003258 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 }
3260
Ihab Awadf9e92732013-12-05 18:02:52 -08003261 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003262 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3263 }
3264
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003265 private static void logv(String msg) {
3266 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3267 }
3268
Ihab Awadf9e92732013-12-05 18:02:52 -08003269 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003270 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3271 }
3272
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003273 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003275 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003276 }
3277
Sanket Padawe356d7632015-06-22 14:03:32 -07003278 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003279 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003280 final long identity = Binder.clearCallingIdentity();
3281 try {
3282 final Phone phone = PhoneFactory.getPhone(slotIndex);
3283 if (phone == null) {
3284 return PhoneConstants.PHONE_TYPE_NONE;
3285 } else {
3286 return phone.getPhoneType();
3287 }
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003291 }
3292
3293 /**
3294 * Returns the CDMA ERI icon index to display
3295 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003296 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003297 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3298 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3299 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003300 }
3301
Sanket Padawe356d7632015-06-22 14:03:32 -07003302 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003303 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3304 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003306 mApp, subId, callingPackage, callingFeatureId,
3307 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003308 return -1;
3309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003310
3311 final long identity = Binder.clearCallingIdentity();
3312 try {
3313 final Phone phone = getPhone(subId);
3314 if (phone != null) {
3315 return phone.getCdmaEriIconIndex();
3316 } else {
3317 return -1;
3318 }
3319 } finally {
3320 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003322 }
3323
3324 /**
3325 * Returns the CDMA ERI icon mode,
3326 * 0 - ON
3327 * 1 - FLASHING
3328 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003329 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003330 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3331 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3332 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003333 }
3334
Sanket Padawe356d7632015-06-22 14:03:32 -07003335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003336 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3337 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003339 mApp, subId, callingPackage, callingFeatureId,
3340 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003341 return -1;
3342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003343
3344 final long identity = Binder.clearCallingIdentity();
3345 try {
3346 final Phone phone = getPhone(subId);
3347 if (phone != null) {
3348 return phone.getCdmaEriIconMode();
3349 } else {
3350 return -1;
3351 }
3352 } finally {
3353 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003355 }
3356
3357 /**
3358 * Returns the CDMA ERI text,
3359 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003360 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003361 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3362 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3363 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003364 }
3365
Sanket Padawe356d7632015-06-22 14:03:32 -07003366 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003367 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3368 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003370 mApp, subId, callingPackage, callingFeatureId,
3371 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003372 return null;
3373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003374
3375 final long identity = Binder.clearCallingIdentity();
3376 try {
3377 final Phone phone = getPhone(subId);
3378 if (phone != null) {
3379 return phone.getCdmaEriText();
3380 } else {
3381 return null;
3382 }
3383 } finally {
3384 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003386 }
3387
3388 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003389 * Returns the CDMA MDN.
3390 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003391 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003392 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3394 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395
3396 final long identity = Binder.clearCallingIdentity();
3397 try {
3398 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003399 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400 return phone.getLine1Number();
3401 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003402 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 return null;
3404 }
3405 } finally {
3406 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003407 }
3408 }
3409
3410 /**
3411 * Returns the CDMA MIN.
3412 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003413 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003414 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3416 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417
3418 final long identity = Binder.clearCallingIdentity();
3419 try {
3420 final Phone phone = getPhone(subId);
3421 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3422 return phone.getCdmaMin();
3423 } else {
3424 return null;
3425 }
3426 } finally {
3427 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003428 }
3429 }
3430
Hall Liud892bec2018-11-30 14:51:45 -08003431 @Override
3432 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3433 INumberVerificationCallback callback, String callingPackage) {
3434 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3435 != PERMISSION_GRANTED) {
3436 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3437 }
3438 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3439
3440 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3441 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003442 throw new SecurityException("Calling package must be configured in the device config: "
3443 + "calling package: " + callingPackage
3444 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003445 }
3446
3447 if (range == null) {
3448 throw new NullPointerException("Range must be non-null");
3449 }
3450
3451 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003452 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003453
3454 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3455 }
3456
Junda Liuca05d5d2014-08-14 22:36:34 -07003457 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003458 * Returns true if CDMA provisioning needs to run.
3459 */
3460 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461 final long identity = Binder.clearCallingIdentity();
3462 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003463 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 } finally {
3465 Binder.restoreCallingIdentity(identity);
3466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003467 }
3468
3469 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003470 * Sets the voice mail number of a given subId.
3471 */
3472 @Override
3473 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003474 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3475 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003476
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3480 new Pair<String, String>(alphaTag, number), new Integer(subId));
3481 return success;
3482 } finally {
3483 Binder.restoreCallingIdentity(identity);
3484 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003485 }
3486
Ta-wei Yen87c49842016-05-13 21:19:52 -07003487 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003488 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3489 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003490 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3491 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003492 if (!TextUtils.equals(callingPackage, systemDialer)) {
3493 throw new SecurityException("caller must be system dialer");
3494 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003495
3496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3499 if (phoneAccountHandle == null) {
3500 return null;
3501 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503 } finally {
3504 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003505 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003506 }
3507
3508 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003509 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3510 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003511 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003512 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003513 mApp, subId, callingPackage, callingFeatureId,
3514 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003515 return null;
3516 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003517
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003518 final long identity = Binder.clearCallingIdentity();
3519 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003520 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003524 }
3525
3526 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003527 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3528 VisualVoicemailSmsFilterSettings settings) {
3529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530
3531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003535 } finally {
3536 Binder.restoreCallingIdentity(identity);
3537 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003538 }
3539
3540 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003541 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003547 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003551 }
3552
3553 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003554 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3555 String callingPackage, int subId) {
3556 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003561 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003562 } finally {
3563 Binder.restoreCallingIdentity(identity);
3564 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003565 }
3566
3567 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003568 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003570
3571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003578 }
3579
3580 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003581 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3582 String callingAttributionTag, int subId, String number, int port, String text,
3583 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003584 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003585 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003586 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003587 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003588 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3589 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003590 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003591
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003592 /**
fionaxu0152e512016-11-14 13:36:14 -08003593 * Sets the voice activation state of a given subId.
3594 */
3595 @Override
3596 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003597 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3598 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003599
3600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 final Phone phone = getPhone(subId);
3603 if (phone != null) {
3604 phone.setVoiceActivationState(activationState);
3605 } else {
3606 loge("setVoiceActivationState fails with invalid subId: " + subId);
3607 }
3608 } finally {
3609 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003610 }
3611 }
3612
3613 /**
3614 * Sets the data activation state of a given subId.
3615 */
3616 @Override
3617 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3619 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620
3621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 final Phone phone = getPhone(subId);
3624 if (phone != null) {
3625 phone.setDataActivationState(activationState);
3626 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003627 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003628 }
3629 } finally {
3630 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003631 }
3632 }
3633
3634 /**
3635 * Returns the voice activation state of a given subId.
3636 */
3637 @Override
3638 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003640
fionaxu0152e512016-11-14 13:36:14 -08003641 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 if (phone != null) {
3645 return phone.getVoiceActivationState();
3646 } else {
3647 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3648 }
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003651 }
3652 }
3653
3654 /**
3655 * Returns the data activation state of a given subId.
3656 */
3657 @Override
3658 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660
fionaxu0152e512016-11-14 13:36:14 -08003661 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 if (phone != null) {
3665 return phone.getDataActivationState();
3666 } else {
3667 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3668 }
3669 } finally {
3670 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003671 }
3672 }
3673
3674 /**
Wink Saville36469e72014-06-11 15:17:00 -07003675 * Returns the unread count of voicemails for a subId
3676 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003677 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003678 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3679 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003680 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003681 mApp, subId, callingPackage, callingFeatureId,
3682 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003683 return 0;
3684 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 final Phone phone = getPhone(subId);
3688 if (phone != null) {
3689 return phone.getVoiceMessageCount();
3690 } else {
3691 return 0;
3692 }
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003696 }
3697
3698 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003699 * returns true, if the device is in a state where both voice and data
3700 * are supported simultaneously. This can change based on location or network condition.
3701 */
3702 @Override
3703 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 final Phone phone = getPhone(subId);
3707 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
3710 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003711 }
3712
3713 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003714 * Send the dialer code if called from the current default dialer or the caller has
3715 * carrier privilege.
3716 * @param inputCode The dialer code to send
3717 */
3718 @Override
3719 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003720 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003722 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3723 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003724 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003725 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003726 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728
3729 final long identity = Binder.clearCallingIdentity();
3730 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003731 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
fionaxu235cc5e2017-03-06 22:25:57 -08003735 }
3736
Pengquan Menga1bb6272018-09-06 09:59:22 -07003737 @Override
3738 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003739 TelephonyPermissions
3740 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3741 mApp, subId, "getNetworkSelectionMode");
3742 final long identity = Binder.clearCallingIdentity();
3743 try {
3744 if (!isActiveSubscription(subId)) {
3745 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3746 }
3747 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3748 } finally {
3749 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003750 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003751 }
3752
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003754 public boolean isInEmergencySmsMode() {
3755 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3756 final long identity = Binder.clearCallingIdentity();
3757 try {
3758 for (Phone phone : PhoneFactory.getPhones()) {
3759 if (phone.isInEmergencySmsMode()) {
3760 return true;
3761 }
3762 }
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
3766 return false;
3767 }
3768
shilu366312e2019-12-17 09:28:10 -08003769 /**
3770 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3771 * @param subId The subscription to use to check the configuration.
3772 * @param c The callback that will be used to send the result.
3773 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003774 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003775 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3776 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003777 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3778 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003779
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003780 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3781 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3782 "IMS not available on device.");
3783 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003784 final long token = Binder.clearCallingIdentity();
3785 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003786 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003787 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003789 } catch (ImsException e) {
3790 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003791 } finally {
3792 Binder.restoreCallingIdentity(token);
3793 }
3794 }
3795
shilu366312e2019-12-17 09:28:10 -08003796 /**
3797 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3798 * @param subId The subscription to use to check the configuration.
3799 * @param c The callback that will be used to send the result.
3800 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003801 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003802 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003803 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3804 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003805 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3806 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3807 }
Meng Wangafbc5852019-09-19 17:37:13 -07003808 final long token = Binder.clearCallingIdentity();
3809 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003810 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003811 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3812 .removeRegistrationCallbackForSubscription(c, subId);
3813 } catch (ImsException e) {
3814 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3815 + "is inactive, ignoring unregister.");
3816 // If the subscription is no longer active, just return, since the callback
3817 // will already have been removed internally.
3818 } finally {
3819 Binder.restoreCallingIdentity(token);
3820 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003821 }
3822
Brad Ebingera34a6c22019-10-22 17:36:18 -07003823 /**
3824 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3825 */
3826 @Override
3827 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3828 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3829 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3830 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3831 "IMS not available on device.");
3832 }
3833 final long token = Binder.clearCallingIdentity();
3834 try {
3835 Phone phone = getPhone(subId);
3836 if (phone == null) {
3837 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3838 + subId + "'");
3839 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3840 }
3841 phone.getImsRegistrationState(regState -> {
3842 try {
3843 consumer.accept((regState == null)
3844 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3845 } catch (RemoteException e) {
3846 // Ignore if the remote process is no longer available to call back.
3847 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3848 }
3849 });
3850 } finally {
3851 Binder.restoreCallingIdentity(token);
3852 }
3853 }
3854
3855 /**
3856 * Get the transport type for the IMS service registration state.
3857 */
3858 @Override
3859 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003860 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3861 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003862 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3863 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3864 "IMS not available on device.");
3865 }
3866 final long token = Binder.clearCallingIdentity();
3867 try {
3868 Phone phone = getPhone(subId);
3869 if (phone == null) {
3870 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3871 + subId + "'");
3872 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3873 }
3874 phone.getImsRegistrationTech(regTech -> {
3875 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3876 int regTechConverted = (regTech == null)
3877 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3878 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3879 regTechConverted);
3880 try {
3881 consumer.accept(regTechConverted);
3882 } catch (RemoteException e) {
3883 // Ignore if the remote process is no longer available to call back.
3884 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3885 }
3886 });
3887 } finally {
3888 Binder.restoreCallingIdentity(token);
3889 }
3890 }
3891
shilu366312e2019-12-17 09:28:10 -08003892 /**
3893 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3894 * @param subId The subscription to use to check the configuration.
3895 * @param c The callback that will be used to send the result.
3896 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003898 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3899 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003900 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3901 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003902 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3903 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3904 "IMS not available on device.");
3905 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3907 final long token = Binder.clearCallingIdentity();
3908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003911 } catch (ImsException e) {
3912 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 } finally {
3914 Binder.restoreCallingIdentity(token);
3915 }
3916 }
3917
shilu366312e2019-12-17 09:28:10 -08003918 /**
3919 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3920 * @param subId The subscription to use to check the configuration.
3921 * @param c The callback that will be used to send the result.
3922 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003923 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003924 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003925 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3926 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003927 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3928 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3929 }
Meng Wangafbc5852019-09-19 17:37:13 -07003930
3931 final long token = Binder.clearCallingIdentity();
3932 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003933 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003934 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003935 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003936 } catch (ImsException e) {
3937 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3938 + "is inactive, ignoring unregister.");
3939 // If the subscription is no longer active, just return, since the callback
3940 // will already have been removed internally.
3941 } finally {
3942 Binder.restoreCallingIdentity(token);
3943 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003944 }
3945
3946 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003947 public boolean isCapable(int subId, int capability, int regTech) {
3948 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003949 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3950 final long token = Binder.clearCallingIdentity();
3951 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003952 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003953 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003954 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003955 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3956 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003957 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003958 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3959 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003960 } finally {
3961 Binder.restoreCallingIdentity(token);
3962 }
3963 }
3964
3965 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003966 public boolean isAvailable(int subId, int capability, int regTech) {
3967 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 final long token = Binder.clearCallingIdentity();
3969 try {
3970 Phone phone = getPhone(subId);
3971 if (phone == null) return false;
3972 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003973 } catch (com.android.ims.ImsException e) {
3974 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3975 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 } finally {
3977 Binder.restoreCallingIdentity(token);
3978 }
3979 }
3980
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003981 /**
3982 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3983 * subscription.
3984 * @param subId The subscription to use to check the configuration.
3985 * @param callback The callback that will be used to send the result.
3986 * @param capability The MmTelFeature capability that will be used to send the result.
3987 * @param transportType The transport type of the MmTelFeature capability.
3988 */
3989 @Override
3990 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3991 int transportType) {
3992 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3993 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3994 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3995 "IMS not available on device.");
3996 }
3997 final long token = Binder.clearCallingIdentity();
3998 try {
3999 int slotId = getSlotIndex(subId);
4000 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4001 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4002 + subId + "'");
4003 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4004 }
4005 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4006 transportType, aBoolean -> {
4007 try {
4008 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4009 } catch (RemoteException e) {
4010 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4011 + "running. Ignore");
4012 }
4013 });
4014 } finally {
4015 Binder.restoreCallingIdentity(token);
4016 }
4017 }
4018
shilu366312e2019-12-17 09:28:10 -08004019 /**
4020 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4021 * @param subId The subscription to use to check the configuration.
4022 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 @Override
4024 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004025 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4026 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004027
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4029 final long token = Binder.clearCallingIdentity();
4030 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004031 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004033 } catch (ImsException e) {
4034 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 } finally {
4036 Binder.restoreCallingIdentity(token);
4037 }
4038 }
4039
4040 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004041 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004043 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004047 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004049 } catch (ImsException e) {
4050 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 } finally {
4052 Binder.restoreCallingIdentity(identity);
4053 }
4054 }
4055
shilu366312e2019-12-17 09:28:10 -08004056 /**
4057 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4058 * @param subId The subscription to use to check the configuration.
4059 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004061 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004062 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4063 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004067 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4068 } catch (ImsException e) {
4069 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
4073 }
4074
4075 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004076 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004078 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004082 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004083 } catch (ImsException e) {
4084 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
4088 }
4089
shilu366312e2019-12-17 09:28:10 -08004090 /**
4091 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4092 * @param subId The subscription to use to check the configuration.
4093 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004094 @Override
4095 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004096 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4097 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 final long identity = Binder.clearCallingIdentity();
4099 try {
4100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004101 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004102 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004103 } catch (ImsException e) {
4104 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 } finally {
4106 Binder.restoreCallingIdentity(identity);
4107 }
4108 }
4109
4110 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004111 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004113 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004117 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004118 } catch (ImsException e) {
4119 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004120 } finally {
4121 Binder.restoreCallingIdentity(identity);
4122 }
4123 }
4124
shilu366312e2019-12-17 09:28:10 -08004125 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004126 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4127 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4128 * @param subId The subscription to use to check the configuration.
4129 */
4130 @Override
4131 public boolean isCrossSimCallingEnabledByUser(int subId) {
4132 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4133 mApp, subId, "isCrossSimCallingEnabledByUser");
4134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4137 return ImsManager.getInstance(mApp,
4138 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4139 } catch (ImsException e) {
4140 throw new ServiceSpecificException(e.getCode());
4141 } finally {
4142 Binder.restoreCallingIdentity(identity);
4143 }
4144 }
4145
4146 /**
4147 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4148 * Requires MODIFY_PHONE_STATE permission.
4149 * @param subId The subscription to use to check the configuration.
4150 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4151 * false otherwise
4152 */
4153 @Override
4154 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4156 "setCrossSimCallingEnabled");
4157 final long identity = Binder.clearCallingIdentity();
4158 try {
4159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4160 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4161 .setCrossSimCallingEnabled(isEnabled);
4162 } catch (ImsException e) {
4163 throw new ServiceSpecificException(e.getCode());
4164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
4167 }
4168
4169 /**
shilu366312e2019-12-17 09:28:10 -08004170 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4171 * @param subId The subscription to use to check the configuration.
4172 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004173 @Override
4174 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004175 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4176 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004180 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004182 } catch (ImsException e) {
4183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
4187 }
4188
4189 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004190 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004192 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004196 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004198 } catch (ImsException e) {
4199 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
4203 }
4204
4205 @Override
4206 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4208 "setVoWiFiNonPersistent");
4209 final long identity = Binder.clearCallingIdentity();
4210 try {
4211 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004212 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004213 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004214 } catch (ImsException e) {
4215 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004216 } finally {
4217 Binder.restoreCallingIdentity(identity);
4218 }
4219 }
4220
shilu366312e2019-12-17 09:28:10 -08004221 /**
4222 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4223 * @param subId The subscription to use to check the configuration.
4224 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 @Override
4226 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004227 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4228 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 final long identity = Binder.clearCallingIdentity();
4230 try {
4231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004232 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004234 } catch (ImsException e) {
4235 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 } finally {
4237 Binder.restoreCallingIdentity(identity);
4238 }
4239 }
4240
4241 @Override
4242 public void setVoWiFiModeSetting(int subId, int mode) {
4243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4244 "setVoWiFiModeSetting");
4245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004248 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004249 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004250 } catch (ImsException e) {
4251 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 } finally {
4253 Binder.restoreCallingIdentity(identity);
4254 }
4255 }
4256
4257 @Override
4258 public int getVoWiFiRoamingModeSetting(int subId) {
4259 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4260 final long identity = Binder.clearCallingIdentity();
4261 try {
4262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004263 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004264 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004265 } catch (ImsException e) {
4266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
4270 }
4271
4272 @Override
4273 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4275 "setVoWiFiRoamingModeSetting");
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004279 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004280 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004281 } catch (ImsException e) {
4282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 } finally {
4284 Binder.restoreCallingIdentity(identity);
4285 }
4286 }
4287
4288 @Override
4289 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4291 "setRttCapabilityEnabled");
4292 final long identity = Binder.clearCallingIdentity();
4293 try {
4294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004295 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4296 } catch (ImsException e) {
4297 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
4301 }
4302
shilu366312e2019-12-17 09:28:10 -08004303 /**
4304 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4305 * @param subId The subscription to use to check the configuration.
4306 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 @Override
4308 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004309 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4310 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 final long identity = Binder.clearCallingIdentity();
4312 try {
4313 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004314 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004316 } catch (ImsException e) {
4317 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 } finally {
4319 Binder.restoreCallingIdentity(identity);
4320 }
4321 }
4322
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004323 @Override
4324 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4325 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004328 if (!isImsAvailableOnDevice()) {
4329 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4330 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004331 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004332 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004333 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004334 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004335 } catch (ImsException e) {
4336 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004337 } finally {
4338 Binder.restoreCallingIdentity(identity);
4339 }
4340 }
4341
4342 @Override
4343 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4344 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4345 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004346 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4347 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4348 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004349 try {
4350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004351 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004352 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004353 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004354 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4355 + "is inactive, ignoring unregister.");
4356 // If the subscription is no longer active, just return, since the callback will already
4357 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
allenwtsu99c623b2020-01-03 18:24:23 +08004363
4364 private void checkModifyPhoneStatePermission(int subId, String message) {
4365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4366 message);
4367 }
4368
4369 private boolean isImsProvisioningRequired(int subId, int capability,
4370 boolean isMmtelCapability) {
4371 Phone phone = getPhone(subId);
4372 if (phone == null) {
4373 loge("phone instance null for subid " + subId);
4374 return false;
4375 }
4376 if (isMmtelCapability) {
4377 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4378 return false;
4379 }
4380 } else {
4381 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4382 return false;
4383 }
4384 }
4385 return true;
4386 }
4387
4388 @Override
4389 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4390 boolean isProvisioned) {
4391 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4392
4393 final long identity = Binder.clearCallingIdentity();
4394 try {
4395 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4396 if (!isImsProvisioningRequired(subId, capability, false)) {
4397 return;
4398 }
4399
4400 // this capability requires provisioning, route to the correct API.
4401 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4402 switch (capability) {
4403 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4404 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4405 ims.setEabProvisioned(isProvisioned);
4406 break;
4407 default: {
4408 throw new IllegalArgumentException("Tried to set provisioning for "
4409 + "rcs capability '" + capability + "', which does not require "
4410 + "provisioning.");
4411 }
4412 }
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
4416
4417 }
4418
4419
4420 @Override
4421 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4422 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4426 if (!isImsProvisioningRequired(subId, capability, false)) {
4427 return true;
4428 }
4429
4430 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4431 switch (capability) {
4432 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4433 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4434 return ims.isEabProvisionedOnDevice();
4435
4436 default: {
4437 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4438 + "capability '" + capability + "', which does not require "
4439 + "provisioning.");
4440 }
4441 }
4442
4443 } finally {
4444 Binder.restoreCallingIdentity(identity);
4445 }
4446 }
4447
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004448 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004449 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4450 boolean isProvisioned) {
4451 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4452 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4453 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4454 }
allenwtsu99c623b2020-01-03 18:24:23 +08004455 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004456 final long identity = Binder.clearCallingIdentity();
4457 try {
4458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004459 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004460 return;
4461 }
4462
4463 // this capability requires provisioning, route to the correct API.
4464 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4465 switch (capability) {
4466 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4467 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4468 ims.setVolteProvisioned(isProvisioned);
4469 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4470 ims.setWfcProvisioned(isProvisioned);
4471 }
4472 break;
4473 }
4474 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4475 // There is currently no difference in VT provisioning type.
4476 ims.setVtProvisioned(isProvisioned);
4477 break;
4478 }
4479 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4480 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4481 // change the capability of the feature instead if needed.
4482 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4483 == isProvisioned) {
4484 // No change in provisioning.
4485 return;
4486 }
4487 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4488 try {
4489 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004490 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004491 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4492 + ", Exception" + e.getMessage());
4493 }
4494 break;
4495 }
4496 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004497 throw new IllegalArgumentException("Tried to set provisioning for "
4498 + "MmTel capability '" + capability + "', which does not require "
4499 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004500 }
4501 }
4502
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
4506 }
4507
4508 @Override
4509 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4510 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4511 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4512 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4513 }
4514 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004518 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004519 return true;
4520 }
4521
4522 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4523 switch (capability) {
4524 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4525 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4526 return ims.isVolteProvisionedOnDevice();
4527 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4528 return ims.isWfcProvisionedOnDevice();
4529 }
4530 // This should never happen, since we are checking tech above to make sure it
4531 // is either LTE or IWLAN.
4532 throw new IllegalArgumentException("Invalid radio technology for voice "
4533 + "capability.");
4534 }
4535 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4536 // There is currently no difference in VT provisioning type.
4537 return ims.isVtProvisionedOnDevice();
4538 }
4539 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4540 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4541 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4542 }
4543 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004544 throw new IllegalArgumentException(
4545 "Tried to get provisioning for MmTel capability '" + capability
4546 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004547 }
4548 }
4549
4550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
4555 @Override
4556 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4557 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4558 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4559 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4560 }
4561 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4562 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4563 return (provisionedBits & capability) > 0;
4564 }
4565
4566 @Override
4567 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4568 boolean isProvisioned) {
4569 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4570 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4571 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4572 }
4573 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4574 "setProvisioningStatusForCapability");
4575 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4576 // If the current provisioning status for capability already matches isProvisioned,
4577 // do nothing.
4578 if (((provisionedBits & capability) > 0) == isProvisioned) {
4579 return;
4580 }
4581 if (isProvisioned) {
4582 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4583 } else {
4584 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4585 }
4586 }
4587
4588 /**
4589 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4590 * technology. The bitfield should mirror the bitfield defined by
4591 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4592 */
4593 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4594 String key = getMmTelProvisioningKey(subId, tech);
4595 // Default is no capabilities are provisioned.
4596 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4597 }
4598
4599 /**
4600 * Sets the MmTel capability provisioning bitfield (defined by
4601 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4602 * technology specified.
4603 *
4604 * Note: This is a synchronous command and should not be called on UI thread.
4605 */
4606 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4607 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4608 String key = getMmTelProvisioningKey(subId, tech);
4609 editor.putInt(key, newField);
4610 editor.commit();
4611 }
4612
4613 private static String getMmTelProvisioningKey(int subId, int tech) {
4614 // resulting key is provision_ims_mmtel_{subId}_{tech}
4615 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4616 }
4617
4618 /**
4619 * Query CarrierConfig to see if the specified capability requires provisioning for the
4620 * carrier associated with the subscription id.
4621 */
4622 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4623 int capability) {
4624 CarrierConfigManager configManager = new CarrierConfigManager(context);
4625 PersistableBundle c = configManager.getConfigForSubId(subId);
4626 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004627 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004628 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4629 false);
4630 boolean requireVoiceVtProvisioning = c.getBoolean(
4631 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4632
4633 // First check to make sure that the capability requires provisioning.
4634 switch (capability) {
4635 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4636 // intentional fallthrough
4637 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4638 if (requireVoiceVtProvisioning) {
4639 // Voice and Video requires provisioning
4640 return true;
4641 }
4642 break;
4643 }
4644 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4645 if (requireUtProvisioning) {
4646 // UT requires provisioning
4647 return true;
4648 }
4649 break;
4650 }
4651 }
4652 return false;
4653 }
4654
allenwtsu99c623b2020-01-03 18:24:23 +08004655 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4656 int capability) {
4657 CarrierConfigManager configManager = new CarrierConfigManager(context);
4658 PersistableBundle c = configManager.getConfigForSubId(subId);
4659
4660 boolean requireRcsProvisioning = c.getBoolean(
4661 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4662
4663 // First check to make sure that the capability requires provisioning.
4664 switch (capability) {
4665 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4666 // intentional fallthrough
4667 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4668 if (requireRcsProvisioning) {
4669 // OPTION or PRESENCE requires provisioning
4670 return true;
4671 }
4672 break;
4673 }
4674 }
4675 return false;
4676 }
4677
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004678 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004679 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004680 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4681 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4682 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004683 enforceReadPrivilegedPermission("getImsProvisioningInt");
4684 final long identity = Binder.clearCallingIdentity();
4685 try {
4686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004687 int slotId = getSlotIndex(subId);
4688 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4689 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4690 + subId + "' for key:" + key);
4691 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4692 }
calvinpanb5a34062021-02-08 19:59:36 +08004693 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004694 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004695 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4696 + subId + "' for key:" + key);
4697 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004698 } finally {
4699 Binder.restoreCallingIdentity(identity);
4700 }
4701 }
4702
4703 @Override
4704 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004705 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4706 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4707 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004708 enforceReadPrivilegedPermission("getImsProvisioningString");
4709 final long identity = Binder.clearCallingIdentity();
4710 try {
4711 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004712 int slotId = getSlotIndex(subId);
4713 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4714 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4715 + subId + "' for key:" + key);
4716 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4717 }
calvinpanb5a34062021-02-08 19:59:36 +08004718 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004719 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004720 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4721 + subId + "' for key:" + key);
4722 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004723 } finally {
4724 Binder.restoreCallingIdentity(identity);
4725 }
4726 }
4727
4728 @Override
4729 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004730 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4731 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4732 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4734 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004735 final long identity = Binder.clearCallingIdentity();
4736 try {
4737 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004738 int slotId = getSlotIndex(subId);
4739 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4740 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4741 + subId + "' for key:" + key);
4742 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4743 }
calvinpanb5a34062021-02-08 19:59:36 +08004744 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4745 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004746 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004747 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004748 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
4752 }
4753
4754 @Override
4755 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004756 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4757 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4758 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4760 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004761 final long identity = Binder.clearCallingIdentity();
4762 try {
4763 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004764 int slotId = getSlotIndex(subId);
4765 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4766 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4767 + subId + "' for key:" + key);
4768 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4769 }
calvinpanb5a34062021-02-08 19:59:36 +08004770 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4771 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004772 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004773 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004774 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004775 } finally {
4776 Binder.restoreCallingIdentity(identity);
4777 }
4778 }
4779
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004780 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004781 int slotId = SubscriptionManager.getSlotIndex(subId);
4782 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004783 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4784 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 }
4786 return slotId;
4787 }
4788
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004789 private int getSlotIndex(int subId) {
4790 int slotId = SubscriptionManager.getSlotIndex(subId);
4791 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4792 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4793 }
4794 return slotId;
4795 }
4796
Wink Saville36469e72014-06-11 15:17:00 -07004797 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004798 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004799 */
4800 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004801 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4802 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004803 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004804 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004805 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004806 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004807 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004808 mApp, subId, callingPackage, callingFeatureId,
4809 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004810 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4811 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 final long identity = Binder.clearCallingIdentity();
4814 try {
4815 final Phone phone = getPhone(subId);
4816 if (phone != null) {
4817 return phone.getServiceState().getDataNetworkType();
4818 } else {
4819 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4820 }
4821 } finally {
4822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004824 }
4825
4826 /**
4827 * Returns the data network type
4828 */
4829 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004830 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4831 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4832 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004833 }
4834
4835 /**
4836 * Returns the data network type for a subId
4837 */
4838 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004839 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4840 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004842 mApp, subId, callingPackage, callingFeatureId,
4843 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004844 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4845 }
4846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 final long identity = Binder.clearCallingIdentity();
4848 try {
4849 final Phone phone = getPhone(subId);
4850 if (phone != null) {
4851 return phone.getServiceState().getDataNetworkType();
4852 } else {
4853 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4854 }
4855 } finally {
4856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004858 }
4859
4860 /**
Wink Saville36469e72014-06-11 15:17:00 -07004861 * Returns the Voice network type for a subId
4862 */
4863 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004864 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4865 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004867 mApp, subId, callingPackage, callingFeatureId,
4868 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004869 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4870 }
4871
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872 final long identity = Binder.clearCallingIdentity();
4873 try {
4874 final Phone phone = getPhone(subId);
4875 if (phone != null) {
4876 return phone.getServiceState().getVoiceNetworkType();
4877 } else {
4878 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4879 }
4880 } finally {
4881 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004883 }
4884
4885 /**
4886 * @return true if a ICC card is present
4887 */
4888 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004889 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004890 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4891 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004892 }
4893
4894 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004895 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004896 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004897 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004898 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899 final long identity = Binder.clearCallingIdentity();
4900 try {
4901 final Phone phone = PhoneFactory.getPhone(slotIndex);
4902 if (phone != null) {
4903 return phone.getIccCard().hasIccCard();
4904 } else {
4905 return false;
4906 }
4907 } finally {
4908 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004910 }
4911
4912 /**
4913 * Return if the current radio is LTE on CDMA. This
4914 * is a tri-state return value as for a period of time
4915 * the mode may be unknown.
4916 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004917 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004918 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004919 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004920 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004921 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004922 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4923 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4924 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004925 }
4926
Sanket Padawe356d7632015-06-22 14:03:32 -07004927 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004928 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4929 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004930 try {
4931 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4932 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004933 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4934 }
4935
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 final Phone phone = getPhone(subId);
4939 if (phone == null) {
4940 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4941 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004942 return TelephonyProperties.lte_on_cdma_device()
4943 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 }
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004947 }
Wink Saville36469e72014-06-11 15:17:00 -07004948 }
4949
Wink Saville36469e72014-06-11 15:17:00 -07004950 /**
4951 * {@hide}
4952 * Returns Default subId, 0 in the case of single standby.
4953 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004954 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004955 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004956 }
4957
Shishir Agrawala9f32182016-04-12 12:00:16 -07004958 private int getSlotForDefaultSubscription() {
4959 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4960 }
4961
Wink Savilleb564aae2014-10-23 10:18:09 -07004962 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004963 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004964 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004965
Pengquan Menge92a50d2018-09-21 15:54:48 -07004966 private boolean isActiveSubscription(int subId) {
4967 return mSubscriptionController.isActiveSubId(subId);
4968 }
4969
Ihab Awadf2177b72013-11-25 13:33:23 -08004970 /**
4971 * @see android.telephony.TelephonyManager.WifiCallingChoices
4972 */
4973 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 final long identity = Binder.clearCallingIdentity();
4975 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004976 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4978 getWhenToMakeWifiCallsDefaultPreference());
4979 } finally {
4980 Binder.restoreCallingIdentity(identity);
4981 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004982 }
4983
4984 /**
4985 * @see android.telephony.TelephonyManager.WifiCallingChoices
4986 */
4987 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004991 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4993 } finally {
4994 Binder.restoreCallingIdentity(identity);
4995 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004996 }
4997
Sailesh Nepald1e68152013-12-12 19:08:02 -08004998 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004999 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005000 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005001 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005002
Jordan Liu4c733742019-02-28 12:03:40 -08005003 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5004 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5005 if (phoneId == -1) {
5006 throw new IllegalArgumentException("Given slot index: " + slotIndex
5007 + " does not correspond to an active phone");
5008 }
5009 return PhoneFactory.getPhone(phoneId);
5010 }
5011
Shishir Agrawal566b7612013-10-28 14:41:00 -07005012 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005013 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5014 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005015 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5016 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005018 if (DBG) {
5019 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5020 }
5021 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5022 p2);
5023 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005024
Jordan Liu4c733742019-02-28 12:03:40 -08005025
5026 @Override
5027 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5028 int slotIndex, String callingPackage, String aid, int p2) {
5029 enforceModifyPermission();
5030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5031 if (DBG) {
5032 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5033 }
5034 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5035 callingPackage, aid, p2);
5036 }
5037
5038 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5039 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 final long identity = Binder.clearCallingIdentity();
5041 try {
5042 if (TextUtils.equals(ISDR_AID, aid)) {
5043 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005044 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5045 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 if (bestComponent == null
5047 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5048 loge("The calling package is not allowed to access ISD-R.");
5049 throw new SecurityException(
5050 "The calling package is not allowed to access ISD-R.");
5051 }
Derek Tan740e1672017-06-27 14:56:27 -07005052 }
Derek Tan740e1672017-06-27 14:56:27 -07005053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005055 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5056 null /* workSource */);
5057 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 return response;
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
5061 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005062 }
5063
5064 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005065 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5067 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005068 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5069 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5070 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005071
Jordan Liu4c733742019-02-28 12:03:40 -08005072 @Override
5073 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5074 enforceModifyPermission();
5075 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5076 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5077 channel);
5078 }
5079
5080 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 final long identity = Binder.clearCallingIdentity();
5082 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 if (channel < 0) {
5084 return false;
5085 }
Jordan Liu4c733742019-02-28 12:03:40 -08005086 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5087 null /* workSource */);
5088 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005089 return success;
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005092 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005093 }
5094
5095 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005096 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005097 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5099 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005100 if (DBG) {
5101 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5102 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5103 + p3 + " data=" + data);
5104 }
5105 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5106 command, p1, p2, p3, data);
5107 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005108
Jordan Liu4c733742019-02-28 12:03:40 -08005109 @Override
5110 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5111 int command, int p1, int p2, int p3, String data) {
5112 enforceModifyPermission();
5113 if (DBG) {
5114 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5115 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5116 + p3 + " data=" + data);
5117 }
5118 return iccTransmitApduLogicalChannelWithPermission(
5119 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5120 data);
5121 }
5122
5123 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5124 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005125 final long identity = Binder.clearCallingIdentity();
5126 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005127 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 return "";
5129 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005130
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005132 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5133 null /* workSource */);
5134 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 // Append the returned status code to the end of the response payload.
5137 String s = Integer.toHexString(
5138 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5139 if (response.payload != null) {
5140 s = IccUtils.bytesToHexString(response.payload) + s;
5141 }
5142 return s;
5143 } finally {
5144 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005145 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005146 }
Jake Hambye994d462014-02-03 13:10:13 -08005147
Evan Charltonc66da362014-05-16 14:06:40 -07005148 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005149 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5150 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5152 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005154 if (DBG) {
5155 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5156 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5157 }
5158 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5159 cla, command, p1, p2, p3, data);
5160 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005161
Jordan Liu4c733742019-02-28 12:03:40 -08005162 @Override
5163 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5164 int command, int p1, int p2, int p3, String data) {
5165 enforceModifyPermission();
5166 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5167 if (DBG) {
5168 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5169 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5170 + " data=" + data);
5171 }
5172
5173 return iccTransmitApduBasicChannelWithPermission(
5174 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5175 p2, p3, data);
5176 }
5177
5178 // open APDU basic channel assuming the caller has sufficient permissions
5179 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5180 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 final long identity = Binder.clearCallingIdentity();
5182 try {
5183 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5184 && TextUtils.equals(ISDR_AID, data)) {
5185 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005186 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5187 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188 if (bestComponent == null
5189 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5190 loge("The calling package is not allowed to select ISD-R.");
5191 throw new SecurityException(
5192 "The calling package is not allowed to select ISD-R.");
5193 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005194 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005195
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005197 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5198 null /* workSource */);
5199 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005200
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 // Append the returned status code to the end of the response payload.
5202 String s = Integer.toHexString(
5203 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5204 if (response.payload != null) {
5205 s = IccUtils.bytesToHexString(response.payload) + s;
5206 }
5207 return s;
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005210 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005211 }
5212
5213 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005214 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005215 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5217 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005219 final long identity = Binder.clearCallingIdentity();
5220 try {
5221 if (DBG) {
5222 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5223 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5224 }
5225
5226 IccIoResult response =
5227 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5228 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5229 subId);
5230
5231 if (DBG) {
5232 log("Exchange SIM_IO [R]" + response);
5233 }
5234
5235 byte[] result = null;
5236 int length = 2;
5237 if (response.payload != null) {
5238 length = 2 + response.payload.length;
5239 result = new byte[length];
5240 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5241 } else {
5242 result = new byte[length];
5243 }
5244
5245 result[length - 1] = (byte) response.sw2;
5246 result[length - 2] = (byte) response.sw1;
5247 return result;
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005250 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005251 }
5252
Nathan Haroldb3014052017-01-25 15:57:32 -08005253 /**
5254 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5255 * on a particular subscription
5256 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005257 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5258 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005260 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005261 return null;
5262 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263
5264 final long identity = Binder.clearCallingIdentity();
5265 try {
5266 if (appType != TelephonyManager.APPTYPE_USIM
5267 && appType != TelephonyManager.APPTYPE_SIM) {
5268 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5269 return null;
5270 }
5271 Object response = sendRequest(
5272 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5273 if (response instanceof String[]) {
5274 return (String[]) response;
5275 }
yincheng zhao2737e882019-09-06 17:06:54 -07005276 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005278 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279 } finally {
5280 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005281 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005282 }
5283
yincheng zhao2737e882019-09-06 17:06:54 -07005284 /**
5285 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5286 * subscription.
5287 *
5288 * @param subId the id of the subscription.
5289 * @param appType the uicc app type, must be USIM or SIM.
5290 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5291 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005292 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005293 * @return number of fplmns that is successfully written to the SIM.
5294 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005295 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5296 String callingFeatureId) {
5297 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5298 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005299 if (DBG) logv("no permissions for setForbiddenplmns");
5300 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5301 }
5302 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5303 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5304 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5305 }
5306 if (fplmns == null) {
5307 throw new IllegalArgumentException("Fplmn List provided is null");
5308 }
5309 for (String fplmn : fplmns) {
5310 if (!CellIdentity.isValidPlmn(fplmn)) {
5311 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5312 }
5313 }
5314 final long identity = Binder.clearCallingIdentity();
5315 try {
5316 Object response = sendRequest(
5317 CMD_SET_FORBIDDEN_PLMNS,
5318 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5319 subId);
5320 return (int) response;
5321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
5324 }
5325
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005326 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005327 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5329 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 final long identity = Binder.clearCallingIdentity();
5332 try {
5333 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5334 if (response.payload == null) {
5335 return "";
5336 }
Evan Charltonc66da362014-05-16 14:06:40 -07005337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005338 // Append the returned status code to the end of the response payload.
5339 String s = Integer.toHexString(
5340 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5341 s = IccUtils.bytesToHexString(response.payload) + s;
5342 return s;
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
5345 }
Evan Charltonc66da362014-05-16 14:06:40 -07005346 }
5347
Jake Hambye994d462014-02-03 13:10:13 -08005348 /**
5349 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5350 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5351 *
5352 * @param itemID the ID of the item to read
5353 * @return the NV item as a String, or null on error.
5354 */
5355 @Override
5356 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5359 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360
5361 final long identity = Binder.clearCallingIdentity();
5362 try {
5363 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005364 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5366 return value;
5367 } finally {
5368 Binder.restoreCallingIdentity(identity);
5369 }
Jake Hambye994d462014-02-03 13:10:13 -08005370 }
5371
5372 /**
5373 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5374 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5375 *
5376 * @param itemID the ID of the item to read
5377 * @param itemValue the value to write, as a String
5378 * @return true on success; false on any failure
5379 */
5380 @Override
5381 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005382 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005383 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5384 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385
5386 final long identity = Binder.clearCallingIdentity();
5387 try {
5388 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5389 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005390 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5392 return success;
5393 } finally {
5394 Binder.restoreCallingIdentity(identity);
5395 }
Jake Hambye994d462014-02-03 13:10:13 -08005396 }
5397
5398 /**
5399 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5400 * Used for device configuration by some CDMA operators.
5401 *
5402 * @param preferredRoamingList byte array containing the new PRL
5403 * @return true on success; false on any failure
5404 */
5405 @Override
5406 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5408 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409
5410 final long identity = Binder.clearCallingIdentity();
5411 try {
5412 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5413 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5414 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5415 return success;
5416 } finally {
5417 Binder.restoreCallingIdentity(identity);
5418 }
Jake Hambye994d462014-02-03 13:10:13 -08005419 }
5420
5421 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005422 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005423 * Used for device configuration by some CDMA operators.
5424 *
chen xu6dac5ab2018-10-26 17:39:23 -07005425 * @param slotIndex - device slot.
5426 *
Jake Hambye994d462014-02-03 13:10:13 -08005427 * @return true on success; false on any failure
5428 */
5429 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005430 public boolean resetModemConfig(int slotIndex) {
5431 Phone phone = PhoneFactory.getPhone(slotIndex);
5432 if (phone != null) {
5433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5434 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435
chen xu6dac5ab2018-10-26 17:39:23 -07005436 final long identity = Binder.clearCallingIdentity();
5437 try {
5438 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5439 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5440 return success;
5441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005444 }
chen xu6dac5ab2018-10-26 17:39:23 -07005445 return false;
5446 }
5447
5448 /**
5449 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5450 *
5451 * @param slotIndex - device slot.
5452 *
5453 * @return true on success; false on any failure
5454 */
5455 @Override
5456 public boolean rebootModem(int slotIndex) {
5457 Phone phone = PhoneFactory.getPhone(slotIndex);
5458 if (phone != null) {
5459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5460 mApp, phone.getSubId(), "rebootModem");
5461
5462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5465 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5466 return success;
5467 } finally {
5468 Binder.restoreCallingIdentity(identity);
5469 }
5470 }
5471 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005472 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005473
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005474 public String[] getPcscfAddress(String apnType, String callingPackage,
5475 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005476 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5478 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005479 return new String[0];
5480 }
5481
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 final long identity = Binder.clearCallingIdentity();
5483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005484 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
Wink Saville36469e72014-06-11 15:17:00 -07005488 }
5489
Brad Ebinger51f743a2017-01-23 13:50:20 -08005490 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005491 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5492 * {@link #disableIms(int)}.
5493 * @param slotIndex device slot.
5494 */
5495 public void resetIms(int slotIndex) {
5496 enforceModifyPermission();
5497
5498 final long identity = Binder.clearCallingIdentity();
5499 try {
5500 if (mImsResolver == null) {
5501 // may happen if the does not support IMS.
5502 return;
5503 }
5504 mImsResolver.disableIms(slotIndex);
5505 mImsResolver.enableIms(slotIndex);
5506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508 }
5509 }
5510
5511 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005512 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5513 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005514 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005515 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -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 Ebinger9c0eb502019-01-23 15:06:19 -08005521 // may happen if the device does not support IMS.
5522 return;
5523 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005524 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005528 }
5529
5530 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005531 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5532 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005533 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005534 public void disableIms(int slotId) {
5535 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005539 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005540 // may happen if the device does not support IMS.
5541 return;
5542 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005543 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005547 }
5548
5549 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005550 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5551 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005552 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005553 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005554 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005559 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005560 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5561 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005562 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005563 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005567 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005568 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005569 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5570 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005571 @Override
5572 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005573 enforceModifyPermission();
5574
5575 final long identity = Binder.clearCallingIdentity();
5576 try {
5577 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005578 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005579 } finally {
5580 Binder.restoreCallingIdentity(identity);
5581 }
5582 }
5583
5584 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005585 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005586 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005587 */
5588 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5589 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590
5591 final long identity = Binder.clearCallingIdentity();
5592 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005593 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005594 // may happen if the device does not support IMS.
5595 return null;
5596 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005597 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 } finally {
5599 Binder.restoreCallingIdentity(identity);
5600 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005601 }
5602
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005603 /**
5604 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005605 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005606 */
5607 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5608 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609
5610 final long identity = Binder.clearCallingIdentity();
5611 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005612 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005613 // may happen if the device does not support IMS.
5614 return null;
5615 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005616 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005620 }
5621
Brad Ebinger884c07b2018-02-15 16:17:40 -08005622 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005623 * Sets the ImsService Package Name that Telephony will bind to.
5624 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005625 * @param slotIndex the slot ID that the ImsService should bind for.
5626 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005627 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005628 * @param featureTypes An integer array of feature types associated with a packageName.
5629 * @param packageName The name of the package that the current configuration will be replaced
5630 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005631 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005632 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005633 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5634 int[] featureTypes, String packageName) {
5635 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5636 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5638 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005639 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 final long identity = Binder.clearCallingIdentity();
5642 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005643 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005644 // may happen if the device does not support IMS.
5645 return false;
5646 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005647 Map<Integer, String> featureConfig = new HashMap<>();
5648 for (int featureType : featureTypes) {
5649 featureConfig.put(featureType, packageName);
5650 }
5651 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5652 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005656 }
5657
5658 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005659 * Clears any carrier ImsService overrides for the slot index specified that were previously
5660 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5661 *
5662 * This should only be used for testing.
5663 *
5664 * @param slotIndex the slot ID that the ImsService should bind for.
5665 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5666 */
5667 @Override
5668 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5669 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5670 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5671 "clearCarrierImsServiceOverride");
5672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5673 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5674 "clearCarrierImsServiceOverride");
5675
5676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 if (mImsResolver == null) {
5679 // may happen if the device does not support IMS.
5680 return false;
5681 }
5682 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
5686 }
5687
5688 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005689 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005690 *
5691 * @param slotId The slot that the ImsService is associated with.
5692 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5693 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005694 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005695 * @return the package name of the ImsService configuration.
5696 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005697 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5698 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005699 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005700 TelephonyPermissions
5701 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5702 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5703 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 final long identity = Binder.clearCallingIdentity();
5706 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005707 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005708 // may happen if the device does not support IMS.
5709 return "";
5710 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005711 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005712 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5713 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 } finally {
5715 Binder.restoreCallingIdentity(identity);
5716 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005717 }
5718
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005719 /**
5720 * Get the MmTelFeature state associated with the requested subscription id.
5721 * @param subId The subscription that the MmTelFeature is associated with.
5722 * @param callback A callback with an integer containing the
5723 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5724 */
5725 @Override
5726 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5727 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5728 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5729 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5730 "IMS not available on device.");
5731 }
5732 final long token = Binder.clearCallingIdentity();
5733 try {
5734 int slotId = getSlotIndex(subId);
5735 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5736 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5737 + subId + "'");
5738 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5739 }
5740 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5741 try {
5742 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5743 } catch (RemoteException e) {
5744 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5745 + "Ignore");
5746 }
5747 });
5748 } finally {
5749 Binder.restoreCallingIdentity(token);
5750 }
5751 }
5752
Daniel Brightbb5840b2021-01-12 15:48:18 -08005753 /**
5754 * Sets the ims registration state on all valid {@link Phone}s.
5755 */
5756 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005761 // NOTE: Before S, this method only set the default phone.
5762 for (final Phone phone : PhoneFactory.getPhones()) {
5763 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5764 phone.setImsRegistrationState(registered);
5765 }
5766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Wink Saville36469e72014-06-11 15:17:00 -07005770 }
5771
5772 /**
Stuart Scott54788802015-03-30 13:18:01 -07005773 * Set the network selection mode to automatic.
5774 *
5775 */
5776 @Override
5777 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5779 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780
5781 final long identity = Binder.clearCallingIdentity();
5782 try {
shilufc958392020-01-20 11:36:01 -08005783 if (!isActiveSubscription(subId)) {
5784 return;
5785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005787 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5788 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 } finally {
5790 Binder.restoreCallingIdentity(identity);
5791 }
Stuart Scott54788802015-03-30 13:18:01 -07005792 }
5793
Jack Yud10cdd42020-09-28 20:28:01 -07005794 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005795 * Ask the radio to connect to the input network and change selection mode to manual.
5796 *
5797 * @param subId the id of the subscription.
5798 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5799 * the operator to attach to.
5800 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5801 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5802 * normal network selection next time.
5803 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005804 */
5805 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005806 public boolean setNetworkSelectionModeManual(
5807 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5809 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005810
5811 if (!isActiveSubscription(subId)) {
5812 return false;
5813 }
5814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815 final long identity = Binder.clearCallingIdentity();
5816 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005817 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005819 if (DBG) {
5820 log("setNetworkSelectionModeManual: subId: " + subId
5821 + " operator: " + operatorInfo);
5822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
5826 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005827 }
shilu84f6e8b2019-12-19 13:58:01 -08005828 /**
5829 * Get the manual network selection
5830 *
5831 * @param subId the id of the subscription.
5832 *
5833 * @return the previously saved user selected PLMN
5834 */
5835 @Override
5836 public String getManualNetworkSelectionPlmn(int subId) {
5837 TelephonyPermissions
5838 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5839 mApp, subId, "getManualNetworkSelectionPlmn");
5840
5841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005844 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005845 }
5846
5847 final Phone phone = getPhone(subId);
5848 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005849 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005850 }
5851 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5852 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5853 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
5857 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005858
5859 /**
5860 * Scans for available networks.
5861 */
5862 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005863 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5864 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5866 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005867 LocationAccessPolicy.LocationPermissionResult locationResult =
5868 LocationAccessPolicy.checkLocationPermission(mApp,
5869 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5870 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005871 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005872 .setCallingPid(Binder.getCallingPid())
5873 .setCallingUid(Binder.getCallingUid())
5874 .setMethod("getCellNetworkScanResults")
5875 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005876 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5877 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005878 .build());
5879 switch (locationResult) {
5880 case DENIED_HARD:
5881 throw new SecurityException("Not allowed to access scan results -- location");
5882 case DENIED_SOFT:
5883 return null;
5884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005885
Pengquan Menga1bb6272018-09-06 09:59:22 -07005886 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 try {
5888 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005889 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 } finally {
5892 Binder.restoreCallingIdentity(identity);
5893 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005894 }
5895
5896 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005897 * Get the call forwarding info, given the call forwarding reason.
5898 */
5899 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005900 public void getCallForwarding(int subId, int callForwardingReason,
5901 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005902 enforceReadPrivilegedPermission("getCallForwarding");
5903 long identity = Binder.clearCallingIdentity();
5904 try {
5905 if (DBG) {
5906 log("getCallForwarding: subId " + subId
5907 + " callForwardingReason" + callForwardingReason);
5908 }
Hall Liu27d24262020-09-18 19:04:59 -07005909
5910 Phone phone = getPhone(subId);
5911 if (phone == null) {
5912 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005913 callback.onError(
5914 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005915 } catch (RemoteException e) {
5916 // ignore
5917 }
5918 return;
5919 }
5920
5921 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5922 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5923 @Override
5924 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5925 try {
5926 callback.onCallForwardingInfoAvailable(info);
5927 } catch (RemoteException e) {
5928 // ignore
5929 }
5930 }
5931
5932 @Override
5933 public void onError(int error) {
5934 try {
5935 callback.onError(error);
5936 } catch (RemoteException e) {
5937 // ignore
5938 }
5939 }
5940 });
5941 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005942 } finally {
5943 Binder.restoreCallingIdentity(identity);
5944 }
5945 }
5946
5947 /**
5948 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5949 * reason, the number to forward, and the timeout before the forwarding is attempted.
5950 */
5951 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005952 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5953 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005954 enforceModifyPermission();
5955 long identity = Binder.clearCallingIdentity();
5956 try {
5957 if (DBG) {
5958 log("setCallForwarding: subId " + subId
5959 + " callForwardingInfo" + callForwardingInfo);
5960 }
Hall Liu27d24262020-09-18 19:04:59 -07005961
5962 Phone phone = getPhone(subId);
5963 if (phone == null) {
5964 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005965 callback.accept(
5966 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005967 } catch (RemoteException e) {
5968 // ignore
5969 }
5970 return;
5971 }
5972
5973 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5974 FunctionalUtils.ignoreRemoteException(callback::accept));
5975
5976 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005977 } finally {
5978 Binder.restoreCallingIdentity(identity);
5979 }
5980 }
5981
5982 /**
Hall Liu27d24262020-09-18 19:04:59 -07005983 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005984 */
5985 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005986 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005987 enforceReadPrivilegedPermission("getCallForwarding");
5988 long identity = Binder.clearCallingIdentity();
5989 try {
Hall Liu27d24262020-09-18 19:04:59 -07005990
5991 Phone phone = getPhone(subId);
5992 if (phone == null) {
5993 try {
5994 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5995 } catch (RemoteException e) {
5996 // ignore
5997 }
5998 return;
5999 }
6000
6001 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
6002
Shuo Qian4a594052020-01-23 11:59:30 -08006003 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07006004 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006005 } finally {
6006 Binder.restoreCallingIdentity(identity);
6007 }
6008 }
6009
6010 /**
Hall Liu27d24262020-09-18 19:04:59 -07006011 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006012 */
6013 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006014 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006015 enforceModifyPermission();
6016 long identity = Binder.clearCallingIdentity();
6017 try {
Hall Liu27d24262020-09-18 19:04:59 -07006018 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6019
6020 Phone phone = getPhone(subId);
6021 if (phone == null) {
6022 try {
6023 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6024 } catch (RemoteException e) {
6025 // ignore
6026 }
6027 return;
6028 }
6029
6030 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6031 FunctionalUtils.ignoreRemoteException(callback::accept));
6032
6033 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
6037 }
6038
6039 /**
yinxub1bed742017-04-17 11:45:04 -07006040 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006041 *
yinxub1bed742017-04-17 11:45:04 -07006042 * @param subId id of the subscription
6043 * @param request contains the radio access networks with bands/channels to scan
6044 * @param messenger callback messenger for scan results or errors
6045 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006046 * @return the id of the requested scan which can be used to stop the scan.
6047 */
6048 @Override
6049 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006050 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6052 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006053 LocationAccessPolicy.LocationPermissionResult locationResult =
6054 LocationAccessPolicy.checkLocationPermission(mApp,
6055 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6056 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006057 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006058 .setCallingPid(Binder.getCallingPid())
6059 .setCallingUid(Binder.getCallingUid())
6060 .setMethod("requestNetworkScan")
6061 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006062 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6063 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006064 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006065 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006066 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6067 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006068 if (e != null) {
6069 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6070 throw e;
6071 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006072 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006073 return TelephonyScanManager.INVALID_SCAN_ID;
6074 }
6075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 }
Hall Liu912dfd32019-04-25 14:02:26 -07006077 int callingUid = Binder.getCallingUid();
6078 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006079 final long identity = Binder.clearCallingIdentity();
6080 try {
6081 return mNetworkScanRequestTracker.startNetworkScan(
6082 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006083 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006084 } finally {
6085 Binder.restoreCallingIdentity(identity);
6086 }
yinxu504e1392017-04-12 16:03:22 -07006087 }
6088
Hall Liub2ac8ef2019-02-28 15:56:23 -08006089 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006090 NetworkScanRequest request, int subId, String callingPackage) {
6091 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006092 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6093 boolean hasNetworkScanPermission =
6094 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6095 == PERMISSION_GRANTED;
6096
6097 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6098 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6099 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006100 }
6101
6102 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6103 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006104 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6105 return new SecurityException("Specific channels must not be"
6106 + " scanned without location access.");
6107 }
6108 }
6109 }
6110
Hall Liub2ac8ef2019-02-28 15:56:23 -08006111 return null;
6112 }
6113
yinxu504e1392017-04-12 16:03:22 -07006114 /**
6115 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006116 *
6117 * @param subId id of the subscription
6118 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006119 */
6120 @Override
6121 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6123 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124
Hall Liu912dfd32019-04-25 14:02:26 -07006125 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126 final long identity = Binder.clearCallingIdentity();
6127 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006128 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
yinxu504e1392017-04-12 16:03:22 -07006132 }
6133
6134 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006135 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006136 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006137 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006138 */
6139 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006140 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006141 TelephonyPermissions
6142 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006143 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144
6145 final long identity = Binder.clearCallingIdentity();
6146 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006147 if (DBG) log("getAllowedNetworkTypesBitmask");
6148 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6149 int networkTypesBitmask = (result != null ? result[0] : -1);
6150 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6151 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 } finally {
6153 Binder.restoreCallingIdentity(identity);
6154 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006155 }
6156
6157 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006158 * Get the allowed network types for certain reason.
6159 *
6160 * @param subId the id of the subscription.
6161 * @param reason the reason the allowed network type change is taking place
6162 * @return the allowed network types.
6163 */
6164 @Override
6165 public long getAllowedNetworkTypesForReason(int subId,
6166 @TelephonyManager.AllowedNetworkTypesReason int reason) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006167 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6168 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006169 final long identity = Binder.clearCallingIdentity();
6170 try {
6171 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6172 } finally {
6173 Binder.restoreCallingIdentity(identity);
6174 }
6175 }
6176
6177 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006178 * Enable/Disable E-UTRA-NR Dual Connectivity
6179 * @param subId subscription id of the sim card
6180 * @param nrDualConnectivityState expected NR dual connectivity state
6181 * This can be passed following states
6182 * <ol>
6183 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6184 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6185 * <li>Disable NR dual connectivity and force secondary cell to be released
6186 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6187 * </ol>
6188 * @return operation result.
6189 */
6190 @Override
6191 public int setNrDualConnectivityState(int subId,
6192 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6194 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006195 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006196 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6197 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6198 }
6199
Sooraj Sasindran37444802020-08-11 10:40:43 -07006200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6204 nrDualConnectivityState, subId,
6205 workSource);
6206 if (DBG) log("enableNRDualConnectivity result: " + result);
6207 return result;
6208 } finally {
6209 Binder.restoreCallingIdentity(identity);
6210 }
6211 }
6212
6213 /**
6214 * Is E-UTRA-NR Dual Connectivity enabled
6215 * @return true if dual connectivity is enabled else false
6216 */
6217 @Override
6218 public boolean isNrDualConnectivityEnabled(int subId) {
6219 TelephonyPermissions
6220 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6221 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006222 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006223 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6224 return false;
6225 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6230 null, subId, workSource);
6231 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6232 return isEnabled;
6233 } finally {
6234 Binder.restoreCallingIdentity(identity);
6235 }
6236 }
6237
6238 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006239 * Set the allowed network types of the device and
6240 * provide the reason triggering the allowed network change.
6241 *
6242 * @param subId the id of the subscription.
6243 * @param reason the reason the allowed network type change is taking place
6244 * @param allowedNetworkTypes the allowed network types.
6245 * @return true on success; false on any failure.
6246 */
6247 @Override
6248 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006249 @TelephonyManager.AllowedNetworkTypesReason int reason,
6250 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6252 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006253 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6254 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6255 return false;
6256 }
6257
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006258 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6259 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6260
6261
6262 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6263 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6264 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006265 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006266
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006267 final long identity = Binder.clearCallingIdentity();
6268 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006269 Boolean success = (Boolean) sendRequest(
6270 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6271 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6272
6273 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6274 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006275 } finally {
6276 Binder.restoreCallingIdentity(identity);
6277 }
6278 }
6279
6280 /**
Miaoa84611c2019-03-15 09:21:10 +08006281 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006282 *
Miaoa84611c2019-03-15 09:21:10 +08006283 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006284 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006285 * @hide
6286 */
6287 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006288 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006289 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006290 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006291 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292 try {
Miaoa84611c2019-03-15 09:21:10 +08006293 if (phone != null) {
6294 return phone.hasMatchedTetherApnSetting();
6295 } else {
6296 return false;
6297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006298 } finally {
6299 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006300 }
Junda Liu475951f2014-11-07 16:45:03 -08006301 }
6302
6303 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006304 * Enable or disable always reporting signal strength changes from radio.
6305 *
6306 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6307 */
6308 @Override
6309 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6310 enforceModifyPermission();
6311 enforceSystemCaller();
6312
6313 final long identity = Binder.clearCallingIdentity();
6314 final Phone phone = getPhone(subId);
6315 try {
6316 if (phone != null) {
6317 if (DBG) {
6318 log("setAlwaysReportSignalStrength: subId=" + subId
6319 + " isEnable=" + isEnable);
6320 }
6321 phone.setAlwaysReportSignalStrength(isEnable);
6322 } else {
6323 loge("setAlwaysReportSignalStrength: no phone found for subId="
6324 + subId);
6325 }
6326 } finally {
6327 Binder.restoreCallingIdentity(identity);
6328 }
6329 }
6330
6331 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006332 * Get the user enabled state of Mobile Data.
6333 *
6334 * TODO: remove and use isUserDataEnabled.
6335 * This can't be removed now because some vendor codes
6336 * calls through ITelephony directly while they should
6337 * use TelephonyManager.
6338 *
6339 * @return true on enabled
6340 */
6341 @Override
6342 public boolean getDataEnabled(int subId) {
6343 return isUserDataEnabled(subId);
6344 }
6345
6346 /**
6347 * Get whether mobile data is enabled per user setting.
6348 *
6349 * There are other factors deciding whether mobile data is actually enabled, but they are
6350 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006351 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006352 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006353 *
6354 * @return {@code true} if data is enabled else {@code false}
6355 */
6356 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006357 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006358 try {
6359 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6360 null);
6361 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6363 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006364 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365
6366 final long identity = Binder.clearCallingIdentity();
6367 try {
6368 int phoneId = mSubscriptionController.getPhoneId(subId);
6369 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6370 Phone phone = PhoneFactory.getPhone(phoneId);
6371 if (phone != null) {
6372 boolean retVal = phone.isUserDataEnabled();
6373 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6374 return retVal;
6375 } else {
6376 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6377 return false;
6378 }
6379 } finally {
6380 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006381 }
6382 }
6383
6384 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006385 * Checks if the device is capable of mobile data by considering whether whether the
6386 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6387 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006388 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006389 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006390 */
6391 @Override
6392 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006393 try {
6394 try {
6395 mApp.enforceCallingOrSelfPermission(
6396 android.Manifest.permission.ACCESS_NETWORK_STATE,
6397 null);
6398 } catch (Exception e) {
6399 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6400 "isDataEnabled");
6401 }
6402 } catch (Exception e) {
6403 enforceReadPrivilegedPermission("isDataEnabled");
6404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405
6406 final long identity = Binder.clearCallingIdentity();
6407 try {
6408 int phoneId = mSubscriptionController.getPhoneId(subId);
6409 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6410 Phone phone = PhoneFactory.getPhone(phoneId);
6411 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006412 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6414 return retVal;
6415 } else {
6416 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6417 return false;
6418 }
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006421 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006422 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006423
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006424 /**
6425 * Check if data is enabled for a specific reason
6426 * @param subId Subscription index
6427 * @param reason the reason the data enable change is taking place
6428 * @return {@code true} if the overall data is enabled; {@code false} if not.
6429 */
6430 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006431 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006432 @TelephonyManager.DataEnabledReason int reason) {
6433 try {
6434 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6435 null);
6436 } catch (Exception e) {
6437 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006438 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006439 }
6440
6441
6442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 int phoneId = mSubscriptionController.getPhoneId(subId);
6445 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006446 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006447 + " reason=" + reason);
6448 }
6449 Phone phone = PhoneFactory.getPhone(phoneId);
6450 if (phone != null) {
6451 boolean retVal;
6452 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6453 retVal = phone.isUserDataEnabled();
6454 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006455 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006456 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006457 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006458 return retVal;
6459 } else {
6460 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006461 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006462 + subId + " retVal=false");
6463 }
6464 return false;
6465 }
6466 } finally {
6467 Binder.restoreCallingIdentity(identity);
6468 }
6469 }
6470
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006471 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006472 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006473 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6474 // Skip the check if it's one of these special uids
6475 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6476 }
6477
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006478 //load access rules from carrier configs, and check those as well: b/139133814
6479 SubscriptionController subController = SubscriptionController.getInstance();
6480 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6481 || subController == null) return privilegeFromSim;
6482
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006483 PackageManager pkgMgr = phone.getContext().getPackageManager();
6484 String[] packages = pkgMgr.getPackagesForUid(uid);
6485
6486 final long identity = Binder.clearCallingIdentity();
6487 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006488 int subId = phone.getSubId();
6489 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6490 // A test override is in place for the privileges for this subId, so don't try to
6491 // read the subscription privileges.
6492 return privilegeFromSim;
6493 }
6494 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006495 SubscriptionManager subManager = (SubscriptionManager)
6496 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6497 for (String pkg : packages) {
6498 if (subManager.canManageSubscription(subInfo, pkg)) {
6499 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6500 }
6501 }
6502 return privilegeFromSim;
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
6508 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6509 String pkgName) {
6510 //load access rules from carrier configs, and check those as well: b/139133814
6511 SubscriptionController subController = SubscriptionController.getInstance();
6512 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6513 || subController == null) return privilegeFromSim;
6514
6515 final long identity = Binder.clearCallingIdentity();
6516 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006517 int subId = phone.getSubId();
6518 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6519 // A test override is in place for the privileges for this subId, so don't try to
6520 // read the subscription privileges.
6521 return privilegeFromSim;
6522 }
6523 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006524 SubscriptionManager subManager = (SubscriptionManager)
6525 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6526 return subManager.canManageSubscription(subInfo, pkgName)
6527 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
6531 }
6532
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006533 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006534 public int getCarrierPrivilegeStatus(int subId) {
6535 final Phone phone = getPhone(subId);
6536 if (phone == null) {
6537 loge("getCarrierPrivilegeStatus: Invalid subId");
6538 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6539 }
6540 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006541 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006542 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006543 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6544 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006545
6546 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6547 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006548 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006549 }
Junda Liu29340342014-07-10 15:23:27 -07006550
6551 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006552 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006553 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006554 final Phone phone = getPhone(subId);
6555 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006556 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006557 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6558 }
6559 UiccProfile profile =
6560 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6561 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006562 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006563 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6564 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006565 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006566 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006567 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006568 }
6569
6570 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006571 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6572 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006573 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006574 }
6575
6576 int phoneId = SubscriptionManager.getPhoneId(subId);
6577 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006578 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006579 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006580 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6581 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006582 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6583 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6584 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006585 }
6586
6587 @Override
6588 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006589 if (TextUtils.isEmpty(pkgName))
6590 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006591 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6592 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6593 UiccCard card = UiccController.getInstance().getUiccCard(i);
6594 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006595 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006596 continue;
6597 }
6598
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006599 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6600 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6601 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006602 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6603 break;
6604 }
6605 }
6606
6607 return result;
Junda Liu29340342014-07-10 15:23:27 -07006608 }
Derek Tan89e89d42014-07-08 17:00:10 -07006609
6610 @Override
Junda Liue64de782015-04-16 17:19:16 -07006611 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6612 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6613 loge("phoneId " + phoneId + " is not valid.");
6614 return null;
6615 }
6616 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006617 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006618 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006619 return null ;
6620 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006621 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006622 }
6623
Amith Yamasani6e118872016-02-19 12:53:51 -08006624 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006625 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006626 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006627 List<String> privilegedPackages = new ArrayList<>();
6628 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006629 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6630 // has UICC in that slot.
6631 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006632 if (card.hasCarrierPrivilegeRules()) {
6633 if (packages == null) {
6634 // Only check packages in user 0 for now
6635 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006636 PackageManager.MATCH_DISABLED_COMPONENTS
6637 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006638 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006639 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006640 }
6641 for (int p = packages.size() - 1; p >= 0; p--) {
6642 PackageInfo pkgInfo = packages.get(p);
6643 if (pkgInfo != null && pkgInfo.packageName != null
6644 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006645 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006646 privilegedPackages.add(pkgInfo.packageName);
6647 }
6648 }
6649 }
6650 }
6651 return privilegedPackages;
6652 }
6653
chen xuf7e9fe82019-05-09 19:31:02 -07006654 @Override
6655 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006656 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6657
6658 final long identity = Binder.clearCallingIdentity();
6659
chen xuf7e9fe82019-05-09 19:31:02 -07006660 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006661 try {
6662 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6663 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6664 }
6665 } finally {
6666 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006667 }
6668 return privilegedPackages;
6669 }
6670
Wink Savilleb564aae2014-10-23 10:18:09 -07006671 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006672 final Phone phone = getPhone(subId);
6673 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006674 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006675 return null;
6676 }
6677 String iccId = card.getIccId();
6678 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006679 return null;
6680 }
6681 return iccId;
6682 }
6683
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006684 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006685 public void setCallComposerStatus(int subId, int status) {
6686 enforceModifyPermission();
6687
6688 final long identity = Binder.clearCallingIdentity();
6689 try {
6690 Phone phone = getPhone(subId);
6691 if (phone != null) {
6692 Phone defaultPhone = phone.getImsPhone();
6693 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6694 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6695 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006696 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6697 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006698 }
6699 }
Shuo Qian284ae752020-12-22 19:10:14 -08006700 } catch (ImsException e) {
6701 throw new ServiceSpecificException(e.getCode());
6702 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006703 Binder.restoreCallingIdentity(identity);
6704 }
6705 }
6706
6707 @Override
6708 public int getCallComposerStatus(int subId) {
6709 enforceReadPrivilegedPermission("getCallComposerStatus");
6710
6711 final long identity = Binder.clearCallingIdentity();
6712 try {
6713 Phone phone = getPhone(subId);
6714 if (phone != null) {
6715 Phone defaultPhone = phone.getImsPhone();
6716 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6717 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6718 return imsPhone.getCallComposerStatus();
6719 }
6720 }
6721 } finally {
6722 Binder.restoreCallingIdentity(identity);
6723 }
6724 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6725 }
6726
6727 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006728 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6729 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006730 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006731 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 final long identity = Binder.clearCallingIdentity();
6734 try {
6735 final String iccId = getIccId(subId);
6736 final Phone phone = getPhone(subId);
6737 if (phone == null) {
6738 return false;
6739 }
6740 final String subscriberId = phone.getSubscriberId();
6741
6742 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006743 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006744 + subscriberId + " to " + number);
6745 }
6746
6747 if (TextUtils.isEmpty(iccId)) {
6748 return false;
6749 }
6750
6751 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6752
6753 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6754 if (alphaTag == null) {
6755 editor.remove(alphaTagPrefKey);
6756 } else {
6757 editor.putString(alphaTagPrefKey, alphaTag);
6758 }
6759
6760 // Record both the line number and IMSI for this ICCID, since we need to
6761 // track all merged IMSIs based on line number
6762 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6763 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6764 if (number == null) {
6765 editor.remove(numberPrefKey);
6766 editor.remove(subscriberPrefKey);
6767 } else {
6768 editor.putString(numberPrefKey, number);
6769 editor.putString(subscriberPrefKey, subscriberId);
6770 }
6771
6772 editor.commit();
6773 return true;
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006776 }
Derek Tan7226c842014-07-02 17:42:23 -07006777 }
6778
6779 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006780 public String getLine1NumberForDisplay(int subId, String callingPackage,
6781 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006782 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006783 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006784 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006785 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
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 numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6794 if (DBG_MERGE) {
6795 log("getLine1NumberForDisplay returning "
6796 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6797 }
6798 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006800 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6801 return null;
6802 } finally {
6803 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006804 }
Derek Tan7226c842014-07-02 17:42:23 -07006805 }
6806
6807 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006808 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6809 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006810 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006811 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006812 return null;
6813 }
Derek Tan97ebb422014-09-05 16:55:38 -07006814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006815 final long identity = Binder.clearCallingIdentity();
6816 try {
6817 String iccId = getIccId(subId);
6818 if (iccId != null) {
6819 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6820 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6821 }
6822 return null;
6823 } finally {
6824 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006825 }
Derek Tan7226c842014-07-02 17:42:23 -07006826 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006827
6828 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006829 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6830 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006831 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6832 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006834 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006835 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006836 return null;
6837 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006838
Jordan Liub49b04b2019-05-06 14:45:15 -07006839 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6840 // the process, where TelephonyManager was instantiated.
6841 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006842 final long identity = Binder.clearCallingIdentity();
6843 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006844 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845 final TelephonyManager tele = TelephonyManager.from(context);
6846 final SubscriptionManager sub = SubscriptionManager.from(context);
6847
6848 // Figure out what subscribers are currently active
6849 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850
Jordan Liub49b04b2019-05-06 14:45:15 -07006851 // Only consider subs which match the current subId
6852 // This logic can be simplified. See b/131189269 for progress.
6853 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006854 activeSubscriberIds.add(tele.getSubscriberId(subId));
6855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856
6857 // First pass, find a number override for an active subscriber
6858 String mergeNumber = null;
6859 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6860 for (String key : prefs.keySet()) {
6861 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6862 final String subscriberId = (String) prefs.get(key);
6863 if (activeSubscriberIds.contains(subscriberId)) {
6864 final String iccId = key.substring(
6865 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6866 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6867 mergeNumber = (String) prefs.get(numberKey);
6868 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006869 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870 + " for active subscriber " + subscriberId);
6871 }
6872 if (!TextUtils.isEmpty(mergeNumber)) {
6873 break;
6874 }
6875 }
6876 }
6877 }
6878
6879 // Shortcut when no active merged subscribers
6880 if (TextUtils.isEmpty(mergeNumber)) {
6881 return null;
6882 }
6883
6884 // Second pass, find all subscribers under that line override
6885 final ArraySet<String> result = new ArraySet<>();
6886 for (String key : prefs.keySet()) {
6887 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6888 final String number = (String) prefs.get(key);
6889 if (mergeNumber.equals(number)) {
6890 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6891 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6892 final String subscriberId = (String) prefs.get(subscriberKey);
6893 if (!TextUtils.isEmpty(subscriberId)) {
6894 result.add(subscriberId);
6895 }
6896 }
6897 }
6898 }
6899
6900 final String[] resultArray = result.toArray(new String[result.size()]);
6901 Arrays.sort(resultArray);
6902 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006903 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6905 }
6906 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006907 } finally {
6908 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006909 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006910 }
6911
6912 @Override
zoey chen38003472019-12-13 17:16:31 +08006913 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6914 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006915
6916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 final TelephonyManager telephonyManager = mApp.getSystemService(
6919 TelephonyManager.class);
6920 String subscriberId = telephonyManager.getSubscriberId(subId);
6921 if (subscriberId == null) {
6922 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006923 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006924 + subId);
6925 }
6926 return null;
6927 }
6928
6929 final SubscriptionInfo info = SubscriptionController.getInstance()
6930 .getSubscriptionInfo(subId);
6931 final ParcelUuid groupUuid = info.getGroupUuid();
6932 // If it doesn't belong to any group, return just subscriberId of itself.
6933 if (groupUuid == null) {
6934 return new String[]{subscriberId};
6935 }
6936
6937 // Get all subscriberIds from the group.
6938 final List<String> mergedSubscriberIds = new ArrayList<>();
6939 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006940 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006941 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006942 for (SubscriptionInfo subInfo : groupInfos) {
6943 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6944 if (subscriberId != null) {
6945 mergedSubscriberIds.add(subscriberId);
6946 }
6947 }
6948
6949 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6950 } finally {
6951 Binder.restoreCallingIdentity(identity);
6952
6953 }
6954 }
6955
6956 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006957 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006958 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006959 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960
6961 final long identity = Binder.clearCallingIdentity();
6962 try {
6963 final Phone phone = getPhone(subId);
6964 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
6967 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006968 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006969
6970 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006971 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006972 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6973 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006974 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6975 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006976
6977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 final Phone phone = getPhone(subId);
6980 if (phone == null) {
6981 return false;
6982 }
6983 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6984 cdmaNonRoamingList);
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006987 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006988 }
6989
6990 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006991 @Deprecated
6992 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6993 enforceModifyPermission();
6994
6995 int returnValue = 0;
6996 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006997 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006998 if(result.exception == null) {
6999 if (result.result != null) {
7000 byte[] responseData = (byte[])(result.result);
7001 if(responseData.length > oemResp.length) {
7002 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7003 responseData.length + "bytes. Buffer Size is " +
7004 oemResp.length + "bytes.");
7005 }
7006 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7007 returnValue = responseData.length;
7008 }
7009 } else {
7010 CommandException ex = (CommandException) result.exception;
7011 returnValue = ex.getCommandError().ordinal();
7012 if(returnValue > 0) returnValue *= -1;
7013 }
7014 } catch (RuntimeException e) {
7015 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7016 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7017 if(returnValue > 0) returnValue *= -1;
7018 }
7019
7020 return returnValue;
7021 }
7022
7023 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007024 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007025 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007026 try {
7027 TelephonyPermissions
7028 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7029 mApp, phone.getSubId(), "getRadioAccessFamily");
7030 } catch (SecurityException e) {
7031 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7032 throw e;
7033 }
chen xub97461a2018-10-26 14:17:57 -07007034 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007035 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007036 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038 final long identity = Binder.clearCallingIdentity();
7039 try {
chen xub97461a2018-10-26 14:17:57 -07007040 TelephonyPermissions
7041 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7042 mApp, phone.getSubId(), "getRadioAccessFamily");
7043 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044 } finally {
7045 Binder.restoreCallingIdentity(identity);
7046 }
chen xub97461a2018-10-26 14:17:57 -07007047 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007048 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007049
7050 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007051 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007052 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007053 try {
7054 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7055 Binder.getCallingUid())) {
7056 throw new SecurityException("Package uid and package name do not match: "
7057 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7058 }
7059 } catch (PackageManager.NameNotFoundException e) {
7060 throw new SecurityException("Package name invalid:" + callingPackage);
7061 }
7062 RoleManager rm = mApp.getSystemService(RoleManager.class);
7063 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7064 if (!dialerRoleHolders.contains(callingPackage)) {
7065 throw new SecurityException("App must be the dialer role holder to"
7066 + " upload a call composer pic");
7067 }
7068
7069 Executors.newSingleThreadExecutor().execute(() -> {
7070 ByteArrayOutputStream output = new ByteArrayOutputStream(
7071 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7072 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7073 boolean readUntilEnd = false;
7074 int totalBytesRead = 0;
7075 byte[] buffer = new byte[16 * 1024];
7076 while (true) {
7077 int numRead;
7078 try {
7079 numRead = input.read(buffer);
7080 } catch (IOException e) {
7081 try {
7082 fd.checkError();
7083 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7084 null);
7085 } catch (IOException e1) {
7086 // This means that the other side closed explicitly with an error. If this
7087 // happens, log and ignore.
7088 loge("Remote end of call composer picture pipe closed: " + e1);
7089 }
7090 break;
7091 }
7092 if (numRead == -1) {
7093 readUntilEnd = true;
7094 break;
7095 }
7096 totalBytesRead += numRead;
7097 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7098 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7099 try {
7100 input.close();
7101 } catch (IOException e) {
7102 // ignore
7103 }
7104 break;
7105 }
7106 output.write(buffer, 0, numRead);
7107 }
7108 // Generally, the remote end will close the file descriptors. The only case where we
7109 // close is above, where the picture size is too big.
7110
7111 try {
7112 fd.checkError();
7113 } catch (IOException e) {
7114 loge("Remote end for call composer closed with an error: " + e);
7115 return;
7116 }
7117
Hall Liuaa4211e2021-01-20 15:43:39 -08007118 if (!readUntilEnd) {
7119 loge("Did not finish reading entire image; aborting");
7120 return;
7121 }
Hall Liu82694d52020-12-11 18:22:04 -08007122
Hall Liuaa4211e2021-01-20 15:43:39 -08007123 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7124 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7125 new CallComposerPictureTransfer.Factory() {},
7126 imageData,
7127 (result) -> {
7128 if (result.first != null) {
7129 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7130 Bundle outputResult = new Bundle();
7131 outputResult.putParcelable(
7132 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7133 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7134 outputResult);
7135 } else {
7136 callback.send(result.second, null);
7137 }
7138 }
7139 );
Hall Liu82694d52020-12-11 18:22:04 -08007140 });
7141 }
7142
7143 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007144 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007145 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007146 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007147
7148 final long identity = Binder.clearCallingIdentity();
7149 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007150 ImsManager.getInstance(defaultPhone.getContext(),
7151 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007152 } finally {
7153 Binder.restoreCallingIdentity(identity);
7154 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007155 }
7156
7157 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007158 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007159 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7161 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007162 return false;
7163 }
Svet Ganovb320e182015-04-16 12:30:10 -07007164
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007165 final long identity = Binder.clearCallingIdentity();
7166 try {
7167 // Check the user preference and the system-level IMS setting. Even if the user has
7168 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7169 // In the long run, we may instead need to check if there exists a connection service
7170 // which can support video calling.
7171 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007172 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007173 return imsManager.isVtEnabledByPlatform()
7174 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7175 && imsManager.isVtEnabledByUser();
7176 } finally {
7177 Binder.restoreCallingIdentity(identity);
7178 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007179 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007180
Andrew Leea1239f22015-03-02 17:44:07 -08007181 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007182 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7183 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007185 mApp, subId, callingPackage, callingFeatureId,
7186 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 return false;
7188 }
7189
7190 final long identity = Binder.clearCallingIdentity();
7191 try {
7192 CarrierConfigManager configManager =
7193 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007194 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007195 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7196 } finally {
7197 Binder.restoreCallingIdentity(identity);
7198 }
Andrew Leea1239f22015-03-02 17:44:07 -08007199 }
7200
7201 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007202 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007203 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007204 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 return false;
7206 }
7207
7208 final long identity = Binder.clearCallingIdentity();
7209 try {
7210 CarrierConfigManager configManager =
7211 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007212 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7214 } finally {
7215 Binder.restoreCallingIdentity(identity);
7216 }
Andrew Leea1239f22015-03-02 17:44:07 -08007217 }
7218
Andrew Lee9431b832015-03-09 18:46:45 -07007219 @Override
7220 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007221 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007222 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007223 }
7224
7225 @Override
7226 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 final long identity = Binder.clearCallingIdentity();
7228 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007229 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
Andrew Lee9431b832015-03-09 18:46:45 -07007233 }
7234
Hall Liuf6668912018-10-31 17:05:23 -07007235 /**
7236 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7237 * support for the feature and device firmware support.
7238 *
7239 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7240 */
7241 @Override
7242 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007244 final Phone phone = getPhone(subscriptionId);
7245 if (phone == null) {
7246 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7247 return false;
7248 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007250 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007251 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7252 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007253 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254 return isCarrierSupported && isDeviceSupported;
7255 } finally {
7256 Binder.restoreCallingIdentity(identity);
7257 }
Hall Liu98187582018-01-22 19:15:32 -08007258 }
7259
Hall Liuf6668912018-10-31 17:05:23 -07007260 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007261 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7262 * RTT setting, will return true if the device and carrier both support RTT.
7263 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007264 */
7265 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007266 final long identity = Binder.clearCallingIdentity();
7267 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007268 boolean isRttSupported = isRttSupported(subscriptionId);
7269 boolean isUserRttSettingOn = Settings.Secure.getInt(
7270 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7271 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7272 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7273 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007274 } finally {
7275 Binder.restoreCallingIdentity(identity);
7276 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007277 }
7278
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007279 @Deprecated
7280 @Override
7281 public String getDeviceId(String callingPackage) {
7282 return getDeviceIdWithFeature(callingPackage, null);
7283 }
7284
Sanket Padawe7310cc72015-01-14 09:53:20 -08007285 /**
7286 * Returns the unique device ID of phone, for example, the IMEI for
7287 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7288 *
7289 * <p>Requires Permission:
7290 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7291 */
7292 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007293 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007294 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007295 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007296 return null;
7297 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007298 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007299 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007300 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007301 return null;
7302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007303
7304 final long identity = Binder.clearCallingIdentity();
7305 try {
7306 return phone.getDeviceId();
7307 } finally {
7308 Binder.restoreCallingIdentity(identity);
7309 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007310 }
7311
Ping Sunc67b7c22016-03-02 19:16:45 +08007312 /**
7313 * {@hide}
7314 * Returns the IMS Registration Status on a particular subid
7315 *
7316 * @param subId
7317 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007318 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007319 Phone phone = getPhone(subId);
7320 if (phone != null) {
7321 return phone.isImsRegistered();
7322 } else {
7323 return false;
7324 }
7325 }
7326
Santos Cordon7a1885b2015-02-03 11:15:19 -08007327 @Override
7328 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 final long identity = Binder.clearCallingIdentity();
7330 try {
7331 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7332 } finally {
7333 Binder.restoreCallingIdentity(identity);
7334 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007335 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007336
Tyler Gunnf70ed162019-04-03 15:28:53 -07007337 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007338 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007339 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007341 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007342 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7343 }
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
7349 }
7350 }
7351
7352 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007353 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007354 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7355 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007356 final long identity = Binder.clearCallingIdentity();
7357 try {
7358 Phone phone = getPhone(subscriptionId);
7359 if (phone == null) {
7360 return null;
7361 }
7362 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
7366 }
7367
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007368 /**
7369 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007370 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007371 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 final long identity = Binder.clearCallingIdentity();
7373 try {
7374 Phone phone = getPhone(subId);
7375 if (phone != null) {
7376 return phone.isWifiCallingEnabled();
7377 } else {
7378 return false;
7379 }
7380 } finally {
7381 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007382 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007383 }
7384
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007385 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007386 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007387 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007388 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007389 final long identity = Binder.clearCallingIdentity();
7390 try {
7391 Phone phone = getPhone(subId);
7392 if (phone != null) {
7393 return phone.isVideoEnabled();
7394 } else {
7395 return false;
7396 }
7397 } finally {
7398 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007399 }
7400 }
7401
7402 /**
7403 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7404 * defined in {@link ImsRegistrationImplBase}.
7405 */
7406 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007407 final long identity = Binder.clearCallingIdentity();
7408 try {
7409 Phone phone = getPhone(subId);
7410 if (phone != null) {
7411 return phone.getImsRegistrationTech();
7412 } else {
7413 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7414 }
7415 } finally {
7416 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007417 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007418 }
7419
Stuart Scott8eef64f2015-04-08 15:13:54 -07007420 @Override
7421 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007422 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007423 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7424 return;
7425 }
7426
Svet Ganovcc087f82015-05-12 20:35:54 -07007427 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007428
Svet Ganovcc087f82015-05-12 20:35:54 -07007429 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007430 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7431 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007432 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007433 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007434 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007435 Phone phone = getPhone(subId);
7436 if (phone != null) {
7437 SubscriptionManager.setSubscriptionProperty(subId,
7438 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7439 "user=" + RadioAccessFamily.getRafFromNetworkType(
7440 RILConstants.PREFERRED_NETWORK_MODE));
7441 phone.loadAllowedNetworksFromSubscriptionDatabase();
7442 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007443 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7444 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007445 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007446 // There has been issues when Sms raw table somehow stores orphan
7447 // fragments. They lead to garbled message when new fragments come
7448 // in and combined with those stale ones. In case this happens again,
7449 // user can reset all network settings which will clean up this table.
7450 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007451 // Clean up IMS settings as well here.
7452 int slotId = getSlotIndex(subId);
7453 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7454 ImsManager.getInstance(mApp, slotId).factoryReset();
7455 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007456
7457 // Erase modem config if erase modem on network setting is enabled.
7458 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7459 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7460 if (configValue != null && Boolean.parseBoolean(configValue)) {
7461 sendEraseModemConfig(getDefaultPhone());
7462 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007463 } finally {
7464 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007465 }
7466 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007467
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007468 private void cleanUpSmsRawTable(Context context) {
7469 ContentResolver resolver = context.getContentResolver();
7470 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7471 resolver.delete(uri, null, null);
7472 }
7473
Narayan Kamath1c496c22015-04-16 14:40:19 +01007474 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007475 public String getSimLocaleForSubscriber(int subId) {
7476 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7477 final Phone phone = getPhone(subId);
7478 if (phone == null) {
7479 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007480 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007481 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007482 final long identity = Binder.clearCallingIdentity();
7483 try {
chen xu5d3637b2019-01-21 23:31:38 -08007484 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007485 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007486 if (info == null) {
7487 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7488 return null;
7489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 // Try and fetch the locale from the carrier properties or from the SIM language
7491 // preferences (EF-PL and EF-LI)...
7492 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007493 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007494 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7495 if (localeFromDefaultSim != null) {
7496 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7497 if (DBG) log("Using locale from subId: " + subId + " locale: "
7498 + localeFromDefaultSim);
7499 return localeFromDefaultSim.toLanguageTag();
7500 } else {
7501 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502 }
7503 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505 // The SIM language preferences only store a language (e.g. fr = French), not an
7506 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7507 // the SIM and carrier preferences does not include a country we add the country
7508 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007509 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007510 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007511 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 return mccLocale.toLanguageTag();
7513 }
7514
7515 if (DBG) log("No locale found - returning null");
7516 return null;
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
7519 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007520 }
7521
7522 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007523 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007524 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007525 }
7526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 /**
7528 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7529 */
7530 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007531 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007532 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007533 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007534
Chenjie Yu1ba97252018-01-11 18:16:20 -08007535 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007536 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007537
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007538 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007539 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7540 * representing the state of the modem.
7541 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007542 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7543 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007544 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007545 */
7546 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007547 public void requestModemActivityInfo(ResultReceiver result) {
7548 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007549 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007550
7551 final long identity = Binder.clearCallingIdentity();
7552 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007553 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 } finally {
7555 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007556 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007557 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007558
Siddharth Rayb8114062018-06-17 15:02:38 -07007559 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7560 // less than total activity duration.
7561 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7562 if (info == null) {
7563 return false;
7564 }
7565 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007566 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7567 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7568
Siddharth Rayb8114062018-06-17 15:02:38 -07007569 return (info.isValid()
7570 && (info.getSleepTimeMillis() <= activityDurationMs)
7571 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007572 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007573 && (totalTxTimeMs <= activityDurationMs));
7574 }
7575
Jack Yu85bd38a2015-11-09 11:34:32 -08007576 /**
7577 * {@hide}
7578 * Returns the service state information on specified subscription.
7579 */
7580 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007581 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7582 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007584 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007585 return null;
7586 }
7587
Hall Liuf19c44f2018-11-27 14:38:17 -08007588 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7589 LocationAccessPolicy.checkLocationPermission(mApp,
7590 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7591 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007592 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007593 .setCallingPid(Binder.getCallingPid())
7594 .setCallingUid(Binder.getCallingUid())
7595 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007596 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007597 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007598 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7599 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007600 .build());
7601
7602 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7603 LocationAccessPolicy.checkLocationPermission(mApp,
7604 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7605 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007606 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007607 .setCallingPid(Binder.getCallingPid())
7608 .setCallingUid(Binder.getCallingUid())
7609 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007610 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007611 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007612 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7613 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007614 .build());
7615 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7616 boolean hasFinePermission =
7617 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7618 boolean hasCoarsePermission =
7619 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7620
Jack Yu479f40e2020-10-27 21:29:25 -07007621 final Phone phone = getPhone(subId);
7622 if (phone == null) {
7623 return null;
7624 }
7625
Jordan Liu0f2bc442020-11-18 16:47:37 -08007626 final long identity = Binder.clearCallingIdentity();
7627
Jack Yu479f40e2020-10-27 21:29:25 -07007628 boolean isCallingPackageDataService = phone.getDataServicePackages()
7629 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007631 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7632 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7633 Rlog.d(LOG_TAG,
7634 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7635 return null;
7636 }
7637
Hall Liuf19c44f2018-11-27 14:38:17 -08007638 ServiceState ss = phone.getServiceState();
7639
7640 // Scrub out the location info in ServiceState depending on what level of access
7641 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007642 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007643 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7644 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645 } finally {
7646 Binder.restoreCallingIdentity(identity);
7647 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007648 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007649
7650 /**
7651 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7652 *
7653 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7654 * voicemail ringtone.
7655 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7656 * PhoneAccount.
7657 */
7658 @Override
7659 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007660 final long identity = Binder.clearCallingIdentity();
7661 try {
7662 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7663 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007664 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7668 } finally {
7669 Binder.restoreCallingIdentity(identity);
7670 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007671 }
7672
7673 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007674 * Sets the per-account voicemail ringtone.
7675 *
7676 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7677 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7678 *
7679 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7680 * voicemail ringtone.
7681 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7682 * PhoneAccount.
7683 */
7684 @Override
7685 public void setVoicemailRingtoneUri(String callingPackage,
7686 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007687 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007688 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007689 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7690 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7692 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7693 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007694 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695
7696 final long identity = Binder.clearCallingIdentity();
7697 try {
7698 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7699 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007700 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701 }
7702 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007705 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007706 }
7707
7708 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007709 * Returns whether vibration is set for voicemail notification in Phone settings.
7710 *
7711 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7712 * voicemail vibration setting.
7713 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7714 */
7715 @Override
7716 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 final long identity = Binder.clearCallingIdentity();
7718 try {
7719 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7720 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007721 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007722 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007723
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7725 } finally {
7726 Binder.restoreCallingIdentity(identity);
7727 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007728 }
7729
Youhan Wange64578a2016-05-02 15:32:42 -07007730 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007731 * Sets the per-account voicemail vibration.
7732 *
7733 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7734 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7735 *
7736 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7737 * voicemail vibration setting.
7738 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7739 * specific PhoneAccount.
7740 */
7741 @Override
7742 public void setVoicemailVibrationEnabled(String callingPackage,
7743 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007744 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007745 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007746 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7747 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7749 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7750 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007751 }
7752
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 final long identity = Binder.clearCallingIdentity();
7754 try {
7755 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7756 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007757 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007758 }
7759 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7760 } finally {
7761 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007762 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007763 }
7764
7765 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007766 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7767 *
7768 * @throws SecurityException if the caller does not have the required permission
7769 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007770 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007771 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007772 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007773 }
7774
7775 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007776 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7777 * permission.
7778 *
7779 * @throws SecurityException if the caller does not have the required permission
7780 */
7781 private void enforceSendSmsPermission() {
7782 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7783 }
7784
7785 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007786 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007787 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007788 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007789 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007790 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007791 final long identity = Binder.clearCallingIdentity();
7792 try {
7793 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007794 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 if (componentName == null) {
7796 throw new SecurityException(
7797 "Caller not current active visual voicemail package[null]");
7798 }
7799 String vvmPackage = componentName.getPackageName();
7800 if (!callingPackage.equals(vvmPackage)) {
7801 throw new SecurityException("Caller not current active visual voicemail package["
7802 + vvmPackage + "]");
7803 }
7804 } finally {
7805 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007806 }
7807 }
7808
7809 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007810 * Return the application ID for the app type.
7811 *
7812 * @param subId the subscription ID that this request applies to.
7813 * @param appType the uicc app type.
7814 * @return Application ID for specificied app type, or null if no uicc.
7815 */
7816 @Override
7817 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007818 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007819 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007820
7821 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007822 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 if (phone == null) {
7824 return null;
7825 }
7826 String aid = null;
7827 try {
7828 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7829 .getApplicationByType(appType).getAid();
7830 } catch (Exception e) {
7831 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7832 }
7833 return aid;
7834 } finally {
7835 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007836 }
Youhan Wange64578a2016-05-02 15:32:42 -07007837 }
7838
Youhan Wang4001d252016-05-11 10:29:41 -07007839 /**
7840 * Return the Electronic Serial Number.
7841 *
7842 * @param subId the subscription ID that this request applies to.
7843 * @return ESN or null if error.
7844 */
7845 @Override
7846 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007847 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007848 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007849
7850 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007851 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007852 if (phone == null) {
7853 return null;
7854 }
7855 String esn = null;
7856 try {
7857 esn = phone.getEsn();
7858 } catch (Exception e) {
7859 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7860 }
7861 return esn;
7862 } finally {
7863 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007864 }
Youhan Wang4001d252016-05-11 10:29:41 -07007865 }
7866
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007867 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007868 * Return the Preferred Roaming List Version.
7869 *
7870 * @param subId the subscription ID that this request applies to.
7871 * @return PRLVersion or null if error.
7872 */
7873 @Override
7874 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007875 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007876 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007877
7878 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007879 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007880 if (phone == null) {
7881 return null;
7882 }
7883 String cdmaPrlVersion = null;
7884 try {
7885 cdmaPrlVersion = phone.getCdmaPrlVersion();
7886 } catch (Exception e) {
7887 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7888 }
7889 return cdmaPrlVersion;
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007892 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007893 }
7894
7895 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007896 * Get snapshot of Telephony histograms
7897 * @return List of Telephony histograms
7898 * @hide
7899 */
7900 @Override
7901 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7903 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904
7905 final long identity = Binder.clearCallingIdentity();
7906 try {
7907 return RIL.getTelephonyRILTimingHistograms();
7908 } finally {
7909 Binder.restoreCallingIdentity(identity);
7910 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007911 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007912
7913 /**
7914 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007915 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7916 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007917 * Require system privileges. In the future we may add this to carrier APIs.
7918 *
Michele Berionne482f8202018-11-27 18:57:59 -08007919 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007920 */
7921 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007922 @TelephonyManager.SetCarrierRestrictionResult
7923 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007924 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007925 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007926
Michele Berionne482f8202018-11-27 18:57:59 -08007927 if (carrierRestrictionRules == null) {
7928 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007929 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007931 final long identity = Binder.clearCallingIdentity();
7932 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007933 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007934 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 } finally {
7936 Binder.restoreCallingIdentity(identity);
7937 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007938 }
7939
7940 /**
7941 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007942 * Get the allowed carrier list and the excluded carrier list, including the priority between
7943 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007944 * Require system privileges. In the future we may add this to carrier APIs.
7945 *
Michele Berionne482f8202018-11-27 18:57:59 -08007946 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007947 */
7948 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007949 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007950 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007951 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952
7953 final long identity = Binder.clearCallingIdentity();
7954 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007955 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7956 if (response instanceof CarrierRestrictionRules) {
7957 return (CarrierRestrictionRules) response;
7958 }
7959 // Response is an Exception of some kind,
7960 // which is signalled to the user as a NULL retval
7961 return null;
7962 } catch (Exception e) {
7963 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7964 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007965 } finally {
7966 Binder.restoreCallingIdentity(identity);
7967 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007968 }
7969
fionaxu59545b42016-05-25 15:53:37 -07007970 /**
fionaxu59545b42016-05-25 15:53:37 -07007971 * Action set from carrier signalling broadcast receivers to enable/disable radio
7972 * @param subId the subscription ID that this action applies to.
7973 * @param enabled control enable or disable radio.
7974 * {@hide}
7975 */
7976 @Override
7977 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7978 enforceModifyPermission();
7979 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007980
7981 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007982 if (phone == null) {
7983 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7984 return;
7985 }
7986 try {
7987 phone.carrierActionSetRadioEnabled(enabled);
7988 } catch (Exception e) {
7989 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007990 } finally {
7991 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007992 }
7993 }
7994
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007995 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007996 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7997 * network status based on which carrier apps could apply actions accordingly,
7998 * enable/disable default url handler for example.
7999 *
8000 * @param subId the subscription ID that this action applies to.
8001 * @param report control start/stop reporting the default network status.
8002 * {@hide}
8003 */
8004 @Override
8005 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8006 enforceModifyPermission();
8007 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008008
8009 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008010 if (phone == null) {
8011 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8012 return;
8013 }
8014 try {
8015 phone.carrierActionReportDefaultNetworkStatus(report);
8016 } catch (Exception e) {
8017 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018 } finally {
8019 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008020 }
8021 }
8022
8023 /**
fionaxud9622282017-07-17 17:51:30 -07008024 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8025 * @param subId the subscription ID that this action applies to.
8026 * {@hide}
8027 */
8028 @Override
8029 public void carrierActionResetAll(int subId) {
8030 enforceModifyPermission();
8031 final Phone phone = getPhone(subId);
8032 if (phone == null) {
8033 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8034 return;
8035 }
8036 try {
8037 phone.carrierActionResetAll();
8038 } catch (Exception e) {
8039 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8040 }
8041 }
8042
8043 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008044 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8045 * bug report is being generated.
8046 */
8047 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008048 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008049 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8050 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008051 writer.println("Permission Denial: can't dump Phone from pid="
8052 + Binder.getCallingPid()
8053 + ", uid=" + Binder.getCallingUid()
8054 + "without permission "
8055 + android.Manifest.permission.DUMP);
8056 return;
8057 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008058 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008059 }
Jack Yueb89b242016-06-22 13:27:47 -07008060
Brad Ebingerdac2f002018-04-03 15:17:52 -07008061 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008062 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8063 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8064 @NonNull String[] args) {
8065 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8066 this, in.getFileDescriptor(), out.getFileDescriptor(),
8067 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008068 }
8069
Jack Yueb89b242016-06-22 13:27:47 -07008070 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008071 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008072 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008073 * @param reason the reason the data enable change is taking place
8074 * @param enabled True if enabling the data, otherwise disabling.
8075 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008076 */
8077 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008078 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008079 boolean enabled) {
8080 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8081 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8082 try {
8083 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008084 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008085 } catch (SecurityException se) {
8086 enforceModifyPermission();
8087 }
8088 } else {
8089 enforceModifyPermission();
8090 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008091
8092 final long identity = Binder.clearCallingIdentity();
8093 try {
8094 Phone phone = getPhone(subId);
8095 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008096 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8097 phone.carrierActionSetMeteredApnsEnabled(enabled);
8098 } else {
8099 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8100 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008101 }
8102 } finally {
8103 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008104 }
8105 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008106
8107 /**
8108 * Get Client request stats
8109 * @return List of Client Request Stats
8110 * @hide
8111 */
8112 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008113 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8114 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008116 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008117 return null;
8118 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008119 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008121 final long identity = Binder.clearCallingIdentity();
8122 try {
8123 if (phone != null) {
8124 return phone.getClientRequestStats();
8125 }
8126
8127 return null;
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008131 }
8132
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008133 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008134 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008135 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008136 }
Jack Yueb4124c2017-02-16 15:32:43 -08008137
8138 /**
Grace Chen70990072017-03-24 17:21:30 -07008139 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008140 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008141 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008142 * @param state State of SIM (power down, power up, pass through)
8143 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8144 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8145 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008146 *
8147 **/
8148 @Override
Grace Chen70990072017-03-24 17:21:30 -07008149 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008150 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008151 Phone phone = PhoneFactory.getPhone(slotIndex);
8152
vagdeviaf9a5b92018-08-15 16:01:53 -07008153 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008155 final long identity = Binder.clearCallingIdentity();
8156 try {
8157 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008158 phone.setSimPowerState(state, null, workSource);
8159 }
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
8162 }
8163 }
8164
8165 /**
8166 * Set SIM card power state.
8167 *
8168 * @param slotIndex SIM slot id.
8169 * @param state State of SIM (power down, power up, pass through)
8170 * @param callback callback to trigger after success or failure
8171 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8172 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8173 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8174 *
8175 **/
8176 @Override
8177 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8178 IIntegerConsumer callback) {
8179 enforceModifyPermission();
8180 Phone phone = PhoneFactory.getPhone(slotIndex);
8181
8182 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8183
8184 final long identity = Binder.clearCallingIdentity();
8185 try {
8186 if (phone != null) {
8187 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8188 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008189 }
8190 } finally {
8191 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008192 }
8193 }
Shuo Qiandd210312017-04-12 22:11:33 +00008194
Tyler Gunn65d45c22017-06-05 11:22:26 -07008195 private boolean isUssdApiAllowed(int subId) {
8196 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008197 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008198 if (configManager == null) {
8199 return false;
8200 }
8201 PersistableBundle pb = configManager.getConfigForSubId(subId);
8202 if (pb == null) {
8203 return false;
8204 }
8205 return pb.getBoolean(
8206 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8207 }
8208
Shuo Qiandd210312017-04-12 22:11:33 +00008209 /**
8210 * Check if phone is in emergency callback mode
8211 * @return true if phone is in emergency callback mode
8212 * @param subId sub id
8213 */
goneil9c5f4872017-12-05 14:07:56 -08008214 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008215 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008216 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008217 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218
8219 final long identity = Binder.clearCallingIdentity();
8220 try {
8221 if (phone != null) {
8222 return phone.isInEcm();
8223 } else {
8224 return false;
8225 }
8226 } finally {
8227 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008228 }
8229 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008230
8231 /**
8232 * Get the current signal strength information for the given subscription.
8233 * Because this information is not updated when the device is in a low power state
8234 * it should not be relied-upon to be current.
8235 * @param subId Subscription index
8236 * @return the most recent cached signal strength info from the modem
8237 */
8238 @Override
8239 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240 final long identity = Binder.clearCallingIdentity();
8241 try {
8242 Phone p = getPhone(subId);
8243 if (p == null) {
8244 return null;
8245 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 return p.getSignalStrength();
8248 } finally {
8249 Binder.restoreCallingIdentity(identity);
8250 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008251 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008252
Pengquan Meng77b7f132018-08-22 14:49:57 -07008253 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008254 * Get the current modem radio state for the given slot.
8255 * @param slotIndex slot index.
8256 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008257 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008258 * @return the current radio power state from the modem
8259 */
8260 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008261 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008262 Phone phone = PhoneFactory.getPhone(slotIndex);
8263 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8265 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008266 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8267 }
8268
8269 final long identity = Binder.clearCallingIdentity();
8270 try {
8271 return phone.getRadioPowerState();
8272 } finally {
8273 Binder.restoreCallingIdentity(identity);
8274 }
8275 }
8276 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8277 }
8278
8279 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008280 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8281 *
8282 * <p>Requires one of the following permissions:
8283 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8284 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8285 * privileges.
8286 *
8287 * @param subId subscription id
8288 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8289 * {@code false}.
8290 */
8291 @Override
8292 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008293 try {
8294 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8295 null);
8296 } catch (Exception e) {
8297 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8298 mApp, subId, "isDataRoamingEnabled");
8299 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008300
Pengquan Menga1bb6272018-09-06 09:59:22 -07008301 boolean isEnabled = false;
8302 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008303 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008304 Phone phone = getPhone(subId);
8305 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008306 } finally {
8307 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008308 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008309 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008310 }
8311
8312
8313 /**
8314 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8315 *
8316 * <p> Requires permission:
8317 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8318 * privileges.
8319 *
8320 * @param subId subscription id
8321 * @param isEnabled {@code true} means enable, {@code false} means disable.
8322 */
8323 @Override
8324 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8326 mApp, subId, "setDataRoamingEnabled");
8327
Pengquan Menga1bb6272018-09-06 09:59:22 -07008328 final long identity = Binder.clearCallingIdentity();
8329 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008330 Phone phone = getPhone(subId);
8331 if (phone != null) {
8332 phone.setDataRoamingEnabled(isEnabled);
8333 }
8334 } finally {
8335 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008336 }
8337 }
8338
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008339 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008340 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008341 TelephonyPermissions
8342 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008343 mApp, subId, "isManualNetworkSelectionAllowed");
8344
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008345 boolean isAllowed = true;
8346 final long identity = Binder.clearCallingIdentity();
8347 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008348 Phone phone = getPhone(subId);
8349 if (phone != null) {
8350 isAllowed = phone.isCspPlmnEnabled();
8351 }
8352 } finally {
8353 Binder.restoreCallingIdentity(identity);
8354 }
8355 return isAllowed;
8356 }
8357
8358 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008359 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008360 // Verify that tha callingPackage belongs to the calling UID
8361 mApp.getSystemService(AppOpsManager.class)
8362 .checkPackage(Binder.getCallingUid(), callingPackage);
8363
Jordan Liu1e142fc2019-04-22 15:10:43 -07008364 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008365 try {
8366 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008367 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008368 } catch (SecurityException e) {
8369 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8370 // has carrier privileges on an active UICC
8371 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8372 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008373 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008374 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008375 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008376
8377 final long identity = Binder.clearCallingIdentity();
8378 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008379 UiccController uiccController = UiccController.getInstance();
8380 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008381 if (hasReadPermission) {
8382 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008383 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008384
8385 // Remove private info if the caller doesn't have access
8386 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8387 for (UiccCardInfo cardInfo : cardInfos) {
8388 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8389 // is available
8390 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8391 if (card == null || card.getUiccProfile() == null) {
8392 // assume no access if the card or profile is unavailable
8393 filteredInfos.add(cardInfo.getUnprivileged());
8394 continue;
8395 }
8396 UiccProfile profile = card.getUiccProfile();
8397 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8398 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8399 filteredInfos.add(cardInfo);
8400 } else {
8401 filteredInfos.add(cardInfo.getUnprivileged());
8402 }
8403 }
8404 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008405 } finally {
8406 Binder.restoreCallingIdentity(identity);
8407 }
8408 }
8409
8410 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008411 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008412 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008413
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008414 final long identity = Binder.clearCallingIdentity();
8415 try {
8416 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8417 if (slots == null) {
8418 Rlog.i(LOG_TAG, "slots is null.");
8419 return null;
8420 }
8421
8422 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8423 for (int i = 0; i < slots.length; i++) {
8424 UiccSlot slot = slots[i];
8425 if (slot == null) {
8426 continue;
8427 }
8428
Jordan Liu7be7e652019-05-06 18:55:02 +00008429 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008430 UiccCard card = slot.getUiccCard();
8431 if (card != null) {
8432 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008433 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008434 cardId = slot.getEid();
8435 if (TextUtils.isEmpty(cardId)) {
8436 cardId = slot.getIccId();
8437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008438 }
8439
Jordan Liu857451f2019-05-09 16:35:35 -07008440 if (cardId != null) {
8441 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8442 // if cardId is an EID, it's all digits so this is fine
8443 cardId = IccUtils.stripTrailingFs(cardId);
8444 }
8445
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008446 int cardState = 0;
8447 switch (slot.getCardState()) {
8448 case CARDSTATE_ABSENT:
8449 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8450 break;
8451 case CARDSTATE_PRESENT:
8452 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8453 break;
8454 case CARDSTATE_ERROR:
8455 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8456 break;
8457 case CARDSTATE_RESTRICTED:
8458 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8459 break;
8460 default:
8461 break;
8462
8463 }
8464
8465 infos[i] = new UiccSlotInfo(
8466 slot.isActive(),
8467 slot.isEuicc(),
8468 cardId,
8469 cardState,
8470 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008471 slot.isExtendedApduSupported(),
8472 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008473 }
8474 return infos;
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008477 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008478 }
8479
8480 @Override
8481 public boolean switchSlots(int[] physicalSlots) {
8482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008483
8484 final long identity = Binder.clearCallingIdentity();
8485 try {
8486 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8487 } finally {
8488 Binder.restoreCallingIdentity(identity);
8489 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008490 }
Jack Yu4c988042018-02-27 15:30:01 -08008491
8492 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008493 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008494 final long identity = Binder.clearCallingIdentity();
8495 try {
8496 return UiccController.getInstance().getCardIdForDefaultEuicc();
8497 } finally {
8498 Binder.restoreCallingIdentity(identity);
8499 }
8500 }
8501
Pengquan Meng85728fb2018-03-12 16:31:21 -07008502 /**
goneil47ffb6e2018-04-06 15:40:58 -07008503 * A test API to reload the UICC profile.
8504 *
8505 * <p>Requires that the calling app has permission
8506 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8507 * @hide
8508 */
8509 @Override
8510 public void refreshUiccProfile(int subId) {
8511 enforceModifyPermission();
8512
8513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 Phone phone = getPhone(subId);
8516 if (phone == null) {
8517 return;
8518 }
8519 UiccCard uiccCard = phone.getUiccCard();
8520 if (uiccCard == null) {
8521 return;
8522 }
8523 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8524 if (uiccProfile == null) {
8525 return;
8526 }
8527 uiccProfile.refresh();
8528 } finally {
8529 Binder.restoreCallingIdentity(identity);
8530 }
8531 }
8532
8533 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008534 * Returns false if the mobile data is disabled by default, otherwise return true.
8535 */
8536 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008537 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008538 }
8539
8540 /**
8541 * Returns true if the data roaming is enabled by default, i.e the system property
8542 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8543 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8544 */
8545 private boolean getDefaultDataRoamingEnabled(int subId) {
8546 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008547 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008548 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008549 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8550 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8551 return isDataRoamingEnabled;
8552 }
8553
8554 /**
8555 * Returns the default network type for the given {@code subId}, if the default network type is
8556 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8557 */
8558 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008559 List<Integer> list = TelephonyProperties.default_network();
8560 int phoneId = mSubscriptionController.getPhoneId(subId);
8561 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8562 return list.get(phoneId);
8563 }
8564 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008565 }
fionaxua13278b2018-03-21 00:08:13 -07008566
8567 @Override
8568 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008569 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008571
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
8574 final Phone phone = getPhone(subId);
8575 if (phone == null) {
8576 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8577 return;
8578 }
chen xueaba88a2019-03-15 13:15:10 -07008579 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8580 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008581 if (carrierPrivilegeRules == null) {
8582 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8583 } else {
8584 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8585 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008586 } finally {
8587 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008588 }
fionaxua13278b2018-03-21 00:08:13 -07008589 }
8590
8591 @Override
8592 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008593 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008594
8595 final long identity = Binder.clearCallingIdentity();
8596 try {
8597 final Phone phone = getPhone(subId);
8598 if (phone == null) {
8599 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8600 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8601 }
8602 return phone.getCarrierIdListVersion();
8603 } finally {
8604 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008605 }
fionaxua13278b2018-03-21 00:08:13 -07008606 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008607
8608 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008609 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8610 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008612 mApp, subId, callingPackage, callingFeatureId,
8613 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008614 return -1;
8615 }
8616
8617 final long identity = Binder.clearCallingIdentity();
8618 try {
8619 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8620 } finally {
8621 Binder.restoreCallingIdentity(identity);
8622 }
8623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008624
8625 @Override
8626 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008627 TelephonyPermissions
8628 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008629 mApp, subId, "getCdmaRoamingMode");
8630
8631 final long identity = Binder.clearCallingIdentity();
8632 try {
8633 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8634 } finally {
8635 Binder.restoreCallingIdentity(identity);
8636 }
8637 }
8638
8639 @Override
8640 public boolean setCdmaRoamingMode(int subId, int mode) {
8641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8642 mApp, subId, "setCdmaRoamingMode");
8643
8644 final long identity = Binder.clearCallingIdentity();
8645 try {
8646 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8647 } finally {
8648 Binder.restoreCallingIdentity(identity);
8649 }
8650 }
8651
8652 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008653 public int getCdmaSubscriptionMode(int subId) {
8654 TelephonyPermissions
8655 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8656 mApp, subId, "getCdmaSubscriptionMode");
8657
8658 final long identity = Binder.clearCallingIdentity();
8659 try {
8660 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8661 } finally {
8662 Binder.restoreCallingIdentity(identity);
8663 }
8664 }
8665
8666 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008667 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8669 mApp, subId, "setCdmaSubscriptionMode");
8670
8671 final long identity = Binder.clearCallingIdentity();
8672 try {
8673 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8674 } finally {
8675 Binder.restoreCallingIdentity(identity);
8676 }
8677 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008678
sqianc5eccab2018-10-19 18:46:41 -07008679 @Override
sqian8c685422019-02-22 15:55:18 -08008680 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008681 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008683 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8684 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008685 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8686 }
8687 final long identity = Binder.clearCallingIdentity();
8688 try {
sqian854d44b2018-12-12 16:48:18 -08008689 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8690 for (Phone phone: PhoneFactory.getPhones()) {
8691 if (phone.getEmergencyNumberTracker() != null
8692 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8693 emergencyNumberListInternal.put(
8694 phone.getSubId(),
8695 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8696 }
sqian11b7a0e2018-12-05 18:48:28 -08008697 }
sqian854d44b2018-12-12 16:48:18 -08008698 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
sqianc5eccab2018-10-19 18:46:41 -07008702 }
8703
8704 @Override
sqian8c685422019-02-22 15:55:18 -08008705 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008706 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008707 if (!exactMatch) {
8708 TelephonyPermissions
8709 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008710 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008711 }
8712 final long identity = Binder.clearCallingIdentity();
8713 try {
sqian854d44b2018-12-12 16:48:18 -08008714 for (Phone phone: PhoneFactory.getPhones()) {
8715 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008716 && phone.getEmergencyNumberTracker()
8717 .isEmergencyNumber(number, exactMatch)) {
8718 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008719 }
sqian11b7a0e2018-12-05 18:48:28 -08008720 }
8721 return false;
8722 } finally {
8723 Binder.restoreCallingIdentity(identity);
8724 }
8725 }
8726
sqianf4ca7ed2019-01-15 18:32:07 -08008727 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008728 * Start emergency callback mode for GsmCdmaPhone for testing.
8729 */
8730 @Override
8731 public void startEmergencyCallbackMode() {
8732 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8733 "startEmergencyCallbackMode");
8734 enforceModifyPermission();
8735 final long identity = Binder.clearCallingIdentity();
8736 try {
8737 for (Phone phone : PhoneFactory.getPhones()) {
8738 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8739 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8740 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8741 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8742 gsmCdmaPhone.obtainMessage(
8743 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8744 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8745 }
8746 }
8747 } finally {
8748 Binder.restoreCallingIdentity(identity);
8749 }
8750 }
8751
8752 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008753 * Update emergency number list for test mode.
8754 */
8755 @Override
8756 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8757 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8758 "updateEmergencyNumberListTestMode");
8759
8760 final long identity = Binder.clearCallingIdentity();
8761 try {
8762 for (Phone phone: PhoneFactory.getPhones()) {
8763 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8764 if (tracker != null) {
8765 tracker.executeEmergencyNumberTestModeCommand(action, num);
8766 }
8767 }
8768 } finally {
8769 Binder.restoreCallingIdentity(identity);
8770 }
8771 }
8772
8773 /**
8774 * Get the full emergency number list for test mode.
8775 */
8776 @Override
8777 public List<String> getEmergencyNumberListTestMode() {
8778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8779 "getEmergencyNumberListTestMode");
8780
8781 final long identity = Binder.clearCallingIdentity();
8782 try {
8783 Set<String> emergencyNumbers = new HashSet<>();
8784 for (Phone phone: PhoneFactory.getPhones()) {
8785 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8786 if (tracker != null) {
8787 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8788 emergencyNumbers.add(num.getNumber());
8789 }
8790 }
8791 }
8792 return new ArrayList<>(emergencyNumbers);
8793 } finally {
8794 Binder.restoreCallingIdentity(identity);
8795 }
8796 }
8797
chen xud6b45bd2018-10-30 22:27:10 -07008798 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008799 public int getEmergencyNumberDbVersion(int subId) {
8800 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8801
8802 final long identity = Binder.clearCallingIdentity();
8803 try {
8804 final Phone phone = getPhone(subId);
8805 if (phone == null) {
8806 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8807 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8808 }
8809 return phone.getEmergencyNumberDbVersion();
8810 } finally {
8811 Binder.restoreCallingIdentity(identity);
8812 }
8813 }
8814
8815 @Override
8816 public void notifyOtaEmergencyNumberDbInstalled() {
8817 enforceModifyPermission();
8818
8819 final long identity = Binder.clearCallingIdentity();
8820 try {
8821 for (Phone phone: PhoneFactory.getPhones()) {
8822 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8823 if (tracker != null) {
8824 tracker.updateOtaEmergencyNumberDatabase();
8825 }
8826 }
8827 } finally {
8828 Binder.restoreCallingIdentity(identity);
8829 }
8830 }
8831
8832 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008833 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008834 enforceActiveEmergencySessionPermission();
8835
8836 final long identity = Binder.clearCallingIdentity();
8837 try {
8838 for (Phone phone: PhoneFactory.getPhones()) {
8839 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8840 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008841 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8842 }
8843 }
8844 } finally {
8845 Binder.restoreCallingIdentity(identity);
8846 }
8847 }
8848
8849 @Override
8850 public void resetOtaEmergencyNumberDbFilePath() {
8851 enforceActiveEmergencySessionPermission();
8852
8853 final long identity = Binder.clearCallingIdentity();
8854 try {
8855 for (Phone phone: PhoneFactory.getPhones()) {
8856 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8857 if (tracker != null) {
8858 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008859 }
8860 }
8861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
8864 }
8865
8866 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008867 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8868 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8869 Phone phone = getPhone(subId);
8870 if (phone == null) {
8871 return null;
8872 }
8873 final long identity = Binder.clearCallingIdentity();
8874 try {
8875 UiccProfile profile = UiccController.getInstance()
8876 .getUiccProfileForPhone(phone.getPhoneId());
8877 if (profile != null) {
8878 return profile.getCertsFromCarrierPrivilegeAccessRules();
8879 }
8880 } finally {
8881 Binder.restoreCallingIdentity(identity);
8882 }
8883 return null;
8884 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008885
8886 /**
8887 * Enable or disable a modem stack.
8888 */
8889 @Override
8890 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8891 enforceModifyPermission();
8892
8893 final long identity = Binder.clearCallingIdentity();
8894 try {
8895 Phone phone = PhoneFactory.getPhone(slotIndex);
8896 if (phone == null) {
8897 return false;
8898 } else {
8899 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8900 }
8901 } finally {
8902 Binder.restoreCallingIdentity(identity);
8903 }
8904 }
Michelecea4cf22018-12-21 15:00:11 -08008905
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008906 /**
8907 * Whether a modem stack is enabled or not.
8908 */
8909 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008910 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8911 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008912 Phone phone = PhoneFactory.getPhone(slotIndex);
8913 if (phone == null) return false;
8914
8915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008916 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8917 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008918 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8919 }
8920
8921 final long identity = Binder.clearCallingIdentity();
8922 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008923 try {
8924 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8925 } catch (NoSuchElementException ex) {
8926 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8927 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008928 } finally {
8929 Binder.restoreCallingIdentity(identity);
8930 }
8931 }
8932
Michelecea4cf22018-12-21 15:00:11 -08008933 @Override
Michele0ea7d782019-03-19 14:58:42 -07008934 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008935 enforceModifyPermission();
8936
8937 final long identity = Binder.clearCallingIdentity();
8938 try {
8939 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008940 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008941 .commit();
8942 } finally {
8943 Binder.restoreCallingIdentity(identity);
8944 }
8945 }
8946
8947 @Override
Michele0ea7d782019-03-19 14:58:42 -07008948 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008949 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008950 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008951 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8952 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008953 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008954 }
Michelecea4cf22018-12-21 15:00:11 -08008955
8956 final long identity = Binder.clearCallingIdentity();
8957 try {
Michele0ea7d782019-03-19 14:58:42 -07008958 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008959 } finally {
8960 Binder.restoreCallingIdentity(identity);
8961 }
8962 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008963
Michele0ea7d782019-03-19 14:58:42 -07008964 @TelephonyManager.IsMultiSimSupportedResult
8965 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008966 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8967 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8968 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008969 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8970 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008971 }
8972 // Check if the hardware supports multisim functionality. If usage of multisim is not
8973 // supported by the modem, indicate that it is restricted.
8974 PhoneCapability staticCapability =
8975 mPhoneConfigurationManager.getStaticPhoneCapability();
8976 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008977 loge("isMultiSimSupportedInternal: no static configuration available");
8978 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008979 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008980 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008981 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8982 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008983 }
8984 // Check if support of multiple SIMs is restricted by carrier
8985 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008986 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008987 }
8988
Michele0ea7d782019-03-19 14:58:42 -07008989 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008990 }
8991
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008992 /**
8993 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008994 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8995 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8996 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008997 * @param numOfSims number of active sims we want to switch to
8998 */
8999 @Override
9000 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009001 if (numOfSims == 1) {
9002 enforceModifyPermission();
9003 } else {
9004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9005 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9006 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009007 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009008
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009009 try {
Michele30b57b22019-03-01 12:01:14 -08009010 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009011 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009012 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9013 return;
9014 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009015 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9016 } finally {
9017 Binder.restoreCallingIdentity(identity);
9018 }
9019 }
9020
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009021 @Override
9022 public boolean isApplicationOnUicc(int subId, int appType) {
9023 enforceReadPrivilegedPermission("isApplicationOnUicc");
9024 Phone phone = getPhone(subId);
9025 if (phone == null) {
9026 return false;
9027 }
9028 final long identity = Binder.clearCallingIdentity();
9029 try {
9030 UiccCard uiccCard = phone.getUiccCard();
9031 if (uiccCard == null) {
9032 return false;
9033 }
9034 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9035 if (uiccProfile == null) {
9036 return false;
9037 }
9038 if (TelephonyManager.APPTYPE_SIM <= appType
9039 && appType <= TelephonyManager.APPTYPE_ISIM) {
9040 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9041 }
9042 return false;
9043 } finally {
9044 Binder.restoreCallingIdentity(identity);
9045 }
9046 }
9047
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009048 /**
chen xub4baa772019-04-03 10:23:41 -07009049 * Get whether making changes to modem configurations will trigger reboot.
9050 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009051 */
9052 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009053 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9054 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009056 mApp, subId, callingPackage, callingFeatureId,
9057 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009058 return false;
9059 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009060 final long identity = Binder.clearCallingIdentity();
9061 try {
9062 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9063 } finally {
9064 Binder.restoreCallingIdentity(identity);
9065 }
9066 }
9067
Nathan Harold29f5f052019-02-15 13:41:57 -08009068 private void updateModemStateMetrics() {
9069 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9070 // TODO: check the state for each modem if the api is ready.
9071 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9072 }
9073
Pengquan Meng3889a572019-01-23 11:16:29 -08009074 @Override
9075 public int[] getSlotsMapping() {
9076 enforceReadPrivilegedPermission("getSlotsMapping");
9077
9078 final long identity = Binder.clearCallingIdentity();
9079 try {
9080 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9081 // All logical slots should have a mapping to a physical slot.
9082 int[] logicalSlotsMapping = new int[phoneCount];
9083 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9084 for (int i = 0; i < slotInfos.length; i++) {
9085 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9086 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9087 }
9088 }
9089 return logicalSlotsMapping;
9090 } finally {
9091 Binder.restoreCallingIdentity(identity);
9092 }
9093 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009094
9095 /**
9096 * Get the IRadio HAL Version
9097 */
9098 @Override
9099 public int getRadioHalVersion() {
9100 Phone phone = getDefaultPhone();
9101 if (phone == null) return -1;
9102 HalVersion hv = phone.getHalVersion();
9103 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9104 return hv.major * 100 + hv.minor;
9105 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009106
9107 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009108 * Get the current calling package name.
9109 * @return the current calling package name
9110 */
9111 @Override
9112 public String getCurrentPackageName() {
9113 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9114 }
9115
9116 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009117 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9118 * corresponding network requests on a subId.
9119 *
9120 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009121 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009122 * 2) APN is un-metered for this subscription, or
9123 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009124 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009125 *
9126 * @return whether data is allowed for a apn type.
9127 *
9128 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009129 */
9130 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009131 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009132 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9133 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009134
9135 // Now that all security checks passes, perform the operation as ourselves.
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 Phone phone = getPhone(subId);
9139 if (phone == null) return false;
9140
Jack Yu41407ee2019-05-13 16:54:09 -07009141 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009142 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9143 } finally {
9144 Binder.restoreCallingIdentity(identity);
9145 }
9146 }
9147
9148 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009149 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009150 enforceReadPrivilegedPermission("isApnMetered");
9151
9152 // Now that all security checks passes, perform the operation as ourselves.
9153 final long identity = Binder.clearCallingIdentity();
9154 try {
9155 Phone phone = getPhone(subId);
9156 if (phone == null) return true; // By default return true.
9157
Jack Yu41407ee2019-05-13 16:54:09 -07009158 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009159 } finally {
9160 Binder.restoreCallingIdentity(identity);
9161 }
9162 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009163
9164 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009165 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9166 int subscriptionId, IBooleanConsumer resultCallback) {
9167 enforceModifyPermission();
9168 long token = Binder.clearCallingIdentity();
9169 try {
9170 Phone phone = getPhone(subscriptionId);
9171 if (phone == null) {
9172 try {
9173 if (resultCallback != null) {
9174 resultCallback.accept(false);
9175 }
9176 } catch (RemoteException e) {
9177 // ignore
9178 }
9179 return;
9180 }
9181 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9182 Pair.create(specifiers, (x) -> {
9183 try {
9184 if (resultCallback != null) {
9185 resultCallback.accept(x);
9186 }
9187 } catch (RemoteException e) {
9188 // ignore
9189 }
9190 });
9191 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9192 } finally {
9193 Binder.restoreCallingIdentity(token);
9194 }
9195 }
9196
9197 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009198 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9199 TelephonyPermissions
9200 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9201 mApp, subId, "getSystemSelectionChannels");
9202 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9203 final long identity = Binder.clearCallingIdentity();
9204 try {
9205 List<RadioAccessSpecifier> specifiers =
9206 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9207 null, subId, workSource);
9208 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9209 return specifiers;
9210 } finally {
9211 Binder.restoreCallingIdentity(identity);
9212 }
9213 }
9214
9215 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009216 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009217 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009218 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9219 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9220 if (iccRecords == null) {
9221 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9222 return false;
9223 }
9224 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9225 }
9226
9227 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009228 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9229 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009230 if (callingPackage == null) {
9231 callingPackage = getCurrentPackageName();
9232 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009233 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9234 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009235 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9236 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009237 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9238 }
9239 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9240 Intent intent = new Intent();
9241 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9242 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9243 // Bring up choose default SMS subscription dialog right now
9244 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9245 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9246 mApp.startActivity(intent);
9247 }
chen xud5ca2d52019-05-28 15:20:57 -07009248
9249 @Override
9250 public String getMmsUAProfUrl(int subId) {
9251 //TODO investigate if this API should require proper permission check in R b/133791609
9252 final long identity = Binder.clearCallingIdentity();
9253 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009254 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9255 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9256 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9257 return carrierUAProfUrl;
9258 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009259 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9260 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009261 } finally {
9262 Binder.restoreCallingIdentity(identity);
9263 }
9264 }
9265
9266 @Override
9267 public String getMmsUserAgent(int subId) {
9268 //TODO investigate if this API should require proper permission check in R b/133791609
9269 final long identity = Binder.clearCallingIdentity();
9270 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009271 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9272 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9273 if (!TextUtils.isEmpty(carrierUserAgent)) {
9274 return carrierUserAgent;
9275 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009276 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9277 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009278 } finally {
9279 Binder.restoreCallingIdentity(identity);
9280 }
9281 }
Jack Yub07d4972019-05-28 16:12:25 -07009282
9283 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009284 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9285 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009286
Jack Yub07d4972019-05-28 16:12:25 -07009287 final long identity = Binder.clearCallingIdentity();
9288 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009289 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009290 if (phone == null) return false;
9291
Hall Liua62f5da2020-09-25 10:42:19 -07009292 switch (policy) {
9293 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9294 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9295 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9296 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9297 default:
9298 throw new IllegalArgumentException(policy + " is not a valid policy");
9299 }
Jack Yub07d4972019-05-28 16:12:25 -07009300 } finally {
9301 Binder.restoreCallingIdentity(identity);
9302 }
9303 }
9304
9305 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009306 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009307 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009308 enforceModifyPermission();
9309
changbettyd5c246e2019-12-24 15:40:37 +08009310 final long identity = Binder.clearCallingIdentity();
9311 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009312 Phone phone = getPhone(subscriptionId);
9313 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009314
Hall Liua62f5da2020-09-25 10:42:19 -07009315 switch (policy) {
9316 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9317 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9318 break;
9319 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9320 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9321 break;
9322 default:
9323 throw new IllegalArgumentException(policy + " is not a valid policy");
9324 }
changbettyd5c246e2019-12-24 15:40:37 +08009325 } finally {
9326 Binder.restoreCallingIdentity(identity);
9327 }
9328 }
9329
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009330 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009331 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009332 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9333 * otherwise.
9334 */
9335 @Override
9336 public void setCepEnabled(boolean isCepEnabled) {
9337 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9338
9339 final long identity = Binder.clearCallingIdentity();
9340 try {
9341 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9342 for (Phone phone : PhoneFactory.getPhones()) {
9343 Phone defaultPhone = phone.getImsPhone();
9344 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9345 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9346 ImsPhoneCallTracker imsPhoneCallTracker =
9347 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9348 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9349 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9350 + imsPhone.getMsisdn());
9351 }
9352 }
9353 } finally {
9354 Binder.restoreCallingIdentity(identity);
9355 }
9356 }
allenwtsu46dcc572020-01-08 18:24:03 +08009357
9358 /**
9359 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9360 *
9361 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9362 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9363 * before being read.
9364 */
9365 @Override
9366 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9367 isCompressed) {
9368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9369 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009370 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9371 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9372 }
9373 if (!isImsAvailableOnDevice()) {
9374 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9375 "IMS not available on device.");
9376 }
9377
9378 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009379 try {
Hui Wang761a6682020-10-31 05:12:53 +00009380 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9381 } finally {
9382 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009383 }
9384 }
zoey chene02881a2019-12-30 16:11:23 +08009385
9386 @Override
9387 public boolean isIccLockEnabled(int subId) {
9388 enforceReadPrivilegedPermission("isIccLockEnabled");
9389
9390 // Now that all security checks passes, perform the operation as ourselves.
9391 final long identity = Binder.clearCallingIdentity();
9392 try {
9393 Phone phone = getPhone(subId);
9394 if (phone != null && phone.getIccCard() != null) {
9395 return phone.getIccCard().getIccLockEnabled();
9396 } else {
9397 return false;
9398 }
9399 } finally {
9400 Binder.restoreCallingIdentity(identity);
9401 }
9402 }
9403
9404 /**
9405 * Set the ICC pin lock enabled or disabled.
9406 *
9407 * @return an integer representing the status of IccLock enabled or disabled in the following
9408 * three cases:
9409 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9410 * successfully.
9411 * - Positive number and zero for remaining password attempts.
9412 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9413 *
9414 */
9415 @Override
9416 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9417 enforceModifyPermission();
9418
9419 Phone phone = getPhone(subId);
9420 if (phone == null) {
9421 return 0;
9422 }
9423 // Now that all security checks passes, perform the operation as ourselves.
9424 final long identity = Binder.clearCallingIdentity();
9425 try {
9426 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9427 new Pair<Boolean, String>(enabled, password), phone, null);
9428 return attemptsRemaining;
9429
9430 } catch (Exception e) {
9431 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9432 } finally {
9433 Binder.restoreCallingIdentity(identity);
9434 }
9435 return 0;
9436 }
9437
9438 /**
9439 * Change the ICC password used in ICC pin lock.
9440 *
9441 * @return an integer representing the status of IccLock changed in the following three cases:
9442 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9443 * - Positive number and zero for remaining password attempts.
9444 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9445 *
9446 */
9447 @Override
9448 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9449 enforceModifyPermission();
9450
9451 Phone phone = getPhone(subId);
9452 if (phone == null) {
9453 return 0;
9454 }
9455 // Now that all security checks passes, perform the operation as ourselves.
9456 final long identity = Binder.clearCallingIdentity();
9457 try {
9458 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9459 new Pair<String, String>(oldPassword, newPassword), phone, null);
9460 return attemptsRemaining;
9461
9462 } catch (Exception e) {
9463 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9464 } finally {
9465 Binder.restoreCallingIdentity(identity);
9466 }
9467 return 0;
9468 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009469
9470 /**
9471 * Request for receiving user activity notification
9472 */
9473 @Override
9474 public void requestUserActivityNotification() {
9475 if (!mNotifyUserActivity.get()
9476 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9477 mNotifyUserActivity.set(true);
9478 }
9479 }
9480
9481 /**
9482 * Called when userActivity is signalled in the power manager.
9483 * This is safe to call from any thread, with any window manager locks held or not.
9484 */
9485 @Override
9486 public void userActivity() {
9487 // ***************************************
9488 // * Inherited from PhoneWindowManager *
9489 // ***************************************
9490 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9491 // WITH ITS LOCKS HELD.
9492 //
9493 // This code must be VERY careful about the locks
9494 // it acquires.
9495 // In fact, the current code acquires way too many,
9496 // and probably has lurking deadlocks.
9497
9498 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9499 throw new SecurityException("Only the OS may call notifyUserActivity()");
9500 }
9501
9502 if (mNotifyUserActivity.getAndSet(false)) {
9503 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9504 USER_ACTIVITY_NOTIFICATION_DELAY);
9505 }
9506 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009507
9508 @Override
9509 public boolean canConnectTo5GInDsdsMode() {
9510 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9511 }
Jack Yud10cdd42020-09-28 20:28:01 -07009512
9513 @Override
9514 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9515 String callingFeatureId) {
9516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9517 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9518 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9519 }
9520
9521 Phone phone = getPhone(subId);
9522 if (phone == null) {
9523 throw new RuntimeException("phone is not available");
9524 }
9525 // Now that all security checks passes, perform the operation as ourselves.
9526 final long identity = Binder.clearCallingIdentity();
9527 try {
9528 return phone.getEquivalentHomePlmns();
9529 } finally {
9530 Binder.restoreCallingIdentity(identity);
9531 }
9532 }
Daniel Bright59e67312020-11-13 11:49:37 -08009533
9534 @Override
9535 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009536 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9537 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009538 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009539 if (radioInterfaceCapabilities == null) {
9540 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009541 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009542 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009543 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009544
Hui Wang641e81c2020-10-12 12:14:23 -07009545 @Override
9546 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9547 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009548 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9549 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9550 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9551 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9552 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009553 if (DBG) {
9554 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9555 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9556 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9557 }
9558
9559 if (!SubscriptionManager.isValidSubscriptionId(subId)
9560 || appType < TelephonyManager.APPTYPE_UNKNOWN
9561 || appType > TelephonyManager.APPTYPE_ISIM
9562 || nafUrl == null || securityProtocol == null || callback == null) {
9563 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9564 if (callback != null) {
9565 try {
9566 callback.onAuthenticationFailure(
9567 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9568 } catch (RemoteException exception) {
9569 log("Fail to notify onAuthenticationFailure due to " + exception);
9570 }
9571 return;
9572 }
9573 }
9574
9575 final long token = Binder.clearCallingIdentity();
9576 try {
9577 getGbaManager(subId).bootstrapAuthenticationRequest(
9578 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9579 forceBootStrapping, callback));
9580 } finally {
9581 Binder.restoreCallingIdentity(token);
9582 }
9583 }
9584
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009585 /**
9586 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9587 * requested radio power state will actually be set. See {@link
9588 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9589 *
9590 * @param subId the subscription ID of the phone requesting to set the radio power state.
9591 * @param enable {@code true} if trying to turn radio on.
9592 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9593 * false}.
9594 */
9595 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9596 Phone phone = getPhone(subId);
9597 if (phone != null) {
9598 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9599 return true;
9600 }
9601 return false;
9602 }
9603
9604 private int handleDataThrottlingRequest(int subId,
9605 DataThrottlingRequest dataThrottlingRequest) {
9606 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9607 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9608 if (!setRadioPowerForThermal(subId, true)) {
9609 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9610 }
9611
9612 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9613
9614 int thermalMitigationResult =
9615 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9616 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9617 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9618 }
9619 return thermalMitigationResult;
9620 }
9621
9622 /**
9623 * Thermal mitigation request to control functionalities at modem.
9624 *
9625 * @param subId the id of the subscription.
9626 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9627 *
9628 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9629 */
9630 @Override
9631 @ThermalMitigationResult
9632 public int sendThermalMitigationRequest(
9633 int subId,
9634 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9635 enforceModifyPermission();
9636
9637 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9638 final long identity = Binder.clearCallingIdentity();
9639
9640 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9641 try {
9642 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9643 switch (thermalMitigationAction) {
9644 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9645 thermalMitigationResult =
9646 handleDataThrottlingRequest(subId,
9647 thermalMitigationRequest.getDataThrottlingRequest());
9648 break;
9649 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9650 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9651 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9652 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9653 }
9654
9655 // Ensure that radio is on. If not able to power on due to phone being
9656 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9657 if (!setRadioPowerForThermal(subId, true)) {
9658 thermalMitigationResult =
9659 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9660 break;
9661 }
9662
9663 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9664 false);
9665 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9666 break;
9667 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9668 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9669 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9670 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9671 }
9672
9673 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9674 if (registry != null) {
9675 TelephonyConnectionService service =
9676 registry.getTelephonyConnectionService();
9677 Phone phone = getPhone(subId);
9678 if (phone == null) {
9679 thermalMitigationResult =
9680 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9681 break;
9682 }
9683
9684 if (PhoneConstantConversions.convertCallState(phone.getState())
9685 != TelephonyManager.CALL_STATE_IDLE
9686 || phone.isInEmergencySmsMode() || phone.isInEcm()
9687 || (service != null && service.isEmergencyCallPending())) {
9688 String errorMessage = "Phone state is not valid. call state = "
9689 + PhoneConstantConversions.convertCallState(phone.getState())
9690 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9691 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9692 errorMessage += service == null
9693 ? " TelephonyConnectionService is null"
9694 : " isEmergencyCallPending = "
9695 + service.isEmergencyCallPending();
9696 Log.e(LOG_TAG, errorMessage);
9697 thermalMitigationResult =
9698 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9699 break;
9700 }
9701 } else {
9702 thermalMitigationResult =
9703 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9704 break;
9705 }
9706
9707 // Turn radio off. If not able to power off due to phone being unavailable,
9708 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9709 if (!setRadioPowerForThermal(subId, false)) {
9710 thermalMitigationResult =
9711 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9712 break;
9713 }
9714 thermalMitigationResult =
9715 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9716 break;
9717 default:
9718 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9719 + "not exist. Requested action: " + thermalMitigationAction);
9720 }
9721 } catch (IllegalArgumentException e) {
9722 throw e;
9723 } catch (Exception e) {
9724 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9725 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9726 } finally {
9727 Binder.restoreCallingIdentity(identity);
9728 }
9729
9730 if (DBG) {
9731 log("thermalMitigationRequest returning with thermalMitigationResult: "
9732 + thermalMitigationResult);
9733 }
9734
9735 return thermalMitigationResult;
9736 }
Hui Wang641e81c2020-10-12 12:14:23 -07009737
9738 /**
9739 * Set the GbaService Package Name that Telephony will bind to.
9740 *
9741 * @param subId The sim that the GbaService is associated with.
9742 * @param packageName The name of the package to be replaced with.
9743 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9744 */
9745 @Override
9746 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9747 enforceModifyPermission();
9748
9749 final long identity = Binder.clearCallingIdentity();
9750 try {
9751 return getGbaManager(subId).overrideServicePackage(packageName);
9752 } finally {
9753 Binder.restoreCallingIdentity(identity);
9754 }
9755 }
9756
9757 /**
9758 * Return the package name of the currently bound GbaService.
9759 *
9760 * @param subId The sim that the GbaService is associated with.
9761 * @return the package name of the GbaService configuration, null if GBA is not supported.
9762 */
9763 @Override
9764 public String getBoundGbaService(int subId) {
9765 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9766
9767 final long identity = Binder.clearCallingIdentity();
9768 try {
9769 return getGbaManager(subId).getServicePackage();
9770 } finally {
9771 Binder.restoreCallingIdentity(identity);
9772 }
9773 }
9774
9775 /**
9776 * Set the release time for telephony to unbind GbaService.
9777 *
9778 * @param subId The sim that the GbaService is associated with.
9779 * @param interval The release time to unbind GbaService by millisecond.
9780 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9781 */
9782 @Override
9783 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9784 enforceModifyPermission();
9785
9786 final long identity = Binder.clearCallingIdentity();
9787 try {
9788 return getGbaManager(subId).overrideReleaseTime(interval);
9789 } finally {
9790 Binder.restoreCallingIdentity(identity);
9791 }
9792 }
9793
9794 /**
9795 * Return the release time for telephony to unbind GbaService.
9796 *
9797 * @param subId The sim that the GbaService is associated with.
9798 * @return The release time to unbind GbaService by millisecond.
9799 */
9800 @Override
9801 public int getGbaReleaseTime(int subId) {
9802 enforceReadPrivilegedPermission("getGbaReleaseTime");
9803
9804 final long identity = Binder.clearCallingIdentity();
9805 try {
9806 return getGbaManager(subId).getReleaseTime();
9807 } finally {
9808 Binder.restoreCallingIdentity(identity);
9809 }
9810 }
9811
9812 private GbaManager getGbaManager(int subId) {
9813 GbaManager instance = GbaManager.getInstance(subId);
9814 if (instance == null) {
9815 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9816 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9817 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9818 }
9819 return instance;
9820 }
Hui Wang761a6682020-10-31 05:12:53 +00009821
9822 /**
9823 * indicate whether the device and the carrier can support
9824 * RCS VoLTE single registration.
9825 */
9826 @Override
9827 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009828 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9829 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9830 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9831 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009832
9833 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9834 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9835 }
9836
9837 final long identity = Binder.clearCallingIdentity();
9838 try {
9839 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9840 if (rpm != null) {
9841 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9842 }
9843 return false;
9844 } finally {
9845 Binder.restoreCallingIdentity(identity);
9846 }
9847 }
9848
9849 /**
9850 * Register RCS provisioning callback.
9851 */
9852 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009853 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009854 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009855 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009856 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009857 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9858 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009859
9860 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9861 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9862 }
9863 if (!isImsAvailableOnDevice()) {
9864 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9865 "IMS not available on device.");
9866 }
9867
9868 final long identity = Binder.clearCallingIdentity();
9869 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009870 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009871 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -08009872 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9873 "Service not available for the subscription.");
9874 }
Hui Wang761a6682020-10-31 05:12:53 +00009875 } finally {
9876 Binder.restoreCallingIdentity(identity);
9877 }
9878 }
9879
9880 /**
9881 * Unregister RCS provisioning callback.
9882 */
9883 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009884 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009885 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009886 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009887 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009888 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9889 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009890
9891 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9892 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9893 }
9894 if (!isImsAvailableOnDevice()) {
9895 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9896 "IMS not available on device.");
9897 }
9898
9899 final long identity = Binder.clearCallingIdentity();
9900 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009901 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009902 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
9907
9908 /**
9909 * trigger RCS reconfiguration.
9910 */
9911 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009912 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9913 "triggerRcsReconfiguration",
9914 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009915
9916 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9917 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9918 }
9919 if (!isImsAvailableOnDevice()) {
9920 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9921 "IMS not available on device.");
9922 }
9923
9924 final long identity = Binder.clearCallingIdentity();
9925 try {
9926 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9927 } finally {
9928 Binder.restoreCallingIdentity(identity);
9929 }
9930 }
9931
9932 /**
9933 * Provide the client configuration parameters of the RCS application.
9934 */
9935 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009936 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9937 "setRcsClientConfiguration",
9938 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009939
9940 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9941 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9942 }
9943 if (!isImsAvailableOnDevice()) {
9944 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9945 "IMS not available on device.");
9946 }
9947
9948 final long identity = Binder.clearCallingIdentity();
9949
9950 try {
9951 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9952 if (configBinder == null) {
9953 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9954 } else {
9955 configBinder.setRcsClientConfiguration(rcc);
9956 }
9957 } catch (RemoteException e) {
9958 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9959 } finally {
9960 Binder.restoreCallingIdentity(identity);
9961 }
9962 }
9963
9964 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -08009965 * Enables or disables the test mode for RCS VoLTE single registration.
9966 */
9967 @Override
9968 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9969 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9970 "setRcsSingleRegistrationTestModeEnabled");
9971
9972 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9973 }
9974
9975 /**
9976 * Gets the test mode for RCS VoLTE single registration.
9977 */
9978 @Override
9979 public boolean getRcsSingleRegistrationTestModeEnabled() {
9980 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9981 "getRcsSingleRegistrationTestModeEnabled");
9982
9983 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9984 }
9985
9986 /**
Hui Wang761a6682020-10-31 05:12:53 +00009987 * Overrides the config of RCS VoLTE single registration enabled for the device.
9988 */
9989 @Override
9990 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9991 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9992 "setDeviceSingleRegistrationEnabledOverride");
9993 enforceModifyPermission();
9994
9995 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9996 : Boolean.parseBoolean(enabledStr);
9997 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009998 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +00009999 }
10000
10001 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010002 * Sends a device to device communication message. Only usable via shell.
10003 * @param message message to send.
10004 * @param value message value.
10005 */
10006 @Override
10007 public void sendDeviceToDeviceMessage(int message, int value) {
10008 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010009 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010010 enforceModifyPermission();
10011
10012 final long identity = Binder.clearCallingIdentity();
10013 try {
10014 TelephonyConnectionService service =
10015 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10016 if (service == null) {
10017 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10018 return;
10019 }
10020 service.sendTestDeviceToDeviceMessage(message, value);
10021 } finally {
10022 Binder.restoreCallingIdentity(identity);
10023 }
10024 }
10025
Tyler Gunnbabbda02021-02-10 11:05:02 -080010026 /**
10027 * Sets the specified device to device transport active.
10028 * @param transport The transport to set active.
10029 */
10030 @Override
10031 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10033 "setActiveDeviceToDeviceTransport");
10034 enforceModifyPermission();
10035
10036 final long identity = Binder.clearCallingIdentity();
10037 try {
10038 TelephonyConnectionService service =
10039 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10040 if (service == null) {
10041 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10042 return;
10043 }
10044 service.setActiveDeviceToDeviceTransport(transport);
10045 } finally {
10046 Binder.restoreCallingIdentity(identity);
10047 }
10048 }
Tyler Gunn92479152021-01-20 16:30:10 -080010049
10050 /**
Hui Wang761a6682020-10-31 05:12:53 +000010051 * Gets the config of RCS VoLTE single registration enabled for the device.
10052 */
10053 @Override
10054 public boolean getDeviceSingleRegistrationEnabled() {
10055 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10056 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10057 }
10058
10059 /**
10060 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10061 */
10062 @Override
10063 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10064 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10065 "setCarrierSingleRegistrationEnabledOverride");
10066 enforceModifyPermission();
10067
10068 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10069 : Boolean.parseBoolean(enabledStr);
10070 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10071 subId, enabled);
10072 }
10073
10074 /**
10075 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10076 */
10077 @Override
10078 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10079 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10080 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10081 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010082
10083 /**
10084 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10085 * their mobile plan.
10086 */
10087 @Override
10088 public String getMobileProvisioningUrl() {
10089 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10090 final long identity = Binder.clearCallingIdentity();
10091 try {
10092 return getDefaultPhone().getMobileProvisioningUrl();
10093 } finally {
10094 Binder.restoreCallingIdentity(identity);
10095 }
10096 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010097
James.cf Linbcdf8b32021-01-14 16:44:13 +080010098 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010099 * Get the EAB contact from the EAB database.
10100 */
10101 @Override
10102 public String getContactFromEab(String contact) {
10103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10104 enforceModifyPermission();
10105 final long identity = Binder.clearCallingIdentity();
10106 try {
10107 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10108 } finally {
10109 Binder.restoreCallingIdentity(identity);
10110 }
10111 }
10112
10113 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010114 * Remove the EAB contacts from the EAB database.
10115 */
10116 @Override
10117 public int removeContactFromEab(int subId, String contacts) {
10118 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10119 enforceModifyPermission();
10120 final long identity = Binder.clearCallingIdentity();
10121 try {
10122 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10123 } finally {
10124 Binder.restoreCallingIdentity(identity);
10125 }
10126 }
10127
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010128 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010129 public boolean getDeviceUceEnabled() {
10130 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10131 final long identity = Binder.clearCallingIdentity();
10132 try {
10133 return mApp.getDeviceUceEnabled();
10134 } finally {
10135 Binder.restoreCallingIdentity(identity);
10136 }
10137 }
10138
10139 @Override
10140 public void setDeviceUceEnabled(boolean isEnabled) {
10141 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10142 final long identity = Binder.clearCallingIdentity();
10143 try {
10144 mApp.setDeviceUceEnabled(isEnabled);
10145 } finally {
10146 Binder.restoreCallingIdentity(identity);
10147 }
10148 }
10149
Brad Ebinger14d467f2021-02-12 06:18:28 +000010150 /**
10151 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10152 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10153 */
10154 // Used for SHELL command only right now.
10155 @Override
10156 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10157 List<String> featureTags) {
10158 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10159 "addUceRegistrationOverrideShell");
10160 final long identity = Binder.clearCallingIdentity();
10161 try {
10162 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10163 new ArraySet<>(featureTags));
10164 } catch (ImsException e) {
10165 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10166 } finally {
10167 Binder.restoreCallingIdentity(identity);
10168 }
10169 }
10170
10171 /**
10172 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10173 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10174 */
10175 // Used for SHELL command only right now.
10176 @Override
10177 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10178 List<String> featureTags) {
10179 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10180 "removeUceRegistrationOverrideShell");
10181 final long identity = Binder.clearCallingIdentity();
10182 try {
10183 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10184 new ArraySet<>(featureTags));
10185 } catch (ImsException e) {
10186 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10187 } finally {
10188 Binder.restoreCallingIdentity(identity);
10189 }
10190 }
10191
10192 /**
10193 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10194 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10195 */
10196 // Used for SHELL command only right now.
10197 @Override
10198 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10199 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10200 "clearUceRegistrationOverrideShell");
10201 final long identity = Binder.clearCallingIdentity();
10202 try {
10203 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10204 } catch (ImsException e) {
10205 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10206 } finally {
10207 Binder.restoreCallingIdentity(identity);
10208 }
10209 }
10210
10211 /**
10212 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10213 */
10214 // Used for SHELL command only right now.
10215 @Override
10216 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10217 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10218 "getLatestRcsContactUceCapabilityShell");
10219 final long identity = Binder.clearCallingIdentity();
10220 try {
10221 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10222 } catch (ImsException e) {
10223 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10224 } finally {
10225 Binder.restoreCallingIdentity(identity);
10226 }
10227 }
10228
10229 /**
10230 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10231 * device does not have an active PUBLISH.
10232 */
10233 // Used for SHELL command only right now.
10234 @Override
10235 public String getLastUcePidfXmlShell(int subId) {
10236 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10237 final long identity = Binder.clearCallingIdentity();
10238 try {
10239 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10240 } catch (ImsException e) {
10241 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10242 } finally {
10243 Binder.restoreCallingIdentity(identity);
10244 }
10245 }
10246
10247
James.cf Lin4b784aa2021-01-31 03:25:15 +080010248 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010249 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10250 String callingPackage) {
10251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10252 mApp, subId, "setSignalStrengthUpdateRequest");
10253
10254 final int callingUid = Binder.getCallingUid();
10255 // Verify that tha callingPackage belongs to the calling UID
10256 mApp.getSystemService(AppOpsManager.class)
10257 .checkPackage(callingUid, callingPackage);
10258
10259 validateSignalStrengthUpdateRequest(request, callingUid);
10260
10261 final long identity = Binder.clearCallingIdentity();
10262 try {
10263 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10264 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10265
10266 if (result instanceof IllegalStateException) {
10267 throw (IllegalStateException) result;
10268 }
10269 } finally {
10270 Binder.restoreCallingIdentity(identity);
10271 }
10272 }
10273
10274 @Override
10275 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10276 String callingPackage) {
10277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10278 mApp, subId, "clearSignalStrengthUpdateRequest");
10279
10280 final int callingUid = Binder.getCallingUid();
10281 // Verify that tha callingPackage belongs to the calling UID
10282 mApp.getSystemService(AppOpsManager.class)
10283 .checkPackage(callingUid, callingPackage);
10284
10285 final long identity = Binder.clearCallingIdentity();
10286 try {
10287 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10288 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10289
10290 if (result instanceof IllegalStateException) {
10291 throw (IllegalStateException) result;
10292 }
10293 } finally {
10294 Binder.restoreCallingIdentity(identity);
10295 }
10296 }
10297
10298 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10299 int callingUid) {
10300 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10301 // phone/system process do not have further restriction on request
10302 return;
10303 }
10304
10305 // Applications has restrictions on how to use the request:
10306 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10307 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10308 // This is not system caller which has been checked above
10309 throw new IllegalArgumentException(
10310 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10311 }
10312
10313 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10314 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10315 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10316 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10317 || info.isEnabled()) {
10318 throw new IllegalArgumentException(
10319 "Only system can set hide fields in SignalThresholdInfo");
10320 }
10321
10322 // Thresholds length for each RAN need in range. This has been validated in
10323 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10324 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10325 final int[] thresholds = info.getThresholds();
10326 Objects.requireNonNull(thresholds);
10327 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10328 || thresholds.length
10329 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10330 throw new IllegalArgumentException(
10331 "thresholds length is out of range: " + thresholds.length);
10332 }
10333 }
10334 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010335
10336 /**
10337 * Gets the current phone capability.
10338 *
10339 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10340 * @return the PhoneCapability which describes the data connection capability of modem.
10341 * It's used to evaluate possible phone config change, for example from single
10342 * SIM device to multi-SIM device.
10343 */
10344 @Override
10345 public PhoneCapability getPhoneCapability() {
10346 enforceReadPrivilegedPermission("getPhoneCapability");
10347 final long identity = Binder.clearCallingIdentity();
10348 try {
10349 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10350 } finally {
10351 Binder.restoreCallingIdentity(identity);
10352 }
10353 }
Michele Berionne5e411512020-11-13 02:36:59 +000010354
10355 /**
10356 * Prepare TelephonyManager for an unattended reboot. The reboot is
10357 * required to be done shortly after the API is invoked.
10358 */
10359 @Override
10360 @TelephonyManager.PrepareUnattendedRebootResult
10361 public int prepareForUnattendedReboot() {
10362 enforceRebootPermission();
10363
10364 final long identity = Binder.clearCallingIdentity();
10365 try {
10366 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10367 } finally {
10368 Binder.restoreCallingIdentity(identity);
10369 }
10370 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010371
10372 /**
10373 * Request to get the current slicing configuration including URSP rules and
10374 * NSSAIs (configured, allowed and rejected).
10375 *
10376 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10377 */
10378 @Override
10379 public void getSlicingConfig(ResultReceiver callback) {
10380 enforceReadPrivilegedPermission("getSlicingConfig");
10381
10382 final long identity = Binder.clearCallingIdentity();
10383 try {
10384 Phone phone = getDefaultPhone();
10385 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10386 } finally {
10387 Binder.restoreCallingIdentity(identity);
10388 }
10389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010390}