blob: ef314cf2a1981dc2ff15352096174ee81cde33d5 [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;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800385 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800386
Derek Tan89e89d42014-07-08 17:00:10 -0700387 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700388 * Experiment flag to enable erase modem config on reset network, default value is false
389 */
390 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
391 "reset_network_erase_modem_config_enabled";
392
Rambo Wang0f050d82021-02-12 11:43:36 -0800393 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
394
Naina Nallurid63128d2019-09-17 14:10:30 -0700395 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700396 * A request object to use for transmitting data to an ICC.
397 */
398 private static final class IccAPDUArgument {
399 public int channel, cla, command, p1, p2, p3;
400 public String data;
401
402 public IccAPDUArgument(int channel, int cla, int command,
403 int p1, int p2, int p3, String data) {
404 this.channel = channel;
405 this.cla = cla;
406 this.command = command;
407 this.p1 = p1;
408 this.p2 = p2;
409 this.p3 = p3;
410 this.data = data;
411 }
412 }
413
414 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700415 * A request object to use for transmitting data to an ICC.
416 */
417 private static final class ManualNetworkSelectionArgument {
418 public OperatorInfo operatorInfo;
419 public boolean persistSelection;
420
421 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
422 this.operatorInfo = operatorInfo;
423 this.persistSelection = persistSelection;
424 }
425 }
426
427 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
429 * request after sending. The main thread will notify the request when it is complete.
430 */
431 private static final class MainThreadRequest {
432 /** The argument to use for the request */
433 public Object argument;
434 /** The result of the request that is run on the main thread */
435 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800436 // The subscriber id that this request applies to. Defaults to
437 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
438 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439
Nathan Harold92bed182018-10-12 18:16:49 -0700440 // In cases where subId is unavailable, the caller needs to specify the phone.
441 public Phone phone;
442
vagdeviaf9a5b92018-08-15 16:01:53 -0700443 public WorkSource workSource;
444
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 public MainThreadRequest(Object argument) {
446 this.argument = argument;
447 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800448
Nathan Harold92bed182018-10-12 18:16:49 -0700449 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
450 this.argument = argument;
451 if (phone != null) {
452 this.phone = phone;
453 }
454 this.workSource = workSource;
455 }
456
vagdeviaf9a5b92018-08-15 16:01:53 -0700457 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800458 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800459 if (subId != null) {
460 this.subId = subId;
461 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700462 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464 }
465
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800466 private static final class IncomingThirdPartyCallArgs {
467 public final ComponentName component;
468 public final String callId;
469 public final String callerDisplayName;
470
471 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
472 String callerDisplayName) {
473 this.component = component;
474 this.callId = callId;
475 this.callerDisplayName = callerDisplayName;
476 }
477 }
478
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 /**
480 * A handler that processes messages on the main thread in the phone process. Since many
481 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
482 * inbound binder threads to the main thread in the phone process. The Binder thread
483 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
484 * on, which will be notified when the operation completes and will contain the result of the
485 * request.
486 *
487 * <p>If a MainThreadRequest object is provided in the msg.obj field,
488 * note that request.result must be set to something non-null for the calling thread to
489 * unblock.
490 */
491 private final class MainThreadHandler extends Handler {
492 @Override
493 public void handleMessage(Message msg) {
494 MainThreadRequest request;
495 Message onCompleted;
496 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800497 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800499 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700500
501 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 case CMD_HANDLE_USSD_REQUEST: {
503 request = (MainThreadRequest) msg.obj;
504 final Phone phone = getPhoneFromRequest(request);
505 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
506 String ussdRequest = ussdObject.first;
507 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700508
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 if (!isUssdApiAllowed(request.subId)) {
510 // Carrier does not support use of this API, return failure.
511 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
512 UssdResponse response = new UssdResponse(ussdRequest, null);
513 Bundle returnData = new Bundle();
514 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
515 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700516
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 request.result = true;
518 notifyRequester(request);
519 return;
520 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700521
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 try {
523 request.result = phone != null
524 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
525 } catch (CallStateException cse) {
526 request.result = false;
527 }
528 // Wake up the requesting thread
529 notifyRequester(request);
530 break;
pkanwar32d516d2016-10-14 19:37:38 -0700531 }
532
Yorke Lee716f67e2015-06-17 15:39:16 -0700533 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700534 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700535 final Phone phone = getPhoneFromRequest(request);
536 request.result = phone != null ?
537 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
538 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700539 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700540 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800547 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700548 if (uiccCard == null) {
549 loge("iccTransmitApduLogicalChannel: No UICC");
550 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
554 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 iccArgument.channel, iccArgument.cla, iccArgument.command,
557 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700558 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 break;
561
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 ar = (AsyncResult) msg.obj;
564 request = (MainThreadRequest) ar.userObj;
565 if (ar.exception == null && ar.result != null) {
566 request.result = ar.result;
567 } else {
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
569 if (ar.result == null) {
570 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800571 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800573 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 } else {
575 loge("iccTransmitApduLogicalChannel: Unknown exception");
576 }
577 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 break;
580
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
582 request = (MainThreadRequest) msg.obj;
583 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800584 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 if (uiccCard == null) {
586 loge("iccTransmitApduBasicChannel: No UICC");
587 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 } else {
590 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
591 request);
592 uiccCard.iccTransmitApduBasicChannel(
593 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
594 iccArgument.p3, iccArgument.data, onCompleted);
595 }
596 break;
597
598 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
599 ar = (AsyncResult) msg.obj;
600 request = (MainThreadRequest) ar.userObj;
601 if (ar.exception == null && ar.result != null) {
602 request.result = ar.result;
603 } else {
604 request.result = new IccIoResult(0x6F, 0, (byte[])null);
605 if (ar.result == null) {
606 loge("iccTransmitApduBasicChannel: Empty response");
607 } else if (ar.exception instanceof CommandException) {
608 loge("iccTransmitApduBasicChannel: CommandException: " +
609 ar.exception);
610 } else {
611 loge("iccTransmitApduBasicChannel: Unknown exception");
612 }
613 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700614 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 break;
616
617 case CMD_EXCHANGE_SIM_IO:
618 request = (MainThreadRequest) msg.obj;
619 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800620 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 if (uiccCard == null) {
622 loge("iccExchangeSimIO: No UICC");
623 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 } else {
626 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
627 request);
628 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
629 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
630 iccArgument.data, onCompleted);
631 }
632 break;
633
634 case EVENT_EXCHANGE_SIM_IO_DONE:
635 ar = (AsyncResult) msg.obj;
636 request = (MainThreadRequest) ar.userObj;
637 if (ar.exception == null && ar.result != null) {
638 request.result = ar.result;
639 } else {
640 request.result = new IccIoResult(0x6f, 0, (byte[])null);
641 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 break;
644
Derek Tan4d5e5c12014-02-04 11:54:58 -0800645 case CMD_SEND_ENVELOPE:
646 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800647 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 if (uiccCard == null) {
649 loge("sendEnvelopeWithStatus: No UICC");
650 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700651 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 } else {
653 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
654 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
655 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 break;
657
658 case EVENT_SEND_ENVELOPE_DONE:
659 ar = (AsyncResult) msg.obj;
660 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700661 if (ar.exception == null && ar.result != null) {
662 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800663 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700664 request.result = new IccIoResult(0x6F, 0, (byte[])null);
665 if (ar.result == null) {
666 loge("sendEnvelopeWithStatus: Empty response");
667 } else if (ar.exception instanceof CommandException) {
668 loge("sendEnvelopeWithStatus: CommandException: " +
669 ar.exception);
670 } else {
671 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
672 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800673 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800675 break;
676
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 case CMD_OPEN_CHANNEL:
678 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800679 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800680 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700681 if (uiccCard == null) {
682 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800683 request.result = new IccOpenLogicalChannelResponse(-1,
684 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 } else {
687 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800688 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
689 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700690 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 break;
692
693 case EVENT_OPEN_CHANNEL_DONE:
694 ar = (AsyncResult) msg.obj;
695 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 int[] result = (int[]) ar.result;
699 int channelId = result[0];
700 byte[] selectResponse = null;
701 if (result.length > 1) {
702 selectResponse = new byte[result.length - 1];
703 for (int i = 1; i < result.length; ++i) {
704 selectResponse[i - 1] = (byte) result[i];
705 }
706 }
707 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700708 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 if (ar.result == null) {
711 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700713 if (ar.exception != null) {
714 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
715 }
716
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700717 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700718 if (ar.exception instanceof CommandException) {
719 CommandException.Error error =
720 ((CommandException) (ar.exception)).getCommandError();
721 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700722 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700723 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700724 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700725 }
726 }
727 openChannelResp = new IccOpenLogicalChannelResponse(
728 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700729 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700730 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700731 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700732 break;
733
734 case CMD_CLOSE_CHANNEL:
735 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800736 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700737 if (uiccCard == null) {
738 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900739 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700741 } else {
742 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
743 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
744 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 break;
746
747 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800748 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
749 break;
750
751 case CMD_NV_READ_ITEM:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800754 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
755 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800756 break;
757
758 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700763 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800764 request.result = "";
765 if (ar.result == null) {
766 loge("nvReadItem: Empty response");
767 } else if (ar.exception instanceof CommandException) {
768 loge("nvReadItem: CommandException: " +
769 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700770 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800771 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 }
773 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700775 break;
776
Jake Hambye994d462014-02-03 13:10:13 -0800777 case CMD_NV_WRITE_ITEM:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
780 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800781 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700782 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800783 break;
784
785 case EVENT_NV_WRITE_ITEM_DONE:
786 handleNullReturnEvent(msg, "nvWriteItem");
787 break;
788
789 case CMD_NV_WRITE_CDMA_PRL:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800792 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800793 break;
794
795 case EVENT_NV_WRITE_CDMA_PRL_DONE:
796 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
797 break;
798
chen xu6dac5ab2018-10-26 17:39:23 -0700799 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800800 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700801 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800802 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800803 break;
804
chen xu6dac5ab2018-10-26 17:39:23 -0700805 case EVENT_RESET_MODEM_CONFIG_DONE:
806 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800807 break;
808
Sooraj Sasindran37444802020-08-11 10:40:43 -0700809 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
810 request = (MainThreadRequest) msg.obj;
811 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
812 request);
813 Phone phone = getPhoneFromRequest(request);
814 if (phone != null) {
815 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
816 } else {
817 loge("isNRDualConnectivityEnabled: No phone object");
818 request.result = false;
819 notifyRequester(request);
820 }
821 break;
822 }
823
824 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
825 ar = (AsyncResult) msg.obj;
826 request = (MainThreadRequest) ar.userObj;
827 if (ar.exception == null && ar.result != null) {
828 request.result = ar.result;
829 } else {
830 // request.result must be set to something non-null
831 // for the calling thread to unblock
832 if (request.result != null) {
833 request.result = ar.result;
834 } else {
835 request.result = false;
836 }
837 if (ar.result == null) {
838 loge("isNRDualConnectivityEnabled: Empty response");
839 } else if (ar.exception instanceof CommandException) {
840 loge("isNRDualConnectivityEnabled: CommandException: "
841 + ar.exception);
842 } else {
843 loge("isNRDualConnectivityEnabled: Unknown exception");
844 }
845 }
846 notifyRequester(request);
847 break;
848
849 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
850 request = (MainThreadRequest) msg.obj;
851 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
852 Phone phone = getPhoneFromRequest(request);
853 if (phone != null) {
854 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
855 request.workSource);
856 } else {
857 loge("enableNrDualConnectivity: No phone object");
858 request.result =
859 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
860 notifyRequester(request);
861 }
862 break;
863 }
864
865 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null) {
869 request.result =
870 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
871 } else {
872 request.result =
873 TelephonyManager
874 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
875 if (ar.exception instanceof CommandException) {
876 CommandException.Error error =
877 ((CommandException) (ar.exception)).getCommandError();
878 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
879 request.result =
880 TelephonyManager
881 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000882 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
883 request.result =
884 TelephonyManager
885 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700886 }
887 loge("enableNrDualConnectivity" + ": CommandException: "
888 + ar.exception);
889 } else {
890 loge("enableNrDualConnectivity" + ": Unknown exception");
891 }
892 }
893 notifyRequester(request);
894 break;
895 }
896
SongFerngWang3ef3e072020-12-21 16:41:52 +0800897 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800899 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
900 request);
901 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 break;
903
SongFerngWang3ef3e072020-12-21 16:41:52 +0800904 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 ar = (AsyncResult) msg.obj;
906 request = (MainThreadRequest) ar.userObj;
907 if (ar.exception == null && ar.result != null) {
908 request.result = ar.result; // Integer
909 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530910 // request.result must be set to something non-null
911 // for the calling thread to unblock
912 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800913 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800914 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800916 loge("getAllowedNetworkTypesBitmask: CommandException: "
917 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800918 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800919 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 }
921 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700922 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800923 break;
924
SongFerngWang3ef3e072020-12-21 16:41:52 +0800925 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800926 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800927 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
928 request);
929 Pair<Integer, Long> reasonWithNetworkTypes =
930 (Pair<Integer, Long>) request.argument;
931 getPhoneFromRequest(request).setAllowedNetworkTypes(
932 reasonWithNetworkTypes.first,
933 reasonWithNetworkTypes.second,
934 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800935 break;
936
SongFerngWang3ef3e072020-12-21 16:41:52 +0800937 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
938 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800939 break;
940
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000941 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
942 request = (MainThreadRequest)msg.obj;
943 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800944 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000945 break;
946
947 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
948 ar = (AsyncResult)msg.obj;
949 request = (MainThreadRequest)ar.userObj;
950 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700951 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000952 break;
953
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800954 case CMD_SET_VOICEMAIL_NUMBER:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
957 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800958 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
959 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800960 break;
961
962 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
963 handleNullReturnEvent(msg, "setVoicemailNumber");
964 break;
965
Stuart Scott54788802015-03-30 13:18:01 -0700966 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
967 request = (MainThreadRequest) msg.obj;
968 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
969 request);
970 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
971 break;
972
973 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
974 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
975 break;
976
Shishir Agrawal302c8692015-06-19 13:49:39 -0700977 case CMD_PERFORM_NETWORK_SCAN:
978 request = (MainThreadRequest) msg.obj;
979 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
980 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
981 break;
982
Hall Liu27d24262020-09-18 19:04:59 -0700983 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800984 request = (MainThreadRequest) msg.obj;
985 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700986 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
987 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
988 request.argument;
989 int callForwardingReason = args.first;
990 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800991 break;
Hall Liu27d24262020-09-18 19:04:59 -0700992 }
993 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700996 TelephonyManager.CallForwardingInfoCallback callback =
997 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
998 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800999 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001000 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001001 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1002 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1003 // Service Class is a bit mask per 3gpp 27.007. Search for
1004 // any service for voice call.
1005 if ((callForwardInfo.serviceClass
1006 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001007 callForwardingInfo = new CallForwardingInfo(true,
1008 callForwardInfo.reason,
1009 callForwardInfo.number,
1010 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001011 break;
1012 }
1013 }
1014 // Didn't find a call forward info for voice call.
1015 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001016 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1017 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001018 }
Hall Liu27d24262020-09-18 19:04:59 -07001019 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001020 } else {
1021 if (ar.result == null) {
1022 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1023 }
1024 if (ar.exception != null) {
1025 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1026 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001027 int errorCode = TelephonyManager
1028 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001029 if (ar.exception instanceof CommandException) {
1030 CommandException.Error error =
1031 ((CommandException) (ar.exception)).getCommandError();
1032 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001033 errorCode = TelephonyManager
1034 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001035 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001036 errorCode = TelephonyManager
1037 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001038 }
1039 }
Hall Liu27d24262020-09-18 19:04:59 -07001040 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001041 }
Shuo Qian4a594052020-01-23 11:59:30 -08001042 break;
Hall Liu27d24262020-09-18 19:04:59 -07001043 }
Shuo Qian4a594052020-01-23 11:59:30 -08001044
Hall Liu27d24262020-09-18 19:04:59 -07001045 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001046 request = (MainThreadRequest) msg.obj;
1047 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001048 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001049 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001050 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1051 request.argument).first;
1052 request.phone.setCallForwardingOption(
1053 callForwardingInfoToSet.isEnabled()
1054 ? CommandsInterface.CF_ACTION_ENABLE
1055 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001056 callForwardingInfoToSet.getReason(),
1057 callForwardingInfoToSet.getNumber(),
1058 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1059 break;
Hall Liu27d24262020-09-18 19:04:59 -07001060 }
Shuo Qian4a594052020-01-23 11:59:30 -08001061
Hall Liu27d24262020-09-18 19:04:59 -07001062 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001063 ar = (AsyncResult) msg.obj;
1064 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001065 Consumer<Integer> callback =
1066 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1067 request.argument).second;
1068 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001069 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001070 int errorCode = TelephonyManager.CallForwardingInfoCallback
1071 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001072 if (ar.exception instanceof CommandException) {
1073 CommandException.Error error =
1074 ((CommandException) (ar.exception)).getCommandError();
1075 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001076 errorCode = TelephonyManager.CallForwardingInfoCallback
1077 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001078 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001079 errorCode = TelephonyManager.CallForwardingInfoCallback
1080 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001081 }
1082 }
1083 callback.accept(errorCode);
1084 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001085 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001086 }
Shuo Qian4a594052020-01-23 11:59:30 -08001087 break;
Hall Liu27d24262020-09-18 19:04:59 -07001088 }
Shuo Qian4a594052020-01-23 11:59:30 -08001089
Hall Liu27d24262020-09-18 19:04:59 -07001090 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001091 request = (MainThreadRequest) msg.obj;
1092 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1093 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1094 break;
Hall Liu27d24262020-09-18 19:04:59 -07001095 }
Shuo Qian4a594052020-01-23 11:59:30 -08001096
Hall Liu27d24262020-09-18 19:04:59 -07001097 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001098 ar = (AsyncResult) msg.obj;
1099 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001100 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001101 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1102 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001103 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001104 // Service Class is a bit mask per 3gpp 27.007.
1105 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001106 if (callForwardResults.length > 1
1107 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001108 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001109 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001110 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1111 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001112 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001113 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001114 }
1115 } else {
1116 if (ar.result == null) {
1117 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1118 }
1119 if (ar.exception != null) {
1120 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1121 }
1122 if (ar.exception instanceof CommandException) {
1123 CommandException.Error error =
1124 ((CommandException) (ar.exception)).getCommandError();
1125 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1126 callForwardingStatus =
1127 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1128 }
1129 }
1130 }
Hall Liu27d24262020-09-18 19:04:59 -07001131 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001132 break;
Hall Liu27d24262020-09-18 19:04:59 -07001133 }
Shuo Qian4a594052020-01-23 11:59:30 -08001134
Hall Liu27d24262020-09-18 19:04:59 -07001135 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001136 request = (MainThreadRequest) msg.obj;
1137 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001138 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1139 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001140 break;
Hall Liu27d24262020-09-18 19:04:59 -07001141 }
Shuo Qian4a594052020-01-23 11:59:30 -08001142
Hall Liu27d24262020-09-18 19:04:59 -07001143 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001144 ar = (AsyncResult) msg.obj;
1145 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001146 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1147 Consumer<Integer> callback =
1148 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1149 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001150 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001151 if (ar.exception instanceof CommandException) {
1152 CommandException.Error error =
1153 ((CommandException) (ar.exception)).getCommandError();
1154 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1155 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1156 } else {
1157 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1158 }
1159 } else {
1160 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1161 }
1162 } else {
1163 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1164 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001165 }
Shuo Qian4a594052020-01-23 11:59:30 -08001166 break;
Hall Liu27d24262020-09-18 19:04:59 -07001167 }
Shuo Qian4a594052020-01-23 11:59:30 -08001168
Shishir Agrawal302c8692015-06-19 13:49:39 -07001169 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1170 ar = (AsyncResult) msg.obj;
1171 request = (MainThreadRequest) ar.userObj;
1172 CellNetworkScanResult cellScanResult;
1173 if (ar.exception == null && ar.result != null) {
1174 cellScanResult = new CellNetworkScanResult(
1175 CellNetworkScanResult.STATUS_SUCCESS,
1176 (List<OperatorInfo>) ar.result);
1177 } else {
1178 if (ar.result == null) {
1179 loge("getCellNetworkScanResults: Empty response");
1180 }
1181 if (ar.exception != null) {
1182 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1183 }
1184 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1185 if (ar.exception instanceof CommandException) {
1186 CommandException.Error error =
1187 ((CommandException) (ar.exception)).getCommandError();
1188 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1189 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1190 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1191 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1192 }
1193 }
1194 cellScanResult = new CellNetworkScanResult(errorCode, null);
1195 }
1196 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001197 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001198 break;
1199
1200 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1201 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001202 ManualNetworkSelectionArgument selArg =
1203 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001204 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1205 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001206 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1207 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001208 break;
1209
1210 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
1213 if (ar.exception == null) {
1214 request.result = true;
1215 } else {
1216 request.result = false;
1217 loge("setNetworkSelectionModeManual " + ar.exception);
1218 }
1219 notifyRequester(request);
1220 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001221 break;
1222
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001223 case CMD_GET_MODEM_ACTIVITY_INFO:
1224 request = (MainThreadRequest) msg.obj;
1225 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001226 if (defaultPhone != null) {
1227 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001228 } else {
1229 ResultReceiver result = (ResultReceiver) request.argument;
1230 Bundle bundle = new Bundle();
1231 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001232 new ModemActivityInfo(0, 0, 0,
1233 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001234 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001235 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001236 break;
1237
Hall Liud0f208c2020-10-14 16:54:44 -07001238 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001239 ar = (AsyncResult) msg.obj;
1240 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001241 ResultReceiver result = (ResultReceiver) request.argument;
1242
Hall Liud0f208c2020-10-14 16:54:44 -07001243 ModemActivityInfo ret = null;
1244 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001245 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001246 // Update the last modem activity info and the result of the request.
1247 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1248 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001249 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001250 int[] txTimeMs = info.getTransmitTimeMillis();
1251 int[] lastModemTxTimeMs = mLastModemActivityInfo
1252 .getTransmitTimeMillis();
1253 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1254 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1255 }
Hall Liu49656c02020-10-09 19:00:11 -07001256 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001257 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1258 + mLastModemActivityInfo.getSleepTimeMillis());
1259 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1260 + mLastModemActivityInfo.getIdleTimeMillis());
1261 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1262 mLastModemActivityInfo.setReceiveTimeMillis(
1263 info.getReceiveTimeMillis()
1264 + mLastModemActivityInfo.getReceiveTimeMillis());
1265 }
Hall Liu49656c02020-10-09 19:00:11 -07001266 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001267 mLastModemActivityInfo.getSleepTimeMillis(),
1268 mLastModemActivityInfo.getIdleTimeMillis(),
1269 mLastModemActivityInfo.getTransmitTimeMillis(),
1270 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001271 } else {
1272 if (ar.result == null) {
1273 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001274 error = TelephonyManager.ModemActivityInfoException
1275 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001276 } else if (ar.exception instanceof CommandException) {
1277 loge("queryModemActivityInfo: CommandException: " +
1278 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001279 error = TelephonyManager.ModemActivityInfoException
1280 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001281 } else {
1282 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001283 error = TelephonyManager.ModemActivityInfoException
1284 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001285 }
1286 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001287 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001288 if (ret != null) {
1289 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1290 } else {
1291 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1292 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001293 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001294 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001295 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001296 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001297
Meng Wang1a7c35a2016-05-05 20:56:15 -07001298 case CMD_SET_ALLOWED_CARRIERS:
1299 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001300 CarrierRestrictionRules argument =
1301 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001302 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001303 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 break;
1305
1306 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1307 ar = (AsyncResult) msg.obj;
1308 request = (MainThreadRequest) ar.userObj;
1309 if (ar.exception == null && ar.result != null) {
1310 request.result = ar.result;
1311 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001312 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1313 if (ar.exception instanceof CommandException) {
1314 loge("setAllowedCarriers: CommandException: " + ar.exception);
1315 CommandException.Error error =
1316 ((CommandException) (ar.exception)).getCommandError();
1317 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1318 request.result =
1319 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1320 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001321 } else {
1322 loge("setAllowedCarriers: Unknown exception");
1323 }
1324 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001325 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001326 break;
1327
1328 case CMD_GET_ALLOWED_CARRIERS:
1329 request = (MainThreadRequest) msg.obj;
1330 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001331 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001332 break;
1333
1334 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1335 ar = (AsyncResult) msg.obj;
1336 request = (MainThreadRequest) ar.userObj;
1337 if (ar.exception == null && ar.result != null) {
1338 request.result = ar.result;
1339 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001340 request.result = new IllegalStateException(
1341 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001342 if (ar.result == null) {
1343 loge("getAllowedCarriers: Empty response");
1344 } else if (ar.exception instanceof CommandException) {
1345 loge("getAllowedCarriers: CommandException: " +
1346 ar.exception);
1347 } else {
1348 loge("getAllowedCarriers: Unknown exception");
1349 }
1350 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001351 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001352 break;
1353
Nathan Haroldb3014052017-01-25 15:57:32 -08001354 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1355 ar = (AsyncResult) msg.obj;
1356 request = (MainThreadRequest) ar.userObj;
1357 if (ar.exception == null && ar.result != null) {
1358 request.result = ar.result;
1359 } else {
1360 request.result = new IllegalArgumentException(
1361 "Failed to retrieve Forbidden Plmns");
1362 if (ar.result == null) {
1363 loge("getForbiddenPlmns: Empty response");
1364 } else {
1365 loge("getForbiddenPlmns: Unknown exception");
1366 }
1367 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001368 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001369 break;
1370
1371 case CMD_GET_FORBIDDEN_PLMNS:
1372 request = (MainThreadRequest) msg.obj;
1373 uiccCard = getUiccCardFromRequest(request);
1374 if (uiccCard == null) {
1375 loge("getForbiddenPlmns() UiccCard is null");
1376 request.result = new IllegalArgumentException(
1377 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001378 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001379 break;
1380 }
1381 Integer appType = (Integer) request.argument;
1382 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1383 if (uiccApp == null) {
1384 loge("getForbiddenPlmns() no app with specified type -- "
1385 + appType);
1386 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001387 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001388 break;
1389 } else {
1390 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1391 + " specified type -- " + appType);
1392 }
1393 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1394 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1395 onCompleted);
1396 break;
1397
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001398 case CMD_SWITCH_SLOTS:
1399 request = (MainThreadRequest) msg.obj;
1400 int[] physicalSlots = (int[]) request.argument;
1401 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1402 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1403 break;
1404
1405 case EVENT_SWITCH_SLOTS_DONE:
1406 ar = (AsyncResult) msg.obj;
1407 request = (MainThreadRequest) ar.userObj;
1408 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001409 notifyRequester(request);
1410 break;
1411 case CMD_GET_NETWORK_SELECTION_MODE:
1412 request = (MainThreadRequest) msg.obj;
1413 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1414 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1415 break;
1416
1417 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1418 ar = (AsyncResult) msg.obj;
1419 request = (MainThreadRequest) ar.userObj;
1420 if (ar.exception != null) {
1421 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1422 } else {
1423 int mode = ((int[]) ar.result)[0];
1424 if (mode == 0) {
1425 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1426 } else {
1427 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1428 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001429 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001430 notifyRequester(request);
1431 break;
1432 case CMD_GET_CDMA_ROAMING_MODE:
1433 request = (MainThreadRequest) msg.obj;
1434 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1435 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1436 break;
1437 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1438 ar = (AsyncResult) msg.obj;
1439 request = (MainThreadRequest) ar.userObj;
1440 if (ar.exception != null) {
1441 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1442 } else {
1443 request.result = ((int[]) ar.result)[0];
1444 }
1445 notifyRequester(request);
1446 break;
1447 case CMD_SET_CDMA_ROAMING_MODE:
1448 request = (MainThreadRequest) msg.obj;
1449 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1450 int mode = (int) request.argument;
1451 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1452 break;
1453 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
1456 request.result = ar.exception == null;
1457 notifyRequester(request);
1458 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001459 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1460 request = (MainThreadRequest) msg.obj;
1461 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1462 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1463 break;
1464 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1465 ar = (AsyncResult) msg.obj;
1466 request = (MainThreadRequest) ar.userObj;
1467 if (ar.exception != null) {
1468 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1469 } else {
1470 request.result = ((int[]) ar.result)[0];
1471 }
1472 notifyRequester(request);
1473 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001474 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1475 request = (MainThreadRequest) msg.obj;
1476 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1477 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001478 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1479 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001480 break;
1481 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1482 ar = (AsyncResult) msg.obj;
1483 request = (MainThreadRequest) ar.userObj;
1484 request.result = ar.exception == null;
1485 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001486 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001487 case CMD_GET_ALL_CELL_INFO:
1488 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001490 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 case EVENT_GET_ALL_CELL_INFO_DONE:
1493 ar = (AsyncResult) msg.obj;
1494 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001495 // If a timeout occurs, the response will be null
1496 request.result = (ar.exception == null && ar.result != null)
1497 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001498 synchronized (request) {
1499 request.notifyAll();
1500 }
1501 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001502 case CMD_REQUEST_CELL_INFO_UPDATE:
1503 request = (MainThreadRequest) msg.obj;
1504 request.phone.requestCellInfoUpdate(request.workSource,
1505 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1506 break;
1507 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1508 ar = (AsyncResult) msg.obj;
1509 request = (MainThreadRequest) ar.userObj;
1510 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1511 try {
1512 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001513 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001514 cb.onError(
1515 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1516 ar.exception.getClass().getName(),
1517 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001518 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001519 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001520 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001521 } else {
1522 // use the result as returned
1523 cb.onCellInfo((List<CellInfo>) ar.result);
1524 }
1525 } catch (RemoteException re) {
1526 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1527 }
1528 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001529 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001530 request = (MainThreadRequest) msg.obj;
1531 WorkSource ws = (WorkSource) request.argument;
1532 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001533 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001534 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001535 }
1536 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001537 ar = (AsyncResult) msg.obj;
1538 request = (MainThreadRequest) ar.userObj;
1539 if (ar.exception == null) {
1540 request.result = ar.result;
1541 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001542 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001543 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001544 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001545 }
1546
1547 synchronized (request) {
1548 request.notifyAll();
1549 }
1550 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001551 }
chen xu6dac5ab2018-10-26 17:39:23 -07001552 case CMD_MODEM_REBOOT:
1553 request = (MainThreadRequest) msg.obj;
1554 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001555 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001556 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001557 case EVENT_CMD_MODEM_REBOOT_DONE:
1558 handleNullReturnEvent(msg, "rebootModem");
1559 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001560 case CMD_REQUEST_ENABLE_MODEM:
1561 request = (MainThreadRequest) msg.obj;
1562 boolean enable = (boolean) request.argument;
1563 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001564 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001565 PhoneConfigurationManager.getInstance()
1566 .enablePhone(request.phone, enable, onCompleted);
1567 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001568 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001569 ar = (AsyncResult) msg.obj;
1570 request = (MainThreadRequest) ar.userObj;
1571 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001572 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001573 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001574 if ((boolean) request.result) {
1575 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1576 updateModemStateMetrics();
1577 } else {
1578 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1579 + ar.exception);
1580 }
1581 notifyRequester(request);
1582 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001583 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001584 case CMD_GET_MODEM_STATUS:
1585 request = (MainThreadRequest) msg.obj;
1586 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1587 PhoneConfigurationManager.getInstance()
1588 .getPhoneStatusFromModem(request.phone, onCompleted);
1589 break;
1590 case EVENT_GET_MODEM_STATUS_DONE:
1591 ar = (AsyncResult) msg.obj;
1592 request = (MainThreadRequest) ar.userObj;
1593 int id = request.phone.getPhoneId();
1594 if (ar.exception == null && ar.result != null) {
1595 request.result = ar.result;
1596 //update the cache as modem status has changed
1597 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1598 (boolean) request.result);
1599 } else {
1600 // Return true if modem status cannot be retrieved. For most cases,
1601 // modem status is on. And for older version modems, GET_MODEM_STATUS
1602 // and disable modem are not supported. Modem is always on.
1603 // TODO: this should be fixed in R to support a third
1604 // status UNKNOWN b/131631629
1605 request.result = true;
1606 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1607 + ar.exception);
1608 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001609 notifyRequester(request);
1610 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001611 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1612 request = (MainThreadRequest) msg.obj;
1613 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1614 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1615 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1616 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1617 break;
1618 }
1619 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1620 ar = (AsyncResult) msg.obj;
1621 request = (MainThreadRequest) ar.userObj;
1622 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1623 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1624 args.second.accept(ar.exception == null);
1625 notifyRequester(request);
1626 break;
1627 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001628 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1629 request = (MainThreadRequest) msg.obj;
1630 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1631 Phone phone = getPhoneFromRequest(request);
1632 if (phone != null) {
1633 phone.getSystemSelectionChannels(onCompleted);
1634 } else {
1635 loge("getSystemSelectionChannels: No phone object");
1636 request.result = new ArrayList<RadioAccessSpecifier>();
1637 notifyRequester(request);
1638 }
1639 break;
1640 }
1641 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1642 ar = (AsyncResult) msg.obj;
1643 request = (MainThreadRequest) ar.userObj;
1644 if (ar.exception == null && ar.result != null) {
1645 request.result = ar.result;
1646 } else {
1647 request.result = new IllegalArgumentException(
1648 "Failed to retrieve system selection channels");
1649 if (ar.result == null) {
1650 loge("getSystemSelectionChannels: Empty response");
1651 } else {
1652 loge("getSystemSelectionChannels: Unknown exception");
1653 }
1654 }
1655 notifyRequester(request);
1656 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001657 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1658 ar = (AsyncResult) msg.obj;
1659 request = (MainThreadRequest) ar.userObj;
1660 if (ar.exception == null && ar.result != null) {
1661 request.result = ar.result;
1662 } else {
1663 request.result = -1;
1664 loge("Failed to set Forbidden Plmns");
1665 if (ar.result == null) {
1666 loge("setForbidenPlmns: Empty response");
1667 } else if (ar.exception != null) {
1668 loge("setForbiddenPlmns: Exception: " + ar.exception);
1669 request.result = -1;
1670 } else {
1671 loge("setForbiddenPlmns: Unknown exception");
1672 }
1673 }
1674 notifyRequester(request);
1675 break;
1676 case CMD_SET_FORBIDDEN_PLMNS:
1677 request = (MainThreadRequest) msg.obj;
1678 uiccCard = getUiccCardFromRequest(request);
1679 if (uiccCard == null) {
1680 loge("setForbiddenPlmns: UiccCard is null");
1681 request.result = -1;
1682 notifyRequester(request);
1683 break;
1684 }
1685 Pair<Integer, List<String>> setFplmnsArgs =
1686 (Pair<Integer, List<String>>) request.argument;
1687 appType = setFplmnsArgs.first;
1688 List<String> fplmns = setFplmnsArgs.second;
1689 uiccApp = uiccCard.getApplicationByType(appType);
1690 if (uiccApp == null) {
1691 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1692 request.result = -1;
1693 loge("Failed to get UICC App");
1694 notifyRequester(request);
1695 } else {
1696 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1697 ((SIMRecords) uiccApp.getIccRecords())
1698 .setForbiddenPlmns(onCompleted, fplmns);
1699 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001700 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001701 case CMD_ERASE_MODEM_CONFIG:
1702 request = (MainThreadRequest) msg.obj;
1703 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1704 defaultPhone.eraseModemConfig(onCompleted);
1705 break;
1706 case EVENT_ERASE_MODEM_CONFIG_DONE:
1707 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001708 break;
zoey chene02881a2019-12-30 16:11:23 +08001709
1710 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1711 request = (MainThreadRequest) msg.obj;
1712 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1713 Pair<String, String> changed = (Pair<String, String>) request.argument;
1714 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1715 changed.first, changed.second, onCompleted);
1716 break;
1717 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1718 ar = (AsyncResult) msg.obj;
1719 request = (MainThreadRequest) ar.userObj;
1720 if (ar.exception == null) {
1721 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001722 // If the operation is successful, update the PIN storage
1723 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1724 int phoneId = getPhoneFromRequest(request).getPhoneId();
1725 UiccController.getInstance().getPinStorage()
1726 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001727 } else {
1728 request.result = msg.arg1;
1729 }
1730 notifyRequester(request);
1731 break;
1732
Michele Berionne5e411512020-11-13 02:36:59 +00001733 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001734 request = (MainThreadRequest) msg.obj;
1735 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1736 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1737 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1738 enabled.first, enabled.second, onCompleted);
1739 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001740 }
zoey chene02881a2019-12-30 16:11:23 +08001741 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1742 ar = (AsyncResult) msg.obj;
1743 request = (MainThreadRequest) ar.userObj;
1744 if (ar.exception == null) {
1745 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001746 // If the operation is successful, update the PIN storage
1747 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1748 int phoneId = getPhoneFromRequest(request).getPhoneId();
1749 if (enabled.first) {
1750 UiccController.getInstance().getPinStorage()
1751 .storePin(enabled.second, phoneId);
1752 } else {
1753 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1754 }
zoey chene02881a2019-12-30 16:11:23 +08001755 } else {
1756 request.result = msg.arg1;
1757 }
Michele Berionne5e411512020-11-13 02:36:59 +00001758
1759
zoey chene02881a2019-12-30 16:11:23 +08001760 notifyRequester(request);
1761 break;
1762
Peter Wangdafb9ac2020-01-15 14:13:38 -08001763 case MSG_NOTIFY_USER_ACTIVITY:
1764 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001765 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001766 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1767 getDefaultPhone().getContext().sendBroadcastAsUser(
1768 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1769 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001770
1771 case CMD_SET_DATA_THROTTLING: {
1772 request = (MainThreadRequest) msg.obj;
1773 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1774 DataThrottlingRequest dataThrottlingRequest =
1775 (DataThrottlingRequest) request.argument;
1776 Phone phone = getPhoneFromRequest(request);
1777 if (phone != null) {
1778 phone.setDataThrottling(onCompleted,
1779 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1780 dataThrottlingRequest.getCompletionDurationMillis());
1781 } else {
1782 loge("setDataThrottling: No phone object");
1783 request.result =
1784 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1785 notifyRequester(request);
1786 }
1787
1788 break;
1789 }
1790 case EVENT_SET_DATA_THROTTLING_DONE:
1791 ar = (AsyncResult) msg.obj;
1792 request = (MainThreadRequest) ar.userObj;
1793
1794 if (ar.exception == null) {
1795 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1796 } else if (ar.exception instanceof CommandException) {
1797 loge("setDataThrottling: CommandException: " + ar.exception);
1798 CommandException.Error error =
1799 ((CommandException) (ar.exception)).getCommandError();
1800
1801 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1802 request.result = TelephonyManager
1803 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1804 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1805 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001806 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1807 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001808 } else {
1809 request.result =
1810 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1811 }
1812 } else {
1813 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1814 }
1815 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1816 notifyRequester(request);
1817 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001818
1819 case CMD_SET_SIM_POWER: {
1820 request = (MainThreadRequest) msg.obj;
1821 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1822 request = (MainThreadRequest) msg.obj;
1823 int stateToSet =
1824 ((Pair<Integer, IIntegerConsumer>)
1825 request.argument).first;
1826 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1827 break;
1828 }
1829 case EVENT_SET_SIM_POWER_DONE: {
1830 ar = (AsyncResult) msg.obj;
1831 request = (MainThreadRequest) ar.userObj;
1832 IIntegerConsumer callback =
1833 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1834 if (ar.exception != null) {
1835 loge("setSimPower exception: " + ar.exception);
1836 int errorCode = TelephonyManager.CallForwardingInfoCallback
1837 .RESULT_ERROR_UNKNOWN;
1838 if (ar.exception instanceof CommandException) {
1839 CommandException.Error error =
1840 ((CommandException) (ar.exception)).getCommandError();
1841 if (error == CommandException.Error.SIM_ERR) {
1842 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1843 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1844 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1845 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1846 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1847 } else {
1848 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1849 }
1850 }
1851 try {
1852 callback.accept(errorCode);
1853 } catch (RemoteException e) {
1854 // Ignore if the remote process is no longer available to call back.
1855 Log.w(LOG_TAG, "setSimPower: callback not available.");
1856 }
1857 } else {
1858 try {
1859 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1860 } catch (RemoteException e) {
1861 // Ignore if the remote process is no longer available to call back.
1862 Log.w(LOG_TAG, "setSimPower: callback not available.");
1863 }
1864 }
1865 break;
1866 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001867 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1868 request = (MainThreadRequest) msg.obj;
1869
1870 final Phone phone = getPhoneFromRequest(request);
1871 if (phone == null || phone.getServiceStateTracker() == null) {
1872 request.result = new IllegalStateException("Phone or SST is null");
1873 notifyRequester(request);
1874 break;
1875 }
1876
1877 Pair<Integer, SignalStrengthUpdateRequest> pair =
1878 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1879 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1880 request);
1881 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1882 request.subId, pair.first /*callingUid*/,
1883 pair.second /*request*/, onCompleted);
1884 break;
1885 }
1886 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1887 ar = (AsyncResult) msg.obj;
1888 request = (MainThreadRequest) ar.userObj;
1889 // request.result will be the exception of ar if present, true otherwise.
1890 // Be cautious not to leave result null which will wait() forever
1891 request.result = ar.exception != null ? ar.exception : true;
1892 notifyRequester(request);
1893 break;
1894 }
1895 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1896 request = (MainThreadRequest) msg.obj;
1897
1898 Phone phone = getPhoneFromRequest(request);
1899 if (phone == null || phone.getServiceStateTracker() == null) {
1900 request.result = new IllegalStateException("Phone or SST is null");
1901 notifyRequester(request);
1902 break;
1903 }
1904
1905 Pair<Integer, SignalStrengthUpdateRequest> pair =
1906 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1907 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1908 request);
1909 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1910 request.subId, pair.first /*callingUid*/,
1911 pair.second /*request*/, onCompleted);
1912 break;
1913 }
1914 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1915 ar = (AsyncResult) msg.obj;
1916 request = (MainThreadRequest) ar.userObj;
1917 request.result = ar.exception != null ? ar.exception : true;
1918 notifyRequester(request);
1919 break;
1920 }
Jordan Liu109698e2020-11-24 14:50:34 -08001921
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001922 case CMD_GET_SLICING_CONFIG: {
1923 request = (MainThreadRequest) msg.obj;
1924 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1925 request.phone.getSlicingConfig(onCompleted);
1926 break;
1927 }
1928 case EVENT_GET_SLICING_CONFIG_DONE: {
1929 ar = (AsyncResult) msg.obj;
1930 request = (MainThreadRequest) ar.userObj;
1931 ResultReceiver result = (ResultReceiver) request.argument;
1932
1933 SlicingConfig slicingConfig = null;
1934 Bundle bundle = new Bundle();
1935 int resultCode = 0;
1936 if (ar.exception != null) {
1937 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1938 + ar.exception);
1939 resultCode = TelephonyManager.SlicingException.ERROR_MODEM_ERROR;
1940 } else if (ar.result == null) {
1941 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
1942 resultCode = TelephonyManager.SlicingException.ERROR_TIMEOUT;
1943 } else {
1944 // use the result as returned
1945 resultCode = TelephonyManager.SlicingException.SUCCESS;
1946 slicingConfig = (SlicingConfig) ar.result;
1947 }
1948
1949 if (slicingConfig == null) {
1950 slicingConfig = new SlicingConfig();
1951 }
1952 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1953 result.send(resultCode, bundle);
1954 notifyRequester(request);
1955 break;
1956 }
1957
Michele Berionne5e411512020-11-13 02:36:59 +00001958 case CMD_PREPARE_UNATTENDED_REBOOT:
1959 request = (MainThreadRequest) msg.obj;
1960 request.result =
1961 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1962 notifyRequester(request);
1963 break;
1964
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 default:
1966 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1967 break;
1968 }
1969 }
Jake Hambye994d462014-02-03 13:10:13 -08001970
Pengquan Menga1bb6272018-09-06 09:59:22 -07001971 private void notifyRequester(MainThreadRequest request) {
1972 synchronized (request) {
1973 request.notifyAll();
1974 }
1975 }
1976
Jake Hambye994d462014-02-03 13:10:13 -08001977 private void handleNullReturnEvent(Message msg, String command) {
1978 AsyncResult ar = (AsyncResult) msg.obj;
1979 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1980 if (ar.exception == null) {
1981 request.result = true;
1982 } else {
1983 request.result = false;
1984 if (ar.exception instanceof CommandException) {
1985 loge(command + ": CommandException: " + ar.exception);
1986 } else {
1987 loge(command + ": Unknown exception");
1988 }
1989 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001990 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 }
1993
1994 /**
1995 * Posts the specified command to be executed on the main thread,
1996 * waits for the request to complete, and returns the result.
1997 * @see #sendRequestAsync
1998 */
1999 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002000 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2001 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002002 }
2003
2004 /**
2005 * Posts the specified command to be executed on the main thread,
2006 * waits for the request to complete, and returns the result.
2007 * @see #sendRequestAsync
2008 */
2009 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2010 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002011 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002012 }
2013
2014 /**
2015 * Posts the specified command to be executed on the main thread,
2016 * waits for the request to complete, and returns the result.
2017 * @see #sendRequestAsync
2018 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002019 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002020 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2021 }
2022
2023 /**
2024 * Posts the specified command to be executed on the main thread,
2025 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2026 * if not timeout or null otherwise.
2027 * @see #sendRequestAsync
2028 */
2029 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2030 long timeoutInMs) {
2031 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002032 }
2033
2034 /**
2035 * Posts the specified command to be executed on the main thread,
2036 * waits for the request to complete, and returns the result.
2037 * @see #sendRequestAsync
2038 */
Nathan Harold92bed182018-10-12 18:16:49 -07002039 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002040 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002041 }
2042
2043 /**
2044 * Posts the specified command to be executed on the main thread,
2045 * waits for the request to complete, and returns the result.
2046 * @see #sendRequestAsync
2047 */
2048 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002049 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2050 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002051 }
2052
2053 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002054 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2055 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2056 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002057 * @see #sendRequestAsync
2058 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002059 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2060 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2062 throw new RuntimeException("This method will deadlock if called from the main thread.");
2063 }
2064
Nathan Harold92bed182018-10-12 18:16:49 -07002065 MainThreadRequest request = null;
2066 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2067 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2068 } else if (phone != null) {
2069 request = new MainThreadRequest(argument, phone, workSource);
2070 } else {
2071 request = new MainThreadRequest(argument, subId, workSource);
2072 }
2073
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 Message msg = mMainThreadHandler.obtainMessage(command, request);
2075 msg.sendToTarget();
2076
Rambo Wang0f050d82021-02-12 11:43:36 -08002077
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002079 if (timeoutInMs >= 0) {
2080 // Wait for at least timeoutInMs before returning null request result
2081 long now = SystemClock.elapsedRealtime();
2082 long deadline = now + timeoutInMs;
2083 while (request == null && now < deadline) {
2084 try {
2085 request.wait(deadline - now);
2086 } catch (InterruptedException e) {
2087 // Do nothing, go back and check if request is completed or timeout
2088 } finally {
2089 now = SystemClock.elapsedRealtime();
2090 }
2091 }
2092 } else {
2093 // Wait for the request to complete
2094 while (request.result == null) {
2095 try {
2096 request.wait();
2097 } catch (InterruptedException e) {
2098 // Do nothing, go back and wait until the request is complete
2099 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 }
2101 }
2102 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002103 if (request.result == null) {
2104 Log.wtf(LOG_TAG,
2105 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 return request.result;
2108 }
2109
2110 /**
2111 * Asynchronous ("fire and forget") version of sendRequest():
2112 * Posts the specified command to be executed on the main thread, and
2113 * returns immediately.
2114 * @see #sendRequest
2115 */
2116 private void sendRequestAsync(int command) {
2117 mMainThreadHandler.sendEmptyMessage(command);
2118 }
2119
2120 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002121 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002122 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002123 */
2124 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002125 sendRequestAsync(command, argument, null, null);
2126 }
2127
2128 /**
2129 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2130 * @see {@link #sendRequest(int,Object)}
2131 */
2132 private void sendRequestAsync(
2133 int command, Object argument, Phone phone, WorkSource workSource) {
2134 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002135 Message msg = mMainThreadHandler.obtainMessage(command, request);
2136 msg.sendToTarget();
2137 }
2138
2139 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 * Initialize the singleton PhoneInterfaceManager instance.
2141 * This is only done once, at startup, from PhoneApp.onCreate().
2142 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002143 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144 synchronized (PhoneInterfaceManager.class) {
2145 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002146 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 } else {
2148 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2149 }
2150 return sInstance;
2151 }
2152 }
2153
2154 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002155 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002158 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002159 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2161 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002162 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002163 mTelephonySharedPreferences =
2164 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002165 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002166 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002167 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002168 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002169
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 publish();
2171 }
2172
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002173 private Phone getDefaultPhone() {
2174 Phone thePhone = getPhone(getDefaultSubscription());
2175 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2176 }
2177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 private void publish() {
2179 if (DBG) log("publish: " + this);
2180
Peter Wangc035ce42020-01-08 21:00:22 -08002181 TelephonyFrameworkInitializer
2182 .getTelephonyServiceManager()
2183 .getTelephonyServiceRegisterer()
2184 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
Stuart Scott584921c2015-01-15 17:10:34 -08002187 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002188 if (request.phone != null) {
2189 return request.phone;
2190 } else {
2191 return getPhoneFromSubId(request.subId);
2192 }
2193 }
2194
2195 private Phone getPhoneFromSubId(int subId) {
2196 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2197 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002198 }
2199
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002200 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2201 Phone phone = getPhoneFromRequest(request);
2202 return phone == null ? null :
2203 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2204 }
2205
Wink Saville36469e72014-06-11 15:17:00 -07002206 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002207 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002208 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002209 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210
Naina Nallurid63128d2019-09-17 14:10:30 -07002211 private void sendEraseModemConfig(Phone phone) {
2212 if (phone != null) {
2213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2214 mApp, phone.getSubId(), "eraseModemConfig");
2215 final long identity = Binder.clearCallingIdentity();
2216 try {
2217 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2218 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2219 } finally {
2220 Binder.restoreCallingIdentity(identity);
2221 }
2222 }
2223 }
2224
Peter Wang44b186e2020-01-13 23:33:09 -08002225 private boolean isImsAvailableOnDevice() {
2226 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2227 if (pm == null) {
2228 // For some reason package manger is not available.. This will fail internally anyway,
2229 // so do not throw error and allow.
2230 return true;
2231 }
2232 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2233 }
2234
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002236 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002237 }
2238
Wink Savilleb564aae2014-10-23 10:18:09 -07002239 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 if (DBG) log("dial: " + number);
2241 // No permission check needed here: This is just a wrapper around the
2242 // ACTION_DIAL intent, which is available to any app since it puts up
2243 // the UI before it does anything.
2244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002245 final long identity = Binder.clearCallingIdentity();
2246 try {
2247 String url = createTelUrl(number);
2248 if (url == null) {
2249 return;
2250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002252 // PENDING: should we just silently fail if phone is offhook or ringing?
2253 PhoneConstants.State state = mCM.getState(subId);
2254 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2255 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2256 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2257 mApp.startActivity(intent);
2258 }
2259 } finally {
2260 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 }
2262 }
2263
2264 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002265 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002266 }
2267
Wink Savilleb564aae2014-10-23 10:18:09 -07002268 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 if (DBG) log("call: " + number);
2270
2271 // This is just a wrapper around the ACTION_CALL intent, but we still
2272 // need to do a permission check since we're calling startActivity()
2273 // from the context of the phone app.
2274 enforceCallPermission();
2275
Jordan Liu1617b712019-07-10 15:06:26 -07002276 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 != AppOpsManager.MODE_ALLOWED) {
2278 return;
2279 }
2280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281 final long identity = Binder.clearCallingIdentity();
2282 try {
2283 String url = createTelUrl(number);
2284 if (url == null) {
2285 return;
2286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002288 boolean isValid = false;
2289 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2290 if (slist != null) {
2291 for (SubscriptionInfo subInfoRecord : slist) {
2292 if (subInfoRecord.getSubscriptionId() == subId) {
2293 isValid = true;
2294 break;
2295 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002296 }
Wink Saville08874612014-08-31 19:19:58 -07002297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 if (!isValid) {
2299 return;
2300 }
Wink Saville08874612014-08-31 19:19:58 -07002301
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2303 intent.putExtra(SUBSCRIPTION_KEY, subId);
2304 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2305 mApp.startActivity(intent);
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
2308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
Wink Savilleb564aae2014-10-23 10:18:09 -07002311 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002312 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002313 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2314 }
2315
Wink Savilleb564aae2014-10-23 10:18:09 -07002316 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002317 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002318 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2319 }
2320
Wink Savilleb564aae2014-10-23 10:18:09 -07002321 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002323
2324 final long identity = Binder.clearCallingIdentity();
2325 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002326 Phone phone = getPhone(subId);
2327 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328 checkSimPin.start();
2329 return checkSimPin.unlockSim(null, pin);
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334
Wink Savilleb564aae2014-10-23 10:18:09 -07002335 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337
2338 final long identity = Binder.clearCallingIdentity();
2339 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002340 Phone phone = getPhone(subId);
2341 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342 checkSimPuk.start();
2343 return checkSimPuk.unlockSim(puk, pin);
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
2346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 }
2348
2349 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002350 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 * a synchronous one.
2352 */
2353 private static class UnlockSim extends Thread {
2354
2355 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002356 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002357
2358 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002359 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2360 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361
2362 // For replies from SimCard interface
2363 private Handler mHandler;
2364
2365 // For async handler to identify request type
2366 private static final int SUPPLY_PIN_COMPLETE = 100;
2367
Michele Berionne5e411512020-11-13 02:36:59 +00002368 UnlockSim(int phoneId, IccCard simCard) {
2369 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 mSimCard = simCard;
2371 }
2372
2373 @Override
2374 public void run() {
2375 Looper.prepare();
2376 synchronized (UnlockSim.this) {
2377 mHandler = new Handler() {
2378 @Override
2379 public void handleMessage(Message msg) {
2380 AsyncResult ar = (AsyncResult) msg.obj;
2381 switch (msg.what) {
2382 case SUPPLY_PIN_COMPLETE:
2383 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2384 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002385 mRetryCount = msg.arg1;
2386 if (ar.exception != null) {
2387 if (ar.exception instanceof CommandException &&
2388 ((CommandException)(ar.exception)).getCommandError()
2389 == CommandException.Error.PASSWORD_INCORRECT) {
2390 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002391 } //When UiccCardApp dispose,handle message and return exception
2392 else if (ar.exception instanceof CommandException &&
2393 ((CommandException) (ar.exception)).getCommandError()
2394 == CommandException.Error.ABORTED) {
2395 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002396 } else {
2397 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2398 }
2399 } else {
2400 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 mDone = true;
2403 UnlockSim.this.notifyAll();
2404 }
2405 break;
2406 }
2407 }
2408 };
2409 UnlockSim.this.notifyAll();
2410 }
2411 Looper.loop();
2412 }
2413
2414 /*
2415 * Use PIN or PUK to unlock SIM card
2416 *
2417 * If PUK is null, unlock SIM card with PIN
2418 *
2419 * If PUK is not null, unlock SIM card with PUK and set PIN code
2420 */
Wink Saville9de0f752013-10-22 19:04:03 -07002421 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002422
2423 while (mHandler == null) {
2424 try {
2425 wait();
2426 } catch (InterruptedException e) {
2427 Thread.currentThread().interrupt();
2428 }
2429 }
2430 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2431
2432 if (puk == null) {
2433 mSimCard.supplyPin(pin, callback);
2434 } else {
2435 mSimCard.supplyPuk(puk, pin, callback);
2436 }
2437
2438 while (!mDone) {
2439 try {
2440 Log.d(LOG_TAG, "wait for done");
2441 wait();
2442 } catch (InterruptedException e) {
2443 // Restore the interrupted status
2444 Thread.currentThread().interrupt();
2445 }
2446 }
2447 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002448 int[] resultArray = new int[2];
2449 resultArray[0] = mResult;
2450 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002451
2452 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2453 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2454 }
2455
Wink Saville9de0f752013-10-22 19:04:03 -07002456 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458 }
2459
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002460 /**
2461 * This method has been removed due to privacy and stability concerns.
2462 */
2463 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002465 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2466 return;
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
Nathan Harold1f889d82020-06-04 17:05:26 -07002469 @Override
2470 public void updateServiceLocationWithPackageName(String callingPackage) {
2471 mApp.getSystemService(AppOpsManager.class)
2472 .checkPackage(Binder.getCallingUid(), callingPackage);
2473
Nathan Haroldf096d982020-11-18 17:18:06 -08002474 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002475 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2476 // Callers targeting S have no business invoking this method.
2477 return;
2478 }
2479
2480 LocationAccessPolicy.LocationPermissionResult locationResult =
2481 LocationAccessPolicy.checkLocationPermission(mApp,
2482 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2483 .setCallingPackage(callingPackage)
2484 .setCallingFeatureId(null)
2485 .setCallingPid(Binder.getCallingPid())
2486 .setCallingUid(Binder.getCallingUid())
2487 .setMethod("updateServiceLocation")
2488 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2489 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2490 .build());
2491 // Apps that lack location permission have no business calling this method;
2492 // however, because no permission was declared in the public API, denials must
2493 // all be "soft".
2494 switch (locationResult) {
2495 case DENIED_HARD: /* fall through */
2496 case DENIED_SOFT:
2497 return;
2498 }
2499
2500 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002501 final long identity = Binder.clearCallingIdentity();
2502 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002503 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002505 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002510 }
2511
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002512 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002513 @Override
2514 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002515 return isRadioOnWithFeature(callingPackage, null);
2516 }
2517
2518
2519 @Override
2520 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2521 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2522 callingFeatureId);
2523 }
2524
2525 @Deprecated
2526 @Override
2527 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2528 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002529 }
2530
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002532 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2533 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002534 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002535 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002536 return false;
2537 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002538
2539 final long identity = Binder.clearCallingIdentity();
2540 try {
2541 return isRadioOnForSubscriber(subId);
2542 } finally {
2543 Binder.restoreCallingIdentity(identity);
2544 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002545 }
2546
2547 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 final long identity = Binder.clearCallingIdentity();
2549 try {
2550 final Phone phone = getPhone(subId);
2551 if (phone != null) {
2552 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2553 } else {
2554 return false;
2555 }
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002559 }
2560
2561 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002562 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 }
Wink Saville36469e72014-06-11 15:17:00 -07002564
Wink Savilleb564aae2014-10-23 10:18:09 -07002565 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 final Phone phone = getPhone(subId);
2571 if (phone != null) {
2572 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2573 }
2574 } finally {
2575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002576 }
Wink Saville36469e72014-06-11 15:17:00 -07002577 }
2578
2579 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002580 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002581 }
2582
Wink Savilleb564aae2014-10-23 10:18:09 -07002583 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002584 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585
2586 final long identity = Binder.clearCallingIdentity();
2587 try {
2588 final Phone phone = getPhone(subId);
2589 if (phone == null) {
2590 return false;
2591 }
2592 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2593 toggleRadioOnOffForSubscriber(subId);
2594 }
2595 return true;
2596 } finally {
2597 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002599 }
Wink Saville36469e72014-06-11 15:17:00 -07002600
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002601 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002602 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002603 /*
2604 * If any of the Radios are available, it will need to be
2605 * shutdown. So return true if any Radio is available.
2606 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2610 Phone phone = PhoneFactory.getPhone(i);
2611 if (phone != null && phone.isRadioAvailable()) return true;
2612 }
2613 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2614 return false;
2615 } finally {
2616 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002617 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002618 }
2619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002621 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622 enforceModifyPermission();
2623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2627 logv("Shutting down Phone " + i);
2628 shutdownRadioUsingPhoneId(i);
2629 }
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002632 }
2633 }
2634
2635 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002636 Phone phone = PhoneFactory.getPhone(phoneId);
2637 if (phone != null && phone.isRadioAvailable()) {
2638 phone.shutdownRadio();
2639 }
2640 }
2641
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2648 if (defaultPhone != null) {
2649 defaultPhone.setRadioPower(turnOn);
2650 return true;
2651 } else {
2652 loge("There's no default phone.");
2653 return false;
2654 }
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002657 }
Wink Saville36469e72014-06-11 15:17:00 -07002658 }
2659
Wink Savilleb564aae2014-10-23 10:18:09 -07002660 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662
2663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 if (phone != null) {
2667 phone.setRadioPower(turnOn);
2668 return true;
2669 } else {
2670 return false;
2671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002675 }
2676
Wink Saville36469e72014-06-11 15:17:00 -07002677 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 public boolean enableDataConnectivity() {
2680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 int subId = mSubscriptionController.getDefaultDataSubId();
2685 final Phone phone = getPhone(subId);
2686 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002687 phone.getDataEnabledSettings().setDataEnabled(
2688 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 return true;
2690 } else {
2691 return false;
2692 }
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 }
2697
Wink Saville36469e72014-06-11 15:17:00 -07002698 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002699 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 public boolean disableDataConnectivity() {
2701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 int subId = mSubscriptionController.getDefaultDataSubId();
2706 final Phone phone = getPhone(subId);
2707 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002708 phone.getDataEnabledSettings().setDataEnabled(
2709 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 return true;
2711 } else {
2712 return false;
2713 }
2714 } finally {
2715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 }
2718
Sanket Padawe356d7632015-06-22 14:03:32 -07002719 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002720 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 final Phone phone = getPhone(subId);
2724 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002725 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 } else {
2727 return false;
2728 }
2729 } finally {
2730 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002732 }
2733
2734 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002735 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002736 }
2737
pkanwarae03a6b2016-11-06 20:37:09 -08002738 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 enforceCallPermission();
2740
2741 final long identity = Binder.clearCallingIdentity();
2742 try {
2743 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2744 return;
2745 }
2746 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2747 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2748 } finally {
2749 Binder.restoreCallingIdentity(identity);
2750 }
pkanwar32d516d2016-10-14 19:37:38 -07002751 };
2752
Wink Savilleb564aae2014-10-23 10:18:09 -07002753 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755
2756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2759 return false;
2760 }
2761 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 }
2766
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002767 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002768 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002769 }
2770
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002771 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 Phone phone = PhoneFactory.getPhone(slotIndex);
2775 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2776 PhoneConstantConversions.convertCallState(phone.getState());
2777 } finally {
2778 Binder.restoreCallingIdentity(identity);
2779 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781
Sanket Padawe356d7632015-06-22 14:03:32 -07002782 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002783 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002784 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2785 }
2786
2787 @Override
2788 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002791 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 if (phone != null) {
2793 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2794 } else {
2795 return PhoneConstantConversions.convertDataState(
2796 PhoneConstants.DataState.DISCONNECTED);
2797 }
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002801 }
2802
Sanket Padawe356d7632015-06-22 14:03:32 -07002803 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002804 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002805 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2806 }
2807
2808 @Override
2809 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 final long identity = Binder.clearCallingIdentity();
2811 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002812 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002813 if (phone != null) {
2814 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2815 } else {
2816 return TelephonyManager.DATA_ACTIVITY_NONE;
2817 }
2818 } finally {
2819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 }
2822
2823 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002824 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002825 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002826 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002827
2828 LocationAccessPolicy.LocationPermissionResult locationResult =
2829 LocationAccessPolicy.checkLocationPermission(mApp,
2830 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2831 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002832 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002833 .setCallingPid(Binder.getCallingPid())
2834 .setCallingUid(Binder.getCallingUid())
2835 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002836 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002837 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2838 .build());
2839 switch (locationResult) {
2840 case DENIED_HARD:
2841 throw new SecurityException("Not allowed to access cell location");
2842 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002843 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2844 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
2846
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002847 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002851 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002852 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002853 } finally {
2854 Binder.restoreCallingIdentity(identity);
2855 }
Svetoslav64fad262015-04-14 14:35:21 -07002856 }
2857
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002859 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002860 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2861 // registered cell info, so return a NULL country instead.
2862 final long identity = Binder.clearCallingIdentity();
2863 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002864 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2865 // Get default phone in this case.
2866 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2867 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002868 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002869 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002870 if (phone == null) return "";
2871 ServiceStateTracker sst = phone.getServiceStateTracker();
2872 if (sst == null) return "";
2873 LocaleTracker lt = sst.getLocaleTracker();
2874 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002875 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002876 } finally {
2877 Binder.restoreCallingIdentity(identity);
2878 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002879 }
2880
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002881 /**
2882 * This method was removed due to potential issues caused by performing partial
2883 * updates of service state, and lack of a credible use case.
2884 *
2885 * This has the ability to break the telephony implementation by disabling notification of
2886 * changes in device connectivity. DO NOT USE THIS!
2887 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002888 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002889 public void enableLocationUpdates() {
2890 mApp.enforceCallingOrSelfPermission(
2891 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 }
2893
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002894 /**
2895 * This method was removed due to potential issues caused by performing partial
2896 * updates of service state, and lack of a credible use case.
2897 *
2898 * This has the ability to break the telephony implementation by disabling notification of
2899 * changes in device connectivity. DO NOT USE THIS!
2900 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002901 @Override
2902 public void disableLocationUpdates() {
2903 mApp.enforceCallingOrSelfPermission(
2904 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002905 }
2906
2907 @Override
2908 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002909 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2910 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002911 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002912 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2913 throw new SecurityException(
2914 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2915 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002916
Jordan Liu1617b712019-07-10 15:06:26 -07002917 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2919 return null;
2920 }
Svetoslav64fad262015-04-14 14:35:21 -07002921
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002922 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002923
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002924 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002925 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002926
Nathan Haroldf180aac2018-06-01 18:43:55 -07002927 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2928 for (CellInfo ci : info) {
2929 if (ci instanceof CellInfoGsm) {
2930 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2931 } else if (ci instanceof CellInfoWcdma) {
2932 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002934 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002935 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002936 }
2937
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002938 private List<CellInfo> getCachedCellInfo() {
2939 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2940 for (Phone phone : PhoneFactory.getPhones()) {
2941 List<CellInfo> info = phone.getAllCellInfo();
2942 if (info != null) cellInfos.addAll(info);
2943 }
2944 return cellInfos;
2945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946
2947 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002948 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002949 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002950 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002951
2952 LocationAccessPolicy.LocationPermissionResult locationResult =
2953 LocationAccessPolicy.checkLocationPermission(mApp,
2954 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2955 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002956 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002957 .setCallingPid(Binder.getCallingPid())
2958 .setCallingUid(Binder.getCallingUid())
2959 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002960 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002961 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2962 .build());
2963 switch (locationResult) {
2964 case DENIED_HARD:
2965 throw new SecurityException("Not allowed to access cell info");
2966 case DENIED_SOFT:
2967 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002968 }
2969
Nathan Haroldf096d982020-11-18 17:18:06 -08002970 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002971 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2972 return getCachedCellInfo();
2973 }
2974
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002975 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002977 final long identity = Binder.clearCallingIdentity();
2978 try {
2979 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2980 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002981 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002982 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 if (info != null) cellInfos.addAll(info);
2984 }
2985 return cellInfos;
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002988 }
2989 }
2990
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002991 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002992 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2993 String callingFeatureId) {
2994 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2995 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002996 }
2997
2998 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002999 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3000 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003001 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003002 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003003 }
3004
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003005 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3006 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003007 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003008 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003009
3010 LocationAccessPolicy.LocationPermissionResult locationResult =
3011 LocationAccessPolicy.checkLocationPermission(mApp,
3012 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3013 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003014 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003015 .setCallingPid(Binder.getCallingPid())
3016 .setCallingUid(Binder.getCallingUid())
3017 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003018 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3019 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003020 .build());
3021 switch (locationResult) {
3022 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003023 if (TelephonyPermissions
3024 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003025 // Safetynet logging for b/154934934
3026 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3027 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003028 throw new SecurityException("Not allowed to access cell info");
3029 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003030 if (TelephonyPermissions
3031 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003032 // Safetynet logging for b/154934934
3033 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3034 }
Nathan Harold5320c422019-05-09 10:26:08 -07003035 try {
3036 cb.onCellInfo(new ArrayList<CellInfo>());
3037 } catch (RemoteException re) {
3038 // Drop without consequences
3039 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003040 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003041 }
3042
Nathan Harolda939a962019-05-09 10:13:47 -07003043
3044 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003045 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3046
3047 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3048 }
3049
3050 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003052 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003053 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003054
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003057 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003058 } finally {
3059 Binder.restoreCallingIdentity(identity);
3060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003061 }
3062
Shishir Agrawala9f32182016-04-12 12:00:16 -07003063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003064 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003065 Phone phone = PhoneFactory.getPhone(slotIndex);
3066 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003067 return null;
3068 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003069 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003070 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003071 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003072 return null;
3073 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 return phone.getImei();
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003081 }
3082
3083 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003084 public String getTypeAllocationCodeForSlot(int slotIndex) {
3085 Phone phone = PhoneFactory.getPhone(slotIndex);
3086 String tac = null;
3087 if (phone != null) {
3088 String imei = phone.getImei();
3089 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3090 }
3091 return tac;
3092 }
3093
3094 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003095 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003096 Phone phone = PhoneFactory.getPhone(slotIndex);
3097 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003098 return null;
3099 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003100
Jeff Davidson913390f2018-02-23 17:11:49 -08003101 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003102 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003103 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003104 return null;
3105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106
3107 final long identity = Binder.clearCallingIdentity();
3108 try {
3109 return phone.getMeid();
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
3112 }
Jack Yu2af8d712017-03-15 17:14:14 -07003113 }
3114
3115 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003116 public String getManufacturerCodeForSlot(int slotIndex) {
3117 Phone phone = PhoneFactory.getPhone(slotIndex);
3118 String manufacturerCode = null;
3119 if (phone != null) {
3120 String meid = phone.getMeid();
3121 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3122 }
3123 return manufacturerCode;
3124 }
3125
3126 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003127 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3128 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003129 Phone phone = PhoneFactory.getPhone(slotIndex);
3130 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003131 return null;
3132 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003133 int subId = phone.getSubId();
3134 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003135 mApp, subId, callingPackage, callingFeatureId,
3136 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003137 return null;
3138 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003139
3140 final long identity = Binder.clearCallingIdentity();
3141 try {
3142 return phone.getDeviceSvn();
3143 } finally {
3144 Binder.restoreCallingIdentity(identity);
3145 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003146 }
3147
fionaxu43304da2017-11-27 22:51:16 -08003148 @Override
3149 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 final Phone phone = getPhone(subId);
3153 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
fionaxu43304da2017-11-27 22:51:16 -08003157 }
3158
3159 @Override
3160 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003161 final long identity = Binder.clearCallingIdentity();
3162 try {
3163 final Phone phone = getPhone(subId);
3164 return phone == null ? null : phone.getCarrierName();
3165 } finally {
3166 Binder.restoreCallingIdentity(identity);
3167 }
fionaxu43304da2017-11-27 22:51:16 -08003168 }
3169
calvinpanffe225e2018-11-01 19:43:06 +08003170 @Override
chen xu0026ca62019-03-06 15:28:50 -08003171 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003172 final long identity = Binder.clearCallingIdentity();
3173 try {
3174 final Phone phone = getPhone(subId);
3175 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003176 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003177 } finally {
3178 Binder.restoreCallingIdentity(identity);
3179 }
3180 }
3181
3182 @Override
chen xu0026ca62019-03-06 15:28:50 -08003183 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003187 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
3191 }
3192
chen xu651eec72018-11-11 19:03:44 -08003193 @Override
chen xu864e11c2018-12-06 22:10:03 -08003194 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3195 if (!isSubscriptionMccMnc) {
3196 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3197 }
chen xu651eec72018-11-11 19:03:44 -08003198 final Phone phone = PhoneFactory.getPhone(slotIndex);
3199 if (phone == null) {
3200 return TelephonyManager.UNKNOWN_CARRIER_ID;
3201 }
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
3208 }
3209
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003210 //
3211 // Internal helper methods.
3212 //
3213
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003214 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003215 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3216 *
3217 * @throws SecurityException if the caller does not have the required permission
3218 */
3219 private void enforceModifyPermission() {
3220 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3221 }
3222
Shuo Qiancd19c462020-01-16 20:51:11 -08003223 /**
3224 * Make sure the caller is system.
3225 *
3226 * @throws SecurityException if the caller is not system.
3227 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003228 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003229 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3230 throw new SecurityException("Caller must be system");
3231 }
3232 }
3233
Shuo Qian3b6ee772019-11-13 17:43:31 -08003234 private void enforceActiveEmergencySessionPermission() {
3235 mApp.enforceCallingOrSelfPermission(
3236 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3237 }
3238
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003239 /**
3240 * Make sure the caller has the CALL_PHONE permission.
3241 *
3242 * @throws SecurityException if the caller does not have the required permission
3243 */
3244 private void enforceCallPermission() {
3245 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3246 }
3247
paulhu5a773602019-08-23 19:17:33 +08003248 private void enforceSettingsPermission() {
3249 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003250 }
3251
Michele Berionne5e411512020-11-13 02:36:59 +00003252 private void enforceRebootPermission() {
3253 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3254 }
3255
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003256 private String createTelUrl(String number) {
3257 if (TextUtils.isEmpty(number)) {
3258 return null;
3259 }
3260
Jake Hambye994d462014-02-03 13:10:13 -08003261 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003262 }
3263
Ihab Awadf9e92732013-12-05 18:02:52 -08003264 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003265 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3266 }
3267
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003268 private static void logv(String msg) {
3269 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3270 }
3271
Ihab Awadf9e92732013-12-05 18:02:52 -08003272 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003273 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3274 }
3275
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003276 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003277 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003278 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003279 }
3280
Sanket Padawe356d7632015-06-22 14:03:32 -07003281 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003282 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 final Phone phone = PhoneFactory.getPhone(slotIndex);
3286 if (phone == null) {
3287 return PhoneConstants.PHONE_TYPE_NONE;
3288 } else {
3289 return phone.getPhoneType();
3290 }
3291 } finally {
3292 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003294 }
3295
3296 /**
3297 * Returns the CDMA ERI icon index to display
3298 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003299 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003300 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3301 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3302 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003303 }
3304
Sanket Padawe356d7632015-06-22 14:03:32 -07003305 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003306 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3307 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003309 mApp, subId, callingPackage, callingFeatureId,
3310 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003311 return -1;
3312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003313
3314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 final Phone phone = getPhone(subId);
3317 if (phone != null) {
3318 return phone.getCdmaEriIconIndex();
3319 } else {
3320 return -1;
3321 }
3322 } finally {
3323 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003325 }
3326
3327 /**
3328 * Returns the CDMA ERI icon mode,
3329 * 0 - ON
3330 * 1 - FLASHING
3331 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003333 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3334 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3335 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003336 }
3337
Sanket Padawe356d7632015-06-22 14:03:32 -07003338 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003339 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3340 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003342 mApp, subId, callingPackage, callingFeatureId,
3343 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003344 return -1;
3345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 final Phone phone = getPhone(subId);
3350 if (phone != null) {
3351 return phone.getCdmaEriIconMode();
3352 } else {
3353 return -1;
3354 }
3355 } finally {
3356 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003358 }
3359
3360 /**
3361 * Returns the CDMA ERI text,
3362 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003364 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3365 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3366 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003367 }
3368
Sanket Padawe356d7632015-06-22 14:03:32 -07003369 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003370 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3371 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003373 mApp, subId, callingPackage, callingFeatureId,
3374 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003375 return null;
3376 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003377
3378 final long identity = Binder.clearCallingIdentity();
3379 try {
3380 final Phone phone = getPhone(subId);
3381 if (phone != null) {
3382 return phone.getCdmaEriText();
3383 } else {
3384 return null;
3385 }
3386 } finally {
3387 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 }
3390
3391 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003392 * Returns the CDMA MDN.
3393 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003394 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003395 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3397 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003398
3399 final long identity = Binder.clearCallingIdentity();
3400 try {
3401 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003402 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003403 return phone.getLine1Number();
3404 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003405 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406 return null;
3407 }
3408 } finally {
3409 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003410 }
3411 }
3412
3413 /**
3414 * Returns the CDMA MIN.
3415 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003416 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003417 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3419 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003420
3421 final long identity = Binder.clearCallingIdentity();
3422 try {
3423 final Phone phone = getPhone(subId);
3424 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3425 return phone.getCdmaMin();
3426 } else {
3427 return null;
3428 }
3429 } finally {
3430 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003431 }
3432 }
3433
Hall Liud892bec2018-11-30 14:51:45 -08003434 @Override
3435 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3436 INumberVerificationCallback callback, String callingPackage) {
3437 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3438 != PERMISSION_GRANTED) {
3439 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3440 }
3441 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3442
3443 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3444 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003445 throw new SecurityException("Calling package must be configured in the device config: "
3446 + "calling package: " + callingPackage
3447 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003448 }
3449
3450 if (range == null) {
3451 throw new NullPointerException("Range must be non-null");
3452 }
3453
3454 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003455 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003456
3457 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3458 }
3459
Junda Liuca05d5d2014-08-14 22:36:34 -07003460 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003461 * Returns true if CDMA provisioning needs to run.
3462 */
3463 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 final long identity = Binder.clearCallingIdentity();
3465 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003466 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003467 } finally {
3468 Binder.restoreCallingIdentity(identity);
3469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003470 }
3471
3472 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003473 * Sets the voice mail number of a given subId.
3474 */
3475 @Override
3476 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003477 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3478 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3483 new Pair<String, String>(alphaTag, number), new Integer(subId));
3484 return success;
3485 } finally {
3486 Binder.restoreCallingIdentity(identity);
3487 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003488 }
3489
Ta-wei Yen87c49842016-05-13 21:19:52 -07003490 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003491 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3492 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003493 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3494 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003495 if (!TextUtils.equals(callingPackage, systemDialer)) {
3496 throw new SecurityException("caller must be system dialer");
3497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003498
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3502 if (phoneAccountHandle == null) {
3503 return null;
3504 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003505 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003508 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003509 }
3510
3511 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003512 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3513 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003514 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003516 mApp, subId, callingPackage, callingFeatureId,
3517 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003518 return null;
3519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003520
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003521 final long identity = Binder.clearCallingIdentity();
3522 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003523 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003524 } finally {
3525 Binder.restoreCallingIdentity(identity);
3526 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003527 }
3528
3529 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003530 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3531 VisualVoicemailSmsFilterSettings settings) {
3532 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533
3534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003537 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538 } finally {
3539 Binder.restoreCallingIdentity(identity);
3540 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003541 }
3542
3543 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003544 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3545 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003546
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003550 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551 } finally {
3552 Binder.restoreCallingIdentity(identity);
3553 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003554 }
3555
3556 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003557 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3558 String callingPackage, int subId) {
3559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003560
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003564 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003565 } finally {
3566 Binder.restoreCallingIdentity(identity);
3567 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003568 }
3569
3570 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003571 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003577 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003578 } finally {
3579 Binder.restoreCallingIdentity(identity);
3580 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003581 }
3582
3583 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003584 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3585 String callingAttributionTag, int subId, String number, int port, String text,
3586 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003588 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003589 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003590 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003591 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3592 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003593 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003594
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003595 /**
fionaxu0152e512016-11-14 13:36:14 -08003596 * Sets the voice activation state of a given subId.
3597 */
3598 @Override
3599 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3601 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003602
3603 final long identity = Binder.clearCallingIdentity();
3604 try {
3605 final Phone phone = getPhone(subId);
3606 if (phone != null) {
3607 phone.setVoiceActivationState(activationState);
3608 } else {
3609 loge("setVoiceActivationState fails with invalid subId: " + subId);
3610 }
3611 } finally {
3612 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003613 }
3614 }
3615
3616 /**
3617 * Sets the data activation state of a given subId.
3618 */
3619 @Override
3620 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3622 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003623
3624 final long identity = Binder.clearCallingIdentity();
3625 try {
3626 final Phone phone = getPhone(subId);
3627 if (phone != null) {
3628 phone.setDataActivationState(activationState);
3629 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003630 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003631 }
3632 } finally {
3633 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003634 }
3635 }
3636
3637 /**
3638 * Returns the voice activation state of a given subId.
3639 */
3640 @Override
3641 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643
fionaxu0152e512016-11-14 13:36:14 -08003644 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 if (phone != null) {
3648 return phone.getVoiceActivationState();
3649 } else {
3650 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3651 }
3652 } finally {
3653 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003654 }
3655 }
3656
3657 /**
3658 * Returns the data activation state of a given subId.
3659 */
3660 @Override
3661 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663
fionaxu0152e512016-11-14 13:36:14 -08003664 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 if (phone != null) {
3668 return phone.getDataActivationState();
3669 } else {
3670 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3671 }
3672 } finally {
3673 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003674 }
3675 }
3676
3677 /**
Wink Saville36469e72014-06-11 15:17:00 -07003678 * Returns the unread count of voicemails for a subId
3679 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003680 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003681 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3682 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003684 mApp, subId, callingPackage, callingFeatureId,
3685 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003686 return 0;
3687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 final Phone phone = getPhone(subId);
3691 if (phone != null) {
3692 return phone.getVoiceMessageCount();
3693 } else {
3694 return 0;
3695 }
3696 } finally {
3697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003698 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003699 }
3700
3701 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003702 * returns true, if the device is in a state where both voice and data
3703 * are supported simultaneously. This can change based on location or network condition.
3704 */
3705 @Override
3706 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 final Phone phone = getPhone(subId);
3710 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003714 }
3715
3716 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003717 * Send the dialer code if called from the current default dialer or the caller has
3718 * carrier privilege.
3719 * @param inputCode The dialer code to send
3720 */
3721 @Override
3722 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003724 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003725 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3726 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003727 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003728 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003729 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731
3732 final long identity = Binder.clearCallingIdentity();
3733 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003734 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735 } finally {
3736 Binder.restoreCallingIdentity(identity);
3737 }
fionaxu235cc5e2017-03-06 22:25:57 -08003738 }
3739
Pengquan Menga1bb6272018-09-06 09:59:22 -07003740 @Override
3741 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003742 TelephonyPermissions
3743 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3744 mApp, subId, "getNetworkSelectionMode");
3745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 if (!isActiveSubscription(subId)) {
3748 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3749 }
3750 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3751 } finally {
3752 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003753 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003754 }
3755
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003757 public boolean isInEmergencySmsMode() {
3758 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3759 final long identity = Binder.clearCallingIdentity();
3760 try {
3761 for (Phone phone : PhoneFactory.getPhones()) {
3762 if (phone.isInEmergencySmsMode()) {
3763 return true;
3764 }
3765 }
3766 } finally {
3767 Binder.restoreCallingIdentity(identity);
3768 }
3769 return false;
3770 }
3771
shilu366312e2019-12-17 09:28:10 -08003772 /**
3773 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3774 * @param subId The subscription to use to check the configuration.
3775 * @param c The callback that will be used to send the result.
3776 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003777 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003778 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3779 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003780 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3781 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003782
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003783 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3784 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3785 "IMS not available on device.");
3786 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003787 final long token = Binder.clearCallingIdentity();
3788 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003789 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003790 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003791 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003792 } catch (ImsException e) {
3793 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003794 } finally {
3795 Binder.restoreCallingIdentity(token);
3796 }
3797 }
3798
shilu366312e2019-12-17 09:28:10 -08003799 /**
3800 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3801 * @param subId The subscription to use to check the configuration.
3802 * @param c The callback that will be used to send the result.
3803 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003804 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003805 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003806 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3807 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003808 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3809 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3810 }
Meng Wangafbc5852019-09-19 17:37:13 -07003811 final long token = Binder.clearCallingIdentity();
3812 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003813 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003814 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3815 .removeRegistrationCallbackForSubscription(c, subId);
3816 } catch (ImsException e) {
3817 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3818 + "is inactive, ignoring unregister.");
3819 // If the subscription is no longer active, just return, since the callback
3820 // will already have been removed internally.
3821 } finally {
3822 Binder.restoreCallingIdentity(token);
3823 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 }
3825
Brad Ebingera34a6c22019-10-22 17:36:18 -07003826 /**
3827 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3828 */
3829 @Override
3830 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3831 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3832 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3833 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3834 "IMS not available on device.");
3835 }
3836 final long token = Binder.clearCallingIdentity();
3837 try {
3838 Phone phone = getPhone(subId);
3839 if (phone == null) {
3840 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3841 + subId + "'");
3842 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3843 }
3844 phone.getImsRegistrationState(regState -> {
3845 try {
3846 consumer.accept((regState == null)
3847 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3848 } catch (RemoteException e) {
3849 // Ignore if the remote process is no longer available to call back.
3850 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3851 }
3852 });
3853 } finally {
3854 Binder.restoreCallingIdentity(token);
3855 }
3856 }
3857
3858 /**
3859 * Get the transport type for the IMS service registration state.
3860 */
3861 @Override
3862 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003863 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3864 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003865 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3866 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3867 "IMS not available on device.");
3868 }
3869 final long token = Binder.clearCallingIdentity();
3870 try {
3871 Phone phone = getPhone(subId);
3872 if (phone == null) {
3873 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3874 + subId + "'");
3875 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3876 }
3877 phone.getImsRegistrationTech(regTech -> {
3878 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3879 int regTechConverted = (regTech == null)
3880 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3881 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3882 regTechConverted);
3883 try {
3884 consumer.accept(regTechConverted);
3885 } catch (RemoteException e) {
3886 // Ignore if the remote process is no longer available to call back.
3887 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3888 }
3889 });
3890 } finally {
3891 Binder.restoreCallingIdentity(token);
3892 }
3893 }
3894
shilu366312e2019-12-17 09:28:10 -08003895 /**
3896 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3897 * @param subId The subscription to use to check the configuration.
3898 * @param c The callback that will be used to send the result.
3899 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003900 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003901 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3902 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003903 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3904 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003905 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3906 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3907 "IMS not available on device.");
3908 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3910 final long token = Binder.clearCallingIdentity();
3911 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003912 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003914 } catch (ImsException e) {
3915 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003916 } finally {
3917 Binder.restoreCallingIdentity(token);
3918 }
3919 }
3920
shilu366312e2019-12-17 09:28:10 -08003921 /**
3922 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3923 * @param subId The subscription to use to check the configuration.
3924 * @param c The callback that will be used to send the result.
3925 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003926 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003927 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003928 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3929 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3931 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3932 }
Meng Wangafbc5852019-09-19 17:37:13 -07003933
3934 final long token = Binder.clearCallingIdentity();
3935 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003936 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003937 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003938 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003939 } catch (ImsException e) {
3940 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3941 + "is inactive, ignoring unregister.");
3942 // If the subscription is no longer active, just return, since the callback
3943 // will already have been removed internally.
3944 } finally {
3945 Binder.restoreCallingIdentity(token);
3946 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003947 }
3948
3949 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003950 public boolean isCapable(int subId, int capability, int regTech) {
3951 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3953 final long token = Binder.clearCallingIdentity();
3954 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003956 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003957 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003958 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3959 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003960 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003961 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3962 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003963 } finally {
3964 Binder.restoreCallingIdentity(token);
3965 }
3966 }
3967
3968 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003969 public boolean isAvailable(int subId, int capability, int regTech) {
3970 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 final long token = Binder.clearCallingIdentity();
3972 try {
3973 Phone phone = getPhone(subId);
3974 if (phone == null) return false;
3975 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003976 } catch (com.android.ims.ImsException e) {
3977 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3978 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 } finally {
3980 Binder.restoreCallingIdentity(token);
3981 }
3982 }
3983
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003984 /**
3985 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3986 * subscription.
3987 * @param subId The subscription to use to check the configuration.
3988 * @param callback The callback that will be used to send the result.
3989 * @param capability The MmTelFeature capability that will be used to send the result.
3990 * @param transportType The transport type of the MmTelFeature capability.
3991 */
3992 @Override
3993 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3994 int transportType) {
3995 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3996 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3997 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3998 "IMS not available on device.");
3999 }
4000 final long token = Binder.clearCallingIdentity();
4001 try {
4002 int slotId = getSlotIndex(subId);
4003 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4004 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4005 + subId + "'");
4006 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4007 }
4008 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4009 transportType, aBoolean -> {
4010 try {
4011 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4012 } catch (RemoteException e) {
4013 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4014 + "running. Ignore");
4015 }
4016 });
4017 } finally {
4018 Binder.restoreCallingIdentity(token);
4019 }
4020 }
4021
shilu366312e2019-12-17 09:28:10 -08004022 /**
4023 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4024 * @param subId The subscription to use to check the configuration.
4025 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 @Override
4027 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004028 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4029 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004030
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4032 final long token = Binder.clearCallingIdentity();
4033 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004034 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004036 } catch (ImsException e) {
4037 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004038 } finally {
4039 Binder.restoreCallingIdentity(token);
4040 }
4041 }
4042
4043 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004044 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004046 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004050 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004052 } catch (ImsException e) {
4053 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 } finally {
4055 Binder.restoreCallingIdentity(identity);
4056 }
4057 }
4058
shilu366312e2019-12-17 09:28:10 -08004059 /**
4060 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4061 * @param subId The subscription to use to check the configuration.
4062 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004064 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004065 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4066 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 final long identity = Binder.clearCallingIdentity();
4068 try {
4069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004070 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4071 } catch (ImsException e) {
4072 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004073 } finally {
4074 Binder.restoreCallingIdentity(identity);
4075 }
4076 }
4077
4078 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004079 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004081 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004085 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004086 } catch (ImsException e) {
4087 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 } finally {
4089 Binder.restoreCallingIdentity(identity);
4090 }
4091 }
4092
shilu366312e2019-12-17 09:28:10 -08004093 /**
4094 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4095 * @param subId The subscription to use to check the configuration.
4096 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004097 @Override
4098 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004099 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4100 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 final long identity = Binder.clearCallingIdentity();
4102 try {
4103 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004104 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004105 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004106 } catch (ImsException e) {
4107 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
4111 }
4112
4113 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004114 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004116 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004117 final long identity = Binder.clearCallingIdentity();
4118 try {
4119 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004121 } catch (ImsException e) {
4122 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 } finally {
4124 Binder.restoreCallingIdentity(identity);
4125 }
4126 }
4127
shilu366312e2019-12-17 09:28:10 -08004128 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004129 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4130 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4131 * @param subId The subscription to use to check the configuration.
4132 */
4133 @Override
4134 public boolean isCrossSimCallingEnabledByUser(int subId) {
4135 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4136 mApp, subId, "isCrossSimCallingEnabledByUser");
4137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4140 return ImsManager.getInstance(mApp,
4141 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4142 } catch (ImsException e) {
4143 throw new ServiceSpecificException(e.getCode());
4144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
4149 /**
4150 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4151 * Requires MODIFY_PHONE_STATE permission.
4152 * @param subId The subscription to use to check the configuration.
4153 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4154 * false otherwise
4155 */
4156 @Override
4157 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4158 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4159 "setCrossSimCallingEnabled");
4160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4163 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4164 .setCrossSimCallingEnabled(isEnabled);
4165 } catch (ImsException e) {
4166 throw new ServiceSpecificException(e.getCode());
4167 } finally {
4168 Binder.restoreCallingIdentity(identity);
4169 }
4170 }
4171
4172 /**
shilu366312e2019-12-17 09:28:10 -08004173 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4174 * @param subId The subscription to use to check the configuration.
4175 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004176 @Override
4177 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004178 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4179 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004183 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004185 } catch (ImsException e) {
4186 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004187 } finally {
4188 Binder.restoreCallingIdentity(identity);
4189 }
4190 }
4191
4192 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004193 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004195 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 final long identity = Binder.clearCallingIdentity();
4197 try {
4198 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004201 } catch (ImsException e) {
4202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
4206 }
4207
4208 @Override
4209 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4211 "setVoWiFiNonPersistent");
4212 final long identity = Binder.clearCallingIdentity();
4213 try {
4214 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004215 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004216 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 } catch (ImsException e) {
4218 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222 }
4223
shilu366312e2019-12-17 09:28:10 -08004224 /**
4225 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4226 * @param subId The subscription to use to check the configuration.
4227 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004228 @Override
4229 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004230 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4231 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004235 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004236 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004237 } catch (ImsException e) {
4238 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 } finally {
4240 Binder.restoreCallingIdentity(identity);
4241 }
4242 }
4243
4244 @Override
4245 public void setVoWiFiModeSetting(int subId, int mode) {
4246 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4247 "setVoWiFiModeSetting");
4248 final long identity = Binder.clearCallingIdentity();
4249 try {
4250 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004251 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004252 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004253 } catch (ImsException e) {
4254 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004255 } finally {
4256 Binder.restoreCallingIdentity(identity);
4257 }
4258 }
4259
4260 @Override
4261 public int getVoWiFiRoamingModeSetting(int subId) {
4262 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004266 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004267 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004268 } catch (ImsException e) {
4269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
4273 }
4274
4275 @Override
4276 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4278 "setVoWiFiRoamingModeSetting");
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004282 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004283 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004284 } catch (ImsException e) {
4285 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
4289 }
4290
4291 @Override
4292 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4294 "setRttCapabilityEnabled");
4295 final long identity = Binder.clearCallingIdentity();
4296 try {
4297 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004298 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4299 } catch (ImsException e) {
4300 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
4304 }
4305
shilu366312e2019-12-17 09:28:10 -08004306 /**
4307 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4308 * @param subId The subscription to use to check the configuration.
4309 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004310 @Override
4311 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004312 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4313 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004314 final long identity = Binder.clearCallingIdentity();
4315 try {
4316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004317 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004318 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004319 } catch (ImsException e) {
4320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004321 } finally {
4322 Binder.restoreCallingIdentity(identity);
4323 }
4324 }
4325
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004326 @Override
4327 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4328 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4329 final long identity = Binder.clearCallingIdentity();
4330 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004331 if (!isImsAvailableOnDevice()) {
4332 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4333 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004334 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004335 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004336 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004337 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004338 } catch (ImsException e) {
4339 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004340 } finally {
4341 Binder.restoreCallingIdentity(identity);
4342 }
4343 }
4344
4345 @Override
4346 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4347 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4348 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004349 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4350 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4351 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004352 try {
4353 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004354 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004355 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004356 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004357 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4358 + "is inactive, ignoring unregister.");
4359 // If the subscription is no longer active, just return, since the callback will already
4360 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004361 } finally {
4362 Binder.restoreCallingIdentity(identity);
4363 }
4364 }
4365
allenwtsu99c623b2020-01-03 18:24:23 +08004366
4367 private void checkModifyPhoneStatePermission(int subId, String message) {
4368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4369 message);
4370 }
4371
4372 private boolean isImsProvisioningRequired(int subId, int capability,
4373 boolean isMmtelCapability) {
4374 Phone phone = getPhone(subId);
4375 if (phone == null) {
4376 loge("phone instance null for subid " + subId);
4377 return false;
4378 }
4379 if (isMmtelCapability) {
4380 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4381 return false;
4382 }
4383 } else {
4384 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4385 return false;
4386 }
4387 }
4388 return true;
4389 }
4390
4391 @Override
4392 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4393 boolean isProvisioned) {
4394 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4395
4396 final long identity = Binder.clearCallingIdentity();
4397 try {
4398 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4399 if (!isImsProvisioningRequired(subId, capability, false)) {
4400 return;
4401 }
4402
4403 // this capability requires provisioning, route to the correct API.
4404 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4405 switch (capability) {
4406 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4407 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4408 ims.setEabProvisioned(isProvisioned);
4409 break;
4410 default: {
4411 throw new IllegalArgumentException("Tried to set provisioning for "
4412 + "rcs capability '" + capability + "', which does not require "
4413 + "provisioning.");
4414 }
4415 }
4416 } finally {
4417 Binder.restoreCallingIdentity(identity);
4418 }
4419
4420 }
4421
4422
4423 @Override
4424 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4425 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4426 final long identity = Binder.clearCallingIdentity();
4427 try {
4428 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4429 if (!isImsProvisioningRequired(subId, capability, false)) {
4430 return true;
4431 }
4432
4433 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4434 switch (capability) {
4435 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4436 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4437 return ims.isEabProvisionedOnDevice();
4438
4439 default: {
4440 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4441 + "capability '" + capability + "', which does not require "
4442 + "provisioning.");
4443 }
4444 }
4445
4446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
4449 }
4450
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004451 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004452 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4453 boolean isProvisioned) {
4454 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4455 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4456 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4457 }
allenwtsu99c623b2020-01-03 18:24:23 +08004458 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004459 final long identity = Binder.clearCallingIdentity();
4460 try {
4461 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004462 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004463 return;
4464 }
4465
4466 // this capability requires provisioning, route to the correct API.
4467 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4468 switch (capability) {
4469 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4470 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4471 ims.setVolteProvisioned(isProvisioned);
4472 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4473 ims.setWfcProvisioned(isProvisioned);
4474 }
4475 break;
4476 }
4477 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4478 // There is currently no difference in VT provisioning type.
4479 ims.setVtProvisioned(isProvisioned);
4480 break;
4481 }
4482 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4483 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4484 // change the capability of the feature instead if needed.
4485 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4486 == isProvisioned) {
4487 // No change in provisioning.
4488 return;
4489 }
4490 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4491 try {
4492 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004493 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004494 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4495 + ", Exception" + e.getMessage());
4496 }
4497 break;
4498 }
4499 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004500 throw new IllegalArgumentException("Tried to set provisioning for "
4501 + "MmTel capability '" + capability + "', which does not require "
4502 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004503 }
4504 }
4505
4506 } finally {
4507 Binder.restoreCallingIdentity(identity);
4508 }
4509 }
4510
4511 @Override
4512 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4513 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4514 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4515 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4516 }
4517 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4518 final long identity = Binder.clearCallingIdentity();
4519 try {
4520 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004521 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004522 return true;
4523 }
4524
4525 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4526 switch (capability) {
4527 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4528 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4529 return ims.isVolteProvisionedOnDevice();
4530 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4531 return ims.isWfcProvisionedOnDevice();
4532 }
4533 // This should never happen, since we are checking tech above to make sure it
4534 // is either LTE or IWLAN.
4535 throw new IllegalArgumentException("Invalid radio technology for voice "
4536 + "capability.");
4537 }
4538 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4539 // There is currently no difference in VT provisioning type.
4540 return ims.isVtProvisionedOnDevice();
4541 }
4542 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4543 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4544 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4545 }
4546 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004547 throw new IllegalArgumentException(
4548 "Tried to get provisioning for MmTel capability '" + capability
4549 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004550 }
4551 }
4552
4553 } finally {
4554 Binder.restoreCallingIdentity(identity);
4555 }
4556 }
4557
4558 @Override
4559 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4560 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4561 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4562 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4563 }
4564 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4565 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4566 return (provisionedBits & capability) > 0;
4567 }
4568
4569 @Override
4570 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4571 boolean isProvisioned) {
4572 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4573 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4574 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4575 }
4576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4577 "setProvisioningStatusForCapability");
4578 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4579 // If the current provisioning status for capability already matches isProvisioned,
4580 // do nothing.
4581 if (((provisionedBits & capability) > 0) == isProvisioned) {
4582 return;
4583 }
4584 if (isProvisioned) {
4585 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4586 } else {
4587 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4588 }
4589 }
4590
4591 /**
4592 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4593 * technology. The bitfield should mirror the bitfield defined by
4594 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4595 */
4596 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4597 String key = getMmTelProvisioningKey(subId, tech);
4598 // Default is no capabilities are provisioned.
4599 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4600 }
4601
4602 /**
4603 * Sets the MmTel capability provisioning bitfield (defined by
4604 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4605 * technology specified.
4606 *
4607 * Note: This is a synchronous command and should not be called on UI thread.
4608 */
4609 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4610 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4611 String key = getMmTelProvisioningKey(subId, tech);
4612 editor.putInt(key, newField);
4613 editor.commit();
4614 }
4615
4616 private static String getMmTelProvisioningKey(int subId, int tech) {
4617 // resulting key is provision_ims_mmtel_{subId}_{tech}
4618 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4619 }
4620
4621 /**
4622 * Query CarrierConfig to see if the specified capability requires provisioning for the
4623 * carrier associated with the subscription id.
4624 */
4625 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4626 int capability) {
4627 CarrierConfigManager configManager = new CarrierConfigManager(context);
4628 PersistableBundle c = configManager.getConfigForSubId(subId);
4629 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004630 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4632 false);
4633 boolean requireVoiceVtProvisioning = c.getBoolean(
4634 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4635
4636 // First check to make sure that the capability requires provisioning.
4637 switch (capability) {
4638 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4639 // intentional fallthrough
4640 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4641 if (requireVoiceVtProvisioning) {
4642 // Voice and Video requires provisioning
4643 return true;
4644 }
4645 break;
4646 }
4647 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4648 if (requireUtProvisioning) {
4649 // UT requires provisioning
4650 return true;
4651 }
4652 break;
4653 }
4654 }
4655 return false;
4656 }
4657
allenwtsu99c623b2020-01-03 18:24:23 +08004658 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4659 int capability) {
4660 CarrierConfigManager configManager = new CarrierConfigManager(context);
4661 PersistableBundle c = configManager.getConfigForSubId(subId);
4662
4663 boolean requireRcsProvisioning = c.getBoolean(
4664 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4665
4666 // First check to make sure that the capability requires provisioning.
4667 switch (capability) {
4668 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4669 // intentional fallthrough
4670 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4671 if (requireRcsProvisioning) {
4672 // OPTION or PRESENCE requires provisioning
4673 return true;
4674 }
4675 break;
4676 }
4677 }
4678 return false;
4679 }
4680
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004681 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004682 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4684 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4685 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004686 enforceReadPrivilegedPermission("getImsProvisioningInt");
4687 final long identity = Binder.clearCallingIdentity();
4688 try {
4689 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004690 int slotId = getSlotIndex(subId);
4691 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4692 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4693 + subId + "' for key:" + key);
4694 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4695 }
calvinpanb5a34062021-02-08 19:59:36 +08004696 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004697 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004698 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4699 + subId + "' for key:" + key);
4700 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004701 } finally {
4702 Binder.restoreCallingIdentity(identity);
4703 }
4704 }
4705
4706 @Override
4707 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004708 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4709 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4710 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004711 enforceReadPrivilegedPermission("getImsProvisioningString");
4712 final long identity = Binder.clearCallingIdentity();
4713 try {
4714 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004715 int slotId = getSlotIndex(subId);
4716 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4717 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4718 + subId + "' for key:" + key);
4719 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4720 }
calvinpanb5a34062021-02-08 19:59:36 +08004721 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004722 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004723 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4724 + subId + "' for key:" + key);
4725 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004726 } finally {
4727 Binder.restoreCallingIdentity(identity);
4728 }
4729 }
4730
4731 @Override
4732 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004733 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4734 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4735 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4737 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004741 int slotId = getSlotIndex(subId);
4742 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4743 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4744 + subId + "' for key:" + key);
4745 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4746 }
calvinpanb5a34062021-02-08 19:59:36 +08004747 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4748 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004749 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004750 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004751 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004752 } finally {
4753 Binder.restoreCallingIdentity(identity);
4754 }
4755 }
4756
4757 @Override
4758 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4760 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4761 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4763 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004764 final long identity = Binder.clearCallingIdentity();
4765 try {
4766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004767 int slotId = getSlotIndex(subId);
4768 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4769 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4770 + subId + "' for key:" + key);
4771 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4772 }
calvinpanb5a34062021-02-08 19:59:36 +08004773 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4774 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004775 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004776 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004777 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004778 } finally {
4779 Binder.restoreCallingIdentity(identity);
4780 }
4781 }
4782
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004783 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004784 int slotId = SubscriptionManager.getSlotIndex(subId);
4785 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004786 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4787 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004788 }
4789 return slotId;
4790 }
4791
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004792 private int getSlotIndex(int subId) {
4793 int slotId = SubscriptionManager.getSlotIndex(subId);
4794 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4795 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4796 }
4797 return slotId;
4798 }
4799
Wink Saville36469e72014-06-11 15:17:00 -07004800 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004801 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004802 */
4803 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004804 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4805 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004806 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004807 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004808 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004809 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004810 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004811 mApp, subId, callingPackage, callingFeatureId,
4812 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004813 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4814 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 final long identity = Binder.clearCallingIdentity();
4817 try {
4818 final Phone phone = getPhone(subId);
4819 if (phone != null) {
4820 return phone.getServiceState().getDataNetworkType();
4821 } else {
4822 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4823 }
4824 } finally {
4825 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004827 }
4828
4829 /**
4830 * Returns the data network type
4831 */
4832 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004833 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4834 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4835 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004836 }
4837
4838 /**
4839 * Returns the data network type for a subId
4840 */
4841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004842 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4843 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004845 mApp, subId, callingPackage, callingFeatureId,
4846 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004847 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4848 }
4849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 final Phone phone = getPhone(subId);
4853 if (phone != null) {
4854 return phone.getServiceState().getDataNetworkType();
4855 } else {
4856 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4857 }
4858 } finally {
4859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004861 }
4862
4863 /**
Wink Saville36469e72014-06-11 15:17:00 -07004864 * Returns the Voice network type for a subId
4865 */
4866 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004867 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4868 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004869 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004870 mApp, subId, callingPackage, callingFeatureId,
4871 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004872 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4873 }
4874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 final Phone phone = getPhone(subId);
4878 if (phone != null) {
4879 return phone.getServiceState().getVoiceNetworkType();
4880 } else {
4881 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4882 }
4883 } finally {
4884 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004886 }
4887
4888 /**
4889 * @return true if a ICC card is present
4890 */
4891 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004892 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004893 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4894 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004895 }
4896
4897 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004898 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004899 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004900 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004901 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 final Phone phone = PhoneFactory.getPhone(slotIndex);
4905 if (phone != null) {
4906 return phone.getIccCard().hasIccCard();
4907 } else {
4908 return false;
4909 }
4910 } finally {
4911 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004913 }
4914
4915 /**
4916 * Return if the current radio is LTE on CDMA. This
4917 * is a tri-state return value as for a period of time
4918 * the mode may be unknown.
4919 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004920 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004921 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004922 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004923 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004924 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004925 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4926 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4927 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004928 }
4929
Sanket Padawe356d7632015-06-22 14:03:32 -07004930 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004931 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4932 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004933 try {
4934 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4935 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004936 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4937 }
4938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 final long identity = Binder.clearCallingIdentity();
4940 try {
4941 final Phone phone = getPhone(subId);
4942 if (phone == null) {
4943 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4944 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004945 return TelephonyProperties.lte_on_cdma_device()
4946 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947 }
4948 } finally {
4949 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004950 }
Wink Saville36469e72014-06-11 15:17:00 -07004951 }
4952
Wink Saville36469e72014-06-11 15:17:00 -07004953 /**
4954 * {@hide}
4955 * Returns Default subId, 0 in the case of single standby.
4956 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004957 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004958 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004959 }
4960
Shishir Agrawala9f32182016-04-12 12:00:16 -07004961 private int getSlotForDefaultSubscription() {
4962 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4963 }
4964
Wink Savilleb564aae2014-10-23 10:18:09 -07004965 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004966 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004967 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004968
Pengquan Menge92a50d2018-09-21 15:54:48 -07004969 private boolean isActiveSubscription(int subId) {
4970 return mSubscriptionController.isActiveSubId(subId);
4971 }
4972
Ihab Awadf2177b72013-11-25 13:33:23 -08004973 /**
4974 * @see android.telephony.TelephonyManager.WifiCallingChoices
4975 */
4976 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 final long identity = Binder.clearCallingIdentity();
4978 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004979 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4981 getWhenToMakeWifiCallsDefaultPreference());
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
4984 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004985 }
4986
4987 /**
4988 * @see android.telephony.TelephonyManager.WifiCallingChoices
4989 */
4990 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004994 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004999 }
5000
Sailesh Nepald1e68152013-12-12 19:08:02 -08005001 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005002 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005003 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005004 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005005
Jordan Liu4c733742019-02-28 12:03:40 -08005006 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5007 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5008 if (phoneId == -1) {
5009 throw new IllegalArgumentException("Given slot index: " + slotIndex
5010 + " does not correspond to an active phone");
5011 }
5012 return PhoneFactory.getPhone(phoneId);
5013 }
5014
Shishir Agrawal566b7612013-10-28 14:41:00 -07005015 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005016 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5017 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5019 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005021 if (DBG) {
5022 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5023 }
5024 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5025 p2);
5026 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005027
Jordan Liu4c733742019-02-28 12:03:40 -08005028
5029 @Override
5030 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5031 int slotIndex, String callingPackage, String aid, int p2) {
5032 enforceModifyPermission();
5033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5034 if (DBG) {
5035 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5036 }
5037 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5038 callingPackage, aid, p2);
5039 }
5040
5041 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5042 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 final long identity = Binder.clearCallingIdentity();
5044 try {
5045 if (TextUtils.equals(ISDR_AID, aid)) {
5046 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005047 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5048 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 if (bestComponent == null
5050 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5051 loge("The calling package is not allowed to access ISD-R.");
5052 throw new SecurityException(
5053 "The calling package is not allowed to access ISD-R.");
5054 }
Derek Tan740e1672017-06-27 14:56:27 -07005055 }
Derek Tan740e1672017-06-27 14:56:27 -07005056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005058 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5059 null /* workSource */);
5060 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061 return response;
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
5064 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005065 }
5066
5067 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005068 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5070 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005071 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5072 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5073 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005074
Jordan Liu4c733742019-02-28 12:03:40 -08005075 @Override
5076 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5077 enforceModifyPermission();
5078 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5079 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5080 channel);
5081 }
5082
5083 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084 final long identity = Binder.clearCallingIdentity();
5085 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 if (channel < 0) {
5087 return false;
5088 }
Jordan Liu4c733742019-02-28 12:03:40 -08005089 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5090 null /* workSource */);
5091 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 return success;
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005095 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005096 }
5097
5098 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005099 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005100 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5102 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005103 if (DBG) {
5104 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5105 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5106 + p3 + " data=" + data);
5107 }
5108 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5109 command, p1, p2, p3, data);
5110 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005111
Jordan Liu4c733742019-02-28 12:03:40 -08005112 @Override
5113 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5114 int command, int p1, int p2, int p3, String data) {
5115 enforceModifyPermission();
5116 if (DBG) {
5117 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5118 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5119 + p3 + " data=" + data);
5120 }
5121 return iccTransmitApduLogicalChannelWithPermission(
5122 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5123 data);
5124 }
5125
5126 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5127 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 final long identity = Binder.clearCallingIdentity();
5129 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005130 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 return "";
5132 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005135 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5136 null /* workSource */);
5137 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 // Append the returned status code to the end of the response payload.
5140 String s = Integer.toHexString(
5141 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5142 if (response.payload != null) {
5143 s = IccUtils.bytesToHexString(response.payload) + s;
5144 }
5145 return s;
5146 } finally {
5147 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005148 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005149 }
Jake Hambye994d462014-02-03 13:10:13 -08005150
Evan Charltonc66da362014-05-16 14:06:40 -07005151 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005152 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5153 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5155 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005156 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005157 if (DBG) {
5158 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5159 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5160 }
5161 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5162 cla, command, p1, p2, p3, data);
5163 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005164
Jordan Liu4c733742019-02-28 12:03:40 -08005165 @Override
5166 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5167 int command, int p1, int p2, int p3, String data) {
5168 enforceModifyPermission();
5169 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5170 if (DBG) {
5171 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5172 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5173 + " data=" + data);
5174 }
5175
5176 return iccTransmitApduBasicChannelWithPermission(
5177 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5178 p2, p3, data);
5179 }
5180
5181 // open APDU basic channel assuming the caller has sufficient permissions
5182 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5183 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005184 final long identity = Binder.clearCallingIdentity();
5185 try {
5186 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5187 && TextUtils.equals(ISDR_AID, data)) {
5188 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005189 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5190 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 if (bestComponent == null
5192 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5193 loge("The calling package is not allowed to select ISD-R.");
5194 throw new SecurityException(
5195 "The calling package is not allowed to select ISD-R.");
5196 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005197 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005200 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5201 null /* workSource */);
5202 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 // Append the returned status code to the end of the response payload.
5205 String s = Integer.toHexString(
5206 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5207 if (response.payload != null) {
5208 s = IccUtils.bytesToHexString(response.payload) + s;
5209 }
5210 return s;
5211 } finally {
5212 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005213 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005214 }
5215
5216 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005217 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005218 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5220 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 if (DBG) {
5225 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5226 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5227 }
5228
5229 IccIoResult response =
5230 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5231 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5232 subId);
5233
5234 if (DBG) {
5235 log("Exchange SIM_IO [R]" + response);
5236 }
5237
5238 byte[] result = null;
5239 int length = 2;
5240 if (response.payload != null) {
5241 length = 2 + response.payload.length;
5242 result = new byte[length];
5243 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5244 } else {
5245 result = new byte[length];
5246 }
5247
5248 result[length - 1] = (byte) response.sw2;
5249 result[length - 2] = (byte) response.sw1;
5250 return result;
5251 } finally {
5252 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005253 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005254 }
5255
Nathan Haroldb3014052017-01-25 15:57:32 -08005256 /**
5257 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5258 * on a particular subscription
5259 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005260 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5261 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005263 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005264 return null;
5265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266
5267 final long identity = Binder.clearCallingIdentity();
5268 try {
5269 if (appType != TelephonyManager.APPTYPE_USIM
5270 && appType != TelephonyManager.APPTYPE_SIM) {
5271 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5272 return null;
5273 }
5274 Object response = sendRequest(
5275 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5276 if (response instanceof String[]) {
5277 return (String[]) response;
5278 }
yincheng zhao2737e882019-09-06 17:06:54 -07005279 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005280 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005281 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 } finally {
5283 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005284 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005285 }
5286
yincheng zhao2737e882019-09-06 17:06:54 -07005287 /**
5288 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5289 * subscription.
5290 *
5291 * @param subId the id of the subscription.
5292 * @param appType the uicc app type, must be USIM or SIM.
5293 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5294 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005295 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005296 * @return number of fplmns that is successfully written to the SIM.
5297 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005298 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5299 String callingFeatureId) {
5300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5301 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005302 if (DBG) logv("no permissions for setForbiddenplmns");
5303 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5304 }
5305 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5306 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5307 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5308 }
5309 if (fplmns == null) {
5310 throw new IllegalArgumentException("Fplmn List provided is null");
5311 }
5312 for (String fplmn : fplmns) {
5313 if (!CellIdentity.isValidPlmn(fplmn)) {
5314 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5315 }
5316 }
5317 final long identity = Binder.clearCallingIdentity();
5318 try {
5319 Object response = sendRequest(
5320 CMD_SET_FORBIDDEN_PLMNS,
5321 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5322 subId);
5323 return (int) response;
5324 } finally {
5325 Binder.restoreCallingIdentity(identity);
5326 }
5327 }
5328
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005329 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005330 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5332 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5337 if (response.payload == null) {
5338 return "";
5339 }
Evan Charltonc66da362014-05-16 14:06:40 -07005340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 // Append the returned status code to the end of the response payload.
5342 String s = Integer.toHexString(
5343 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5344 s = IccUtils.bytesToHexString(response.payload) + s;
5345 return s;
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
5348 }
Evan Charltonc66da362014-05-16 14:06:40 -07005349 }
5350
Jake Hambye994d462014-02-03 13:10:13 -08005351 /**
5352 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5353 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5354 *
5355 * @param itemID the ID of the item to read
5356 * @return the NV item as a String, or null on error.
5357 */
5358 @Override
5359 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005360 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5362 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363
5364 final long identity = Binder.clearCallingIdentity();
5365 try {
5366 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005367 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5369 return value;
5370 } finally {
5371 Binder.restoreCallingIdentity(identity);
5372 }
Jake Hambye994d462014-02-03 13:10:13 -08005373 }
5374
5375 /**
5376 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5377 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5378 *
5379 * @param itemID the ID of the item to read
5380 * @param itemValue the value to write, as a String
5381 * @return true on success; false on any failure
5382 */
5383 @Override
5384 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005385 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5387 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388
5389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5392 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005393 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5395 return success;
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
Jake Hambye994d462014-02-03 13:10:13 -08005399 }
5400
5401 /**
5402 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5403 * Used for device configuration by some CDMA operators.
5404 *
5405 * @param preferredRoamingList byte array containing the new PRL
5406 * @return true on success; false on any failure
5407 */
5408 @Override
5409 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5411 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412
5413 final long identity = Binder.clearCallingIdentity();
5414 try {
5415 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5416 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5417 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5418 return success;
5419 } finally {
5420 Binder.restoreCallingIdentity(identity);
5421 }
Jake Hambye994d462014-02-03 13:10:13 -08005422 }
5423
5424 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005425 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005426 * Used for device configuration by some CDMA operators.
5427 *
chen xu6dac5ab2018-10-26 17:39:23 -07005428 * @param slotIndex - device slot.
5429 *
Jake Hambye994d462014-02-03 13:10:13 -08005430 * @return true on success; false on any failure
5431 */
5432 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005433 public boolean resetModemConfig(int slotIndex) {
5434 Phone phone = PhoneFactory.getPhone(slotIndex);
5435 if (phone != null) {
5436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5437 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438
chen xu6dac5ab2018-10-26 17:39:23 -07005439 final long identity = Binder.clearCallingIdentity();
5440 try {
5441 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5442 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5443 return success;
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
5446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 }
chen xu6dac5ab2018-10-26 17:39:23 -07005448 return false;
5449 }
5450
5451 /**
5452 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5453 *
5454 * @param slotIndex - device slot.
5455 *
5456 * @return true on success; false on any failure
5457 */
5458 @Override
5459 public boolean rebootModem(int slotIndex) {
5460 Phone phone = PhoneFactory.getPhone(slotIndex);
5461 if (phone != null) {
5462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5463 mApp, phone.getSubId(), "rebootModem");
5464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5468 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5469 return success;
5470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
5473 }
5474 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005475 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005476
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005477 public String[] getPcscfAddress(String apnType, String callingPackage,
5478 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005479 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5481 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005482 return new String[0];
5483 }
5484
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 final long identity = Binder.clearCallingIdentity();
5486 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005487 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005488 } finally {
5489 Binder.restoreCallingIdentity(identity);
5490 }
Wink Saville36469e72014-06-11 15:17:00 -07005491 }
5492
Brad Ebinger51f743a2017-01-23 13:50:20 -08005493 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005494 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5495 * {@link #disableIms(int)}.
5496 * @param slotIndex device slot.
5497 */
5498 public void resetIms(int slotIndex) {
5499 enforceModifyPermission();
5500
5501 final long identity = Binder.clearCallingIdentity();
5502 try {
5503 if (mImsResolver == null) {
5504 // may happen if the does not support IMS.
5505 return;
5506 }
5507 mImsResolver.disableIms(slotIndex);
5508 mImsResolver.enableIms(slotIndex);
5509 } finally {
5510 Binder.restoreCallingIdentity(identity);
5511 }
5512 }
5513
5514 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005515 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5516 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005517 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005518 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005519 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520
5521 final long identity = Binder.clearCallingIdentity();
5522 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005523 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005524 // may happen if the device does not support IMS.
5525 return;
5526 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005527 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 } finally {
5529 Binder.restoreCallingIdentity(identity);
5530 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005531 }
5532
5533 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005534 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5535 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005536 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005537 public void disableIms(int slotId) {
5538 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539
5540 final long identity = Binder.clearCallingIdentity();
5541 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005542 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005543 // may happen if the device does not support IMS.
5544 return;
5545 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005546 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005547 } finally {
5548 Binder.restoreCallingIdentity(identity);
5549 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005550 }
5551
5552 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005553 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5554 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005555 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005556 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005557 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005558 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559
5560 final long identity = Binder.clearCallingIdentity();
5561 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005562 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005563 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5564 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005565 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005566 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005570 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005571 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005572 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5573 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005574 @Override
5575 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005576 enforceModifyPermission();
5577
5578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005581 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005582 } finally {
5583 Binder.restoreCallingIdentity(identity);
5584 }
5585 }
5586
5587 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005588 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005589 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005590 */
5591 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5592 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005593
5594 final long identity = Binder.clearCallingIdentity();
5595 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005596 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005597 // may happen if the device does not support IMS.
5598 return null;
5599 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005600 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601 } finally {
5602 Binder.restoreCallingIdentity(identity);
5603 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005604 }
5605
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005606 /**
5607 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005608 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005609 */
5610 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5611 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612
5613 final long identity = Binder.clearCallingIdentity();
5614 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005615 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005616 // may happen if the device does not support IMS.
5617 return null;
5618 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005619 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 } finally {
5621 Binder.restoreCallingIdentity(identity);
5622 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005623 }
5624
Brad Ebinger884c07b2018-02-15 16:17:40 -08005625 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005626 * Sets the ImsService Package Name that Telephony will bind to.
5627 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005628 * @param slotIndex the slot ID that the ImsService should bind for.
5629 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005630 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005631 * @param featureTypes An integer array of feature types associated with a packageName.
5632 * @param packageName The name of the package that the current configuration will be replaced
5633 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005634 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005635 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005636 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5637 int[] featureTypes, String packageName) {
5638 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5639 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5641 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005642 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 final long identity = Binder.clearCallingIdentity();
5645 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005646 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005647 // may happen if the device does not support IMS.
5648 return false;
5649 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005650 Map<Integer, String> featureConfig = new HashMap<>();
5651 for (int featureType : featureTypes) {
5652 featureConfig.put(featureType, packageName);
5653 }
5654 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5655 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 } finally {
5657 Binder.restoreCallingIdentity(identity);
5658 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005659 }
5660
5661 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005662 * Clears any carrier ImsService overrides for the slot index specified that were previously
5663 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5664 *
5665 * This should only be used for testing.
5666 *
5667 * @param slotIndex the slot ID that the ImsService should bind for.
5668 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5669 */
5670 @Override
5671 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5672 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5673 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5674 "clearCarrierImsServiceOverride");
5675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5676 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5677 "clearCarrierImsServiceOverride");
5678
5679 final long identity = Binder.clearCallingIdentity();
5680 try {
5681 if (mImsResolver == null) {
5682 // may happen if the device does not support IMS.
5683 return false;
5684 }
5685 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5686 } finally {
5687 Binder.restoreCallingIdentity(identity);
5688 }
5689 }
5690
5691 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005692 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005693 *
5694 * @param slotId The slot that the ImsService is associated with.
5695 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5696 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005697 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005698 * @return the package name of the ImsService configuration.
5699 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005700 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5701 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005702 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005703 TelephonyPermissions
5704 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5705 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5706 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005707
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 final long identity = Binder.clearCallingIdentity();
5709 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005710 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005711 // may happen if the device does not support IMS.
5712 return "";
5713 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005714 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005715 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5716 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005720 }
5721
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005722 /**
5723 * Get the MmTelFeature state associated with the requested subscription id.
5724 * @param subId The subscription that the MmTelFeature is associated with.
5725 * @param callback A callback with an integer containing the
5726 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5727 */
5728 @Override
5729 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5730 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5731 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5732 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5733 "IMS not available on device.");
5734 }
5735 final long token = Binder.clearCallingIdentity();
5736 try {
5737 int slotId = getSlotIndex(subId);
5738 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5739 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5740 + subId + "'");
5741 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5742 }
5743 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5744 try {
5745 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5746 } catch (RemoteException e) {
5747 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5748 + "Ignore");
5749 }
5750 });
5751 } finally {
5752 Binder.restoreCallingIdentity(token);
5753 }
5754 }
5755
Daniel Brightbb5840b2021-01-12 15:48:18 -08005756 /**
5757 * Sets the ims registration state on all valid {@link Phone}s.
5758 */
5759 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761
5762 final long identity = Binder.clearCallingIdentity();
5763 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005764 // NOTE: Before S, this method only set the default phone.
5765 for (final Phone phone : PhoneFactory.getPhones()) {
5766 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5767 phone.setImsRegistrationState(registered);
5768 }
5769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 } finally {
5771 Binder.restoreCallingIdentity(identity);
5772 }
Wink Saville36469e72014-06-11 15:17:00 -07005773 }
5774
5775 /**
Stuart Scott54788802015-03-30 13:18:01 -07005776 * Set the network selection mode to automatic.
5777 *
5778 */
5779 @Override
5780 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5782 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
shilufc958392020-01-20 11:36:01 -08005786 if (!isActiveSubscription(subId)) {
5787 return;
5788 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005790 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5791 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 } finally {
5793 Binder.restoreCallingIdentity(identity);
5794 }
Stuart Scott54788802015-03-30 13:18:01 -07005795 }
5796
Jack Yud10cdd42020-09-28 20:28:01 -07005797 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005798 * Ask the radio to connect to the input network and change selection mode to manual.
5799 *
5800 * @param subId the id of the subscription.
5801 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5802 * the operator to attach to.
5803 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5804 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5805 * normal network selection next time.
5806 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005807 */
5808 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005809 public boolean setNetworkSelectionModeManual(
5810 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5812 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005813
5814 if (!isActiveSubscription(subId)) {
5815 return false;
5816 }
5817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 final long identity = Binder.clearCallingIdentity();
5819 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005820 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005822 if (DBG) {
5823 log("setNetworkSelectionModeManual: subId: " + subId
5824 + " operator: " + operatorInfo);
5825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005830 }
shilu84f6e8b2019-12-19 13:58:01 -08005831 /**
5832 * Get the manual network selection
5833 *
5834 * @param subId the id of the subscription.
5835 *
5836 * @return the previously saved user selected PLMN
5837 */
5838 @Override
5839 public String getManualNetworkSelectionPlmn(int subId) {
5840 TelephonyPermissions
5841 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5842 mApp, subId, "getManualNetworkSelectionPlmn");
5843
5844 final long identity = Binder.clearCallingIdentity();
5845 try {
5846 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005847 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005848 }
5849
5850 final Phone phone = getPhone(subId);
5851 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005852 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005853 }
5854 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5855 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5856 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
5859 }
5860 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005861
5862 /**
5863 * Scans for available networks.
5864 */
5865 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005866 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5867 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005868 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5869 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005870 LocationAccessPolicy.LocationPermissionResult locationResult =
5871 LocationAccessPolicy.checkLocationPermission(mApp,
5872 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5873 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005874 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005875 .setCallingPid(Binder.getCallingPid())
5876 .setCallingUid(Binder.getCallingUid())
5877 .setMethod("getCellNetworkScanResults")
5878 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005879 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5880 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005881 .build());
5882 switch (locationResult) {
5883 case DENIED_HARD:
5884 throw new SecurityException("Not allowed to access scan results -- location");
5885 case DENIED_SOFT:
5886 return null;
5887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888
Pengquan Menga1bb6272018-09-06 09:59:22 -07005889 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 try {
5891 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005892 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005897 }
5898
5899 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005900 * Get the call forwarding info, given the call forwarding reason.
5901 */
5902 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005903 public void getCallForwarding(int subId, int callForwardingReason,
5904 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005905 enforceReadPrivilegedPermission("getCallForwarding");
5906 long identity = Binder.clearCallingIdentity();
5907 try {
5908 if (DBG) {
5909 log("getCallForwarding: subId " + subId
5910 + " callForwardingReason" + callForwardingReason);
5911 }
Hall Liu27d24262020-09-18 19:04:59 -07005912
5913 Phone phone = getPhone(subId);
5914 if (phone == null) {
5915 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005916 callback.onError(
5917 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005918 } catch (RemoteException e) {
5919 // ignore
5920 }
5921 return;
5922 }
5923
5924 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5925 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5926 @Override
5927 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5928 try {
5929 callback.onCallForwardingInfoAvailable(info);
5930 } catch (RemoteException e) {
5931 // ignore
5932 }
5933 }
5934
5935 @Override
5936 public void onError(int error) {
5937 try {
5938 callback.onError(error);
5939 } catch (RemoteException e) {
5940 // ignore
5941 }
5942 }
5943 });
5944 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005945 } finally {
5946 Binder.restoreCallingIdentity(identity);
5947 }
5948 }
5949
5950 /**
5951 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5952 * reason, the number to forward, and the timeout before the forwarding is attempted.
5953 */
5954 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005955 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5956 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005957 enforceModifyPermission();
5958 long identity = Binder.clearCallingIdentity();
5959 try {
5960 if (DBG) {
5961 log("setCallForwarding: subId " + subId
5962 + " callForwardingInfo" + callForwardingInfo);
5963 }
Hall Liu27d24262020-09-18 19:04:59 -07005964
5965 Phone phone = getPhone(subId);
5966 if (phone == null) {
5967 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005968 callback.accept(
5969 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005970 } catch (RemoteException e) {
5971 // ignore
5972 }
5973 return;
5974 }
5975
5976 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5977 FunctionalUtils.ignoreRemoteException(callback::accept));
5978
5979 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005980 } finally {
5981 Binder.restoreCallingIdentity(identity);
5982 }
5983 }
5984
5985 /**
Hall Liu27d24262020-09-18 19:04:59 -07005986 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005987 */
5988 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005989 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005990 enforceReadPrivilegedPermission("getCallForwarding");
5991 long identity = Binder.clearCallingIdentity();
5992 try {
Hall Liu27d24262020-09-18 19:04:59 -07005993
5994 Phone phone = getPhone(subId);
5995 if (phone == null) {
5996 try {
5997 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5998 } catch (RemoteException e) {
5999 // ignore
6000 }
6001 return;
6002 }
6003
6004 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
6005
Shuo Qian4a594052020-01-23 11:59:30 -08006006 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07006007 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006008 } finally {
6009 Binder.restoreCallingIdentity(identity);
6010 }
6011 }
6012
6013 /**
Hall Liu27d24262020-09-18 19:04:59 -07006014 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006015 */
6016 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006017 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006018 enforceModifyPermission();
6019 long identity = Binder.clearCallingIdentity();
6020 try {
Hall Liu27d24262020-09-18 19:04:59 -07006021 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6022
6023 Phone phone = getPhone(subId);
6024 if (phone == null) {
6025 try {
6026 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6027 } catch (RemoteException e) {
6028 // ignore
6029 }
6030 return;
6031 }
6032
6033 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6034 FunctionalUtils.ignoreRemoteException(callback::accept));
6035
6036 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006037 } finally {
6038 Binder.restoreCallingIdentity(identity);
6039 }
6040 }
6041
6042 /**
yinxub1bed742017-04-17 11:45:04 -07006043 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006044 *
yinxub1bed742017-04-17 11:45:04 -07006045 * @param subId id of the subscription
6046 * @param request contains the radio access networks with bands/channels to scan
6047 * @param messenger callback messenger for scan results or errors
6048 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006049 * @return the id of the requested scan which can be used to stop the scan.
6050 */
6051 @Override
6052 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006053 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6055 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006056 LocationAccessPolicy.LocationPermissionResult locationResult =
6057 LocationAccessPolicy.checkLocationPermission(mApp,
6058 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6059 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006060 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006061 .setCallingPid(Binder.getCallingPid())
6062 .setCallingUid(Binder.getCallingUid())
6063 .setMethod("requestNetworkScan")
6064 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006065 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6066 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006067 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006068 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006069 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6070 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006071 if (e != null) {
6072 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6073 throw e;
6074 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006075 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006076 return TelephonyScanManager.INVALID_SCAN_ID;
6077 }
6078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 }
Hall Liu912dfd32019-04-25 14:02:26 -07006080 int callingUid = Binder.getCallingUid();
6081 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006082 final long identity = Binder.clearCallingIdentity();
6083 try {
6084 return mNetworkScanRequestTracker.startNetworkScan(
6085 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006086 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
yinxu504e1392017-04-12 16:03:22 -07006090 }
6091
Hall Liub2ac8ef2019-02-28 15:56:23 -08006092 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006093 NetworkScanRequest request, int subId, String callingPackage) {
6094 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006095 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6096 boolean hasNetworkScanPermission =
6097 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6098 == PERMISSION_GRANTED;
6099
6100 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6101 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6102 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006103 }
6104
6105 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6106 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006107 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6108 return new SecurityException("Specific channels must not be"
6109 + " scanned without location access.");
6110 }
6111 }
6112 }
6113
Hall Liub2ac8ef2019-02-28 15:56:23 -08006114 return null;
6115 }
6116
yinxu504e1392017-04-12 16:03:22 -07006117 /**
6118 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006119 *
6120 * @param subId id of the subscription
6121 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006122 */
6123 @Override
6124 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6126 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127
Hall Liu912dfd32019-04-25 14:02:26 -07006128 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 final long identity = Binder.clearCallingIdentity();
6130 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006131 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 } finally {
6133 Binder.restoreCallingIdentity(identity);
6134 }
yinxu504e1392017-04-12 16:03:22 -07006135 }
6136
6137 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006138 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006139 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006140 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006141 */
6142 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006143 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006144 TelephonyPermissions
6145 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006146 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147
6148 final long identity = Binder.clearCallingIdentity();
6149 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006150 if (DBG) log("getAllowedNetworkTypesBitmask");
6151 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6152 int networkTypesBitmask = (result != null ? result[0] : -1);
6153 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6154 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 } finally {
6156 Binder.restoreCallingIdentity(identity);
6157 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006158 }
6159
6160 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006161 * Get the allowed network types for certain reason.
6162 *
6163 * @param subId the id of the subscription.
6164 * @param reason the reason the allowed network type change is taking place
6165 * @return the allowed network types.
6166 */
6167 @Override
6168 public long getAllowedNetworkTypesForReason(int subId,
6169 @TelephonyManager.AllowedNetworkTypesReason int reason) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006170 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6171 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006172 final long identity = Binder.clearCallingIdentity();
6173 try {
6174 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6175 } finally {
6176 Binder.restoreCallingIdentity(identity);
6177 }
6178 }
6179
6180 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006181 * Enable/Disable E-UTRA-NR Dual Connectivity
6182 * @param subId subscription id of the sim card
6183 * @param nrDualConnectivityState expected NR dual connectivity state
6184 * This can be passed following states
6185 * <ol>
6186 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6187 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6188 * <li>Disable NR dual connectivity and force secondary cell to be released
6189 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6190 * </ol>
6191 * @return operation result.
6192 */
6193 @Override
6194 public int setNrDualConnectivityState(int subId,
6195 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6197 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006198 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006199 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6200 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6201 }
6202
Sooraj Sasindran37444802020-08-11 10:40:43 -07006203 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6204 final long identity = Binder.clearCallingIdentity();
6205 try {
6206 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6207 nrDualConnectivityState, subId,
6208 workSource);
6209 if (DBG) log("enableNRDualConnectivity result: " + result);
6210 return result;
6211 } finally {
6212 Binder.restoreCallingIdentity(identity);
6213 }
6214 }
6215
6216 /**
6217 * Is E-UTRA-NR Dual Connectivity enabled
6218 * @return true if dual connectivity is enabled else false
6219 */
6220 @Override
6221 public boolean isNrDualConnectivityEnabled(int subId) {
6222 TelephonyPermissions
6223 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6224 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006225 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006226 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6227 return false;
6228 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006229 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6230 final long identity = Binder.clearCallingIdentity();
6231 try {
6232 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6233 null, subId, workSource);
6234 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6235 return isEnabled;
6236 } finally {
6237 Binder.restoreCallingIdentity(identity);
6238 }
6239 }
6240
6241 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006242 * Set the allowed network types of the device and
6243 * provide the reason triggering the allowed network change.
6244 *
6245 * @param subId the id of the subscription.
6246 * @param reason the reason the allowed network type change is taking place
6247 * @param allowedNetworkTypes the allowed network types.
6248 * @return true on success; false on any failure.
6249 */
6250 @Override
6251 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006252 @TelephonyManager.AllowedNetworkTypesReason int reason,
6253 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6255 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006256 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6257 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6258 return false;
6259 }
6260
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006261 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6262 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6263
6264
6265 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6266 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6267 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006268 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006269
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006270 final long identity = Binder.clearCallingIdentity();
6271 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006272 Boolean success = (Boolean) sendRequest(
6273 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6274 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6275
6276 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6277 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
6281 }
6282
6283 /**
Miaoa84611c2019-03-15 09:21:10 +08006284 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006285 *
Miaoa84611c2019-03-15 09:21:10 +08006286 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006287 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006288 * @hide
6289 */
6290 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006291 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006292 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006294 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295 try {
Miaoa84611c2019-03-15 09:21:10 +08006296 if (phone != null) {
6297 return phone.hasMatchedTetherApnSetting();
6298 } else {
6299 return false;
6300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 } finally {
6302 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006303 }
Junda Liu475951f2014-11-07 16:45:03 -08006304 }
6305
6306 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006307 * Enable or disable always reporting signal strength changes from radio.
6308 *
6309 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6310 */
6311 @Override
6312 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6313 enforceModifyPermission();
6314 enforceSystemCaller();
6315
6316 final long identity = Binder.clearCallingIdentity();
6317 final Phone phone = getPhone(subId);
6318 try {
6319 if (phone != null) {
6320 if (DBG) {
6321 log("setAlwaysReportSignalStrength: subId=" + subId
6322 + " isEnable=" + isEnable);
6323 }
6324 phone.setAlwaysReportSignalStrength(isEnable);
6325 } else {
6326 loge("setAlwaysReportSignalStrength: no phone found for subId="
6327 + subId);
6328 }
6329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
6332 }
6333
6334 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006335 * Get the user enabled state of Mobile Data.
6336 *
6337 * TODO: remove and use isUserDataEnabled.
6338 * This can't be removed now because some vendor codes
6339 * calls through ITelephony directly while they should
6340 * use TelephonyManager.
6341 *
6342 * @return true on enabled
6343 */
6344 @Override
6345 public boolean getDataEnabled(int subId) {
6346 return isUserDataEnabled(subId);
6347 }
6348
6349 /**
6350 * Get whether mobile data is enabled per user setting.
6351 *
6352 * There are other factors deciding whether mobile data is actually enabled, but they are
6353 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006354 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006355 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006356 *
6357 * @return {@code true} if data is enabled else {@code false}
6358 */
6359 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006360 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006361 try {
6362 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6363 null);
6364 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6366 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006367 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368
6369 final long identity = Binder.clearCallingIdentity();
6370 try {
6371 int phoneId = mSubscriptionController.getPhoneId(subId);
6372 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6373 Phone phone = PhoneFactory.getPhone(phoneId);
6374 if (phone != null) {
6375 boolean retVal = phone.isUserDataEnabled();
6376 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6377 return retVal;
6378 } else {
6379 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6380 return false;
6381 }
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006384 }
6385 }
6386
6387 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006388 * Checks if the device is capable of mobile data by considering whether whether the
6389 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6390 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006391 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006392 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006393 */
6394 @Override
6395 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006396 try {
6397 try {
6398 mApp.enforceCallingOrSelfPermission(
6399 android.Manifest.permission.ACCESS_NETWORK_STATE,
6400 null);
6401 } catch (Exception e) {
6402 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6403 "isDataEnabled");
6404 }
6405 } catch (Exception e) {
6406 enforceReadPrivilegedPermission("isDataEnabled");
6407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006408
6409 final long identity = Binder.clearCallingIdentity();
6410 try {
6411 int phoneId = mSubscriptionController.getPhoneId(subId);
6412 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6413 Phone phone = PhoneFactory.getPhone(phoneId);
6414 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006415 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006416 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6417 return retVal;
6418 } else {
6419 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6420 return false;
6421 }
6422 } finally {
6423 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006424 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006425 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006426
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006427 /**
6428 * Check if data is enabled for a specific reason
6429 * @param subId Subscription index
6430 * @param reason the reason the data enable change is taking place
6431 * @return {@code true} if the overall data is enabled; {@code false} if not.
6432 */
6433 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006434 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006435 @TelephonyManager.DataEnabledReason int reason) {
6436 try {
6437 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6438 null);
6439 } catch (Exception e) {
6440 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006441 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006442 }
6443
6444
6445 final long identity = Binder.clearCallingIdentity();
6446 try {
6447 int phoneId = mSubscriptionController.getPhoneId(subId);
6448 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006449 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006450 + " reason=" + reason);
6451 }
6452 Phone phone = PhoneFactory.getPhone(phoneId);
6453 if (phone != null) {
6454 boolean retVal;
6455 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6456 retVal = phone.isUserDataEnabled();
6457 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006458 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006459 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006460 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006461 return retVal;
6462 } else {
6463 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006464 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006465 + subId + " retVal=false");
6466 }
6467 return false;
6468 }
6469 } finally {
6470 Binder.restoreCallingIdentity(identity);
6471 }
6472 }
6473
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006474 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006475 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006476 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6477 // Skip the check if it's one of these special uids
6478 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6479 }
6480
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006481 //load access rules from carrier configs, and check those as well: b/139133814
6482 SubscriptionController subController = SubscriptionController.getInstance();
6483 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6484 || subController == null) return privilegeFromSim;
6485
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006486 PackageManager pkgMgr = phone.getContext().getPackageManager();
6487 String[] packages = pkgMgr.getPackagesForUid(uid);
6488
6489 final long identity = Binder.clearCallingIdentity();
6490 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006491 int subId = phone.getSubId();
6492 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6493 // A test override is in place for the privileges for this subId, so don't try to
6494 // read the subscription privileges.
6495 return privilegeFromSim;
6496 }
6497 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006498 SubscriptionManager subManager = (SubscriptionManager)
6499 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6500 for (String pkg : packages) {
6501 if (subManager.canManageSubscription(subInfo, pkg)) {
6502 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6503 }
6504 }
6505 return privilegeFromSim;
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
6509 }
6510
6511 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6512 String pkgName) {
6513 //load access rules from carrier configs, and check those as well: b/139133814
6514 SubscriptionController subController = SubscriptionController.getInstance();
6515 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6516 || subController == null) return privilegeFromSim;
6517
6518 final long identity = Binder.clearCallingIdentity();
6519 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006520 int subId = phone.getSubId();
6521 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6522 // A test override is in place for the privileges for this subId, so don't try to
6523 // read the subscription privileges.
6524 return privilegeFromSim;
6525 }
6526 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006527 SubscriptionManager subManager = (SubscriptionManager)
6528 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6529 return subManager.canManageSubscription(subInfo, pkgName)
6530 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
6534 }
6535
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006536 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006537 public int getCarrierPrivilegeStatus(int subId) {
6538 final Phone phone = getPhone(subId);
6539 if (phone == null) {
6540 loge("getCarrierPrivilegeStatus: Invalid subId");
6541 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6542 }
6543 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006544 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006545 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006546 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6547 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006548
6549 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6550 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006551 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006552 }
Junda Liu29340342014-07-10 15:23:27 -07006553
6554 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006555 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006556 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006557 final Phone phone = getPhone(subId);
6558 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006559 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006560 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6561 }
6562 UiccProfile profile =
6563 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6564 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006565 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006566 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6567 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006568 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006569 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006570 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006571 }
6572
6573 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006574 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6575 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006576 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006577 }
6578
6579 int phoneId = SubscriptionManager.getPhoneId(subId);
6580 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006581 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006582 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006583 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6584 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006585 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6586 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6587 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006588 }
6589
6590 @Override
6591 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006592 if (TextUtils.isEmpty(pkgName))
6593 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006594 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6595 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6596 UiccCard card = UiccController.getInstance().getUiccCard(i);
6597 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006598 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006599 continue;
6600 }
6601
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006602 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6603 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6604 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006605 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6606 break;
6607 }
6608 }
6609
6610 return result;
Junda Liu29340342014-07-10 15:23:27 -07006611 }
Derek Tan89e89d42014-07-08 17:00:10 -07006612
6613 @Override
Junda Liue64de782015-04-16 17:19:16 -07006614 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6615 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6616 loge("phoneId " + phoneId + " is not valid.");
6617 return null;
6618 }
6619 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006620 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006621 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006622 return null ;
6623 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006624 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006625 }
6626
Amith Yamasani6e118872016-02-19 12:53:51 -08006627 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006628 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006629 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006630 List<String> privilegedPackages = new ArrayList<>();
6631 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006632 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6633 // has UICC in that slot.
6634 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006635 if (card.hasCarrierPrivilegeRules()) {
6636 if (packages == null) {
6637 // Only check packages in user 0 for now
6638 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006639 PackageManager.MATCH_DISABLED_COMPONENTS
6640 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006641 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006642 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006643 }
6644 for (int p = packages.size() - 1; p >= 0; p--) {
6645 PackageInfo pkgInfo = packages.get(p);
6646 if (pkgInfo != null && pkgInfo.packageName != null
6647 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006648 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006649 privilegedPackages.add(pkgInfo.packageName);
6650 }
6651 }
6652 }
6653 }
6654 return privilegedPackages;
6655 }
6656
chen xuf7e9fe82019-05-09 19:31:02 -07006657 @Override
6658 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006659 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6660
6661 final long identity = Binder.clearCallingIdentity();
6662
chen xuf7e9fe82019-05-09 19:31:02 -07006663 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006664 try {
6665 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6666 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6667 }
6668 } finally {
6669 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006670 }
6671 return privilegedPackages;
6672 }
6673
Wink Savilleb564aae2014-10-23 10:18:09 -07006674 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006675 final Phone phone = getPhone(subId);
6676 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006677 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006678 return null;
6679 }
6680 String iccId = card.getIccId();
6681 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006682 return null;
6683 }
6684 return iccId;
6685 }
6686
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006687 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006688 public void setCallComposerStatus(int subId, int status) {
6689 enforceModifyPermission();
6690
6691 final long identity = Binder.clearCallingIdentity();
6692 try {
6693 Phone phone = getPhone(subId);
6694 if (phone != null) {
6695 Phone defaultPhone = phone.getImsPhone();
6696 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6697 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6698 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006699 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6700 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006701 }
6702 }
Shuo Qian284ae752020-12-22 19:10:14 -08006703 } catch (ImsException e) {
6704 throw new ServiceSpecificException(e.getCode());
6705 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006706 Binder.restoreCallingIdentity(identity);
6707 }
6708 }
6709
6710 @Override
6711 public int getCallComposerStatus(int subId) {
6712 enforceReadPrivilegedPermission("getCallComposerStatus");
6713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
6716 Phone phone = getPhone(subId);
6717 if (phone != null) {
6718 Phone defaultPhone = phone.getImsPhone();
6719 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6720 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6721 return imsPhone.getCallComposerStatus();
6722 }
6723 }
6724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
6727 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6728 }
6729
6730 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006731 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6732 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006733 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736 final long identity = Binder.clearCallingIdentity();
6737 try {
6738 final String iccId = getIccId(subId);
6739 final Phone phone = getPhone(subId);
6740 if (phone == null) {
6741 return false;
6742 }
6743 final String subscriberId = phone.getSubscriberId();
6744
6745 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006746 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747 + subscriberId + " to " + number);
6748 }
6749
6750 if (TextUtils.isEmpty(iccId)) {
6751 return false;
6752 }
6753
6754 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6755
6756 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6757 if (alphaTag == null) {
6758 editor.remove(alphaTagPrefKey);
6759 } else {
6760 editor.putString(alphaTagPrefKey, alphaTag);
6761 }
6762
6763 // Record both the line number and IMSI for this ICCID, since we need to
6764 // track all merged IMSIs based on line number
6765 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6766 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6767 if (number == null) {
6768 editor.remove(numberPrefKey);
6769 editor.remove(subscriberPrefKey);
6770 } else {
6771 editor.putString(numberPrefKey, number);
6772 editor.putString(subscriberPrefKey, subscriberId);
6773 }
6774
6775 editor.commit();
6776 return true;
6777 } finally {
6778 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006779 }
Derek Tan7226c842014-07-02 17:42:23 -07006780 }
6781
6782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006783 public String getLine1NumberForDisplay(int subId, String callingPackage,
6784 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006785 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006787 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006788 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006789 return null;
6790 }
Derek Tan97ebb422014-09-05 16:55:38 -07006791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 final long identity = Binder.clearCallingIdentity();
6793 try {
6794 String iccId = getIccId(subId);
6795 if (iccId != null) {
6796 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6797 if (DBG_MERGE) {
6798 log("getLine1NumberForDisplay returning "
6799 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6800 }
6801 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006802 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6804 return null;
6805 } finally {
6806 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006807 }
Derek Tan7226c842014-07-02 17:42:23 -07006808 }
6809
6810 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006811 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6812 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006813 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006814 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006815 return null;
6816 }
Derek Tan97ebb422014-09-05 16:55:38 -07006817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 final long identity = Binder.clearCallingIdentity();
6819 try {
6820 String iccId = getIccId(subId);
6821 if (iccId != null) {
6822 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6823 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6824 }
6825 return null;
6826 } finally {
6827 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006828 }
Derek Tan7226c842014-07-02 17:42:23 -07006829 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006830
6831 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006832 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6833 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006834 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6835 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006837 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006838 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006839 return null;
6840 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006841
Jordan Liub49b04b2019-05-06 14:45:15 -07006842 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6843 // the process, where TelephonyManager was instantiated.
6844 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006845 final long identity = Binder.clearCallingIdentity();
6846 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006847 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006848 final TelephonyManager tele = TelephonyManager.from(context);
6849 final SubscriptionManager sub = SubscriptionManager.from(context);
6850
6851 // Figure out what subscribers are currently active
6852 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853
Jordan Liub49b04b2019-05-06 14:45:15 -07006854 // Only consider subs which match the current subId
6855 // This logic can be simplified. See b/131189269 for progress.
6856 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006857 activeSubscriberIds.add(tele.getSubscriberId(subId));
6858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859
6860 // First pass, find a number override for an active subscriber
6861 String mergeNumber = null;
6862 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6863 for (String key : prefs.keySet()) {
6864 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6865 final String subscriberId = (String) prefs.get(key);
6866 if (activeSubscriberIds.contains(subscriberId)) {
6867 final String iccId = key.substring(
6868 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6869 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6870 mergeNumber = (String) prefs.get(numberKey);
6871 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006872 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 + " for active subscriber " + subscriberId);
6874 }
6875 if (!TextUtils.isEmpty(mergeNumber)) {
6876 break;
6877 }
6878 }
6879 }
6880 }
6881
6882 // Shortcut when no active merged subscribers
6883 if (TextUtils.isEmpty(mergeNumber)) {
6884 return null;
6885 }
6886
6887 // Second pass, find all subscribers under that line override
6888 final ArraySet<String> result = new ArraySet<>();
6889 for (String key : prefs.keySet()) {
6890 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6891 final String number = (String) prefs.get(key);
6892 if (mergeNumber.equals(number)) {
6893 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6894 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6895 final String subscriberId = (String) prefs.get(subscriberKey);
6896 if (!TextUtils.isEmpty(subscriberId)) {
6897 result.add(subscriberId);
6898 }
6899 }
6900 }
6901 }
6902
6903 final String[] resultArray = result.toArray(new String[result.size()]);
6904 Arrays.sort(resultArray);
6905 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006906 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6908 }
6909 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006910 } finally {
6911 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006912 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006913 }
6914
6915 @Override
zoey chen38003472019-12-13 17:16:31 +08006916 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6917 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006918
6919 final long identity = Binder.clearCallingIdentity();
6920 try {
6921 final TelephonyManager telephonyManager = mApp.getSystemService(
6922 TelephonyManager.class);
6923 String subscriberId = telephonyManager.getSubscriberId(subId);
6924 if (subscriberId == null) {
6925 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006926 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006927 + subId);
6928 }
6929 return null;
6930 }
6931
6932 final SubscriptionInfo info = SubscriptionController.getInstance()
6933 .getSubscriptionInfo(subId);
6934 final ParcelUuid groupUuid = info.getGroupUuid();
6935 // If it doesn't belong to any group, return just subscriberId of itself.
6936 if (groupUuid == null) {
6937 return new String[]{subscriberId};
6938 }
6939
6940 // Get all subscriberIds from the group.
6941 final List<String> mergedSubscriberIds = new ArrayList<>();
6942 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006943 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006944 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006945 for (SubscriptionInfo subInfo : groupInfos) {
6946 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6947 if (subscriberId != null) {
6948 mergedSubscriberIds.add(subscriberId);
6949 }
6950 }
6951
6952 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6953 } finally {
6954 Binder.restoreCallingIdentity(identity);
6955
6956 }
6957 }
6958
6959 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006960 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006961 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006962 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963
6964 final long identity = Binder.clearCallingIdentity();
6965 try {
6966 final Phone phone = getPhone(subId);
6967 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006971 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006972
6973 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006974 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006975 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6976 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006977 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6978 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979
6980 final long identity = Binder.clearCallingIdentity();
6981 try {
6982 final Phone phone = getPhone(subId);
6983 if (phone == null) {
6984 return false;
6985 }
6986 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6987 cdmaNonRoamingList);
6988 } finally {
6989 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006990 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006991 }
6992
6993 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006994 @Deprecated
6995 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6996 enforceModifyPermission();
6997
6998 int returnValue = 0;
6999 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007000 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007001 if(result.exception == null) {
7002 if (result.result != null) {
7003 byte[] responseData = (byte[])(result.result);
7004 if(responseData.length > oemResp.length) {
7005 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7006 responseData.length + "bytes. Buffer Size is " +
7007 oemResp.length + "bytes.");
7008 }
7009 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7010 returnValue = responseData.length;
7011 }
7012 } else {
7013 CommandException ex = (CommandException) result.exception;
7014 returnValue = ex.getCommandError().ordinal();
7015 if(returnValue > 0) returnValue *= -1;
7016 }
7017 } catch (RuntimeException e) {
7018 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7019 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7020 if(returnValue > 0) returnValue *= -1;
7021 }
7022
7023 return returnValue;
7024 }
7025
7026 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007027 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007028 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007029 try {
7030 TelephonyPermissions
7031 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7032 mApp, phone.getSubId(), "getRadioAccessFamily");
7033 } catch (SecurityException e) {
7034 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7035 throw e;
7036 }
chen xub97461a2018-10-26 14:17:57 -07007037 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007038 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007039 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007040 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 final long identity = Binder.clearCallingIdentity();
7042 try {
chen xub97461a2018-10-26 14:17:57 -07007043 TelephonyPermissions
7044 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7045 mApp, phone.getSubId(), "getRadioAccessFamily");
7046 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
chen xub97461a2018-10-26 14:17:57 -07007050 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007051 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007052
7053 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007054 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007055 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007056 try {
7057 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7058 Binder.getCallingUid())) {
7059 throw new SecurityException("Package uid and package name do not match: "
7060 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7061 }
7062 } catch (PackageManager.NameNotFoundException e) {
7063 throw new SecurityException("Package name invalid:" + callingPackage);
7064 }
7065 RoleManager rm = mApp.getSystemService(RoleManager.class);
7066 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7067 if (!dialerRoleHolders.contains(callingPackage)) {
7068 throw new SecurityException("App must be the dialer role holder to"
7069 + " upload a call composer pic");
7070 }
7071
7072 Executors.newSingleThreadExecutor().execute(() -> {
7073 ByteArrayOutputStream output = new ByteArrayOutputStream(
7074 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7075 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7076 boolean readUntilEnd = false;
7077 int totalBytesRead = 0;
7078 byte[] buffer = new byte[16 * 1024];
7079 while (true) {
7080 int numRead;
7081 try {
7082 numRead = input.read(buffer);
7083 } catch (IOException e) {
7084 try {
7085 fd.checkError();
7086 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7087 null);
7088 } catch (IOException e1) {
7089 // This means that the other side closed explicitly with an error. If this
7090 // happens, log and ignore.
7091 loge("Remote end of call composer picture pipe closed: " + e1);
7092 }
7093 break;
7094 }
7095 if (numRead == -1) {
7096 readUntilEnd = true;
7097 break;
7098 }
7099 totalBytesRead += numRead;
7100 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7101 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7102 try {
7103 input.close();
7104 } catch (IOException e) {
7105 // ignore
7106 }
7107 break;
7108 }
7109 output.write(buffer, 0, numRead);
7110 }
7111 // Generally, the remote end will close the file descriptors. The only case where we
7112 // close is above, where the picture size is too big.
7113
7114 try {
7115 fd.checkError();
7116 } catch (IOException e) {
7117 loge("Remote end for call composer closed with an error: " + e);
7118 return;
7119 }
7120
Hall Liuaa4211e2021-01-20 15:43:39 -08007121 if (!readUntilEnd) {
7122 loge("Did not finish reading entire image; aborting");
7123 return;
7124 }
Hall Liu82694d52020-12-11 18:22:04 -08007125
Hall Liuaa4211e2021-01-20 15:43:39 -08007126 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7127 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7128 new CallComposerPictureTransfer.Factory() {},
7129 imageData,
7130 (result) -> {
7131 if (result.first != null) {
7132 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7133 Bundle outputResult = new Bundle();
7134 outputResult.putParcelable(
7135 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7136 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7137 outputResult);
7138 } else {
7139 callback.send(result.second, null);
7140 }
7141 }
7142 );
Hall Liu82694d52020-12-11 18:22:04 -08007143 });
7144 }
7145
7146 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007147 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007148 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007149 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007153 ImsManager.getInstance(defaultPhone.getContext(),
7154 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 } finally {
7156 Binder.restoreCallingIdentity(identity);
7157 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007158 }
7159
7160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007161 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007162 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007163 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7164 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007165 return false;
7166 }
Svet Ganovb320e182015-04-16 12:30:10 -07007167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007168 final long identity = Binder.clearCallingIdentity();
7169 try {
7170 // Check the user preference and the system-level IMS setting. Even if the user has
7171 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7172 // In the long run, we may instead need to check if there exists a connection service
7173 // which can support video calling.
7174 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007175 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 return imsManager.isVtEnabledByPlatform()
7177 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7178 && imsManager.isVtEnabledByUser();
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
7181 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007182 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007183
Andrew Leea1239f22015-03-02 17:44:07 -08007184 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007185 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7186 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007188 mApp, subId, callingPackage, callingFeatureId,
7189 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007190 return false;
7191 }
7192
7193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 CarrierConfigManager configManager =
7196 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007197 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007198 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7199 } finally {
7200 Binder.restoreCallingIdentity(identity);
7201 }
Andrew Leea1239f22015-03-02 17:44:07 -08007202 }
7203
7204 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007205 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007207 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007208 return false;
7209 }
7210
7211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 CarrierConfigManager configManager =
7214 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007215 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7217 } finally {
7218 Binder.restoreCallingIdentity(identity);
7219 }
Andrew Leea1239f22015-03-02 17:44:07 -08007220 }
7221
Andrew Lee9431b832015-03-09 18:46:45 -07007222 @Override
7223 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007224 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007225 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007226 }
7227
7228 @Override
7229 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 final long identity = Binder.clearCallingIdentity();
7231 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007232 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235 }
Andrew Lee9431b832015-03-09 18:46:45 -07007236 }
7237
Hall Liuf6668912018-10-31 17:05:23 -07007238 /**
7239 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7240 * support for the feature and device firmware support.
7241 *
7242 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7243 */
7244 @Override
7245 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007247 final Phone phone = getPhone(subscriptionId);
7248 if (phone == null) {
7249 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7250 return false;
7251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007252 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007253 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7255 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007256 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257 return isCarrierSupported && isDeviceSupported;
7258 } finally {
7259 Binder.restoreCallingIdentity(identity);
7260 }
Hall Liu98187582018-01-22 19:15:32 -08007261 }
7262
Hall Liuf6668912018-10-31 17:05:23 -07007263 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007264 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7265 * RTT setting, will return true if the device and carrier both support RTT.
7266 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007267 */
7268 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007269 final long identity = Binder.clearCallingIdentity();
7270 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007271 boolean isRttSupported = isRttSupported(subscriptionId);
7272 boolean isUserRttSettingOn = Settings.Secure.getInt(
7273 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7274 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7275 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7276 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007277 } finally {
7278 Binder.restoreCallingIdentity(identity);
7279 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007280 }
7281
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007282 @Deprecated
7283 @Override
7284 public String getDeviceId(String callingPackage) {
7285 return getDeviceIdWithFeature(callingPackage, null);
7286 }
7287
Sanket Padawe7310cc72015-01-14 09:53:20 -08007288 /**
7289 * Returns the unique device ID of phone, for example, the IMEI for
7290 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7291 *
7292 * <p>Requires Permission:
7293 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7294 */
7295 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007296 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007297 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007298 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007299 return null;
7300 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007301 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007302 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007303 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007304 return null;
7305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306
7307 final long identity = Binder.clearCallingIdentity();
7308 try {
7309 return phone.getDeviceId();
7310 } finally {
7311 Binder.restoreCallingIdentity(identity);
7312 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007313 }
7314
Ping Sunc67b7c22016-03-02 19:16:45 +08007315 /**
7316 * {@hide}
7317 * Returns the IMS Registration Status on a particular subid
7318 *
7319 * @param subId
7320 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007321 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007322 Phone phone = getPhone(subId);
7323 if (phone != null) {
7324 return phone.isImsRegistered();
7325 } else {
7326 return false;
7327 }
7328 }
7329
Santos Cordon7a1885b2015-02-03 11:15:19 -08007330 @Override
7331 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 final long identity = Binder.clearCallingIdentity();
7333 try {
7334 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7335 } finally {
7336 Binder.restoreCallingIdentity(identity);
7337 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007338 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007339
Tyler Gunnf70ed162019-04-03 15:28:53 -07007340 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007341 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007342 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007343 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007344 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007345 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7346 }
7347 final long identity = Binder.clearCallingIdentity();
7348 try {
7349 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7350 } finally {
7351 Binder.restoreCallingIdentity(identity);
7352 }
7353 }
7354
7355 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007356 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007357 TelephonyPermissions
7358 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7359 mApp,
7360 subscriptionId,
7361 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007362 final long identity = Binder.clearCallingIdentity();
7363 try {
7364 Phone phone = getPhone(subscriptionId);
7365 if (phone == null) {
7366 return null;
7367 }
7368 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7369 } finally {
7370 Binder.restoreCallingIdentity(identity);
7371 }
7372 }
7373
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007374 /**
7375 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007376 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007377 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007378 final long identity = Binder.clearCallingIdentity();
7379 try {
7380 Phone phone = getPhone(subId);
7381 if (phone != null) {
7382 return phone.isWifiCallingEnabled();
7383 } else {
7384 return false;
7385 }
7386 } finally {
7387 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007388 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007389 }
7390
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007391 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007392 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007393 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007394 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 final long identity = Binder.clearCallingIdentity();
7396 try {
7397 Phone phone = getPhone(subId);
7398 if (phone != null) {
7399 return phone.isVideoEnabled();
7400 } else {
7401 return false;
7402 }
7403 } finally {
7404 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007405 }
7406 }
7407
7408 /**
7409 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7410 * defined in {@link ImsRegistrationImplBase}.
7411 */
7412 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 final long identity = Binder.clearCallingIdentity();
7414 try {
7415 Phone phone = getPhone(subId);
7416 if (phone != null) {
7417 return phone.getImsRegistrationTech();
7418 } else {
7419 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7420 }
7421 } finally {
7422 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007423 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007424 }
7425
Stuart Scott8eef64f2015-04-08 15:13:54 -07007426 @Override
7427 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007428 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007429 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7430 return;
7431 }
7432
Svet Ganovcc087f82015-05-12 20:35:54 -07007433 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007434
Svet Ganovcc087f82015-05-12 20:35:54 -07007435 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007436 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7437 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007438 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007439 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007440 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007441 Phone phone = getPhone(subId);
7442 if (phone != null) {
7443 SubscriptionManager.setSubscriptionProperty(subId,
7444 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7445 "user=" + RadioAccessFamily.getRafFromNetworkType(
7446 RILConstants.PREFERRED_NETWORK_MODE));
7447 phone.loadAllowedNetworksFromSubscriptionDatabase();
7448 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007449 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7450 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007451 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007452 // There has been issues when Sms raw table somehow stores orphan
7453 // fragments. They lead to garbled message when new fragments come
7454 // in and combined with those stale ones. In case this happens again,
7455 // user can reset all network settings which will clean up this table.
7456 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007457 // Clean up IMS settings as well here.
7458 int slotId = getSlotIndex(subId);
7459 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7460 ImsManager.getInstance(mApp, slotId).factoryReset();
7461 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007462
7463 // Erase modem config if erase modem on network setting is enabled.
7464 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7465 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7466 if (configValue != null && Boolean.parseBoolean(configValue)) {
7467 sendEraseModemConfig(getDefaultPhone());
7468 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007469 } finally {
7470 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007471 }
7472 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007473
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007474 private void cleanUpSmsRawTable(Context context) {
7475 ContentResolver resolver = context.getContentResolver();
7476 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7477 resolver.delete(uri, null, null);
7478 }
7479
Narayan Kamath1c496c22015-04-16 14:40:19 +01007480 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007481 public String getSimLocaleForSubscriber(int subId) {
7482 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7483 final Phone phone = getPhone(subId);
7484 if (phone == null) {
7485 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007486 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007487 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007488 final long identity = Binder.clearCallingIdentity();
7489 try {
chen xu5d3637b2019-01-21 23:31:38 -08007490 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007491 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007492 if (info == null) {
7493 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7494 return null;
7495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 // Try and fetch the locale from the carrier properties or from the SIM language
7497 // preferences (EF-PL and EF-LI)...
7498 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007500 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7501 if (localeFromDefaultSim != null) {
7502 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7503 if (DBG) log("Using locale from subId: " + subId + " locale: "
7504 + localeFromDefaultSim);
7505 return localeFromDefaultSim.toLanguageTag();
7506 } else {
7507 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007508 }
7509 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007510
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 // The SIM language preferences only store a language (e.g. fr = French), not an
7512 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7513 // the SIM and carrier preferences does not include a country we add the country
7514 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007515 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007517 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 return mccLocale.toLanguageTag();
7519 }
7520
7521 if (DBG) log("No locale found - returning null");
7522 return null;
7523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007526 }
7527
7528 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007529 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007530 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007531 }
7532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 /**
7534 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7535 */
7536 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007537 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007538 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007539 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007540
Chenjie Yu1ba97252018-01-11 18:16:20 -08007541 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007542 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007543
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007544 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007545 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7546 * representing the state of the modem.
7547 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007548 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7549 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007550 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007551 */
7552 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007553 public void requestModemActivityInfo(ResultReceiver result) {
7554 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007555 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007556
7557 final long identity = Binder.clearCallingIdentity();
7558 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007559 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007560 } finally {
7561 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007562 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007563 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007564
Siddharth Rayb8114062018-06-17 15:02:38 -07007565 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7566 // less than total activity duration.
7567 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7568 if (info == null) {
7569 return false;
7570 }
7571 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007572 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7573 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7574
Siddharth Rayb8114062018-06-17 15:02:38 -07007575 return (info.isValid()
7576 && (info.getSleepTimeMillis() <= activityDurationMs)
7577 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007578 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007579 && (totalTxTimeMs <= activityDurationMs));
7580 }
7581
Jack Yu85bd38a2015-11-09 11:34:32 -08007582 /**
7583 * {@hide}
7584 * Returns the service state information on specified subscription.
7585 */
7586 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007587 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7588 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007590 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007591 return null;
7592 }
7593
Hall Liuf19c44f2018-11-27 14:38:17 -08007594 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7595 LocationAccessPolicy.checkLocationPermission(mApp,
7596 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7597 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007598 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007599 .setCallingPid(Binder.getCallingPid())
7600 .setCallingUid(Binder.getCallingUid())
7601 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007602 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007603 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007604 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7605 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007606 .build());
7607
7608 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7609 LocationAccessPolicy.checkLocationPermission(mApp,
7610 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7611 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007612 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007613 .setCallingPid(Binder.getCallingPid())
7614 .setCallingUid(Binder.getCallingUid())
7615 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007616 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007617 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007618 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7619 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007620 .build());
7621 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7622 boolean hasFinePermission =
7623 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7624 boolean hasCoarsePermission =
7625 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7626
Jack Yu479f40e2020-10-27 21:29:25 -07007627 final Phone phone = getPhone(subId);
7628 if (phone == null) {
7629 return null;
7630 }
7631
Jordan Liu0f2bc442020-11-18 16:47:37 -08007632 final long identity = Binder.clearCallingIdentity();
7633
Jack Yu479f40e2020-10-27 21:29:25 -07007634 boolean isCallingPackageDataService = phone.getDataServicePackages()
7635 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007637 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7638 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7639 Rlog.d(LOG_TAG,
7640 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7641 return null;
7642 }
7643
Hall Liuf19c44f2018-11-27 14:38:17 -08007644 ServiceState ss = phone.getServiceState();
7645
7646 // Scrub out the location info in ServiceState depending on what level of access
7647 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007648 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007649 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7650 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007654 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007655
7656 /**
7657 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7658 *
7659 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7660 * voicemail ringtone.
7661 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7662 * PhoneAccount.
7663 */
7664 @Override
7665 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 final long identity = Binder.clearCallingIdentity();
7667 try {
7668 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7669 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007670 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7674 } finally {
7675 Binder.restoreCallingIdentity(identity);
7676 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007677 }
7678
7679 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007680 * Sets the per-account voicemail ringtone.
7681 *
7682 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7683 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7684 *
7685 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7686 * voicemail ringtone.
7687 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7688 * PhoneAccount.
7689 */
7690 @Override
7691 public void setVoicemailRingtoneUri(String callingPackage,
7692 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007693 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007694 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007695 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7696 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7698 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7699 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007701
7702 final long identity = Binder.clearCallingIdentity();
7703 try {
7704 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7705 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007706 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007707 }
7708 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7709 } finally {
7710 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007711 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007712 }
7713
7714 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007715 * Returns whether vibration is set for voicemail notification in Phone settings.
7716 *
7717 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7718 * voicemail vibration setting.
7719 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7720 */
7721 @Override
7722 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 final long identity = Binder.clearCallingIdentity();
7724 try {
7725 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7726 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007727 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007730 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7731 } finally {
7732 Binder.restoreCallingIdentity(identity);
7733 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007734 }
7735
Youhan Wange64578a2016-05-02 15:32:42 -07007736 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007737 * Sets the per-account voicemail vibration.
7738 *
7739 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7740 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7741 *
7742 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7743 * voicemail vibration setting.
7744 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7745 * specific PhoneAccount.
7746 */
7747 @Override
7748 public void setVoicemailVibrationEnabled(String callingPackage,
7749 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007750 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007752 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7753 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7755 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7756 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007757 }
7758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 final long identity = Binder.clearCallingIdentity();
7760 try {
7761 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7762 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007763 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007764 }
7765 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7766 } finally {
7767 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007768 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007769 }
7770
7771 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007772 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7773 *
7774 * @throws SecurityException if the caller does not have the required permission
7775 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007776 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007777 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007778 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007779 }
7780
7781 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007782 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7783 * permission.
7784 *
7785 * @throws SecurityException if the caller does not have the required permission
7786 */
7787 private void enforceSendSmsPermission() {
7788 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7789 }
7790
7791 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007792 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007793 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007794 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007795 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007796 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007797 final long identity = Binder.clearCallingIdentity();
7798 try {
7799 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007800 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007801 if (componentName == null) {
7802 throw new SecurityException(
7803 "Caller not current active visual voicemail package[null]");
7804 }
7805 String vvmPackage = componentName.getPackageName();
7806 if (!callingPackage.equals(vvmPackage)) {
7807 throw new SecurityException("Caller not current active visual voicemail package["
7808 + vvmPackage + "]");
7809 }
7810 } finally {
7811 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007812 }
7813 }
7814
7815 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007816 * Return the application ID for the app type.
7817 *
7818 * @param subId the subscription ID that this request applies to.
7819 * @param appType the uicc app type.
7820 * @return Application ID for specificied app type, or null if no uicc.
7821 */
7822 @Override
7823 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007824 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007825 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826
7827 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007828 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007829 if (phone == null) {
7830 return null;
7831 }
7832 String aid = null;
7833 try {
7834 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7835 .getApplicationByType(appType).getAid();
7836 } catch (Exception e) {
7837 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7838 }
7839 return aid;
7840 } finally {
7841 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007842 }
Youhan Wange64578a2016-05-02 15:32:42 -07007843 }
7844
Youhan Wang4001d252016-05-11 10:29:41 -07007845 /**
7846 * Return the Electronic Serial Number.
7847 *
7848 * @param subId the subscription ID that this request applies to.
7849 * @return ESN or null if error.
7850 */
7851 @Override
7852 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007853 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007854 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007855
7856 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007857 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007858 if (phone == null) {
7859 return null;
7860 }
7861 String esn = null;
7862 try {
7863 esn = phone.getEsn();
7864 } catch (Exception e) {
7865 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7866 }
7867 return esn;
7868 } finally {
7869 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007870 }
Youhan Wang4001d252016-05-11 10:29:41 -07007871 }
7872
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007873 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007874 * Return the Preferred Roaming List Version.
7875 *
7876 * @param subId the subscription ID that this request applies to.
7877 * @return PRLVersion or null if error.
7878 */
7879 @Override
7880 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007881 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007882 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007883
7884 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007885 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007886 if (phone == null) {
7887 return null;
7888 }
7889 String cdmaPrlVersion = null;
7890 try {
7891 cdmaPrlVersion = phone.getCdmaPrlVersion();
7892 } catch (Exception e) {
7893 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7894 }
7895 return cdmaPrlVersion;
7896 } finally {
7897 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007898 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007899 }
7900
7901 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007902 * Get snapshot of Telephony histograms
7903 * @return List of Telephony histograms
7904 * @hide
7905 */
7906 @Override
7907 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7909 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007910
7911 final long identity = Binder.clearCallingIdentity();
7912 try {
7913 return RIL.getTelephonyRILTimingHistograms();
7914 } finally {
7915 Binder.restoreCallingIdentity(identity);
7916 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007917 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007918
7919 /**
7920 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007921 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7922 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007923 * Require system privileges. In the future we may add this to carrier APIs.
7924 *
Michele Berionne482f8202018-11-27 18:57:59 -08007925 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007926 */
7927 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007928 @TelephonyManager.SetCarrierRestrictionResult
7929 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007930 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007931 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007932
Michele Berionne482f8202018-11-27 18:57:59 -08007933 if (carrierRestrictionRules == null) {
7934 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007935 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007937 final long identity = Binder.clearCallingIdentity();
7938 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007939 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007940 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941 } finally {
7942 Binder.restoreCallingIdentity(identity);
7943 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007944 }
7945
7946 /**
7947 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007948 * Get the allowed carrier list and the excluded carrier list, including the priority between
7949 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007950 * Require system privileges. In the future we may add this to carrier APIs.
7951 *
Michele Berionne482f8202018-11-27 18:57:59 -08007952 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007953 */
7954 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007955 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007956 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007957 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958
7959 final long identity = Binder.clearCallingIdentity();
7960 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007961 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7962 if (response instanceof CarrierRestrictionRules) {
7963 return (CarrierRestrictionRules) response;
7964 }
7965 // Response is an Exception of some kind,
7966 // which is signalled to the user as a NULL retval
7967 return null;
7968 } catch (Exception e) {
7969 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7970 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007974 }
7975
fionaxu59545b42016-05-25 15:53:37 -07007976 /**
fionaxu59545b42016-05-25 15:53:37 -07007977 * Action set from carrier signalling broadcast receivers to enable/disable radio
7978 * @param subId the subscription ID that this action applies to.
7979 * @param enabled control enable or disable radio.
7980 * {@hide}
7981 */
7982 @Override
7983 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7984 enforceModifyPermission();
7985 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007986
7987 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007988 if (phone == null) {
7989 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7990 return;
7991 }
7992 try {
7993 phone.carrierActionSetRadioEnabled(enabled);
7994 } catch (Exception e) {
7995 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007996 } finally {
7997 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007998 }
7999 }
8000
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008001 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008002 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8003 * network status based on which carrier apps could apply actions accordingly,
8004 * enable/disable default url handler for example.
8005 *
8006 * @param subId the subscription ID that this action applies to.
8007 * @param report control start/stop reporting the default network status.
8008 * {@hide}
8009 */
8010 @Override
8011 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8012 enforceModifyPermission();
8013 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014
8015 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008016 if (phone == null) {
8017 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8018 return;
8019 }
8020 try {
8021 phone.carrierActionReportDefaultNetworkStatus(report);
8022 } catch (Exception e) {
8023 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008024 } finally {
8025 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008026 }
8027 }
8028
8029 /**
fionaxud9622282017-07-17 17:51:30 -07008030 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8031 * @param subId the subscription ID that this action applies to.
8032 * {@hide}
8033 */
8034 @Override
8035 public void carrierActionResetAll(int subId) {
8036 enforceModifyPermission();
8037 final Phone phone = getPhone(subId);
8038 if (phone == null) {
8039 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8040 return;
8041 }
8042 try {
8043 phone.carrierActionResetAll();
8044 } catch (Exception e) {
8045 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8046 }
8047 }
8048
8049 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008050 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8051 * bug report is being generated.
8052 */
8053 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008054 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008055 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8056 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008057 writer.println("Permission Denial: can't dump Phone from pid="
8058 + Binder.getCallingPid()
8059 + ", uid=" + Binder.getCallingUid()
8060 + "without permission "
8061 + android.Manifest.permission.DUMP);
8062 return;
8063 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008064 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008065 }
Jack Yueb89b242016-06-22 13:27:47 -07008066
Brad Ebingerdac2f002018-04-03 15:17:52 -07008067 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008068 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8069 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8070 @NonNull String[] args) {
8071 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8072 this, in.getFileDescriptor(), out.getFileDescriptor(),
8073 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008074 }
8075
Jack Yueb89b242016-06-22 13:27:47 -07008076 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008077 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008078 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008079 * @param reason the reason the data enable change is taking place
8080 * @param enabled True if enabling the data, otherwise disabling.
8081 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008082 */
8083 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008084 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008085 boolean enabled) {
8086 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8087 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8088 try {
8089 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008090 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008091 } catch (SecurityException se) {
8092 enforceModifyPermission();
8093 }
8094 } else {
8095 enforceModifyPermission();
8096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097
8098 final long identity = Binder.clearCallingIdentity();
8099 try {
8100 Phone phone = getPhone(subId);
8101 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008102 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8103 phone.carrierActionSetMeteredApnsEnabled(enabled);
8104 } else {
8105 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008107 }
8108 } finally {
8109 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008110 }
8111 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008112
8113 /**
8114 * Get Client request stats
8115 * @return List of Client Request Stats
8116 * @hide
8117 */
8118 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008119 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8120 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008122 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008123 return null;
8124 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008125 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008127 final long identity = Binder.clearCallingIdentity();
8128 try {
8129 if (phone != null) {
8130 return phone.getClientRequestStats();
8131 }
8132
8133 return null;
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
8136 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008137 }
8138
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008139 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008140 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008141 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008142 }
Jack Yueb4124c2017-02-16 15:32:43 -08008143
8144 /**
Grace Chen70990072017-03-24 17:21:30 -07008145 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008146 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008147 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008148 * @param state State of SIM (power down, power up, pass through)
8149 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8150 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8151 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008152 *
8153 **/
8154 @Override
Grace Chen70990072017-03-24 17:21:30 -07008155 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008156 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008157 Phone phone = PhoneFactory.getPhone(slotIndex);
8158
vagdeviaf9a5b92018-08-15 16:01:53 -07008159 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8160
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 final long identity = Binder.clearCallingIdentity();
8162 try {
8163 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008164 phone.setSimPowerState(state, null, workSource);
8165 }
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
8169 }
8170
8171 /**
8172 * Set SIM card power state.
8173 *
8174 * @param slotIndex SIM slot id.
8175 * @param state State of SIM (power down, power up, pass through)
8176 * @param callback callback to trigger after success or failure
8177 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8178 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8179 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8180 *
8181 **/
8182 @Override
8183 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8184 IIntegerConsumer callback) {
8185 enforceModifyPermission();
8186 Phone phone = PhoneFactory.getPhone(slotIndex);
8187
8188 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8189
8190 final long identity = Binder.clearCallingIdentity();
8191 try {
8192 if (phone != null) {
8193 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8194 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008195 }
8196 } finally {
8197 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008198 }
8199 }
Shuo Qiandd210312017-04-12 22:11:33 +00008200
Tyler Gunn65d45c22017-06-05 11:22:26 -07008201 private boolean isUssdApiAllowed(int subId) {
8202 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008203 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008204 if (configManager == null) {
8205 return false;
8206 }
8207 PersistableBundle pb = configManager.getConfigForSubId(subId);
8208 if (pb == null) {
8209 return false;
8210 }
8211 return pb.getBoolean(
8212 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8213 }
8214
Shuo Qiandd210312017-04-12 22:11:33 +00008215 /**
8216 * Check if phone is in emergency callback mode
8217 * @return true if phone is in emergency callback mode
8218 * @param subId sub id
8219 */
goneil9c5f4872017-12-05 14:07:56 -08008220 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008221 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008222 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008223 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224
8225 final long identity = Binder.clearCallingIdentity();
8226 try {
8227 if (phone != null) {
8228 return phone.isInEcm();
8229 } else {
8230 return false;
8231 }
8232 } finally {
8233 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008234 }
8235 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008236
8237 /**
8238 * Get the current signal strength information for the given subscription.
8239 * Because this information is not updated when the device is in a low power state
8240 * it should not be relied-upon to be current.
8241 * @param subId Subscription index
8242 * @return the most recent cached signal strength info from the modem
8243 */
8244 @Override
8245 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 final long identity = Binder.clearCallingIdentity();
8247 try {
8248 Phone p = getPhone(subId);
8249 if (p == null) {
8250 return null;
8251 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008253 return p.getSignalStrength();
8254 } finally {
8255 Binder.restoreCallingIdentity(identity);
8256 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008257 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008258
Pengquan Meng77b7f132018-08-22 14:49:57 -07008259 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008260 * Get the current modem radio state for the given slot.
8261 * @param slotIndex slot index.
8262 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008263 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008264 * @return the current radio power state from the modem
8265 */
8266 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008267 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008268 Phone phone = PhoneFactory.getPhone(slotIndex);
8269 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8271 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008272 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8273 }
8274
8275 final long identity = Binder.clearCallingIdentity();
8276 try {
8277 return phone.getRadioPowerState();
8278 } finally {
8279 Binder.restoreCallingIdentity(identity);
8280 }
8281 }
8282 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8283 }
8284
8285 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008286 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8287 *
8288 * <p>Requires one of the following permissions:
8289 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8290 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8291 * privileges.
8292 *
8293 * @param subId subscription id
8294 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8295 * {@code false}.
8296 */
8297 @Override
8298 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008299 try {
8300 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8301 null);
8302 } catch (Exception e) {
8303 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8304 mApp, subId, "isDataRoamingEnabled");
8305 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008306
Pengquan Menga1bb6272018-09-06 09:59:22 -07008307 boolean isEnabled = false;
8308 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008309 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008310 Phone phone = getPhone(subId);
8311 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008312 } finally {
8313 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008314 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008315 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008316 }
8317
8318
8319 /**
8320 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8321 *
8322 * <p> Requires permission:
8323 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8324 * privileges.
8325 *
8326 * @param subId subscription id
8327 * @param isEnabled {@code true} means enable, {@code false} means disable.
8328 */
8329 @Override
8330 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008331 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8332 mApp, subId, "setDataRoamingEnabled");
8333
Pengquan Menga1bb6272018-09-06 09:59:22 -07008334 final long identity = Binder.clearCallingIdentity();
8335 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008336 Phone phone = getPhone(subId);
8337 if (phone != null) {
8338 phone.setDataRoamingEnabled(isEnabled);
8339 }
8340 } finally {
8341 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008342 }
8343 }
8344
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008345 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008346 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008347 TelephonyPermissions
8348 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008349 mApp, subId, "isManualNetworkSelectionAllowed");
8350
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008351 boolean isAllowed = true;
8352 final long identity = Binder.clearCallingIdentity();
8353 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008354 Phone phone = getPhone(subId);
8355 if (phone != null) {
8356 isAllowed = phone.isCspPlmnEnabled();
8357 }
8358 } finally {
8359 Binder.restoreCallingIdentity(identity);
8360 }
8361 return isAllowed;
8362 }
8363
8364 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008365 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008366 // Verify that tha callingPackage belongs to the calling UID
8367 mApp.getSystemService(AppOpsManager.class)
8368 .checkPackage(Binder.getCallingUid(), callingPackage);
8369
Jordan Liu1e142fc2019-04-22 15:10:43 -07008370 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008371 try {
8372 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008373 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008374 } catch (SecurityException e) {
8375 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8376 // has carrier privileges on an active UICC
8377 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8378 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008379 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008380 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008381 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008382
8383 final long identity = Binder.clearCallingIdentity();
8384 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008385 UiccController uiccController = UiccController.getInstance();
8386 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008387 if (hasReadPermission) {
8388 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008389 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008390
8391 // Remove private info if the caller doesn't have access
8392 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8393 for (UiccCardInfo cardInfo : cardInfos) {
8394 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8395 // is available
8396 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8397 if (card == null || card.getUiccProfile() == null) {
8398 // assume no access if the card or profile is unavailable
8399 filteredInfos.add(cardInfo.getUnprivileged());
8400 continue;
8401 }
8402 UiccProfile profile = card.getUiccProfile();
8403 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8404 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8405 filteredInfos.add(cardInfo);
8406 } else {
8407 filteredInfos.add(cardInfo.getUnprivileged());
8408 }
8409 }
8410 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008411 } finally {
8412 Binder.restoreCallingIdentity(identity);
8413 }
8414 }
8415
8416 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008417 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008418 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008420 final long identity = Binder.clearCallingIdentity();
8421 try {
8422 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8423 if (slots == null) {
8424 Rlog.i(LOG_TAG, "slots is null.");
8425 return null;
8426 }
8427
8428 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8429 for (int i = 0; i < slots.length; i++) {
8430 UiccSlot slot = slots[i];
8431 if (slot == null) {
8432 continue;
8433 }
8434
Jordan Liu7be7e652019-05-06 18:55:02 +00008435 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008436 UiccCard card = slot.getUiccCard();
8437 if (card != null) {
8438 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008439 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008440 cardId = slot.getEid();
8441 if (TextUtils.isEmpty(cardId)) {
8442 cardId = slot.getIccId();
8443 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008444 }
8445
Jordan Liu857451f2019-05-09 16:35:35 -07008446 if (cardId != null) {
8447 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8448 // if cardId is an EID, it's all digits so this is fine
8449 cardId = IccUtils.stripTrailingFs(cardId);
8450 }
8451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008452 int cardState = 0;
8453 switch (slot.getCardState()) {
8454 case CARDSTATE_ABSENT:
8455 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8456 break;
8457 case CARDSTATE_PRESENT:
8458 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8459 break;
8460 case CARDSTATE_ERROR:
8461 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8462 break;
8463 case CARDSTATE_RESTRICTED:
8464 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8465 break;
8466 default:
8467 break;
8468
8469 }
8470
8471 infos[i] = new UiccSlotInfo(
8472 slot.isActive(),
8473 slot.isEuicc(),
8474 cardId,
8475 cardState,
8476 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008477 slot.isExtendedApduSupported(),
8478 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008479 }
8480 return infos;
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008483 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008484 }
8485
8486 @Override
8487 public boolean switchSlots(int[] physicalSlots) {
8488 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008489
8490 final long identity = Binder.clearCallingIdentity();
8491 try {
8492 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8493 } finally {
8494 Binder.restoreCallingIdentity(identity);
8495 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008496 }
Jack Yu4c988042018-02-27 15:30:01 -08008497
8498 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008499 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 return UiccController.getInstance().getCardIdForDefaultEuicc();
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
8506 }
8507
Pengquan Meng85728fb2018-03-12 16:31:21 -07008508 /**
goneil47ffb6e2018-04-06 15:40:58 -07008509 * A test API to reload the UICC profile.
8510 *
8511 * <p>Requires that the calling app has permission
8512 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8513 * @hide
8514 */
8515 @Override
8516 public void refreshUiccProfile(int subId) {
8517 enforceModifyPermission();
8518
8519 final long identity = Binder.clearCallingIdentity();
8520 try {
8521 Phone phone = getPhone(subId);
8522 if (phone == null) {
8523 return;
8524 }
8525 UiccCard uiccCard = phone.getUiccCard();
8526 if (uiccCard == null) {
8527 return;
8528 }
8529 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8530 if (uiccProfile == null) {
8531 return;
8532 }
8533 uiccProfile.refresh();
8534 } finally {
8535 Binder.restoreCallingIdentity(identity);
8536 }
8537 }
8538
8539 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008540 * Returns false if the mobile data is disabled by default, otherwise return true.
8541 */
8542 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008543 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008544 }
8545
8546 /**
8547 * Returns true if the data roaming is enabled by default, i.e the system property
8548 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8549 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8550 */
8551 private boolean getDefaultDataRoamingEnabled(int subId) {
8552 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008553 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008554 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008555 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8556 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8557 return isDataRoamingEnabled;
8558 }
8559
8560 /**
8561 * Returns the default network type for the given {@code subId}, if the default network type is
8562 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8563 */
8564 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008565 List<Integer> list = TelephonyProperties.default_network();
8566 int phoneId = mSubscriptionController.getPhoneId(subId);
8567 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8568 return list.get(phoneId);
8569 }
8570 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008571 }
fionaxua13278b2018-03-21 00:08:13 -07008572
8573 @Override
8574 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008575 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008576 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008577
8578 final long identity = Binder.clearCallingIdentity();
8579 try {
8580 final Phone phone = getPhone(subId);
8581 if (phone == null) {
8582 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8583 return;
8584 }
chen xueaba88a2019-03-15 13:15:10 -07008585 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8586 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008587 if (carrierPrivilegeRules == null) {
8588 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8589 } else {
8590 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8591 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008592 } finally {
8593 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008594 }
fionaxua13278b2018-03-21 00:08:13 -07008595 }
8596
8597 @Override
8598 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008599 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008600
8601 final long identity = Binder.clearCallingIdentity();
8602 try {
8603 final Phone phone = getPhone(subId);
8604 if (phone == null) {
8605 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8606 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8607 }
8608 return phone.getCarrierIdListVersion();
8609 } finally {
8610 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008611 }
fionaxua13278b2018-03-21 00:08:13 -07008612 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008613
8614 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008615 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8616 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008618 mApp, subId, callingPackage, callingFeatureId,
8619 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008620 return -1;
8621 }
8622
8623 final long identity = Binder.clearCallingIdentity();
8624 try {
8625 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
8629 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008630
8631 @Override
8632 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008633 TelephonyPermissions
8634 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008635 mApp, subId, "getCdmaRoamingMode");
8636
8637 final long identity = Binder.clearCallingIdentity();
8638 try {
8639 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8640 } finally {
8641 Binder.restoreCallingIdentity(identity);
8642 }
8643 }
8644
8645 @Override
8646 public boolean setCdmaRoamingMode(int subId, int mode) {
8647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8648 mApp, subId, "setCdmaRoamingMode");
8649
8650 final long identity = Binder.clearCallingIdentity();
8651 try {
8652 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8653 } finally {
8654 Binder.restoreCallingIdentity(identity);
8655 }
8656 }
8657
8658 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008659 public int getCdmaSubscriptionMode(int subId) {
8660 TelephonyPermissions
8661 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8662 mApp, subId, "getCdmaSubscriptionMode");
8663
8664 final long identity = Binder.clearCallingIdentity();
8665 try {
8666 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8667 } finally {
8668 Binder.restoreCallingIdentity(identity);
8669 }
8670 }
8671
8672 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008673 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8675 mApp, subId, "setCdmaSubscriptionMode");
8676
8677 final long identity = Binder.clearCallingIdentity();
8678 try {
8679 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008684
sqianc5eccab2018-10-19 18:46:41 -07008685 @Override
sqian8c685422019-02-22 15:55:18 -08008686 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008687 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008689 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8690 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008691 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8692 }
8693 final long identity = Binder.clearCallingIdentity();
8694 try {
sqian854d44b2018-12-12 16:48:18 -08008695 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8696 for (Phone phone: PhoneFactory.getPhones()) {
8697 if (phone.getEmergencyNumberTracker() != null
8698 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8699 emergencyNumberListInternal.put(
8700 phone.getSubId(),
8701 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8702 }
sqian11b7a0e2018-12-05 18:48:28 -08008703 }
sqian854d44b2018-12-12 16:48:18 -08008704 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008705 } finally {
8706 Binder.restoreCallingIdentity(identity);
8707 }
sqianc5eccab2018-10-19 18:46:41 -07008708 }
8709
8710 @Override
sqian8c685422019-02-22 15:55:18 -08008711 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008712 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008713 if (!exactMatch) {
8714 TelephonyPermissions
8715 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008716 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008717 }
8718 final long identity = Binder.clearCallingIdentity();
8719 try {
sqian854d44b2018-12-12 16:48:18 -08008720 for (Phone phone: PhoneFactory.getPhones()) {
8721 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008722 && phone.getEmergencyNumberTracker()
8723 .isEmergencyNumber(number, exactMatch)) {
8724 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008725 }
sqian11b7a0e2018-12-05 18:48:28 -08008726 }
8727 return false;
8728 } finally {
8729 Binder.restoreCallingIdentity(identity);
8730 }
8731 }
8732
sqianf4ca7ed2019-01-15 18:32:07 -08008733 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008734 * Start emergency callback mode for GsmCdmaPhone for testing.
8735 */
8736 @Override
8737 public void startEmergencyCallbackMode() {
8738 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8739 "startEmergencyCallbackMode");
8740 enforceModifyPermission();
8741 final long identity = Binder.clearCallingIdentity();
8742 try {
8743 for (Phone phone : PhoneFactory.getPhones()) {
8744 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8745 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8746 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8747 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8748 gsmCdmaPhone.obtainMessage(
8749 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8750 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8751 }
8752 }
8753 } finally {
8754 Binder.restoreCallingIdentity(identity);
8755 }
8756 }
8757
8758 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008759 * Update emergency number list for test mode.
8760 */
8761 @Override
8762 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8763 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8764 "updateEmergencyNumberListTestMode");
8765
8766 final long identity = Binder.clearCallingIdentity();
8767 try {
8768 for (Phone phone: PhoneFactory.getPhones()) {
8769 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8770 if (tracker != null) {
8771 tracker.executeEmergencyNumberTestModeCommand(action, num);
8772 }
8773 }
8774 } finally {
8775 Binder.restoreCallingIdentity(identity);
8776 }
8777 }
8778
8779 /**
8780 * Get the full emergency number list for test mode.
8781 */
8782 @Override
8783 public List<String> getEmergencyNumberListTestMode() {
8784 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8785 "getEmergencyNumberListTestMode");
8786
8787 final long identity = Binder.clearCallingIdentity();
8788 try {
8789 Set<String> emergencyNumbers = new HashSet<>();
8790 for (Phone phone: PhoneFactory.getPhones()) {
8791 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8792 if (tracker != null) {
8793 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8794 emergencyNumbers.add(num.getNumber());
8795 }
8796 }
8797 }
8798 return new ArrayList<>(emergencyNumbers);
8799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
8802 }
8803
chen xud6b45bd2018-10-30 22:27:10 -07008804 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008805 public int getEmergencyNumberDbVersion(int subId) {
8806 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8807
8808 final long identity = Binder.clearCallingIdentity();
8809 try {
8810 final Phone phone = getPhone(subId);
8811 if (phone == null) {
8812 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8813 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8814 }
8815 return phone.getEmergencyNumberDbVersion();
8816 } finally {
8817 Binder.restoreCallingIdentity(identity);
8818 }
8819 }
8820
8821 @Override
8822 public void notifyOtaEmergencyNumberDbInstalled() {
8823 enforceModifyPermission();
8824
8825 final long identity = Binder.clearCallingIdentity();
8826 try {
8827 for (Phone phone: PhoneFactory.getPhones()) {
8828 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8829 if (tracker != null) {
8830 tracker.updateOtaEmergencyNumberDatabase();
8831 }
8832 }
8833 } finally {
8834 Binder.restoreCallingIdentity(identity);
8835 }
8836 }
8837
8838 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008839 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008840 enforceActiveEmergencySessionPermission();
8841
8842 final long identity = Binder.clearCallingIdentity();
8843 try {
8844 for (Phone phone: PhoneFactory.getPhones()) {
8845 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8846 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008847 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8848 }
8849 }
8850 } finally {
8851 Binder.restoreCallingIdentity(identity);
8852 }
8853 }
8854
8855 @Override
8856 public void resetOtaEmergencyNumberDbFilePath() {
8857 enforceActiveEmergencySessionPermission();
8858
8859 final long identity = Binder.clearCallingIdentity();
8860 try {
8861 for (Phone phone: PhoneFactory.getPhones()) {
8862 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8863 if (tracker != null) {
8864 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008865 }
8866 }
8867 } finally {
8868 Binder.restoreCallingIdentity(identity);
8869 }
8870 }
8871
8872 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008873 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8874 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8875 Phone phone = getPhone(subId);
8876 if (phone == null) {
8877 return null;
8878 }
8879 final long identity = Binder.clearCallingIdentity();
8880 try {
8881 UiccProfile profile = UiccController.getInstance()
8882 .getUiccProfileForPhone(phone.getPhoneId());
8883 if (profile != null) {
8884 return profile.getCertsFromCarrierPrivilegeAccessRules();
8885 }
8886 } finally {
8887 Binder.restoreCallingIdentity(identity);
8888 }
8889 return null;
8890 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008891
8892 /**
8893 * Enable or disable a modem stack.
8894 */
8895 @Override
8896 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8897 enforceModifyPermission();
8898
8899 final long identity = Binder.clearCallingIdentity();
8900 try {
8901 Phone phone = PhoneFactory.getPhone(slotIndex);
8902 if (phone == null) {
8903 return false;
8904 } else {
8905 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8906 }
8907 } finally {
8908 Binder.restoreCallingIdentity(identity);
8909 }
8910 }
Michelecea4cf22018-12-21 15:00:11 -08008911
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008912 /**
8913 * Whether a modem stack is enabled or not.
8914 */
8915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008916 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8917 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008918 Phone phone = PhoneFactory.getPhone(slotIndex);
8919 if (phone == null) return false;
8920
8921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008922 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8923 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008924 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8925 }
8926
8927 final long identity = Binder.clearCallingIdentity();
8928 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008929 try {
8930 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8931 } catch (NoSuchElementException ex) {
8932 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8933 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008934 } finally {
8935 Binder.restoreCallingIdentity(identity);
8936 }
8937 }
8938
Michelecea4cf22018-12-21 15:00:11 -08008939 @Override
Michele0ea7d782019-03-19 14:58:42 -07008940 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008941 enforceModifyPermission();
8942
8943 final long identity = Binder.clearCallingIdentity();
8944 try {
8945 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008946 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008947 .commit();
8948 } finally {
8949 Binder.restoreCallingIdentity(identity);
8950 }
8951 }
8952
8953 @Override
Michele0ea7d782019-03-19 14:58:42 -07008954 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008955 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008957 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8958 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008959 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008960 }
Michelecea4cf22018-12-21 15:00:11 -08008961
8962 final long identity = Binder.clearCallingIdentity();
8963 try {
Michele0ea7d782019-03-19 14:58:42 -07008964 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008965 } finally {
8966 Binder.restoreCallingIdentity(identity);
8967 }
8968 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008969
Michele0ea7d782019-03-19 14:58:42 -07008970 @TelephonyManager.IsMultiSimSupportedResult
8971 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008972 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8973 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8974 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008975 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8976 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008977 }
8978 // Check if the hardware supports multisim functionality. If usage of multisim is not
8979 // supported by the modem, indicate that it is restricted.
8980 PhoneCapability staticCapability =
8981 mPhoneConfigurationManager.getStaticPhoneCapability();
8982 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008983 loge("isMultiSimSupportedInternal: no static configuration available");
8984 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008985 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008986 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008987 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8988 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008989 }
8990 // Check if support of multiple SIMs is restricted by carrier
8991 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008992 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008993 }
8994
Michele0ea7d782019-03-19 14:58:42 -07008995 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008996 }
8997
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008998 /**
8999 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009000 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9001 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9002 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009003 * @param numOfSims number of active sims we want to switch to
9004 */
9005 @Override
9006 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009007 if (numOfSims == 1) {
9008 enforceModifyPermission();
9009 } else {
9010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9011 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9012 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009013 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009014
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009015 try {
Michele30b57b22019-03-01 12:01:14 -08009016 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009017 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009018 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9019 return;
9020 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009021 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9022 } finally {
9023 Binder.restoreCallingIdentity(identity);
9024 }
9025 }
9026
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009027 @Override
9028 public boolean isApplicationOnUicc(int subId, int appType) {
9029 enforceReadPrivilegedPermission("isApplicationOnUicc");
9030 Phone phone = getPhone(subId);
9031 if (phone == null) {
9032 return false;
9033 }
9034 final long identity = Binder.clearCallingIdentity();
9035 try {
9036 UiccCard uiccCard = phone.getUiccCard();
9037 if (uiccCard == null) {
9038 return false;
9039 }
9040 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9041 if (uiccProfile == null) {
9042 return false;
9043 }
9044 if (TelephonyManager.APPTYPE_SIM <= appType
9045 && appType <= TelephonyManager.APPTYPE_ISIM) {
9046 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9047 }
9048 return false;
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
9052 }
9053
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009054 /**
chen xub4baa772019-04-03 10:23:41 -07009055 * Get whether making changes to modem configurations will trigger reboot.
9056 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009057 */
9058 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009059 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9060 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009062 mApp, subId, callingPackage, callingFeatureId,
9063 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009064 return false;
9065 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009066 final long identity = Binder.clearCallingIdentity();
9067 try {
9068 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
9072 }
9073
Nathan Harold29f5f052019-02-15 13:41:57 -08009074 private void updateModemStateMetrics() {
9075 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9076 // TODO: check the state for each modem if the api is ready.
9077 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9078 }
9079
Pengquan Meng3889a572019-01-23 11:16:29 -08009080 @Override
9081 public int[] getSlotsMapping() {
9082 enforceReadPrivilegedPermission("getSlotsMapping");
9083
9084 final long identity = Binder.clearCallingIdentity();
9085 try {
9086 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9087 // All logical slots should have a mapping to a physical slot.
9088 int[] logicalSlotsMapping = new int[phoneCount];
9089 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9090 for (int i = 0; i < slotInfos.length; i++) {
9091 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9092 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9093 }
9094 }
9095 return logicalSlotsMapping;
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009100
9101 /**
9102 * Get the IRadio HAL Version
9103 */
9104 @Override
9105 public int getRadioHalVersion() {
9106 Phone phone = getDefaultPhone();
9107 if (phone == null) return -1;
9108 HalVersion hv = phone.getHalVersion();
9109 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9110 return hv.major * 100 + hv.minor;
9111 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009112
9113 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009114 * Get the current calling package name.
9115 * @return the current calling package name
9116 */
9117 @Override
9118 public String getCurrentPackageName() {
9119 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9120 }
9121
9122 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009123 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9124 * corresponding network requests on a subId.
9125 *
9126 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009127 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009128 * 2) APN is un-metered for this subscription, or
9129 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009130 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009131 *
9132 * @return whether data is allowed for a apn type.
9133 *
9134 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009135 */
9136 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009137 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009138 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9139 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009140
9141 // Now that all security checks passes, perform the operation as ourselves.
9142 final long identity = Binder.clearCallingIdentity();
9143 try {
9144 Phone phone = getPhone(subId);
9145 if (phone == null) return false;
9146
Jack Yu41407ee2019-05-13 16:54:09 -07009147 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009148 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9149 } finally {
9150 Binder.restoreCallingIdentity(identity);
9151 }
9152 }
9153
9154 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009155 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009156 enforceReadPrivilegedPermission("isApnMetered");
9157
9158 // Now that all security checks passes, perform the operation as ourselves.
9159 final long identity = Binder.clearCallingIdentity();
9160 try {
9161 Phone phone = getPhone(subId);
9162 if (phone == null) return true; // By default return true.
9163
Jack Yu41407ee2019-05-13 16:54:09 -07009164 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009165 } finally {
9166 Binder.restoreCallingIdentity(identity);
9167 }
9168 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009169
9170 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009171 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9172 int subscriptionId, IBooleanConsumer resultCallback) {
9173 enforceModifyPermission();
9174 long token = Binder.clearCallingIdentity();
9175 try {
9176 Phone phone = getPhone(subscriptionId);
9177 if (phone == null) {
9178 try {
9179 if (resultCallback != null) {
9180 resultCallback.accept(false);
9181 }
9182 } catch (RemoteException e) {
9183 // ignore
9184 }
9185 return;
9186 }
9187 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9188 Pair.create(specifiers, (x) -> {
9189 try {
9190 if (resultCallback != null) {
9191 resultCallback.accept(x);
9192 }
9193 } catch (RemoteException e) {
9194 // ignore
9195 }
9196 });
9197 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9198 } finally {
9199 Binder.restoreCallingIdentity(token);
9200 }
9201 }
9202
9203 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009204 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9205 TelephonyPermissions
9206 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9207 mApp, subId, "getSystemSelectionChannels");
9208 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9209 final long identity = Binder.clearCallingIdentity();
9210 try {
9211 List<RadioAccessSpecifier> specifiers =
9212 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9213 null, subId, workSource);
9214 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9215 return specifiers;
9216 } finally {
9217 Binder.restoreCallingIdentity(identity);
9218 }
9219 }
9220
9221 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009222 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009223 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009224 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9225 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9226 if (iccRecords == null) {
9227 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9228 return false;
9229 }
9230 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9231 }
9232
9233 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009234 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9235 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009236 if (callingPackage == null) {
9237 callingPackage = getCurrentPackageName();
9238 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009239 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9240 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009241 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9242 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009243 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9244 }
9245 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9246 Intent intent = new Intent();
9247 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9248 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9249 // Bring up choose default SMS subscription dialog right now
9250 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9251 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9252 mApp.startActivity(intent);
9253 }
chen xud5ca2d52019-05-28 15:20:57 -07009254
9255 @Override
9256 public String getMmsUAProfUrl(int subId) {
9257 //TODO investigate if this API should require proper permission check in R b/133791609
9258 final long identity = Binder.clearCallingIdentity();
9259 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009260 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9261 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9262 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9263 return carrierUAProfUrl;
9264 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009265 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9266 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009267 } finally {
9268 Binder.restoreCallingIdentity(identity);
9269 }
9270 }
9271
9272 @Override
9273 public String getMmsUserAgent(int subId) {
9274 //TODO investigate if this API should require proper permission check in R b/133791609
9275 final long identity = Binder.clearCallingIdentity();
9276 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009277 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9278 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9279 if (!TextUtils.isEmpty(carrierUserAgent)) {
9280 return carrierUserAgent;
9281 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009282 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9283 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009284 } finally {
9285 Binder.restoreCallingIdentity(identity);
9286 }
9287 }
Jack Yub07d4972019-05-28 16:12:25 -07009288
9289 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009290 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9291 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009292
Jack Yub07d4972019-05-28 16:12:25 -07009293 final long identity = Binder.clearCallingIdentity();
9294 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009295 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009296 if (phone == null) return false;
9297
Hall Liua62f5da2020-09-25 10:42:19 -07009298 switch (policy) {
9299 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9300 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9301 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9302 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9303 default:
9304 throw new IllegalArgumentException(policy + " is not a valid policy");
9305 }
Jack Yub07d4972019-05-28 16:12:25 -07009306 } finally {
9307 Binder.restoreCallingIdentity(identity);
9308 }
9309 }
9310
9311 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009312 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009313 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009314 enforceModifyPermission();
9315
changbettyd5c246e2019-12-24 15:40:37 +08009316 final long identity = Binder.clearCallingIdentity();
9317 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009318 Phone phone = getPhone(subscriptionId);
9319 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009320
Hall Liua62f5da2020-09-25 10:42:19 -07009321 switch (policy) {
9322 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9323 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9324 break;
9325 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9326 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9327 break;
9328 default:
9329 throw new IllegalArgumentException(policy + " is not a valid policy");
9330 }
changbettyd5c246e2019-12-24 15:40:37 +08009331 } finally {
9332 Binder.restoreCallingIdentity(identity);
9333 }
9334 }
9335
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009336 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009337 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009338 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9339 * otherwise.
9340 */
9341 @Override
9342 public void setCepEnabled(boolean isCepEnabled) {
9343 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9344
9345 final long identity = Binder.clearCallingIdentity();
9346 try {
9347 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9348 for (Phone phone : PhoneFactory.getPhones()) {
9349 Phone defaultPhone = phone.getImsPhone();
9350 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9351 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9352 ImsPhoneCallTracker imsPhoneCallTracker =
9353 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9354 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9355 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9356 + imsPhone.getMsisdn());
9357 }
9358 }
9359 } finally {
9360 Binder.restoreCallingIdentity(identity);
9361 }
9362 }
allenwtsu46dcc572020-01-08 18:24:03 +08009363
9364 /**
9365 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9366 *
9367 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9368 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9369 * before being read.
9370 */
9371 @Override
9372 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9373 isCompressed) {
9374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9375 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009376 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9377 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9378 }
9379 if (!isImsAvailableOnDevice()) {
9380 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9381 "IMS not available on device.");
9382 }
9383
9384 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009385 try {
Hui Wang761a6682020-10-31 05:12:53 +00009386 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9387 } finally {
9388 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009389 }
9390 }
zoey chene02881a2019-12-30 16:11:23 +08009391
9392 @Override
9393 public boolean isIccLockEnabled(int subId) {
9394 enforceReadPrivilegedPermission("isIccLockEnabled");
9395
9396 // Now that all security checks passes, perform the operation as ourselves.
9397 final long identity = Binder.clearCallingIdentity();
9398 try {
9399 Phone phone = getPhone(subId);
9400 if (phone != null && phone.getIccCard() != null) {
9401 return phone.getIccCard().getIccLockEnabled();
9402 } else {
9403 return false;
9404 }
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 }
9409
9410 /**
9411 * Set the ICC pin lock enabled or disabled.
9412 *
9413 * @return an integer representing the status of IccLock enabled or disabled in the following
9414 * three cases:
9415 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9416 * successfully.
9417 * - Positive number and zero for remaining password attempts.
9418 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9419 *
9420 */
9421 @Override
9422 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9423 enforceModifyPermission();
9424
9425 Phone phone = getPhone(subId);
9426 if (phone == null) {
9427 return 0;
9428 }
9429 // Now that all security checks passes, perform the operation as ourselves.
9430 final long identity = Binder.clearCallingIdentity();
9431 try {
9432 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9433 new Pair<Boolean, String>(enabled, password), phone, null);
9434 return attemptsRemaining;
9435
9436 } catch (Exception e) {
9437 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9438 } finally {
9439 Binder.restoreCallingIdentity(identity);
9440 }
9441 return 0;
9442 }
9443
9444 /**
9445 * Change the ICC password used in ICC pin lock.
9446 *
9447 * @return an integer representing the status of IccLock changed in the following three cases:
9448 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9449 * - Positive number and zero for remaining password attempts.
9450 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9451 *
9452 */
9453 @Override
9454 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9455 enforceModifyPermission();
9456
9457 Phone phone = getPhone(subId);
9458 if (phone == null) {
9459 return 0;
9460 }
9461 // Now that all security checks passes, perform the operation as ourselves.
9462 final long identity = Binder.clearCallingIdentity();
9463 try {
9464 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9465 new Pair<String, String>(oldPassword, newPassword), phone, null);
9466 return attemptsRemaining;
9467
9468 } catch (Exception e) {
9469 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9470 } finally {
9471 Binder.restoreCallingIdentity(identity);
9472 }
9473 return 0;
9474 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009475
9476 /**
9477 * Request for receiving user activity notification
9478 */
9479 @Override
9480 public void requestUserActivityNotification() {
9481 if (!mNotifyUserActivity.get()
9482 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9483 mNotifyUserActivity.set(true);
9484 }
9485 }
9486
9487 /**
9488 * Called when userActivity is signalled in the power manager.
9489 * This is safe to call from any thread, with any window manager locks held or not.
9490 */
9491 @Override
9492 public void userActivity() {
9493 // ***************************************
9494 // * Inherited from PhoneWindowManager *
9495 // ***************************************
9496 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9497 // WITH ITS LOCKS HELD.
9498 //
9499 // This code must be VERY careful about the locks
9500 // it acquires.
9501 // In fact, the current code acquires way too many,
9502 // and probably has lurking deadlocks.
9503
9504 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9505 throw new SecurityException("Only the OS may call notifyUserActivity()");
9506 }
9507
9508 if (mNotifyUserActivity.getAndSet(false)) {
9509 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9510 USER_ACTIVITY_NOTIFICATION_DELAY);
9511 }
9512 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009513
9514 @Override
9515 public boolean canConnectTo5GInDsdsMode() {
9516 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9517 }
Jack Yud10cdd42020-09-28 20:28:01 -07009518
9519 @Override
9520 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9521 String callingFeatureId) {
9522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9523 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9524 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9525 }
9526
9527 Phone phone = getPhone(subId);
9528 if (phone == null) {
9529 throw new RuntimeException("phone is not available");
9530 }
9531 // Now that all security checks passes, perform the operation as ourselves.
9532 final long identity = Binder.clearCallingIdentity();
9533 try {
9534 return phone.getEquivalentHomePlmns();
9535 } finally {
9536 Binder.restoreCallingIdentity(identity);
9537 }
9538 }
Daniel Bright59e67312020-11-13 11:49:37 -08009539
9540 @Override
9541 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009542 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9543 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009544 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009545 if (radioInterfaceCapabilities == null) {
9546 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009547 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009548 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009549 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009550
Hui Wang641e81c2020-10-12 12:14:23 -07009551 @Override
9552 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9553 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009554 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9555 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9556 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9557 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9558 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009559 if (DBG) {
9560 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9561 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9562 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9563 }
9564
9565 if (!SubscriptionManager.isValidSubscriptionId(subId)
9566 || appType < TelephonyManager.APPTYPE_UNKNOWN
9567 || appType > TelephonyManager.APPTYPE_ISIM
9568 || nafUrl == null || securityProtocol == null || callback == null) {
9569 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9570 if (callback != null) {
9571 try {
9572 callback.onAuthenticationFailure(
9573 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9574 } catch (RemoteException exception) {
9575 log("Fail to notify onAuthenticationFailure due to " + exception);
9576 }
9577 return;
9578 }
9579 }
9580
9581 final long token = Binder.clearCallingIdentity();
9582 try {
9583 getGbaManager(subId).bootstrapAuthenticationRequest(
9584 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9585 forceBootStrapping, callback));
9586 } finally {
9587 Binder.restoreCallingIdentity(token);
9588 }
9589 }
9590
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009591 /**
9592 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9593 * requested radio power state will actually be set. See {@link
9594 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9595 *
9596 * @param subId the subscription ID of the phone requesting to set the radio power state.
9597 * @param enable {@code true} if trying to turn radio on.
9598 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9599 * false}.
9600 */
9601 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9602 Phone phone = getPhone(subId);
9603 if (phone != null) {
9604 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9605 return true;
9606 }
9607 return false;
9608 }
9609
9610 private int handleDataThrottlingRequest(int subId,
9611 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009612 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9613 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9614 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9615 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9616 throw new IllegalArgumentException("modem does not support data throttling");
9617 }
9618
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009619 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9620 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9621 if (!setRadioPowerForThermal(subId, true)) {
9622 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9623 }
9624
9625 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9626
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009627 if (isDataThrottlingSupported) {
9628 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009629 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009630 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9631 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9632 } else if (thermalMitigationResult
9633 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9634 throw new IllegalArgumentException("modem does not support data throttling");
9635 }
9636 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009637 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009638
9639 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009640 }
9641
9642 /**
9643 * Thermal mitigation request to control functionalities at modem.
9644 *
9645 * @param subId the id of the subscription.
9646 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9647 *
9648 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9649 */
9650 @Override
9651 @ThermalMitigationResult
9652 public int sendThermalMitigationRequest(
9653 int subId,
9654 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9655 enforceModifyPermission();
9656
9657 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9658 final long identity = Binder.clearCallingIdentity();
9659
9660 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9661 try {
9662 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9663 switch (thermalMitigationAction) {
9664 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9665 thermalMitigationResult =
9666 handleDataThrottlingRequest(subId,
9667 thermalMitigationRequest.getDataThrottlingRequest());
9668 break;
9669 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9670 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9671 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9672 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9673 }
9674
9675 // Ensure that radio is on. If not able to power on due to phone being
9676 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9677 if (!setRadioPowerForThermal(subId, true)) {
9678 thermalMitigationResult =
9679 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9680 break;
9681 }
9682
9683 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9684 false);
9685 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9686 break;
9687 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9688 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9689 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9690 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9691 }
9692
9693 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9694 if (registry != null) {
9695 TelephonyConnectionService service =
9696 registry.getTelephonyConnectionService();
9697 Phone phone = getPhone(subId);
9698 if (phone == null) {
9699 thermalMitigationResult =
9700 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9701 break;
9702 }
9703
9704 if (PhoneConstantConversions.convertCallState(phone.getState())
9705 != TelephonyManager.CALL_STATE_IDLE
9706 || phone.isInEmergencySmsMode() || phone.isInEcm()
9707 || (service != null && service.isEmergencyCallPending())) {
9708 String errorMessage = "Phone state is not valid. call state = "
9709 + PhoneConstantConversions.convertCallState(phone.getState())
9710 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9711 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9712 errorMessage += service == null
9713 ? " TelephonyConnectionService is null"
9714 : " isEmergencyCallPending = "
9715 + service.isEmergencyCallPending();
9716 Log.e(LOG_TAG, errorMessage);
9717 thermalMitigationResult =
9718 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9719 break;
9720 }
9721 } else {
9722 thermalMitigationResult =
9723 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9724 break;
9725 }
9726
9727 // Turn radio off. If not able to power off due to phone being unavailable,
9728 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9729 if (!setRadioPowerForThermal(subId, false)) {
9730 thermalMitigationResult =
9731 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9732 break;
9733 }
9734 thermalMitigationResult =
9735 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9736 break;
9737 default:
9738 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9739 + "not exist. Requested action: " + thermalMitigationAction);
9740 }
9741 } catch (IllegalArgumentException e) {
9742 throw e;
9743 } catch (Exception e) {
9744 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9745 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9746 } finally {
9747 Binder.restoreCallingIdentity(identity);
9748 }
9749
9750 if (DBG) {
9751 log("thermalMitigationRequest returning with thermalMitigationResult: "
9752 + thermalMitigationResult);
9753 }
9754
9755 return thermalMitigationResult;
9756 }
Hui Wang641e81c2020-10-12 12:14:23 -07009757
9758 /**
9759 * Set the GbaService Package Name that Telephony will bind to.
9760 *
9761 * @param subId The sim that the GbaService is associated with.
9762 * @param packageName The name of the package to be replaced with.
9763 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9764 */
9765 @Override
9766 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9767 enforceModifyPermission();
9768
9769 final long identity = Binder.clearCallingIdentity();
9770 try {
9771 return getGbaManager(subId).overrideServicePackage(packageName);
9772 } finally {
9773 Binder.restoreCallingIdentity(identity);
9774 }
9775 }
9776
9777 /**
9778 * Return the package name of the currently bound GbaService.
9779 *
9780 * @param subId The sim that the GbaService is associated with.
9781 * @return the package name of the GbaService configuration, null if GBA is not supported.
9782 */
9783 @Override
9784 public String getBoundGbaService(int subId) {
9785 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9786
9787 final long identity = Binder.clearCallingIdentity();
9788 try {
9789 return getGbaManager(subId).getServicePackage();
9790 } finally {
9791 Binder.restoreCallingIdentity(identity);
9792 }
9793 }
9794
9795 /**
9796 * Set the release time for telephony to unbind GbaService.
9797 *
9798 * @param subId The sim that the GbaService is associated with.
9799 * @param interval The release time to unbind GbaService by millisecond.
9800 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9801 */
9802 @Override
9803 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9804 enforceModifyPermission();
9805
9806 final long identity = Binder.clearCallingIdentity();
9807 try {
9808 return getGbaManager(subId).overrideReleaseTime(interval);
9809 } finally {
9810 Binder.restoreCallingIdentity(identity);
9811 }
9812 }
9813
9814 /**
9815 * Return the release time for telephony to unbind GbaService.
9816 *
9817 * @param subId The sim that the GbaService is associated with.
9818 * @return The release time to unbind GbaService by millisecond.
9819 */
9820 @Override
9821 public int getGbaReleaseTime(int subId) {
9822 enforceReadPrivilegedPermission("getGbaReleaseTime");
9823
9824 final long identity = Binder.clearCallingIdentity();
9825 try {
9826 return getGbaManager(subId).getReleaseTime();
9827 } finally {
9828 Binder.restoreCallingIdentity(identity);
9829 }
9830 }
9831
9832 private GbaManager getGbaManager(int subId) {
9833 GbaManager instance = GbaManager.getInstance(subId);
9834 if (instance == null) {
9835 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9836 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9837 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9838 }
9839 return instance;
9840 }
Hui Wang761a6682020-10-31 05:12:53 +00009841
9842 /**
9843 * indicate whether the device and the carrier can support
9844 * RCS VoLTE single registration.
9845 */
9846 @Override
9847 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009848 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9849 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9850 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9851 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009852
9853 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9854 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9855 }
9856
9857 final long identity = Binder.clearCallingIdentity();
9858 try {
9859 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9860 if (rpm != null) {
9861 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9862 }
9863 return false;
9864 } finally {
9865 Binder.restoreCallingIdentity(identity);
9866 }
9867 }
9868
9869 /**
9870 * Register RCS provisioning callback.
9871 */
9872 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009873 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009874 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009875 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009876 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009877 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9878 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009879
9880 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9881 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9882 }
9883 if (!isImsAvailableOnDevice()) {
9884 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9885 "IMS not available on device.");
9886 }
9887
9888 final long identity = Binder.clearCallingIdentity();
9889 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009890 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009891 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -08009892 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9893 "Service not available for the subscription.");
9894 }
Hui Wang761a6682020-10-31 05:12:53 +00009895 } finally {
9896 Binder.restoreCallingIdentity(identity);
9897 }
9898 }
9899
9900 /**
9901 * Unregister RCS provisioning callback.
9902 */
9903 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009904 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009905 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009906 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009907 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009908 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9909 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009910
9911 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9912 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9913 }
9914 if (!isImsAvailableOnDevice()) {
9915 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9916 "IMS not available on device.");
9917 }
9918
9919 final long identity = Binder.clearCallingIdentity();
9920 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009921 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009922 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009923 } finally {
9924 Binder.restoreCallingIdentity(identity);
9925 }
9926 }
9927
9928 /**
9929 * trigger RCS reconfiguration.
9930 */
9931 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009932 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9933 "triggerRcsReconfiguration",
9934 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009935
9936 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9937 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9938 }
9939 if (!isImsAvailableOnDevice()) {
9940 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9941 "IMS not available on device.");
9942 }
9943
9944 final long identity = Binder.clearCallingIdentity();
9945 try {
9946 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9947 } finally {
9948 Binder.restoreCallingIdentity(identity);
9949 }
9950 }
9951
9952 /**
9953 * Provide the client configuration parameters of the RCS application.
9954 */
9955 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009956 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9957 "setRcsClientConfiguration",
9958 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009959
9960 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9961 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9962 }
9963 if (!isImsAvailableOnDevice()) {
9964 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9965 "IMS not available on device.");
9966 }
9967
9968 final long identity = Binder.clearCallingIdentity();
9969
9970 try {
9971 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9972 if (configBinder == null) {
9973 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9974 } else {
9975 configBinder.setRcsClientConfiguration(rcc);
9976 }
9977 } catch (RemoteException e) {
9978 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9979 } finally {
9980 Binder.restoreCallingIdentity(identity);
9981 }
9982 }
9983
9984 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -08009985 * Enables or disables the test mode for RCS VoLTE single registration.
9986 */
9987 @Override
9988 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9989 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9990 "setRcsSingleRegistrationTestModeEnabled");
9991
9992 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9993 }
9994
9995 /**
9996 * Gets the test mode for RCS VoLTE single registration.
9997 */
9998 @Override
9999 public boolean getRcsSingleRegistrationTestModeEnabled() {
10000 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10001 "getRcsSingleRegistrationTestModeEnabled");
10002
10003 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10004 }
10005
10006 /**
Hui Wang761a6682020-10-31 05:12:53 +000010007 * Overrides the config of RCS VoLTE single registration enabled for the device.
10008 */
10009 @Override
10010 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10011 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10012 "setDeviceSingleRegistrationEnabledOverride");
10013 enforceModifyPermission();
10014
10015 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10016 : Boolean.parseBoolean(enabledStr);
10017 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010018 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010019 }
10020
10021 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010022 * Sends a device to device communication message. Only usable via shell.
10023 * @param message message to send.
10024 * @param value message value.
10025 */
10026 @Override
10027 public void sendDeviceToDeviceMessage(int message, int value) {
10028 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010029 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010030 enforceModifyPermission();
10031
10032 final long identity = Binder.clearCallingIdentity();
10033 try {
10034 TelephonyConnectionService service =
10035 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10036 if (service == null) {
10037 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10038 return;
10039 }
10040 service.sendTestDeviceToDeviceMessage(message, value);
10041 } finally {
10042 Binder.restoreCallingIdentity(identity);
10043 }
10044 }
10045
Tyler Gunnbabbda02021-02-10 11:05:02 -080010046 /**
10047 * Sets the specified device to device transport active.
10048 * @param transport The transport to set active.
10049 */
10050 @Override
10051 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10052 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10053 "setActiveDeviceToDeviceTransport");
10054 enforceModifyPermission();
10055
10056 final long identity = Binder.clearCallingIdentity();
10057 try {
10058 TelephonyConnectionService service =
10059 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10060 if (service == null) {
10061 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10062 return;
10063 }
10064 service.setActiveDeviceToDeviceTransport(transport);
10065 } finally {
10066 Binder.restoreCallingIdentity(identity);
10067 }
10068 }
Tyler Gunn92479152021-01-20 16:30:10 -080010069
10070 /**
Hui Wang761a6682020-10-31 05:12:53 +000010071 * Gets the config of RCS VoLTE single registration enabled for the device.
10072 */
10073 @Override
10074 public boolean getDeviceSingleRegistrationEnabled() {
10075 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10076 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10077 }
10078
10079 /**
10080 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10081 */
10082 @Override
10083 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10084 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10085 "setCarrierSingleRegistrationEnabledOverride");
10086 enforceModifyPermission();
10087
10088 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10089 : Boolean.parseBoolean(enabledStr);
10090 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10091 subId, enabled);
10092 }
10093
10094 /**
10095 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10096 */
10097 @Override
10098 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10099 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10100 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10101 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010102
10103 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010104 * Overrides the ims feature validation result
10105 */
10106 @Override
10107 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10109 "setImsFeatureValidationOverride");
10110
10111 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10112 : Boolean.parseBoolean(enabledStr);
10113 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10114 subId, enabled);
10115 }
10116
10117 /**
10118 * Gets the ims feature validation override value
10119 */
10120 @Override
10121 public boolean getImsFeatureValidationOverride(int subId) {
10122 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10123 "getImsFeatureValidationOverride");
10124 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10125 }
10126
10127 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010128 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10129 * their mobile plan.
10130 */
10131 @Override
10132 public String getMobileProvisioningUrl() {
10133 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10134 final long identity = Binder.clearCallingIdentity();
10135 try {
10136 return getDefaultPhone().getMobileProvisioningUrl();
10137 } finally {
10138 Binder.restoreCallingIdentity(identity);
10139 }
10140 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010141
James.cf Linbcdf8b32021-01-14 16:44:13 +080010142 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010143 * Get the EAB contact from the EAB database.
10144 */
10145 @Override
10146 public String getContactFromEab(String contact) {
10147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10148 enforceModifyPermission();
10149 final long identity = Binder.clearCallingIdentity();
10150 try {
10151 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10152 } finally {
10153 Binder.restoreCallingIdentity(identity);
10154 }
10155 }
10156
10157 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010158 * Remove the EAB contacts from the EAB database.
10159 */
10160 @Override
10161 public int removeContactFromEab(int subId, String contacts) {
10162 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10163 enforceModifyPermission();
10164 final long identity = Binder.clearCallingIdentity();
10165 try {
10166 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10167 } finally {
10168 Binder.restoreCallingIdentity(identity);
10169 }
10170 }
10171
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010172 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010173 public boolean getDeviceUceEnabled() {
10174 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10175 final long identity = Binder.clearCallingIdentity();
10176 try {
10177 return mApp.getDeviceUceEnabled();
10178 } finally {
10179 Binder.restoreCallingIdentity(identity);
10180 }
10181 }
10182
10183 @Override
10184 public void setDeviceUceEnabled(boolean isEnabled) {
10185 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10186 final long identity = Binder.clearCallingIdentity();
10187 try {
10188 mApp.setDeviceUceEnabled(isEnabled);
10189 } finally {
10190 Binder.restoreCallingIdentity(identity);
10191 }
10192 }
10193
Brad Ebinger14d467f2021-02-12 06:18:28 +000010194 /**
10195 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10196 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10197 */
10198 // Used for SHELL command only right now.
10199 @Override
10200 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10201 List<String> featureTags) {
10202 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10203 "addUceRegistrationOverrideShell");
10204 final long identity = Binder.clearCallingIdentity();
10205 try {
10206 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10207 new ArraySet<>(featureTags));
10208 } catch (ImsException e) {
10209 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10210 } finally {
10211 Binder.restoreCallingIdentity(identity);
10212 }
10213 }
10214
10215 /**
10216 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10217 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10218 */
10219 // Used for SHELL command only right now.
10220 @Override
10221 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10222 List<String> featureTags) {
10223 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10224 "removeUceRegistrationOverrideShell");
10225 final long identity = Binder.clearCallingIdentity();
10226 try {
10227 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10228 new ArraySet<>(featureTags));
10229 } catch (ImsException e) {
10230 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10231 } finally {
10232 Binder.restoreCallingIdentity(identity);
10233 }
10234 }
10235
10236 /**
10237 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10238 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10239 */
10240 // Used for SHELL command only right now.
10241 @Override
10242 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10243 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10244 "clearUceRegistrationOverrideShell");
10245 final long identity = Binder.clearCallingIdentity();
10246 try {
10247 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10248 } catch (ImsException e) {
10249 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10250 } finally {
10251 Binder.restoreCallingIdentity(identity);
10252 }
10253 }
10254
10255 /**
10256 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10257 */
10258 // Used for SHELL command only right now.
10259 @Override
10260 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10261 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10262 "getLatestRcsContactUceCapabilityShell");
10263 final long identity = Binder.clearCallingIdentity();
10264 try {
10265 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10266 } catch (ImsException e) {
10267 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10268 } finally {
10269 Binder.restoreCallingIdentity(identity);
10270 }
10271 }
10272
10273 /**
10274 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10275 * device does not have an active PUBLISH.
10276 */
10277 // Used for SHELL command only right now.
10278 @Override
10279 public String getLastUcePidfXmlShell(int subId) {
10280 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10281 final long identity = Binder.clearCallingIdentity();
10282 try {
10283 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10284 } catch (ImsException e) {
10285 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10286 } finally {
10287 Binder.restoreCallingIdentity(identity);
10288 }
10289 }
10290
10291
James.cf Lin4b784aa2021-01-31 03:25:15 +080010292 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010293 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10294 String callingPackage) {
10295 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10296 mApp, subId, "setSignalStrengthUpdateRequest");
10297
10298 final int callingUid = Binder.getCallingUid();
10299 // Verify that tha callingPackage belongs to the calling UID
10300 mApp.getSystemService(AppOpsManager.class)
10301 .checkPackage(callingUid, callingPackage);
10302
10303 validateSignalStrengthUpdateRequest(request, callingUid);
10304
10305 final long identity = Binder.clearCallingIdentity();
10306 try {
10307 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10308 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10309
10310 if (result instanceof IllegalStateException) {
10311 throw (IllegalStateException) result;
10312 }
10313 } finally {
10314 Binder.restoreCallingIdentity(identity);
10315 }
10316 }
10317
10318 @Override
10319 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10320 String callingPackage) {
10321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10322 mApp, subId, "clearSignalStrengthUpdateRequest");
10323
10324 final int callingUid = Binder.getCallingUid();
10325 // Verify that tha callingPackage belongs to the calling UID
10326 mApp.getSystemService(AppOpsManager.class)
10327 .checkPackage(callingUid, callingPackage);
10328
10329 final long identity = Binder.clearCallingIdentity();
10330 try {
10331 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10332 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10333
10334 if (result instanceof IllegalStateException) {
10335 throw (IllegalStateException) result;
10336 }
10337 } finally {
10338 Binder.restoreCallingIdentity(identity);
10339 }
10340 }
10341
10342 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10343 int callingUid) {
10344 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10345 // phone/system process do not have further restriction on request
10346 return;
10347 }
10348
10349 // Applications has restrictions on how to use the request:
10350 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10351 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10352 // This is not system caller which has been checked above
10353 throw new IllegalArgumentException(
10354 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10355 }
10356
10357 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10358 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10359 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10360 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10361 || info.isEnabled()) {
10362 throw new IllegalArgumentException(
10363 "Only system can set hide fields in SignalThresholdInfo");
10364 }
10365
10366 // Thresholds length for each RAN need in range. This has been validated in
10367 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10368 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10369 final int[] thresholds = info.getThresholds();
10370 Objects.requireNonNull(thresholds);
10371 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10372 || thresholds.length
10373 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10374 throw new IllegalArgumentException(
10375 "thresholds length is out of range: " + thresholds.length);
10376 }
10377 }
10378 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010379
10380 /**
10381 * Gets the current phone capability.
10382 *
10383 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10384 * @return the PhoneCapability which describes the data connection capability of modem.
10385 * It's used to evaluate possible phone config change, for example from single
10386 * SIM device to multi-SIM device.
10387 */
10388 @Override
10389 public PhoneCapability getPhoneCapability() {
10390 enforceReadPrivilegedPermission("getPhoneCapability");
10391 final long identity = Binder.clearCallingIdentity();
10392 try {
10393 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10394 } finally {
10395 Binder.restoreCallingIdentity(identity);
10396 }
10397 }
Michele Berionne5e411512020-11-13 02:36:59 +000010398
10399 /**
10400 * Prepare TelephonyManager for an unattended reboot. The reboot is
10401 * required to be done shortly after the API is invoked.
10402 */
10403 @Override
10404 @TelephonyManager.PrepareUnattendedRebootResult
10405 public int prepareForUnattendedReboot() {
10406 enforceRebootPermission();
10407
10408 final long identity = Binder.clearCallingIdentity();
10409 try {
10410 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10411 } finally {
10412 Binder.restoreCallingIdentity(identity);
10413 }
10414 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010415
10416 /**
10417 * Request to get the current slicing configuration including URSP rules and
10418 * NSSAIs (configured, allowed and rejected).
10419 *
10420 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10421 */
10422 @Override
10423 public void getSlicingConfig(ResultReceiver callback) {
10424 enforceReadPrivilegedPermission("getSlicingConfig");
10425
10426 final long identity = Binder.clearCallingIdentity();
10427 try {
10428 Phone phone = getDefaultPhone();
10429 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010434}