blob: a5ef88bdcde6db5674f352ead1a89d86aab11683 [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;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800350 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351
Wink Saville3ab207e2014-11-20 13:07:20 -0800352 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800353 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800354 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700355 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800356 private AppOpsManager mAppOps;
357 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800358 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800359 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700360 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800361 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
Peter Wangdafb9ac2020-01-15 14:13:38 -0800363 /** User Activity */
364 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800365 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
366
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700367 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
368
Derek Tan97ebb422014-09-05 16:55:38 -0700369 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
370 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800371 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800372 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700373
Michelecea4cf22018-12-21 15:00:11 -0800374 // String to store multi SIM allowed
375 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
376
Derek Tan740e1672017-06-27 14:56:27 -0700377 // The AID of ISD-R.
378 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
379
yinxub1bed742017-04-17 11:45:04 -0700380 private NetworkScanRequestTracker mNetworkScanRequestTracker;
381
David Kelly5e06a7f2018-03-12 14:10:59 +0000382 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
383 private static final int MANUFACTURER_CODE_LENGTH = 8;
384
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800385 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800386 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800387
Derek Tan89e89d42014-07-08 17:00:10 -0700388 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700389 * Experiment flag to enable erase modem config on reset network, default value is false
390 */
391 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
392 "reset_network_erase_modem_config_enabled";
393
Rambo Wang0f050d82021-02-12 11:43:36 -0800394 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
395
Naina Nallurid63128d2019-09-17 14:10:30 -0700396 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700397 * A request object to use for transmitting data to an ICC.
398 */
399 private static final class IccAPDUArgument {
400 public int channel, cla, command, p1, p2, p3;
401 public String data;
402
403 public IccAPDUArgument(int channel, int cla, int command,
404 int p1, int p2, int p3, String data) {
405 this.channel = channel;
406 this.cla = cla;
407 this.command = command;
408 this.p1 = p1;
409 this.p2 = p2;
410 this.p3 = p3;
411 this.data = data;
412 }
413 }
414
415 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700416 * A request object to use for transmitting data to an ICC.
417 */
418 private static final class ManualNetworkSelectionArgument {
419 public OperatorInfo operatorInfo;
420 public boolean persistSelection;
421
422 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
423 this.operatorInfo = operatorInfo;
424 this.persistSelection = persistSelection;
425 }
426 }
427
428 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
430 * request after sending. The main thread will notify the request when it is complete.
431 */
432 private static final class MainThreadRequest {
433 /** The argument to use for the request */
434 public Object argument;
435 /** The result of the request that is run on the main thread */
436 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800437 // The subscriber id that this request applies to. Defaults to
438 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
439 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700440
Nathan Harold92bed182018-10-12 18:16:49 -0700441 // In cases where subId is unavailable, the caller needs to specify the phone.
442 public Phone phone;
443
vagdeviaf9a5b92018-08-15 16:01:53 -0700444 public WorkSource workSource;
445
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 public MainThreadRequest(Object argument) {
447 this.argument = argument;
448 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800449
Nathan Harold92bed182018-10-12 18:16:49 -0700450 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
451 this.argument = argument;
452 if (phone != null) {
453 this.phone = phone;
454 }
455 this.workSource = workSource;
456 }
457
vagdeviaf9a5b92018-08-15 16:01:53 -0700458 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800459 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800460 if (subId != null) {
461 this.subId = subId;
462 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700463 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 }
466
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800467 private static final class IncomingThirdPartyCallArgs {
468 public final ComponentName component;
469 public final String callId;
470 public final String callerDisplayName;
471
472 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
473 String callerDisplayName) {
474 this.component = component;
475 this.callId = callId;
476 this.callerDisplayName = callerDisplayName;
477 }
478 }
479
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480 /**
481 * A handler that processes messages on the main thread in the phone process. Since many
482 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
483 * inbound binder threads to the main thread in the phone process. The Binder thread
484 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
485 * on, which will be notified when the operation completes and will contain the result of the
486 * request.
487 *
488 * <p>If a MainThreadRequest object is provided in the msg.obj field,
489 * note that request.result must be set to something non-null for the calling thread to
490 * unblock.
491 */
492 private final class MainThreadHandler extends Handler {
493 @Override
494 public void handleMessage(Message msg) {
495 MainThreadRequest request;
496 Message onCompleted;
497 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800500 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700501
502 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 case CMD_HANDLE_USSD_REQUEST: {
504 request = (MainThreadRequest) msg.obj;
505 final Phone phone = getPhoneFromRequest(request);
506 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
507 String ussdRequest = ussdObject.first;
508 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700509
Pengquan Menga1bb6272018-09-06 09:59:22 -0700510 if (!isUssdApiAllowed(request.subId)) {
511 // Carrier does not support use of this API, return failure.
512 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
513 UssdResponse response = new UssdResponse(ussdRequest, null);
514 Bundle returnData = new Bundle();
515 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
516 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700517
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 request.result = true;
519 notifyRequester(request);
520 return;
521 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700522
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 try {
524 request.result = phone != null
525 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
526 } catch (CallStateException cse) {
527 request.result = false;
528 }
529 // Wake up the requesting thread
530 notifyRequester(request);
531 break;
pkanwar32d516d2016-10-14 19:37:38 -0700532 }
533
Yorke Lee716f67e2015-06-17 15:39:16 -0700534 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700535 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700536 final Phone phone = getPhoneFromRequest(request);
537 request.result = phone != null ?
538 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
539 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700540 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700541 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700542 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700544
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700546 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800548 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700549 if (uiccCard == null) {
550 loge("iccTransmitApduLogicalChannel: No UICC");
551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700554 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
555 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 iccArgument.channel, iccArgument.cla, iccArgument.command,
558 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700560 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 break;
562
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
566 if (ar.exception == null && ar.result != null) {
567 request.result = ar.result;
568 } else {
569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
570 if (ar.result == null) {
571 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800572 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800574 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 } else {
576 loge("iccTransmitApduLogicalChannel: Unknown exception");
577 }
578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 break;
581
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
583 request = (MainThreadRequest) msg.obj;
584 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800585 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 if (uiccCard == null) {
587 loge("iccTransmitApduBasicChannel: No UICC");
588 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700590 } else {
591 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
592 request);
593 uiccCard.iccTransmitApduBasicChannel(
594 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
595 iccArgument.p3, iccArgument.data, onCompleted);
596 }
597 break;
598
599 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
600 ar = (AsyncResult) msg.obj;
601 request = (MainThreadRequest) ar.userObj;
602 if (ar.exception == null && ar.result != null) {
603 request.result = ar.result;
604 } else {
605 request.result = new IccIoResult(0x6F, 0, (byte[])null);
606 if (ar.result == null) {
607 loge("iccTransmitApduBasicChannel: Empty response");
608 } else if (ar.exception instanceof CommandException) {
609 loge("iccTransmitApduBasicChannel: CommandException: " +
610 ar.exception);
611 } else {
612 loge("iccTransmitApduBasicChannel: Unknown exception");
613 }
614 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 break;
617
618 case CMD_EXCHANGE_SIM_IO:
619 request = (MainThreadRequest) msg.obj;
620 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800621 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 if (uiccCard == null) {
623 loge("iccExchangeSimIO: No UICC");
624 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700625 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 } else {
627 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
628 request);
629 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
630 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
631 iccArgument.data, onCompleted);
632 }
633 break;
634
635 case EVENT_EXCHANGE_SIM_IO_DONE:
636 ar = (AsyncResult) msg.obj;
637 request = (MainThreadRequest) ar.userObj;
638 if (ar.exception == null && ar.result != null) {
639 request.result = ar.result;
640 } else {
641 request.result = new IccIoResult(0x6f, 0, (byte[])null);
642 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 break;
645
Derek Tan4d5e5c12014-02-04 11:54:58 -0800646 case CMD_SEND_ENVELOPE:
647 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800648 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700649 if (uiccCard == null) {
650 loge("sendEnvelopeWithStatus: No UICC");
651 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700653 } else {
654 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
655 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
656 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800657 break;
658
659 case EVENT_SEND_ENVELOPE_DONE:
660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800664 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700665 request.result = new IccIoResult(0x6F, 0, (byte[])null);
666 if (ar.result == null) {
667 loge("sendEnvelopeWithStatus: Empty response");
668 } else if (ar.exception instanceof CommandException) {
669 loge("sendEnvelopeWithStatus: CommandException: " +
670 ar.exception);
671 } else {
672 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
673 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800674 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700675 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800676 break;
677
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 case CMD_OPEN_CHANNEL:
679 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800680 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800681 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 if (uiccCard == null) {
683 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800684 request.result = new IccOpenLogicalChannelResponse(-1,
685 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700686 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700687 } else {
688 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800689 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
690 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700691 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 break;
693
694 case EVENT_OPEN_CHANNEL_DONE:
695 ar = (AsyncResult) msg.obj;
696 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700697 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700698 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700699 int[] result = (int[]) ar.result;
700 int channelId = result[0];
701 byte[] selectResponse = null;
702 if (result.length > 1) {
703 selectResponse = new byte[result.length - 1];
704 for (int i = 1; i < result.length; ++i) {
705 selectResponse[i - 1] = (byte) result[i];
706 }
707 }
708 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700709 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 if (ar.result == null) {
712 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700714 if (ar.exception != null) {
715 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
716 }
717
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700718 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700719 if (ar.exception instanceof CommandException) {
720 CommandException.Error error =
721 ((CommandException) (ar.exception)).getCommandError();
722 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700723 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700724 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700725 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700726 }
727 }
728 openChannelResp = new IccOpenLogicalChannelResponse(
729 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700731 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700732 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 break;
734
735 case CMD_CLOSE_CHANNEL:
736 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800737 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700738 if (uiccCard == null) {
739 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900740 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700741 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700742 } else {
743 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
744 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
745 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700746 break;
747
748 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800749 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
750 break;
751
752 case CMD_NV_READ_ITEM:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800755 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
756 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800757 break;
758
759 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800762 if (ar.exception == null && ar.result != null) {
763 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700764 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800765 request.result = "";
766 if (ar.result == null) {
767 loge("nvReadItem: Empty response");
768 } else if (ar.exception instanceof CommandException) {
769 loge("nvReadItem: CommandException: " +
770 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700771 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800772 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700773 }
774 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700775 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700776 break;
777
Jake Hambye994d462014-02-03 13:10:13 -0800778 case CMD_NV_WRITE_ITEM:
779 request = (MainThreadRequest) msg.obj;
780 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
781 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800782 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700783 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
786 case EVENT_NV_WRITE_ITEM_DONE:
787 handleNullReturnEvent(msg, "nvWriteItem");
788 break;
789
790 case CMD_NV_WRITE_CDMA_PRL:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800793 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800794 break;
795
796 case EVENT_NV_WRITE_CDMA_PRL_DONE:
797 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
798 break;
799
chen xu6dac5ab2018-10-26 17:39:23 -0700800 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800801 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700802 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800803 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800804 break;
805
chen xu6dac5ab2018-10-26 17:39:23 -0700806 case EVENT_RESET_MODEM_CONFIG_DONE:
807 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800808 break;
809
Sooraj Sasindran37444802020-08-11 10:40:43 -0700810 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
811 request = (MainThreadRequest) msg.obj;
812 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
813 request);
814 Phone phone = getPhoneFromRequest(request);
815 if (phone != null) {
816 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
817 } else {
818 loge("isNRDualConnectivityEnabled: No phone object");
819 request.result = false;
820 notifyRequester(request);
821 }
822 break;
823 }
824
825 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
826 ar = (AsyncResult) msg.obj;
827 request = (MainThreadRequest) ar.userObj;
828 if (ar.exception == null && ar.result != null) {
829 request.result = ar.result;
830 } else {
831 // request.result must be set to something non-null
832 // for the calling thread to unblock
833 if (request.result != null) {
834 request.result = ar.result;
835 } else {
836 request.result = false;
837 }
838 if (ar.result == null) {
839 loge("isNRDualConnectivityEnabled: Empty response");
840 } else if (ar.exception instanceof CommandException) {
841 loge("isNRDualConnectivityEnabled: CommandException: "
842 + ar.exception);
843 } else {
844 loge("isNRDualConnectivityEnabled: Unknown exception");
845 }
846 }
847 notifyRequester(request);
848 break;
849
850 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
851 request = (MainThreadRequest) msg.obj;
852 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
853 Phone phone = getPhoneFromRequest(request);
854 if (phone != null) {
855 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
856 request.workSource);
857 } else {
858 loge("enableNrDualConnectivity: No phone object");
859 request.result =
860 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
861 notifyRequester(request);
862 }
863 break;
864 }
865
866 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null) {
870 request.result =
871 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
872 } else {
873 request.result =
874 TelephonyManager
875 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
876 if (ar.exception instanceof CommandException) {
877 CommandException.Error error =
878 ((CommandException) (ar.exception)).getCommandError();
879 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
880 request.result =
881 TelephonyManager
882 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000883 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
884 request.result =
885 TelephonyManager
886 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700887 }
888 loge("enableNrDualConnectivity" + ": CommandException: "
889 + ar.exception);
890 } else {
891 loge("enableNrDualConnectivity" + ": Unknown exception");
892 }
893 }
894 notifyRequester(request);
895 break;
896 }
897
SongFerngWang3ef3e072020-12-21 16:41:52 +0800898 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800899 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800900 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
901 request);
902 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 break;
904
SongFerngWang3ef3e072020-12-21 16:41:52 +0800905 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800906 ar = (AsyncResult) msg.obj;
907 request = (MainThreadRequest) ar.userObj;
908 if (ar.exception == null && ar.result != null) {
909 request.result = ar.result; // Integer
910 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530911 // request.result must be set to something non-null
912 // for the calling thread to unblock
913 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800914 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800915 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800916 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800917 loge("getAllowedNetworkTypesBitmask: CommandException: "
918 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800919 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800920 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 }
922 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800924 break;
925
SongFerngWang3ef3e072020-12-21 16:41:52 +0800926 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800927 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800928 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
929 request);
930 Pair<Integer, Long> reasonWithNetworkTypes =
931 (Pair<Integer, Long>) request.argument;
932 getPhoneFromRequest(request).setAllowedNetworkTypes(
933 reasonWithNetworkTypes.first,
934 reasonWithNetworkTypes.second,
935 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800936 break;
937
SongFerngWang3ef3e072020-12-21 16:41:52 +0800938 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
939 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800940 break;
941
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000942 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
943 request = (MainThreadRequest)msg.obj;
944 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800945 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000946 break;
947
948 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
949 ar = (AsyncResult)msg.obj;
950 request = (MainThreadRequest)ar.userObj;
951 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700952 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000953 break;
954
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800955 case CMD_SET_VOICEMAIL_NUMBER:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
958 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800959 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
960 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800961 break;
962
963 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
964 handleNullReturnEvent(msg, "setVoicemailNumber");
965 break;
966
Stuart Scott54788802015-03-30 13:18:01 -0700967 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
968 request = (MainThreadRequest) msg.obj;
969 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
970 request);
971 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
972 break;
973
974 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
975 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
976 break;
977
Shishir Agrawal302c8692015-06-19 13:49:39 -0700978 case CMD_PERFORM_NETWORK_SCAN:
979 request = (MainThreadRequest) msg.obj;
980 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
981 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
982 break;
983
Hall Liu27d24262020-09-18 19:04:59 -0700984 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800985 request = (MainThreadRequest) msg.obj;
986 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700987 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
988 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
989 request.argument;
990 int callForwardingReason = args.first;
991 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800992 break;
Hall Liu27d24262020-09-18 19:04:59 -0700993 }
994 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700997 TelephonyManager.CallForwardingInfoCallback callback =
998 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
999 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001000 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001001 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001002 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1003 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1004 // Service Class is a bit mask per 3gpp 27.007. Search for
1005 // any service for voice call.
1006 if ((callForwardInfo.serviceClass
1007 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001008 callForwardingInfo = new CallForwardingInfo(true,
1009 callForwardInfo.reason,
1010 callForwardInfo.number,
1011 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001012 break;
1013 }
1014 }
1015 // Didn't find a call forward info for voice call.
1016 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001017 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1018 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001019 }
Hall Liu27d24262020-09-18 19:04:59 -07001020 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001021 } else {
1022 if (ar.result == null) {
1023 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1024 }
1025 if (ar.exception != null) {
1026 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1027 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001028 int errorCode = TelephonyManager
1029 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001030 if (ar.exception instanceof CommandException) {
1031 CommandException.Error error =
1032 ((CommandException) (ar.exception)).getCommandError();
1033 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001034 errorCode = TelephonyManager
1035 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001036 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001037 errorCode = TelephonyManager
1038 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001039 }
1040 }
Hall Liu27d24262020-09-18 19:04:59 -07001041 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001042 }
Shuo Qian4a594052020-01-23 11:59:30 -08001043 break;
Hall Liu27d24262020-09-18 19:04:59 -07001044 }
Shuo Qian4a594052020-01-23 11:59:30 -08001045
Hall Liu27d24262020-09-18 19:04:59 -07001046 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001049 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001050 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001051 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1052 request.argument).first;
1053 request.phone.setCallForwardingOption(
1054 callForwardingInfoToSet.isEnabled()
1055 ? CommandsInterface.CF_ACTION_ENABLE
1056 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001057 callForwardingInfoToSet.getReason(),
1058 callForwardingInfoToSet.getNumber(),
1059 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1060 break;
Hall Liu27d24262020-09-18 19:04:59 -07001061 }
Shuo Qian4a594052020-01-23 11:59:30 -08001062
Hall Liu27d24262020-09-18 19:04:59 -07001063 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001066 Consumer<Integer> callback =
1067 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1068 request.argument).second;
1069 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001070 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001071 int errorCode = TelephonyManager.CallForwardingInfoCallback
1072 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001073 if (ar.exception instanceof CommandException) {
1074 CommandException.Error error =
1075 ((CommandException) (ar.exception)).getCommandError();
1076 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001077 errorCode = TelephonyManager.CallForwardingInfoCallback
1078 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001079 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001080 errorCode = TelephonyManager.CallForwardingInfoCallback
1081 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001082 }
1083 }
1084 callback.accept(errorCode);
1085 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001086 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001087 }
Shuo Qian4a594052020-01-23 11:59:30 -08001088 break;
Hall Liu27d24262020-09-18 19:04:59 -07001089 }
Shuo Qian4a594052020-01-23 11:59:30 -08001090
Hall Liu27d24262020-09-18 19:04:59 -07001091 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001092 request = (MainThreadRequest) msg.obj;
1093 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1094 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1095 break;
Hall Liu27d24262020-09-18 19:04:59 -07001096 }
Shuo Qian4a594052020-01-23 11:59:30 -08001097
Hall Liu27d24262020-09-18 19:04:59 -07001098 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001101 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001102 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1103 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001104 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001105 // Service Class is a bit mask per 3gpp 27.007.
1106 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001107 if (callForwardResults.length > 1
1108 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001109 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001110 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001111 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1112 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001113 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001114 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001115 }
1116 } else {
1117 if (ar.result == null) {
1118 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1119 }
1120 if (ar.exception != null) {
1121 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1122 }
1123 if (ar.exception instanceof CommandException) {
1124 CommandException.Error error =
1125 ((CommandException) (ar.exception)).getCommandError();
1126 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1127 callForwardingStatus =
1128 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1129 }
1130 }
1131 }
Hall Liu27d24262020-09-18 19:04:59 -07001132 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001133 break;
Hall Liu27d24262020-09-18 19:04:59 -07001134 }
Shuo Qian4a594052020-01-23 11:59:30 -08001135
Hall Liu27d24262020-09-18 19:04:59 -07001136 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001137 request = (MainThreadRequest) msg.obj;
1138 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001139 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1140 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001141 break;
Hall Liu27d24262020-09-18 19:04:59 -07001142 }
Shuo Qian4a594052020-01-23 11:59:30 -08001143
Hall Liu27d24262020-09-18 19:04:59 -07001144 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001147 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1148 Consumer<Integer> callback =
1149 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1150 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001151 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001152 if (ar.exception instanceof CommandException) {
1153 CommandException.Error error =
1154 ((CommandException) (ar.exception)).getCommandError();
1155 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1156 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1157 } else {
1158 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1159 }
1160 } else {
1161 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1162 }
1163 } else {
1164 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1165 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001166 }
Shuo Qian4a594052020-01-23 11:59:30 -08001167 break;
Hall Liu27d24262020-09-18 19:04:59 -07001168 }
Shuo Qian4a594052020-01-23 11:59:30 -08001169
Shishir Agrawal302c8692015-06-19 13:49:39 -07001170 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 CellNetworkScanResult cellScanResult;
1174 if (ar.exception == null && ar.result != null) {
1175 cellScanResult = new CellNetworkScanResult(
1176 CellNetworkScanResult.STATUS_SUCCESS,
1177 (List<OperatorInfo>) ar.result);
1178 } else {
1179 if (ar.result == null) {
1180 loge("getCellNetworkScanResults: Empty response");
1181 }
1182 if (ar.exception != null) {
1183 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1184 }
1185 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1186 if (ar.exception instanceof CommandException) {
1187 CommandException.Error error =
1188 ((CommandException) (ar.exception)).getCommandError();
1189 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1190 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1191 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1192 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1193 }
1194 }
1195 cellScanResult = new CellNetworkScanResult(errorCode, null);
1196 }
1197 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001198 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 break;
1200
1201 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1202 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001203 ManualNetworkSelectionArgument selArg =
1204 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001205 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1206 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001207 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1208 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001209 break;
1210
1211 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
1214 if (ar.exception == null) {
1215 request.result = true;
1216 } else {
1217 request.result = false;
1218 loge("setNetworkSelectionModeManual " + ar.exception);
1219 }
1220 notifyRequester(request);
1221 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001222 break;
1223
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001224 case CMD_GET_MODEM_ACTIVITY_INFO:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001227 if (defaultPhone != null) {
1228 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001229 } else {
1230 ResultReceiver result = (ResultReceiver) request.argument;
1231 Bundle bundle = new Bundle();
1232 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001233 new ModemActivityInfo(0, 0, 0,
1234 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001235 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001236 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001237 break;
1238
Hall Liud0f208c2020-10-14 16:54:44 -07001239 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001240 ar = (AsyncResult) msg.obj;
1241 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001242 ResultReceiver result = (ResultReceiver) request.argument;
1243
Hall Liud0f208c2020-10-14 16:54:44 -07001244 ModemActivityInfo ret = null;
1245 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001246 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001247 // Update the last modem activity info and the result of the request.
1248 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1249 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001250 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001251 int[] txTimeMs = info.getTransmitTimeMillis();
1252 int[] lastModemTxTimeMs = mLastModemActivityInfo
1253 .getTransmitTimeMillis();
1254 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1255 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1256 }
Hall Liu49656c02020-10-09 19:00:11 -07001257 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001258 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1259 + mLastModemActivityInfo.getSleepTimeMillis());
1260 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1261 + mLastModemActivityInfo.getIdleTimeMillis());
1262 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1263 mLastModemActivityInfo.setReceiveTimeMillis(
1264 info.getReceiveTimeMillis()
1265 + mLastModemActivityInfo.getReceiveTimeMillis());
1266 }
Hall Liu49656c02020-10-09 19:00:11 -07001267 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001268 mLastModemActivityInfo.getSleepTimeMillis(),
1269 mLastModemActivityInfo.getIdleTimeMillis(),
1270 mLastModemActivityInfo.getTransmitTimeMillis(),
1271 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001272 } else {
1273 if (ar.result == null) {
1274 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001275 error = TelephonyManager.ModemActivityInfoException
1276 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001277 } else if (ar.exception instanceof CommandException) {
1278 loge("queryModemActivityInfo: CommandException: " +
1279 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001280 error = TelephonyManager.ModemActivityInfoException
1281 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001282 } else {
1283 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001284 error = TelephonyManager.ModemActivityInfoException
1285 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001286 }
1287 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001288 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001289 if (ret != null) {
1290 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1291 } else {
1292 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1293 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001294 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001295 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001296 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001297 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001298
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 case CMD_SET_ALLOWED_CARRIERS:
1300 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001301 CarrierRestrictionRules argument =
1302 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001304 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001305 break;
1306
1307 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1308 ar = (AsyncResult) msg.obj;
1309 request = (MainThreadRequest) ar.userObj;
1310 if (ar.exception == null && ar.result != null) {
1311 request.result = ar.result;
1312 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001313 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1314 if (ar.exception instanceof CommandException) {
1315 loge("setAllowedCarriers: CommandException: " + ar.exception);
1316 CommandException.Error error =
1317 ((CommandException) (ar.exception)).getCommandError();
1318 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1319 request.result =
1320 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1321 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001322 } else {
1323 loge("setAllowedCarriers: Unknown exception");
1324 }
1325 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001326 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001327 break;
1328
1329 case CMD_GET_ALLOWED_CARRIERS:
1330 request = (MainThreadRequest) msg.obj;
1331 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001332 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001333 break;
1334
1335 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1336 ar = (AsyncResult) msg.obj;
1337 request = (MainThreadRequest) ar.userObj;
1338 if (ar.exception == null && ar.result != null) {
1339 request.result = ar.result;
1340 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001341 request.result = new IllegalStateException(
1342 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001343 if (ar.result == null) {
1344 loge("getAllowedCarriers: Empty response");
1345 } else if (ar.exception instanceof CommandException) {
1346 loge("getAllowedCarriers: CommandException: " +
1347 ar.exception);
1348 } else {
1349 loge("getAllowedCarriers: Unknown exception");
1350 }
1351 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001352 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001353 break;
1354
Nathan Haroldb3014052017-01-25 15:57:32 -08001355 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1356 ar = (AsyncResult) msg.obj;
1357 request = (MainThreadRequest) ar.userObj;
1358 if (ar.exception == null && ar.result != null) {
1359 request.result = ar.result;
1360 } else {
1361 request.result = new IllegalArgumentException(
1362 "Failed to retrieve Forbidden Plmns");
1363 if (ar.result == null) {
1364 loge("getForbiddenPlmns: Empty response");
1365 } else {
1366 loge("getForbiddenPlmns: Unknown exception");
1367 }
1368 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001369 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001370 break;
1371
1372 case CMD_GET_FORBIDDEN_PLMNS:
1373 request = (MainThreadRequest) msg.obj;
1374 uiccCard = getUiccCardFromRequest(request);
1375 if (uiccCard == null) {
1376 loge("getForbiddenPlmns() UiccCard is null");
1377 request.result = new IllegalArgumentException(
1378 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001379 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001380 break;
1381 }
1382 Integer appType = (Integer) request.argument;
1383 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1384 if (uiccApp == null) {
1385 loge("getForbiddenPlmns() no app with specified type -- "
1386 + appType);
1387 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001388 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001389 break;
1390 } else {
1391 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1392 + " specified type -- " + appType);
1393 }
1394 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1395 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1396 onCompleted);
1397 break;
1398
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001399 case CMD_SWITCH_SLOTS:
1400 request = (MainThreadRequest) msg.obj;
1401 int[] physicalSlots = (int[]) request.argument;
1402 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1403 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1404 break;
1405
1406 case EVENT_SWITCH_SLOTS_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001410 notifyRequester(request);
1411 break;
1412 case CMD_GET_NETWORK_SELECTION_MODE:
1413 request = (MainThreadRequest) msg.obj;
1414 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1415 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1416 break;
1417
1418 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 if (ar.exception != null) {
1422 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1423 } else {
1424 int mode = ((int[]) ar.result)[0];
1425 if (mode == 0) {
1426 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1427 } else {
1428 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1429 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001430 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001431 notifyRequester(request);
1432 break;
1433 case CMD_GET_CDMA_ROAMING_MODE:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1436 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1437 break;
1438 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1439 ar = (AsyncResult) msg.obj;
1440 request = (MainThreadRequest) ar.userObj;
1441 if (ar.exception != null) {
1442 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1443 } else {
1444 request.result = ((int[]) ar.result)[0];
1445 }
1446 notifyRequester(request);
1447 break;
1448 case CMD_SET_CDMA_ROAMING_MODE:
1449 request = (MainThreadRequest) msg.obj;
1450 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1451 int mode = (int) request.argument;
1452 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1453 break;
1454 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1455 ar = (AsyncResult) msg.obj;
1456 request = (MainThreadRequest) ar.userObj;
1457 request.result = ar.exception == null;
1458 notifyRequester(request);
1459 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001460 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1461 request = (MainThreadRequest) msg.obj;
1462 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1463 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1464 break;
1465 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1466 ar = (AsyncResult) msg.obj;
1467 request = (MainThreadRequest) ar.userObj;
1468 if (ar.exception != null) {
1469 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1470 } else {
1471 request.result = ((int[]) ar.result)[0];
1472 }
1473 notifyRequester(request);
1474 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001475 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1476 request = (MainThreadRequest) msg.obj;
1477 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1478 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001479 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1480 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001481 break;
1482 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1483 ar = (AsyncResult) msg.obj;
1484 request = (MainThreadRequest) ar.userObj;
1485 request.result = ar.exception == null;
1486 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001487 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001488 case CMD_GET_ALL_CELL_INFO:
1489 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001491 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 case EVENT_GET_ALL_CELL_INFO_DONE:
1494 ar = (AsyncResult) msg.obj;
1495 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001496 // If a timeout occurs, the response will be null
1497 request.result = (ar.exception == null && ar.result != null)
1498 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001499 synchronized (request) {
1500 request.notifyAll();
1501 }
1502 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001503 case CMD_REQUEST_CELL_INFO_UPDATE:
1504 request = (MainThreadRequest) msg.obj;
1505 request.phone.requestCellInfoUpdate(request.workSource,
1506 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1507 break;
1508 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1509 ar = (AsyncResult) msg.obj;
1510 request = (MainThreadRequest) ar.userObj;
1511 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1512 try {
1513 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001514 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001515 cb.onError(
1516 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1517 ar.exception.getClass().getName(),
1518 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001519 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001520 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001521 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001522 } else {
1523 // use the result as returned
1524 cb.onCellInfo((List<CellInfo>) ar.result);
1525 }
1526 } catch (RemoteException re) {
1527 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1528 }
1529 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001530 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001531 request = (MainThreadRequest) msg.obj;
1532 WorkSource ws = (WorkSource) request.argument;
1533 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001534 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001535 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001536 }
1537 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001538 ar = (AsyncResult) msg.obj;
1539 request = (MainThreadRequest) ar.userObj;
1540 if (ar.exception == null) {
1541 request.result = ar.result;
1542 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001543 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001544 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001545 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001546 }
1547
1548 synchronized (request) {
1549 request.notifyAll();
1550 }
1551 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001552 }
chen xu6dac5ab2018-10-26 17:39:23 -07001553 case CMD_MODEM_REBOOT:
1554 request = (MainThreadRequest) msg.obj;
1555 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001556 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001557 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001558 case EVENT_CMD_MODEM_REBOOT_DONE:
1559 handleNullReturnEvent(msg, "rebootModem");
1560 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001561 case CMD_REQUEST_ENABLE_MODEM:
1562 request = (MainThreadRequest) msg.obj;
1563 boolean enable = (boolean) request.argument;
1564 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001565 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001566 PhoneConfigurationManager.getInstance()
1567 .enablePhone(request.phone, enable, onCompleted);
1568 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001569 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001570 ar = (AsyncResult) msg.obj;
1571 request = (MainThreadRequest) ar.userObj;
1572 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001573 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001574 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001575 if ((boolean) request.result) {
1576 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1577 updateModemStateMetrics();
1578 } else {
1579 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1580 + ar.exception);
1581 }
1582 notifyRequester(request);
1583 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001584 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001585 case CMD_GET_MODEM_STATUS:
1586 request = (MainThreadRequest) msg.obj;
1587 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1588 PhoneConfigurationManager.getInstance()
1589 .getPhoneStatusFromModem(request.phone, onCompleted);
1590 break;
1591 case EVENT_GET_MODEM_STATUS_DONE:
1592 ar = (AsyncResult) msg.obj;
1593 request = (MainThreadRequest) ar.userObj;
1594 int id = request.phone.getPhoneId();
1595 if (ar.exception == null && ar.result != null) {
1596 request.result = ar.result;
1597 //update the cache as modem status has changed
1598 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1599 (boolean) request.result);
1600 } else {
1601 // Return true if modem status cannot be retrieved. For most cases,
1602 // modem status is on. And for older version modems, GET_MODEM_STATUS
1603 // and disable modem are not supported. Modem is always on.
1604 // TODO: this should be fixed in R to support a third
1605 // status UNKNOWN b/131631629
1606 request.result = true;
1607 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1608 + ar.exception);
1609 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001610 notifyRequester(request);
1611 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001612 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1613 request = (MainThreadRequest) msg.obj;
1614 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1615 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1616 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1617 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1618 break;
1619 }
1620 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1621 ar = (AsyncResult) msg.obj;
1622 request = (MainThreadRequest) ar.userObj;
1623 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1624 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1625 args.second.accept(ar.exception == null);
1626 notifyRequester(request);
1627 break;
1628 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001629 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1630 request = (MainThreadRequest) msg.obj;
1631 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1632 Phone phone = getPhoneFromRequest(request);
1633 if (phone != null) {
1634 phone.getSystemSelectionChannels(onCompleted);
1635 } else {
1636 loge("getSystemSelectionChannels: No phone object");
1637 request.result = new ArrayList<RadioAccessSpecifier>();
1638 notifyRequester(request);
1639 }
1640 break;
1641 }
1642 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1643 ar = (AsyncResult) msg.obj;
1644 request = (MainThreadRequest) ar.userObj;
1645 if (ar.exception == null && ar.result != null) {
1646 request.result = ar.result;
1647 } else {
Sarah Chin428d1d62021-03-13 03:17:40 -08001648 request.result = new IllegalStateException(
1649 "Failed to retrieve system selecton channels");
Sarah Chin679c08a2020-11-18 13:39:35 -08001650 if (ar.result == null) {
1651 loge("getSystemSelectionChannels: Empty response");
1652 } else {
1653 loge("getSystemSelectionChannels: Unknown exception");
1654 }
1655 }
1656 notifyRequester(request);
1657 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001658 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1659 ar = (AsyncResult) msg.obj;
1660 request = (MainThreadRequest) ar.userObj;
1661 if (ar.exception == null && ar.result != null) {
1662 request.result = ar.result;
1663 } else {
1664 request.result = -1;
1665 loge("Failed to set Forbidden Plmns");
1666 if (ar.result == null) {
1667 loge("setForbidenPlmns: Empty response");
1668 } else if (ar.exception != null) {
1669 loge("setForbiddenPlmns: Exception: " + ar.exception);
1670 request.result = -1;
1671 } else {
1672 loge("setForbiddenPlmns: Unknown exception");
1673 }
1674 }
1675 notifyRequester(request);
1676 break;
1677 case CMD_SET_FORBIDDEN_PLMNS:
1678 request = (MainThreadRequest) msg.obj;
1679 uiccCard = getUiccCardFromRequest(request);
1680 if (uiccCard == null) {
1681 loge("setForbiddenPlmns: UiccCard is null");
1682 request.result = -1;
1683 notifyRequester(request);
1684 break;
1685 }
1686 Pair<Integer, List<String>> setFplmnsArgs =
1687 (Pair<Integer, List<String>>) request.argument;
1688 appType = setFplmnsArgs.first;
1689 List<String> fplmns = setFplmnsArgs.second;
1690 uiccApp = uiccCard.getApplicationByType(appType);
1691 if (uiccApp == null) {
1692 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1693 request.result = -1;
1694 loge("Failed to get UICC App");
1695 notifyRequester(request);
1696 } else {
1697 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1698 ((SIMRecords) uiccApp.getIccRecords())
1699 .setForbiddenPlmns(onCompleted, fplmns);
1700 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001701 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001702 case CMD_ERASE_MODEM_CONFIG:
1703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1705 defaultPhone.eraseModemConfig(onCompleted);
1706 break;
1707 case EVENT_ERASE_MODEM_CONFIG_DONE:
1708 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001709 break;
zoey chene02881a2019-12-30 16:11:23 +08001710
1711 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1712 request = (MainThreadRequest) msg.obj;
1713 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1714 Pair<String, String> changed = (Pair<String, String>) request.argument;
1715 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1716 changed.first, changed.second, onCompleted);
1717 break;
1718 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1719 ar = (AsyncResult) msg.obj;
1720 request = (MainThreadRequest) ar.userObj;
1721 if (ar.exception == null) {
1722 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001723 // If the operation is successful, update the PIN storage
1724 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1725 int phoneId = getPhoneFromRequest(request).getPhoneId();
1726 UiccController.getInstance().getPinStorage()
1727 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001728 } else {
1729 request.result = msg.arg1;
1730 }
1731 notifyRequester(request);
1732 break;
1733
Michele Berionne5e411512020-11-13 02:36:59 +00001734 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001735 request = (MainThreadRequest) msg.obj;
1736 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1737 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1738 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1739 enabled.first, enabled.second, onCompleted);
1740 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001741 }
zoey chene02881a2019-12-30 16:11:23 +08001742 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1743 ar = (AsyncResult) msg.obj;
1744 request = (MainThreadRequest) ar.userObj;
1745 if (ar.exception == null) {
1746 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001747 // If the operation is successful, update the PIN storage
1748 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1749 int phoneId = getPhoneFromRequest(request).getPhoneId();
1750 if (enabled.first) {
1751 UiccController.getInstance().getPinStorage()
1752 .storePin(enabled.second, phoneId);
1753 } else {
1754 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1755 }
zoey chene02881a2019-12-30 16:11:23 +08001756 } else {
1757 request.result = msg.arg1;
1758 }
Michele Berionne5e411512020-11-13 02:36:59 +00001759
1760
zoey chene02881a2019-12-30 16:11:23 +08001761 notifyRequester(request);
1762 break;
1763
Peter Wangdafb9ac2020-01-15 14:13:38 -08001764 case MSG_NOTIFY_USER_ACTIVITY:
1765 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001766 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001767 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1768 getDefaultPhone().getContext().sendBroadcastAsUser(
1769 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1770 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001771
1772 case CMD_SET_DATA_THROTTLING: {
1773 request = (MainThreadRequest) msg.obj;
1774 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1775 DataThrottlingRequest dataThrottlingRequest =
1776 (DataThrottlingRequest) request.argument;
1777 Phone phone = getPhoneFromRequest(request);
1778 if (phone != null) {
1779 phone.setDataThrottling(onCompleted,
1780 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1781 dataThrottlingRequest.getCompletionDurationMillis());
1782 } else {
1783 loge("setDataThrottling: No phone object");
1784 request.result =
1785 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1786 notifyRequester(request);
1787 }
1788
1789 break;
1790 }
1791 case EVENT_SET_DATA_THROTTLING_DONE:
1792 ar = (AsyncResult) msg.obj;
1793 request = (MainThreadRequest) ar.userObj;
1794
1795 if (ar.exception == null) {
1796 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1797 } else if (ar.exception instanceof CommandException) {
1798 loge("setDataThrottling: CommandException: " + ar.exception);
1799 CommandException.Error error =
1800 ((CommandException) (ar.exception)).getCommandError();
1801
1802 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1803 request.result = TelephonyManager
1804 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1805 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1806 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001807 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1808 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001809 } else {
1810 request.result =
1811 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1812 }
1813 } else {
1814 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1815 }
1816 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1817 notifyRequester(request);
1818 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001819
1820 case CMD_SET_SIM_POWER: {
1821 request = (MainThreadRequest) msg.obj;
1822 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1823 request = (MainThreadRequest) msg.obj;
1824 int stateToSet =
1825 ((Pair<Integer, IIntegerConsumer>)
1826 request.argument).first;
1827 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1828 break;
1829 }
1830 case EVENT_SET_SIM_POWER_DONE: {
1831 ar = (AsyncResult) msg.obj;
1832 request = (MainThreadRequest) ar.userObj;
1833 IIntegerConsumer callback =
1834 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1835 if (ar.exception != null) {
1836 loge("setSimPower exception: " + ar.exception);
1837 int errorCode = TelephonyManager.CallForwardingInfoCallback
1838 .RESULT_ERROR_UNKNOWN;
1839 if (ar.exception instanceof CommandException) {
1840 CommandException.Error error =
1841 ((CommandException) (ar.exception)).getCommandError();
1842 if (error == CommandException.Error.SIM_ERR) {
1843 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1844 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1845 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1846 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1847 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1848 } else {
1849 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1850 }
1851 }
1852 try {
1853 callback.accept(errorCode);
1854 } catch (RemoteException e) {
1855 // Ignore if the remote process is no longer available to call back.
1856 Log.w(LOG_TAG, "setSimPower: callback not available.");
1857 }
1858 } else {
1859 try {
1860 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1861 } catch (RemoteException e) {
1862 // Ignore if the remote process is no longer available to call back.
1863 Log.w(LOG_TAG, "setSimPower: callback not available.");
1864 }
1865 }
1866 break;
1867 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001868 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1869 request = (MainThreadRequest) msg.obj;
1870
1871 final Phone phone = getPhoneFromRequest(request);
1872 if (phone == null || phone.getServiceStateTracker() == null) {
1873 request.result = new IllegalStateException("Phone or SST is null");
1874 notifyRequester(request);
1875 break;
1876 }
1877
1878 Pair<Integer, SignalStrengthUpdateRequest> pair =
1879 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1880 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1881 request);
1882 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1883 request.subId, pair.first /*callingUid*/,
1884 pair.second /*request*/, onCompleted);
1885 break;
1886 }
1887 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1888 ar = (AsyncResult) msg.obj;
1889 request = (MainThreadRequest) ar.userObj;
1890 // request.result will be the exception of ar if present, true otherwise.
1891 // Be cautious not to leave result null which will wait() forever
1892 request.result = ar.exception != null ? ar.exception : true;
1893 notifyRequester(request);
1894 break;
1895 }
1896 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1897 request = (MainThreadRequest) msg.obj;
1898
1899 Phone phone = getPhoneFromRequest(request);
1900 if (phone == null || phone.getServiceStateTracker() == null) {
1901 request.result = new IllegalStateException("Phone or SST is null");
1902 notifyRequester(request);
1903 break;
1904 }
1905
1906 Pair<Integer, SignalStrengthUpdateRequest> pair =
1907 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1908 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1909 request);
1910 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1911 request.subId, pair.first /*callingUid*/,
1912 pair.second /*request*/, onCompleted);
1913 break;
1914 }
1915 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1916 ar = (AsyncResult) msg.obj;
1917 request = (MainThreadRequest) ar.userObj;
1918 request.result = ar.exception != null ? ar.exception : true;
1919 notifyRequester(request);
1920 break;
1921 }
Jordan Liu109698e2020-11-24 14:50:34 -08001922
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001923 case CMD_GET_SLICING_CONFIG: {
1924 request = (MainThreadRequest) msg.obj;
1925 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1926 request.phone.getSlicingConfig(onCompleted);
1927 break;
1928 }
1929 case EVENT_GET_SLICING_CONFIG_DONE: {
1930 ar = (AsyncResult) msg.obj;
1931 request = (MainThreadRequest) ar.userObj;
1932 ResultReceiver result = (ResultReceiver) request.argument;
1933
1934 SlicingConfig slicingConfig = null;
1935 Bundle bundle = new Bundle();
1936 int resultCode = 0;
1937 if (ar.exception != null) {
1938 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1939 + ar.exception);
1940 resultCode = TelephonyManager.SlicingException.ERROR_MODEM_ERROR;
1941 } else if (ar.result == null) {
1942 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
1943 resultCode = TelephonyManager.SlicingException.ERROR_TIMEOUT;
1944 } else {
1945 // use the result as returned
1946 resultCode = TelephonyManager.SlicingException.SUCCESS;
1947 slicingConfig = (SlicingConfig) ar.result;
1948 }
1949
1950 if (slicingConfig == null) {
1951 slicingConfig = new SlicingConfig();
1952 }
1953 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1954 result.send(resultCode, bundle);
1955 notifyRequester(request);
1956 break;
1957 }
1958
Michele Berionne5e411512020-11-13 02:36:59 +00001959 case CMD_PREPARE_UNATTENDED_REBOOT:
1960 request = (MainThreadRequest) msg.obj;
1961 request.result =
1962 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1963 notifyRequester(request);
1964 break;
1965
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 default:
1967 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1968 break;
1969 }
1970 }
Jake Hambye994d462014-02-03 13:10:13 -08001971
Pengquan Menga1bb6272018-09-06 09:59:22 -07001972 private void notifyRequester(MainThreadRequest request) {
1973 synchronized (request) {
1974 request.notifyAll();
1975 }
1976 }
1977
Jake Hambye994d462014-02-03 13:10:13 -08001978 private void handleNullReturnEvent(Message msg, String command) {
1979 AsyncResult ar = (AsyncResult) msg.obj;
1980 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1981 if (ar.exception == null) {
1982 request.result = true;
1983 } else {
1984 request.result = false;
1985 if (ar.exception instanceof CommandException) {
1986 loge(command + ": CommandException: " + ar.exception);
1987 } else {
1988 loge(command + ": Unknown exception");
1989 }
1990 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001991 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 }
1994
1995 /**
1996 * Posts the specified command to be executed on the main thread,
1997 * waits for the request to complete, and returns the result.
1998 * @see #sendRequestAsync
1999 */
2000 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002001 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2002 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002003 }
2004
2005 /**
2006 * Posts the specified command to be executed on the main thread,
2007 * waits for the request to complete, and returns the result.
2008 * @see #sendRequestAsync
2009 */
2010 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2011 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002012 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002013 }
2014
2015 /**
2016 * Posts the specified command to be executed on the main thread,
2017 * waits for the request to complete, and returns the result.
2018 * @see #sendRequestAsync
2019 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002020 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002021 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2022 }
2023
2024 /**
2025 * Posts the specified command to be executed on the main thread,
2026 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2027 * if not timeout or null otherwise.
2028 * @see #sendRequestAsync
2029 */
2030 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2031 long timeoutInMs) {
2032 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002033 }
2034
2035 /**
2036 * Posts the specified command to be executed on the main thread,
2037 * waits for the request to complete, and returns the result.
2038 * @see #sendRequestAsync
2039 */
Nathan Harold92bed182018-10-12 18:16:49 -07002040 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002041 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002042 }
2043
2044 /**
2045 * Posts the specified command to be executed on the main thread,
2046 * waits for the request to complete, and returns the result.
2047 * @see #sendRequestAsync
2048 */
2049 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002050 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2051 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002052 }
2053
2054 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002055 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2056 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2057 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002058 * @see #sendRequestAsync
2059 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002060 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2061 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2063 throw new RuntimeException("This method will deadlock if called from the main thread.");
2064 }
2065
Nathan Harold92bed182018-10-12 18:16:49 -07002066 MainThreadRequest request = null;
2067 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2068 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2069 } else if (phone != null) {
2070 request = new MainThreadRequest(argument, phone, workSource);
2071 } else {
2072 request = new MainThreadRequest(argument, subId, workSource);
2073 }
2074
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 Message msg = mMainThreadHandler.obtainMessage(command, request);
2076 msg.sendToTarget();
2077
Rambo Wang0f050d82021-02-12 11:43:36 -08002078
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002080 if (timeoutInMs >= 0) {
2081 // Wait for at least timeoutInMs before returning null request result
2082 long now = SystemClock.elapsedRealtime();
2083 long deadline = now + timeoutInMs;
2084 while (request == null && now < deadline) {
2085 try {
2086 request.wait(deadline - now);
2087 } catch (InterruptedException e) {
2088 // Do nothing, go back and check if request is completed or timeout
2089 } finally {
2090 now = SystemClock.elapsedRealtime();
2091 }
2092 }
2093 } else {
2094 // Wait for the request to complete
2095 while (request.result == null) {
2096 try {
2097 request.wait();
2098 } catch (InterruptedException e) {
2099 // Do nothing, go back and wait until the request is complete
2100 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 }
2102 }
2103 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002104 if (request.result == null) {
2105 Log.wtf(LOG_TAG,
2106 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 return request.result;
2109 }
2110
2111 /**
2112 * Asynchronous ("fire and forget") version of sendRequest():
2113 * Posts the specified command to be executed on the main thread, and
2114 * returns immediately.
2115 * @see #sendRequest
2116 */
2117 private void sendRequestAsync(int command) {
2118 mMainThreadHandler.sendEmptyMessage(command);
2119 }
2120
2121 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002122 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002123 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002124 */
2125 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002126 sendRequestAsync(command, argument, null, null);
2127 }
2128
2129 /**
2130 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2131 * @see {@link #sendRequest(int,Object)}
2132 */
2133 private void sendRequestAsync(
2134 int command, Object argument, Phone phone, WorkSource workSource) {
2135 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002136 Message msg = mMainThreadHandler.obtainMessage(command, request);
2137 msg.sendToTarget();
2138 }
2139
2140 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 * Initialize the singleton PhoneInterfaceManager instance.
2142 * This is only done once, at startup, from PhoneApp.onCreate().
2143 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002144 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 synchronized (PhoneInterfaceManager.class) {
2146 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002147 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 } else {
2149 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2150 }
2151 return sInstance;
2152 }
2153 }
2154
2155 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002156 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002159 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002160 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2162 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002163 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002164 mTelephonySharedPreferences =
2165 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002166 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002167 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002168 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002169 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002170
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171 publish();
2172 }
2173
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002174 private Phone getDefaultPhone() {
2175 Phone thePhone = getPhone(getDefaultSubscription());
2176 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2177 }
2178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 private void publish() {
2180 if (DBG) log("publish: " + this);
2181
Peter Wangc035ce42020-01-08 21:00:22 -08002182 TelephonyFrameworkInitializer
2183 .getTelephonyServiceManager()
2184 .getTelephonyServiceRegisterer()
2185 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 }
2187
Stuart Scott584921c2015-01-15 17:10:34 -08002188 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002189 if (request.phone != null) {
2190 return request.phone;
2191 } else {
2192 return getPhoneFromSubId(request.subId);
2193 }
2194 }
2195
2196 private Phone getPhoneFromSubId(int subId) {
2197 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2198 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002199 }
2200
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002201 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2202 Phone phone = getPhoneFromRequest(request);
2203 return phone == null ? null :
2204 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2205 }
2206
Wink Saville36469e72014-06-11 15:17:00 -07002207 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002208 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002209 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211
Naina Nallurid63128d2019-09-17 14:10:30 -07002212 private void sendEraseModemConfig(Phone phone) {
2213 if (phone != null) {
2214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2215 mApp, phone.getSubId(), "eraseModemConfig");
2216 final long identity = Binder.clearCallingIdentity();
2217 try {
2218 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2219 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
2222 }
2223 }
2224 }
2225
Peter Wang44b186e2020-01-13 23:33:09 -08002226 private boolean isImsAvailableOnDevice() {
2227 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2228 if (pm == null) {
2229 // For some reason package manger is not available.. This will fail internally anyway,
2230 // so do not throw error and allow.
2231 return true;
2232 }
2233 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2234 }
2235
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002237 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002238 }
2239
Wink Savilleb564aae2014-10-23 10:18:09 -07002240 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 if (DBG) log("dial: " + number);
2242 // No permission check needed here: This is just a wrapper around the
2243 // ACTION_DIAL intent, which is available to any app since it puts up
2244 // the UI before it does anything.
2245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246 final long identity = Binder.clearCallingIdentity();
2247 try {
2248 String url = createTelUrl(number);
2249 if (url == null) {
2250 return;
2251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253 // PENDING: should we just silently fail if phone is offhook or ringing?
2254 PhoneConstants.State state = mCM.getState(subId);
2255 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2256 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2257 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2258 mApp.startActivity(intent);
2259 }
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 }
2263 }
2264
2265 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002266 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002267 }
2268
Wink Savilleb564aae2014-10-23 10:18:09 -07002269 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 if (DBG) log("call: " + number);
2271
2272 // This is just a wrapper around the ACTION_CALL intent, but we still
2273 // need to do a permission check since we're calling startActivity()
2274 // from the context of the phone app.
2275 enforceCallPermission();
2276
Jordan Liu1617b712019-07-10 15:06:26 -07002277 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002278 != AppOpsManager.MODE_ALLOWED) {
2279 return;
2280 }
2281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 final long identity = Binder.clearCallingIdentity();
2283 try {
2284 String url = createTelUrl(number);
2285 if (url == null) {
2286 return;
2287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289 boolean isValid = false;
2290 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2291 if (slist != null) {
2292 for (SubscriptionInfo subInfoRecord : slist) {
2293 if (subInfoRecord.getSubscriptionId() == subId) {
2294 isValid = true;
2295 break;
2296 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002297 }
Wink Saville08874612014-08-31 19:19:58 -07002298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299 if (!isValid) {
2300 return;
2301 }
Wink Saville08874612014-08-31 19:19:58 -07002302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2304 intent.putExtra(SUBSCRIPTION_KEY, subId);
2305 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2306 mApp.startActivity(intent);
2307 } finally {
2308 Binder.restoreCallingIdentity(identity);
2309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 }
2311
Wink Savilleb564aae2014-10-23 10:18:09 -07002312 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002313 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002314 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2315 }
2316
Wink Savilleb564aae2014-10-23 10:18:09 -07002317 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002318 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002319 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2320 }
2321
Wink Savilleb564aae2014-10-23 10:18:09 -07002322 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002323 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324
2325 final long identity = Binder.clearCallingIdentity();
2326 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002327 Phone phone = getPhone(subId);
2328 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002329 checkSimPin.start();
2330 return checkSimPin.unlockSim(null, pin);
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335
Wink Savilleb564aae2014-10-23 10:18:09 -07002336 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002338
2339 final long identity = Binder.clearCallingIdentity();
2340 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002341 Phone phone = getPhone(subId);
2342 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343 checkSimPuk.start();
2344 return checkSimPuk.unlockSim(puk, pin);
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
2347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 }
2349
2350 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002351 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 * a synchronous one.
2353 */
2354 private static class UnlockSim extends Thread {
2355
2356 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002357 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358
2359 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002360 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2361 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362
2363 // For replies from SimCard interface
2364 private Handler mHandler;
2365
2366 // For async handler to identify request type
2367 private static final int SUPPLY_PIN_COMPLETE = 100;
2368
Michele Berionne5e411512020-11-13 02:36:59 +00002369 UnlockSim(int phoneId, IccCard simCard) {
2370 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 mSimCard = simCard;
2372 }
2373
2374 @Override
2375 public void run() {
2376 Looper.prepare();
2377 synchronized (UnlockSim.this) {
2378 mHandler = new Handler() {
2379 @Override
2380 public void handleMessage(Message msg) {
2381 AsyncResult ar = (AsyncResult) msg.obj;
2382 switch (msg.what) {
2383 case SUPPLY_PIN_COMPLETE:
2384 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2385 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002386 mRetryCount = msg.arg1;
2387 if (ar.exception != null) {
2388 if (ar.exception instanceof CommandException &&
2389 ((CommandException)(ar.exception)).getCommandError()
2390 == CommandException.Error.PASSWORD_INCORRECT) {
2391 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002392 } //When UiccCardApp dispose,handle message and return exception
2393 else if (ar.exception instanceof CommandException &&
2394 ((CommandException) (ar.exception)).getCommandError()
2395 == CommandException.Error.ABORTED) {
2396 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002397 } else {
2398 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2399 }
2400 } else {
2401 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 mDone = true;
2404 UnlockSim.this.notifyAll();
2405 }
2406 break;
2407 }
2408 }
2409 };
2410 UnlockSim.this.notifyAll();
2411 }
2412 Looper.loop();
2413 }
2414
2415 /*
2416 * Use PIN or PUK to unlock SIM card
2417 *
2418 * If PUK is null, unlock SIM card with PIN
2419 *
2420 * If PUK is not null, unlock SIM card with PUK and set PIN code
2421 */
Wink Saville9de0f752013-10-22 19:04:03 -07002422 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423
2424 while (mHandler == null) {
2425 try {
2426 wait();
2427 } catch (InterruptedException e) {
2428 Thread.currentThread().interrupt();
2429 }
2430 }
2431 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2432
2433 if (puk == null) {
2434 mSimCard.supplyPin(pin, callback);
2435 } else {
2436 mSimCard.supplyPuk(puk, pin, callback);
2437 }
2438
2439 while (!mDone) {
2440 try {
2441 Log.d(LOG_TAG, "wait for done");
2442 wait();
2443 } catch (InterruptedException e) {
2444 // Restore the interrupted status
2445 Thread.currentThread().interrupt();
2446 }
2447 }
2448 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002449 int[] resultArray = new int[2];
2450 resultArray[0] = mResult;
2451 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002452
2453 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2454 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2455 }
2456
Wink Saville9de0f752013-10-22 19:04:03 -07002457 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002458 }
2459 }
2460
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002461 /**
2462 * This method has been removed due to privacy and stability concerns.
2463 */
2464 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002466 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2467 return;
Wink Saville36469e72014-06-11 15:17:00 -07002468 }
2469
Nathan Harold1f889d82020-06-04 17:05:26 -07002470 @Override
2471 public void updateServiceLocationWithPackageName(String callingPackage) {
2472 mApp.getSystemService(AppOpsManager.class)
2473 .checkPackage(Binder.getCallingUid(), callingPackage);
2474
Nathan Haroldf096d982020-11-18 17:18:06 -08002475 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002476 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2477 // Callers targeting S have no business invoking this method.
2478 return;
2479 }
2480
2481 LocationAccessPolicy.LocationPermissionResult locationResult =
2482 LocationAccessPolicy.checkLocationPermission(mApp,
2483 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2484 .setCallingPackage(callingPackage)
2485 .setCallingFeatureId(null)
2486 .setCallingPid(Binder.getCallingPid())
2487 .setCallingUid(Binder.getCallingUid())
2488 .setMethod("updateServiceLocation")
2489 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2490 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2491 .build());
2492 // Apps that lack location permission have no business calling this method;
2493 // however, because no permission was declared in the public API, denials must
2494 // all be "soft".
2495 switch (locationResult) {
2496 case DENIED_HARD: /* fall through */
2497 case DENIED_SOFT:
2498 return;
2499 }
2500
2501 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002502 final long identity = Binder.clearCallingIdentity();
2503 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002504 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002506 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002513 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002514 @Override
2515 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002516 return isRadioOnWithFeature(callingPackage, null);
2517 }
2518
2519
2520 @Override
2521 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2522 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2523 callingFeatureId);
2524 }
2525
2526 @Deprecated
2527 @Override
2528 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2529 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002530 }
2531
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002533 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2534 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002536 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002537 return false;
2538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539
2540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 return isRadioOnForSubscriber(subId);
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
2545 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002546 }
2547
2548 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(subId);
2552 if (phone != null) {
2553 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2554 } else {
2555 return false;
2556 }
2557 } finally {
2558 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 }
2561
2562 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002563 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002564 }
Wink Saville36469e72014-06-11 15:17:00 -07002565
Wink Savilleb564aae2014-10-23 10:18:09 -07002566 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 final Phone phone = getPhone(subId);
2572 if (phone != null) {
2573 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2574 }
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002577 }
Wink Saville36469e72014-06-11 15:17:00 -07002578 }
2579
2580 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002581 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002582 }
2583
Wink Savilleb564aae2014-10-23 10:18:09 -07002584 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002585 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002586
2587 final long identity = Binder.clearCallingIdentity();
2588 try {
2589 final Phone phone = getPhone(subId);
2590 if (phone == null) {
2591 return false;
2592 }
2593 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2594 toggleRadioOnOffForSubscriber(subId);
2595 }
2596 return true;
2597 } finally {
2598 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 }
Wink Saville36469e72014-06-11 15:17:00 -07002601
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002602 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002603 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002604 /*
2605 * If any of the Radios are available, it will need to be
2606 * shutdown. So return true if any Radio is available.
2607 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2611 Phone phone = PhoneFactory.getPhone(i);
2612 if (phone != null && phone.isRadioAvailable()) return true;
2613 }
2614 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2615 return false;
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002618 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002619 }
2620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002622 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 enforceModifyPermission();
2624
2625 final long identity = Binder.clearCallingIdentity();
2626 try {
2627 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2628 logv("Shutting down Phone " + i);
2629 shutdownRadioUsingPhoneId(i);
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002633 }
2634 }
2635
2636 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002637 Phone phone = PhoneFactory.getPhone(phoneId);
2638 if (phone != null && phone.isRadioAvailable()) {
2639 phone.shutdownRadio();
2640 }
2641 }
2642
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002644 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645
2646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2649 if (defaultPhone != null) {
2650 defaultPhone.setRadioPower(turnOn);
2651 return true;
2652 } else {
2653 loge("There's no default phone.");
2654 return false;
2655 }
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002658 }
Wink Saville36469e72014-06-11 15:17:00 -07002659 }
2660
Wink Savilleb564aae2014-10-23 10:18:09 -07002661 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
2666 final Phone phone = getPhone(subId);
2667 if (phone != null) {
2668 phone.setRadioPower(turnOn);
2669 return true;
2670 } else {
2671 return false;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 }
2677
Wink Saville36469e72014-06-11 15:17:00 -07002678 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002679 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 public boolean enableDataConnectivity() {
2681 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002682
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 int subId = mSubscriptionController.getDefaultDataSubId();
2686 final Phone phone = getPhone(subId);
2687 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002688 phone.getDataEnabledSettings().setDataEnabled(
2689 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 return true;
2691 } else {
2692 return false;
2693 }
2694 } finally {
2695 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 }
2698
Wink Saville36469e72014-06-11 15:17:00 -07002699 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002700 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 public boolean disableDataConnectivity() {
2702 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703
2704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 int subId = mSubscriptionController.getDefaultDataSubId();
2707 final Phone phone = getPhone(subId);
2708 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002709 phone.getDataEnabledSettings().setDataEnabled(
2710 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002711 return true;
2712 } else {
2713 return false;
2714 }
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
2719
Sanket Padawe356d7632015-06-22 14:03:32 -07002720 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002721 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 final Phone phone = getPhone(subId);
2725 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002726 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 } else {
2728 return false;
2729 }
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 }
2734
2735 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002736 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002737 }
2738
pkanwarae03a6b2016-11-06 20:37:09 -08002739 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 enforceCallPermission();
2741
2742 final long identity = Binder.clearCallingIdentity();
2743 try {
2744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2745 return;
2746 }
2747 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2748 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2749 } finally {
2750 Binder.restoreCallingIdentity(identity);
2751 }
pkanwar32d516d2016-10-14 19:37:38 -07002752 };
2753
Wink Savilleb564aae2014-10-23 10:18:09 -07002754 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756
2757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2760 return false;
2761 }
2762 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2763 } finally {
2764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 }
2767
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002769 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002770 }
2771
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002772 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773 final long identity = Binder.clearCallingIdentity();
2774 try {
2775 Phone phone = PhoneFactory.getPhone(slotIndex);
2776 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2777 PhoneConstantConversions.convertCallState(phone.getState());
2778 } finally {
2779 Binder.restoreCallingIdentity(identity);
2780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 }
2782
Sanket Padawe356d7632015-06-22 14:03:32 -07002783 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002784 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002785 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2786 }
2787
2788 @Override
2789 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790 final long identity = Binder.clearCallingIdentity();
2791 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002792 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 if (phone != null) {
2794 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2795 } else {
2796 return PhoneConstantConversions.convertDataState(
2797 PhoneConstants.DataState.DISCONNECTED);
2798 }
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 }
2803
Sanket Padawe356d7632015-06-22 14:03:32 -07002804 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002805 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002806 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2807 }
2808
2809 @Override
2810 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 final long identity = Binder.clearCallingIdentity();
2812 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002813 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 if (phone != null) {
2815 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2816 } else {
2817 return TelephonyManager.DATA_ACTIVITY_NONE;
2818 }
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 }
2823
2824 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002825 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002826 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002827 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002828
2829 LocationAccessPolicy.LocationPermissionResult locationResult =
2830 LocationAccessPolicy.checkLocationPermission(mApp,
2831 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2832 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002833 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002834 .setCallingPid(Binder.getCallingPid())
2835 .setCallingUid(Binder.getCallingUid())
2836 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002837 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002838 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2839 .build());
2840 switch (locationResult) {
2841 case DENIED_HARD:
2842 throw new SecurityException("Not allowed to access cell location");
2843 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002844 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2845 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 }
2847
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002848 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002852 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002853 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854 } finally {
2855 Binder.restoreCallingIdentity(identity);
2856 }
Svetoslav64fad262015-04-14 14:35:21 -07002857 }
2858
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002860 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002861 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2862 // registered cell info, so return a NULL country instead.
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002865 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2866 // Get default phone in this case.
2867 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2868 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002869 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002870 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002871 if (phone == null) return "";
2872 ServiceStateTracker sst = phone.getServiceStateTracker();
2873 if (sst == null) return "";
2874 LocaleTracker lt = sst.getLocaleTracker();
2875 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002876 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002877 } finally {
2878 Binder.restoreCallingIdentity(identity);
2879 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002880 }
2881
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002882 /**
2883 * This method was removed due to potential issues caused by performing partial
2884 * updates of service state, and lack of a credible use case.
2885 *
2886 * This has the ability to break the telephony implementation by disabling notification of
2887 * changes in device connectivity. DO NOT USE THIS!
2888 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 public void enableLocationUpdates() {
2891 mApp.enforceCallingOrSelfPermission(
2892 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002893 }
2894
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002895 /**
2896 * This method was removed due to potential issues caused by performing partial
2897 * updates of service state, and lack of a credible use case.
2898 *
2899 * This has the ability to break the telephony implementation by disabling notification of
2900 * changes in device connectivity. DO NOT USE THIS!
2901 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002902 @Override
2903 public void disableLocationUpdates() {
2904 mApp.enforceCallingOrSelfPermission(
2905 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002906 }
2907
2908 @Override
2909 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002910 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2911 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002912 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002913 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2914 throw new SecurityException(
2915 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2916 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002917
Jordan Liu1617b712019-07-10 15:06:26 -07002918 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002919 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2920 return null;
2921 }
Svetoslav64fad262015-04-14 14:35:21 -07002922
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002923 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002924
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002925 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002926 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002927
Nathan Haroldf180aac2018-06-01 18:43:55 -07002928 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2929 for (CellInfo ci : info) {
2930 if (ci instanceof CellInfoGsm) {
2931 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2932 } else if (ci instanceof CellInfoWcdma) {
2933 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2934 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002935 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002936 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 }
2938
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002939 private List<CellInfo> getCachedCellInfo() {
2940 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2941 for (Phone phone : PhoneFactory.getPhones()) {
2942 List<CellInfo> info = phone.getAllCellInfo();
2943 if (info != null) cellInfos.addAll(info);
2944 }
2945 return cellInfos;
2946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002947
2948 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002949 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002950 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002951 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002952
2953 LocationAccessPolicy.LocationPermissionResult locationResult =
2954 LocationAccessPolicy.checkLocationPermission(mApp,
2955 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2956 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002957 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002958 .setCallingPid(Binder.getCallingPid())
2959 .setCallingUid(Binder.getCallingUid())
2960 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002961 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002962 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2963 .build());
2964 switch (locationResult) {
2965 case DENIED_HARD:
2966 throw new SecurityException("Not allowed to access cell info");
2967 case DENIED_SOFT:
2968 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969 }
2970
Nathan Haroldf096d982020-11-18 17:18:06 -08002971 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002972 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2973 return getCachedCellInfo();
2974 }
2975
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002976 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002977 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978 final long identity = Binder.clearCallingIdentity();
2979 try {
2980 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2981 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002982 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002983 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984 if (info != null) cellInfos.addAll(info);
2985 }
2986 return cellInfos;
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002989 }
2990 }
2991
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002992 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002993 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2994 String callingFeatureId) {
2995 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2996 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002997 }
2998
2999 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003000 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3001 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003002 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003003 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003004 }
3005
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003006 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3007 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003008 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003009 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003010
3011 LocationAccessPolicy.LocationPermissionResult locationResult =
3012 LocationAccessPolicy.checkLocationPermission(mApp,
3013 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3014 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003015 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003016 .setCallingPid(Binder.getCallingPid())
3017 .setCallingUid(Binder.getCallingUid())
3018 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003019 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3020 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003021 .build());
3022 switch (locationResult) {
3023 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003024 if (TelephonyPermissions
3025 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003026 // Safetynet logging for b/154934934
3027 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3028 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003029 throw new SecurityException("Not allowed to access cell info");
3030 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003031 if (TelephonyPermissions
3032 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003033 // Safetynet logging for b/154934934
3034 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3035 }
Nathan Harold5320c422019-05-09 10:26:08 -07003036 try {
3037 cb.onCellInfo(new ArrayList<CellInfo>());
3038 } catch (RemoteException re) {
3039 // Drop without consequences
3040 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003041 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003042 }
3043
Nathan Harolda939a962019-05-09 10:13:47 -07003044
3045 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003046 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3047
3048 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3049 }
3050
3051 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003052 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003053 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003054 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003055
3056 final long identity = Binder.clearCallingIdentity();
3057 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003058 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062 }
3063
Shishir Agrawala9f32182016-04-12 12:00:16 -07003064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003065 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003066 Phone phone = PhoneFactory.getPhone(slotIndex);
3067 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003068 return null;
3069 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003070 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003071 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003072 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003073 return null;
3074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003075
3076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 return phone.getImei();
3079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003082 }
3083
3084 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003085 public String getTypeAllocationCodeForSlot(int slotIndex) {
3086 Phone phone = PhoneFactory.getPhone(slotIndex);
3087 String tac = null;
3088 if (phone != null) {
3089 String imei = phone.getImei();
3090 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3091 }
3092 return tac;
3093 }
3094
3095 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003096 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003097 Phone phone = PhoneFactory.getPhone(slotIndex);
3098 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003099 return null;
3100 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003101
Jeff Davidson913390f2018-02-23 17:11:49 -08003102 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003103 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003104 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003105 return null;
3106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003107
3108 final long identity = Binder.clearCallingIdentity();
3109 try {
3110 return phone.getMeid();
3111 } finally {
3112 Binder.restoreCallingIdentity(identity);
3113 }
Jack Yu2af8d712017-03-15 17:14:14 -07003114 }
3115
3116 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003117 public String getManufacturerCodeForSlot(int slotIndex) {
3118 Phone phone = PhoneFactory.getPhone(slotIndex);
3119 String manufacturerCode = null;
3120 if (phone != null) {
3121 String meid = phone.getMeid();
3122 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3123 }
3124 return manufacturerCode;
3125 }
3126
3127 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003128 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3129 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003130 Phone phone = PhoneFactory.getPhone(slotIndex);
3131 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003132 return null;
3133 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003134 int subId = phone.getSubId();
3135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003136 mApp, subId, callingPackage, callingFeatureId,
3137 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003138 return null;
3139 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140
3141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 return phone.getDeviceSvn();
3144 } finally {
3145 Binder.restoreCallingIdentity(identity);
3146 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003147 }
3148
fionaxu43304da2017-11-27 22:51:16 -08003149 @Override
3150 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 final Phone phone = getPhone(subId);
3154 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
3157 }
fionaxu43304da2017-11-27 22:51:16 -08003158 }
3159
3160 @Override
3161 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 final Phone phone = getPhone(subId);
3165 return phone == null ? null : phone.getCarrierName();
3166 } finally {
3167 Binder.restoreCallingIdentity(identity);
3168 }
fionaxu43304da2017-11-27 22:51:16 -08003169 }
3170
calvinpanffe225e2018-11-01 19:43:06 +08003171 @Override
chen xu0026ca62019-03-06 15:28:50 -08003172 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003173 final long identity = Binder.clearCallingIdentity();
3174 try {
3175 final Phone phone = getPhone(subId);
3176 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003177 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
3181 }
3182
3183 @Override
chen xu0026ca62019-03-06 15:28:50 -08003184 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003188 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003189 } finally {
3190 Binder.restoreCallingIdentity(identity);
3191 }
3192 }
3193
chen xu651eec72018-11-11 19:03:44 -08003194 @Override
chen xu864e11c2018-12-06 22:10:03 -08003195 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3196 if (!isSubscriptionMccMnc) {
3197 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3198 }
chen xu651eec72018-11-11 19:03:44 -08003199 final Phone phone = PhoneFactory.getPhone(slotIndex);
3200 if (phone == null) {
3201 return TelephonyManager.UNKNOWN_CARRIER_ID;
3202 }
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3206 } finally {
3207 Binder.restoreCallingIdentity(identity);
3208 }
3209 }
3210
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003211 //
3212 // Internal helper methods.
3213 //
3214
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003215 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003216 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3217 *
3218 * @throws SecurityException if the caller does not have the required permission
3219 */
3220 private void enforceModifyPermission() {
3221 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3222 }
3223
Shuo Qiancd19c462020-01-16 20:51:11 -08003224 /**
3225 * Make sure the caller is system.
3226 *
3227 * @throws SecurityException if the caller is not system.
3228 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003229 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003230 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3231 throw new SecurityException("Caller must be system");
3232 }
3233 }
3234
Shuo Qian3b6ee772019-11-13 17:43:31 -08003235 private void enforceActiveEmergencySessionPermission() {
3236 mApp.enforceCallingOrSelfPermission(
3237 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3238 }
3239
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003240 /**
3241 * Make sure the caller has the CALL_PHONE permission.
3242 *
3243 * @throws SecurityException if the caller does not have the required permission
3244 */
3245 private void enforceCallPermission() {
3246 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3247 }
3248
paulhu5a773602019-08-23 19:17:33 +08003249 private void enforceSettingsPermission() {
3250 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003251 }
3252
Michele Berionne5e411512020-11-13 02:36:59 +00003253 private void enforceRebootPermission() {
3254 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3255 }
3256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 private String createTelUrl(String number) {
3258 if (TextUtils.isEmpty(number)) {
3259 return null;
3260 }
3261
Jake Hambye994d462014-02-03 13:10:13 -08003262 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 }
3264
Ihab Awadf9e92732013-12-05 18:02:52 -08003265 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003266 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3267 }
3268
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003269 private static void logv(String msg) {
3270 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3271 }
3272
Ihab Awadf9e92732013-12-05 18:02:52 -08003273 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003274 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3275 }
3276
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003277 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003278 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003279 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003280 }
3281
Sanket Padawe356d7632015-06-22 14:03:32 -07003282 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003283 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 final Phone phone = PhoneFactory.getPhone(slotIndex);
3287 if (phone == null) {
3288 return PhoneConstants.PHONE_TYPE_NONE;
3289 } else {
3290 return phone.getPhoneType();
3291 }
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003295 }
3296
3297 /**
3298 * Returns the CDMA ERI icon index to display
3299 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003300 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003301 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3302 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3303 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003304 }
3305
Sanket Padawe356d7632015-06-22 14:03:32 -07003306 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003307 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3308 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003310 mApp, subId, callingPackage, callingFeatureId,
3311 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003312 return -1;
3313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003314
3315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 final Phone phone = getPhone(subId);
3318 if (phone != null) {
3319 return phone.getCdmaEriIconIndex();
3320 } else {
3321 return -1;
3322 }
3323 } finally {
3324 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003326 }
3327
3328 /**
3329 * Returns the CDMA ERI icon mode,
3330 * 0 - ON
3331 * 1 - FLASHING
3332 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003333 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003334 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3335 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3336 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003337 }
3338
Sanket Padawe356d7632015-06-22 14:03:32 -07003339 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003340 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3341 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003343 mApp, subId, callingPackage, callingFeatureId,
3344 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003345 return -1;
3346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 final Phone phone = getPhone(subId);
3351 if (phone != null) {
3352 return phone.getCdmaEriIconMode();
3353 } else {
3354 return -1;
3355 }
3356 } finally {
3357 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003358 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003359 }
3360
3361 /**
3362 * Returns the CDMA ERI text,
3363 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003364 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003365 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3366 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3367 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003368 }
3369
Sanket Padawe356d7632015-06-22 14:03:32 -07003370 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003371 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3372 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003374 mApp, subId, callingPackage, callingFeatureId,
3375 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003376 return null;
3377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003378
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 final Phone phone = getPhone(subId);
3382 if (phone != null) {
3383 return phone.getCdmaEriText();
3384 } else {
3385 return null;
3386 }
3387 } finally {
3388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003390 }
3391
3392 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003393 * Returns the CDMA MDN.
3394 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003395 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003396 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003397 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3398 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399
3400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003403 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404 return phone.getLine1Number();
3405 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003406 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407 return null;
3408 }
3409 } finally {
3410 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003411 }
3412 }
3413
3414 /**
3415 * Returns the CDMA MIN.
3416 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003417 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003418 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3420 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 final Phone phone = getPhone(subId);
3425 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3426 return phone.getCdmaMin();
3427 } else {
3428 return null;
3429 }
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003432 }
3433 }
3434
Hall Liud892bec2018-11-30 14:51:45 -08003435 @Override
3436 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3437 INumberVerificationCallback callback, String callingPackage) {
3438 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3439 != PERMISSION_GRANTED) {
3440 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3441 }
3442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3443
3444 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3445 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003446 throw new SecurityException("Calling package must be configured in the device config: "
3447 + "calling package: " + callingPackage
3448 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003449 }
3450
3451 if (range == null) {
3452 throw new NullPointerException("Range must be non-null");
3453 }
3454
3455 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003456 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003457
3458 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3459 }
3460
Junda Liuca05d5d2014-08-14 22:36:34 -07003461 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003462 * Returns true if CDMA provisioning needs to run.
3463 */
3464 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 final long identity = Binder.clearCallingIdentity();
3466 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003467 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003471 }
3472
3473 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003474 * Sets the voice mail number of a given subId.
3475 */
3476 @Override
3477 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003478 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3479 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003480
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3484 new Pair<String, String>(alphaTag, number), new Integer(subId));
3485 return success;
3486 } finally {
3487 Binder.restoreCallingIdentity(identity);
3488 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003489 }
3490
Ta-wei Yen87c49842016-05-13 21:19:52 -07003491 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003492 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003494 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3495 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003496 if (!TextUtils.equals(callingPackage, systemDialer)) {
3497 throw new SecurityException("caller must be system dialer");
3498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3503 if (phoneAccountHandle == null) {
3504 return null;
3505 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003506 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507 } finally {
3508 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003509 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003510 }
3511
3512 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003513 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3514 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003517 mApp, subId, callingPackage, callingFeatureId,
3518 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003519 return null;
3520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003521
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003522 final long identity = Binder.clearCallingIdentity();
3523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003524 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003525 } finally {
3526 Binder.restoreCallingIdentity(identity);
3527 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003528 }
3529
3530 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003531 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3532 VisualVoicemailSmsFilterSettings settings) {
3533 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003538 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003539 } finally {
3540 Binder.restoreCallingIdentity(identity);
3541 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003542 }
3543
3544 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003545 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3546 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003551 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003555 }
3556
3557 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003558 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3559 String callingPackage, int subId) {
3560 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003561
3562 final long identity = Binder.clearCallingIdentity();
3563 try {
3564 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003565 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003566 } finally {
3567 Binder.restoreCallingIdentity(identity);
3568 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003569 }
3570
3571 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003572 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003574
3575 final long identity = Binder.clearCallingIdentity();
3576 try {
3577 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003578 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 } finally {
3580 Binder.restoreCallingIdentity(identity);
3581 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003582 }
3583
3584 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003585 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3586 String callingAttributionTag, int subId, String number, int port, String text,
3587 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003589 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003590 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003591 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003592 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3593 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003594 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003595
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003596 /**
fionaxu0152e512016-11-14 13:36:14 -08003597 * Sets the voice activation state of a given subId.
3598 */
3599 @Override
3600 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3602 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003603
3604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 final Phone phone = getPhone(subId);
3607 if (phone != null) {
3608 phone.setVoiceActivationState(activationState);
3609 } else {
3610 loge("setVoiceActivationState fails with invalid subId: " + subId);
3611 }
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003614 }
3615 }
3616
3617 /**
3618 * Sets the data activation state of a given subId.
3619 */
3620 @Override
3621 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3623 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003624
3625 final long identity = Binder.clearCallingIdentity();
3626 try {
3627 final Phone phone = getPhone(subId);
3628 if (phone != null) {
3629 phone.setDataActivationState(activationState);
3630 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003631 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003632 }
3633 } finally {
3634 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003635 }
3636 }
3637
3638 /**
3639 * Returns the voice activation state of a given subId.
3640 */
3641 @Override
3642 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644
fionaxu0152e512016-11-14 13:36:14 -08003645 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003646 final long identity = Binder.clearCallingIdentity();
3647 try {
3648 if (phone != null) {
3649 return phone.getVoiceActivationState();
3650 } else {
3651 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3652 }
3653 } finally {
3654 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003655 }
3656 }
3657
3658 /**
3659 * Returns the data activation state of a given subId.
3660 */
3661 @Override
3662 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664
fionaxu0152e512016-11-14 13:36:14 -08003665 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 if (phone != null) {
3669 return phone.getDataActivationState();
3670 } else {
3671 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3672 }
3673 } finally {
3674 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003675 }
3676 }
3677
3678 /**
Wink Saville36469e72014-06-11 15:17:00 -07003679 * Returns the unread count of voicemails for a subId
3680 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003681 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003682 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3683 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003685 mApp, subId, callingPackage, callingFeatureId,
3686 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003687 return 0;
3688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 final Phone phone = getPhone(subId);
3692 if (phone != null) {
3693 return phone.getVoiceMessageCount();
3694 } else {
3695 return 0;
3696 }
3697 } finally {
3698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003700 }
3701
3702 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003703 * returns true, if the device is in a state where both voice and data
3704 * are supported simultaneously. This can change based on location or network condition.
3705 */
3706 @Override
3707 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708 final long identity = Binder.clearCallingIdentity();
3709 try {
3710 final Phone phone = getPhone(subId);
3711 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003715 }
3716
3717 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003718 * Send the dialer code if called from the current default dialer or the caller has
3719 * carrier privilege.
3720 * @param inputCode The dialer code to send
3721 */
3722 @Override
3723 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003725 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003726 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3727 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003728 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003729 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003730 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003731 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003732
3733 final long identity = Binder.clearCallingIdentity();
3734 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003735 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
fionaxu235cc5e2017-03-06 22:25:57 -08003739 }
3740
Pengquan Menga1bb6272018-09-06 09:59:22 -07003741 @Override
3742 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003743 TelephonyPermissions
3744 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3745 mApp, subId, "getNetworkSelectionMode");
3746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 if (!isActiveSubscription(subId)) {
3749 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3750 }
3751 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3752 } finally {
3753 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003754 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003755 }
3756
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003758 public boolean isInEmergencySmsMode() {
3759 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3760 final long identity = Binder.clearCallingIdentity();
3761 try {
3762 for (Phone phone : PhoneFactory.getPhones()) {
3763 if (phone.isInEmergencySmsMode()) {
3764 return true;
3765 }
3766 }
3767 } finally {
3768 Binder.restoreCallingIdentity(identity);
3769 }
3770 return false;
3771 }
3772
shilu366312e2019-12-17 09:28:10 -08003773 /**
3774 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3775 * @param subId The subscription to use to check the configuration.
3776 * @param c The callback that will be used to send the result.
3777 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003778 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003779 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3780 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003781 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3782 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003783
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003784 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3785 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3786 "IMS not available on device.");
3787 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003788 final long token = Binder.clearCallingIdentity();
3789 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003790 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003791 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003792 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003793 } catch (ImsException e) {
3794 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003795 } finally {
3796 Binder.restoreCallingIdentity(token);
3797 }
3798 }
3799
shilu366312e2019-12-17 09:28:10 -08003800 /**
3801 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3802 * @param subId The subscription to use to check the configuration.
3803 * @param c The callback that will be used to send the result.
3804 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003805 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003806 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003807 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3808 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003809 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3810 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3811 }
Meng Wangafbc5852019-09-19 17:37:13 -07003812 final long token = Binder.clearCallingIdentity();
3813 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003814 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003815 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3816 .removeRegistrationCallbackForSubscription(c, subId);
3817 } catch (ImsException e) {
3818 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3819 + "is inactive, ignoring unregister.");
3820 // If the subscription is no longer active, just return, since the callback
3821 // will already have been removed internally.
3822 } finally {
3823 Binder.restoreCallingIdentity(token);
3824 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003825 }
3826
Brad Ebingera34a6c22019-10-22 17:36:18 -07003827 /**
3828 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3829 */
3830 @Override
3831 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3832 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3833 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3834 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3835 "IMS not available on device.");
3836 }
3837 final long token = Binder.clearCallingIdentity();
3838 try {
3839 Phone phone = getPhone(subId);
3840 if (phone == null) {
3841 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3842 + subId + "'");
3843 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3844 }
3845 phone.getImsRegistrationState(regState -> {
3846 try {
3847 consumer.accept((regState == null)
3848 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3849 } catch (RemoteException e) {
3850 // Ignore if the remote process is no longer available to call back.
3851 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3852 }
3853 });
3854 } finally {
3855 Binder.restoreCallingIdentity(token);
3856 }
3857 }
3858
3859 /**
3860 * Get the transport type for the IMS service registration state.
3861 */
3862 @Override
3863 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003864 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3865 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003866 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3867 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3868 "IMS not available on device.");
3869 }
3870 final long token = Binder.clearCallingIdentity();
3871 try {
3872 Phone phone = getPhone(subId);
3873 if (phone == null) {
3874 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3875 + subId + "'");
3876 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3877 }
3878 phone.getImsRegistrationTech(regTech -> {
3879 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3880 int regTechConverted = (regTech == null)
3881 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3882 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3883 regTechConverted);
3884 try {
3885 consumer.accept(regTechConverted);
3886 } catch (RemoteException e) {
3887 // Ignore if the remote process is no longer available to call back.
3888 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3889 }
3890 });
3891 } finally {
3892 Binder.restoreCallingIdentity(token);
3893 }
3894 }
3895
shilu366312e2019-12-17 09:28:10 -08003896 /**
3897 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3898 * @param subId The subscription to use to check the configuration.
3899 * @param c The callback that will be used to send the result.
3900 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003902 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3903 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003904 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3905 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003906 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3907 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3908 "IMS not available on device.");
3909 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3911 final long token = Binder.clearCallingIdentity();
3912 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003913 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003914 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003915 } catch (ImsException e) {
3916 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003917 } finally {
3918 Binder.restoreCallingIdentity(token);
3919 }
3920 }
3921
shilu366312e2019-12-17 09:28:10 -08003922 /**
3923 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3924 * @param subId The subscription to use to check the configuration.
3925 * @param c The callback that will be used to send the result.
3926 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003927 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003928 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003929 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3930 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3932 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3933 }
Meng Wangafbc5852019-09-19 17:37:13 -07003934
3935 final long token = Binder.clearCallingIdentity();
3936 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003937 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003938 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003939 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003940 } catch (ImsException e) {
3941 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3942 + "is inactive, ignoring unregister.");
3943 // If the subscription is no longer active, just return, since the callback
3944 // will already have been removed internally.
3945 } finally {
3946 Binder.restoreCallingIdentity(token);
3947 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003948 }
3949
3950 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003951 public boolean isCapable(int subId, int capability, int regTech) {
3952 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3954 final long token = Binder.clearCallingIdentity();
3955 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003956 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003958 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3960 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003961 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003962 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3963 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 } finally {
3965 Binder.restoreCallingIdentity(token);
3966 }
3967 }
3968
3969 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003970 public boolean isAvailable(int subId, int capability, int regTech) {
3971 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 final long token = Binder.clearCallingIdentity();
3973 try {
3974 Phone phone = getPhone(subId);
3975 if (phone == null) return false;
3976 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003977 } catch (com.android.ims.ImsException e) {
3978 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3979 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 } finally {
3981 Binder.restoreCallingIdentity(token);
3982 }
3983 }
3984
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003985 /**
3986 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3987 * subscription.
3988 * @param subId The subscription to use to check the configuration.
3989 * @param callback The callback that will be used to send the result.
3990 * @param capability The MmTelFeature capability that will be used to send the result.
3991 * @param transportType The transport type of the MmTelFeature capability.
3992 */
3993 @Override
3994 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3995 int transportType) {
3996 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3997 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3998 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3999 "IMS not available on device.");
4000 }
4001 final long token = Binder.clearCallingIdentity();
4002 try {
4003 int slotId = getSlotIndex(subId);
4004 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4005 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4006 + subId + "'");
4007 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4008 }
4009 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4010 transportType, aBoolean -> {
4011 try {
4012 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4013 } catch (RemoteException e) {
4014 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4015 + "running. Ignore");
4016 }
4017 });
4018 } finally {
4019 Binder.restoreCallingIdentity(token);
4020 }
4021 }
4022
shilu366312e2019-12-17 09:28:10 -08004023 /**
4024 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4025 * @param subId The subscription to use to check the configuration.
4026 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004027 @Override
4028 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004029 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4030 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004031
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4033 final long token = Binder.clearCallingIdentity();
4034 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004035 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004037 } catch (ImsException e) {
4038 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004039 } finally {
4040 Binder.restoreCallingIdentity(token);
4041 }
4042 }
4043
4044 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004045 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004047 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004048 final long identity = Binder.clearCallingIdentity();
4049 try {
4050 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004051 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004052 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004053 } catch (ImsException e) {
4054 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 } finally {
4056 Binder.restoreCallingIdentity(identity);
4057 }
4058 }
4059
shilu366312e2019-12-17 09:28:10 -08004060 /**
4061 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4062 * @param subId The subscription to use to check the configuration.
4063 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004065 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004066 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4067 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004071 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4072 } catch (ImsException e) {
4073 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 } finally {
4075 Binder.restoreCallingIdentity(identity);
4076 }
4077 }
4078
4079 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004080 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004082 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004086 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004087 } catch (ImsException e) {
4088 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004089 } finally {
4090 Binder.restoreCallingIdentity(identity);
4091 }
4092 }
4093
shilu366312e2019-12-17 09:28:10 -08004094 /**
4095 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4096 * @param subId The subscription to use to check the configuration.
4097 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004098 @Override
4099 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004100 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4101 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004105 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004106 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004107 } catch (ImsException e) {
4108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
4112 }
4113
4114 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004115 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004117 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004121 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004122 } catch (ImsException e) {
4123 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
4127 }
4128
shilu366312e2019-12-17 09:28:10 -08004129 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004130 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4131 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4132 * @param subId The subscription to use to check the configuration.
4133 */
4134 @Override
4135 public boolean isCrossSimCallingEnabledByUser(int subId) {
4136 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4137 mApp, subId, "isCrossSimCallingEnabledByUser");
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4141 return ImsManager.getInstance(mApp,
4142 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4143 } catch (ImsException e) {
4144 throw new ServiceSpecificException(e.getCode());
4145 } finally {
4146 Binder.restoreCallingIdentity(identity);
4147 }
4148 }
4149
4150 /**
4151 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4152 * Requires MODIFY_PHONE_STATE permission.
4153 * @param subId The subscription to use to check the configuration.
4154 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4155 * false otherwise
4156 */
4157 @Override
4158 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4160 "setCrossSimCallingEnabled");
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4164 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4165 .setCrossSimCallingEnabled(isEnabled);
4166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
4168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
4173 /**
shilu366312e2019-12-17 09:28:10 -08004174 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4175 * @param subId The subscription to use to check the configuration.
4176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004177 @Override
4178 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004179 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4180 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004181 final long identity = Binder.clearCallingIdentity();
4182 try {
4183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004184 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004186 } catch (ImsException e) {
4187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
4191 }
4192
4193 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004194 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004196 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 final long identity = Binder.clearCallingIdentity();
4198 try {
4199 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004200 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004202 } catch (ImsException e) {
4203 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
4207 }
4208
4209 @Override
4210 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4212 "setVoWiFiNonPersistent");
4213 final long identity = Binder.clearCallingIdentity();
4214 try {
4215 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004216 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004217 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004218 } catch (ImsException e) {
4219 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004220 } finally {
4221 Binder.restoreCallingIdentity(identity);
4222 }
4223 }
4224
shilu366312e2019-12-17 09:28:10 -08004225 /**
4226 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4227 * @param subId The subscription to use to check the configuration.
4228 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 @Override
4230 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004231 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4232 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004233 final long identity = Binder.clearCallingIdentity();
4234 try {
4235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004236 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004238 } catch (ImsException e) {
4239 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
4243 }
4244
4245 @Override
4246 public void setVoWiFiModeSetting(int subId, int mode) {
4247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4248 "setVoWiFiModeSetting");
4249 final long identity = Binder.clearCallingIdentity();
4250 try {
4251 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004252 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004253 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004254 } catch (ImsException e) {
4255 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
4259 }
4260
4261 @Override
4262 public int getVoWiFiRoamingModeSetting(int subId) {
4263 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4264 final long identity = Binder.clearCallingIdentity();
4265 try {
4266 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004267 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004268 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004269 } catch (ImsException e) {
4270 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004271 } finally {
4272 Binder.restoreCallingIdentity(identity);
4273 }
4274 }
4275
4276 @Override
4277 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4279 "setVoWiFiRoamingModeSetting");
4280 final long identity = Binder.clearCallingIdentity();
4281 try {
4282 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004283 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004284 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004285 } catch (ImsException e) {
4286 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004287 } finally {
4288 Binder.restoreCallingIdentity(identity);
4289 }
4290 }
4291
4292 @Override
4293 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4295 "setRttCapabilityEnabled");
4296 final long identity = Binder.clearCallingIdentity();
4297 try {
4298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004299 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4300 } catch (ImsException e) {
4301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
4305 }
4306
shilu366312e2019-12-17 09:28:10 -08004307 /**
4308 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4309 * @param subId The subscription to use to check the configuration.
4310 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004311 @Override
4312 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004313 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4314 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004315 final long identity = Binder.clearCallingIdentity();
4316 try {
4317 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004318 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004319 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004320 } catch (ImsException e) {
4321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004322 } finally {
4323 Binder.restoreCallingIdentity(identity);
4324 }
4325 }
4326
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004327 @Override
4328 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4329 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4330 final long identity = Binder.clearCallingIdentity();
4331 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004332 if (!isImsAvailableOnDevice()) {
4333 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4334 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004335 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004336 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004337 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004338 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004339 } catch (ImsException e) {
4340 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
4344 }
4345
4346 @Override
4347 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4348 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4349 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004350 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4351 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4352 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004353 try {
4354 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004355 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004356 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004357 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004358 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4359 + "is inactive, ignoring unregister.");
4360 // If the subscription is no longer active, just return, since the callback will already
4361 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004362 } finally {
4363 Binder.restoreCallingIdentity(identity);
4364 }
4365 }
4366
allenwtsu99c623b2020-01-03 18:24:23 +08004367
4368 private void checkModifyPhoneStatePermission(int subId, String message) {
4369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4370 message);
4371 }
4372
4373 private boolean isImsProvisioningRequired(int subId, int capability,
4374 boolean isMmtelCapability) {
4375 Phone phone = getPhone(subId);
4376 if (phone == null) {
4377 loge("phone instance null for subid " + subId);
4378 return false;
4379 }
4380 if (isMmtelCapability) {
4381 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4382 return false;
4383 }
4384 } else {
4385 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4386 return false;
4387 }
4388 }
4389 return true;
4390 }
4391
4392 @Override
4393 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4394 boolean isProvisioned) {
4395 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4396
4397 final long identity = Binder.clearCallingIdentity();
4398 try {
4399 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4400 if (!isImsProvisioningRequired(subId, capability, false)) {
4401 return;
4402 }
4403
4404 // this capability requires provisioning, route to the correct API.
4405 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4406 switch (capability) {
4407 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4408 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4409 ims.setEabProvisioned(isProvisioned);
4410 break;
4411 default: {
4412 throw new IllegalArgumentException("Tried to set provisioning for "
4413 + "rcs capability '" + capability + "', which does not require "
4414 + "provisioning.");
4415 }
4416 }
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
4420
4421 }
4422
4423
4424 @Override
4425 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4426 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4430 if (!isImsProvisioningRequired(subId, capability, false)) {
4431 return true;
4432 }
4433
4434 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4435 switch (capability) {
4436 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4437 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4438 return ims.isEabProvisionedOnDevice();
4439
4440 default: {
4441 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4442 + "capability '" + capability + "', which does not require "
4443 + "provisioning.");
4444 }
4445 }
4446
4447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
4450 }
4451
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004452 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004453 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4454 boolean isProvisioned) {
4455 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4456 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4457 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4458 }
allenwtsu99c623b2020-01-03 18:24:23 +08004459 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004460 final long identity = Binder.clearCallingIdentity();
4461 try {
4462 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004463 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004464 return;
4465 }
4466
4467 // this capability requires provisioning, route to the correct API.
4468 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4469 switch (capability) {
4470 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4471 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4472 ims.setVolteProvisioned(isProvisioned);
4473 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4474 ims.setWfcProvisioned(isProvisioned);
4475 }
4476 break;
4477 }
4478 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4479 // There is currently no difference in VT provisioning type.
4480 ims.setVtProvisioned(isProvisioned);
4481 break;
4482 }
4483 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4484 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4485 // change the capability of the feature instead if needed.
4486 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4487 == isProvisioned) {
4488 // No change in provisioning.
4489 return;
4490 }
4491 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4492 try {
4493 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004494 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004495 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4496 + ", Exception" + e.getMessage());
4497 }
4498 break;
4499 }
4500 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004501 throw new IllegalArgumentException("Tried to set provisioning for "
4502 + "MmTel capability '" + capability + "', which does not require "
4503 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004504 }
4505 }
4506
4507 } finally {
4508 Binder.restoreCallingIdentity(identity);
4509 }
4510 }
4511
4512 @Override
4513 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4514 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4515 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4516 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4517 }
4518 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4519 final long identity = Binder.clearCallingIdentity();
4520 try {
4521 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004522 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004523 return true;
4524 }
4525
4526 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4527 switch (capability) {
4528 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4529 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4530 return ims.isVolteProvisionedOnDevice();
4531 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4532 return ims.isWfcProvisionedOnDevice();
4533 }
4534 // This should never happen, since we are checking tech above to make sure it
4535 // is either LTE or IWLAN.
4536 throw new IllegalArgumentException("Invalid radio technology for voice "
4537 + "capability.");
4538 }
4539 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4540 // There is currently no difference in VT provisioning type.
4541 return ims.isVtProvisionedOnDevice();
4542 }
4543 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4544 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4545 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4546 }
4547 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004548 throw new IllegalArgumentException(
4549 "Tried to get provisioning for MmTel capability '" + capability
4550 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004551 }
4552 }
4553
4554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
4557 }
4558
4559 @Override
4560 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4561 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4562 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4563 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4564 }
4565 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4566 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4567 return (provisionedBits & capability) > 0;
4568 }
4569
4570 @Override
4571 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4572 boolean isProvisioned) {
4573 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4574 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4575 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4576 }
4577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4578 "setProvisioningStatusForCapability");
4579 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4580 // If the current provisioning status for capability already matches isProvisioned,
4581 // do nothing.
4582 if (((provisionedBits & capability) > 0) == isProvisioned) {
4583 return;
4584 }
4585 if (isProvisioned) {
4586 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4587 } else {
4588 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4589 }
4590 }
4591
4592 /**
4593 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4594 * technology. The bitfield should mirror the bitfield defined by
4595 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4596 */
4597 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4598 String key = getMmTelProvisioningKey(subId, tech);
4599 // Default is no capabilities are provisioned.
4600 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4601 }
4602
4603 /**
4604 * Sets the MmTel capability provisioning bitfield (defined by
4605 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4606 * technology specified.
4607 *
4608 * Note: This is a synchronous command and should not be called on UI thread.
4609 */
4610 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4611 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4612 String key = getMmTelProvisioningKey(subId, tech);
4613 editor.putInt(key, newField);
4614 editor.commit();
4615 }
4616
4617 private static String getMmTelProvisioningKey(int subId, int tech) {
4618 // resulting key is provision_ims_mmtel_{subId}_{tech}
4619 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4620 }
4621
4622 /**
4623 * Query CarrierConfig to see if the specified capability requires provisioning for the
4624 * carrier associated with the subscription id.
4625 */
4626 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4627 int capability) {
4628 CarrierConfigManager configManager = new CarrierConfigManager(context);
4629 PersistableBundle c = configManager.getConfigForSubId(subId);
4630 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004631 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004632 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4633 false);
4634 boolean requireVoiceVtProvisioning = c.getBoolean(
4635 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4636
4637 // First check to make sure that the capability requires provisioning.
4638 switch (capability) {
4639 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4640 // intentional fallthrough
4641 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4642 if (requireVoiceVtProvisioning) {
4643 // Voice and Video requires provisioning
4644 return true;
4645 }
4646 break;
4647 }
4648 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4649 if (requireUtProvisioning) {
4650 // UT requires provisioning
4651 return true;
4652 }
4653 break;
4654 }
4655 }
4656 return false;
4657 }
4658
allenwtsu99c623b2020-01-03 18:24:23 +08004659 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4660 int capability) {
4661 CarrierConfigManager configManager = new CarrierConfigManager(context);
4662 PersistableBundle c = configManager.getConfigForSubId(subId);
4663
4664 boolean requireRcsProvisioning = c.getBoolean(
4665 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4666
4667 // First check to make sure that the capability requires provisioning.
4668 switch (capability) {
4669 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4670 // intentional fallthrough
4671 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4672 if (requireRcsProvisioning) {
4673 // OPTION or PRESENCE requires provisioning
4674 return true;
4675 }
4676 break;
4677 }
4678 }
4679 return false;
4680 }
4681
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004682 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004683 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4685 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4686 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004687 enforceReadPrivilegedPermission("getImsProvisioningInt");
4688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004691 int slotId = getSlotIndex(subId);
4692 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4693 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4694 + subId + "' for key:" + key);
4695 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4696 }
calvinpanb5a34062021-02-08 19:59:36 +08004697 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004698 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004699 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4700 + subId + "' for key:" + key);
4701 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004702 } finally {
4703 Binder.restoreCallingIdentity(identity);
4704 }
4705 }
4706
4707 @Override
4708 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004709 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4710 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4711 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004712 enforceReadPrivilegedPermission("getImsProvisioningString");
4713 final long identity = Binder.clearCallingIdentity();
4714 try {
4715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004716 int slotId = getSlotIndex(subId);
4717 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4718 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4719 + subId + "' for key:" + key);
4720 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4721 }
calvinpanb5a34062021-02-08 19:59:36 +08004722 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004723 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004724 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4725 + subId + "' for key:" + key);
4726 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
4730 }
4731
4732 @Override
4733 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4735 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4736 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4738 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004742 int slotId = getSlotIndex(subId);
4743 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4744 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4745 + subId + "' for key:" + key);
4746 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4747 }
calvinpanb5a34062021-02-08 19:59:36 +08004748 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4749 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004750 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004751 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004752 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
4756 }
4757
4758 @Override
4759 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4761 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4762 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4764 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004768 int slotId = getSlotIndex(subId);
4769 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4770 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4771 + subId + "' for key:" + key);
4772 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4773 }
calvinpanb5a34062021-02-08 19:59:36 +08004774 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4775 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004776 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004777 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004778 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
4782 }
4783
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004784 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004785 int slotId = SubscriptionManager.getSlotIndex(subId);
4786 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004787 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4788 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004789 }
4790 return slotId;
4791 }
4792
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004793 private int getSlotIndex(int subId) {
4794 int slotId = SubscriptionManager.getSlotIndex(subId);
4795 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4796 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4797 }
4798 return slotId;
4799 }
4800
Wink Saville36469e72014-06-11 15:17:00 -07004801 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004802 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004803 */
4804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004805 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4806 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004807 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004808 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004809 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004810 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004811 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004812 mApp, subId, callingPackage, callingFeatureId,
4813 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004814 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4815 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 final long identity = Binder.clearCallingIdentity();
4818 try {
4819 final Phone phone = getPhone(subId);
4820 if (phone != null) {
4821 return phone.getServiceState().getDataNetworkType();
4822 } else {
4823 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4824 }
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004828 }
4829
4830 /**
4831 * Returns the data network type
4832 */
4833 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004834 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4835 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4836 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004837 }
4838
4839 /**
4840 * Returns the data network type for a subId
4841 */
4842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004843 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4844 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004846 mApp, subId, callingPackage, callingFeatureId,
4847 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004848 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4849 }
4850
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 final Phone phone = getPhone(subId);
4854 if (phone != null) {
4855 return phone.getServiceState().getDataNetworkType();
4856 } else {
4857 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4858 }
4859 } finally {
4860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004862 }
4863
4864 /**
Wink Saville36469e72014-06-11 15:17:00 -07004865 * Returns the Voice network type for a subId
4866 */
4867 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004868 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4869 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004870 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004871 mApp, subId, callingPackage, callingFeatureId,
4872 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004873 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4874 }
4875
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 final Phone phone = getPhone(subId);
4879 if (phone != null) {
4880 return phone.getServiceState().getVoiceNetworkType();
4881 } else {
4882 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4883 }
4884 } finally {
4885 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004886 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004887 }
4888
4889 /**
4890 * @return true if a ICC card is present
4891 */
4892 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004893 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004894 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4895 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004896 }
4897
4898 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004899 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004900 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004901 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004902 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 final long identity = Binder.clearCallingIdentity();
4904 try {
4905 final Phone phone = PhoneFactory.getPhone(slotIndex);
4906 if (phone != null) {
4907 return phone.getIccCard().hasIccCard();
4908 } else {
4909 return false;
4910 }
4911 } finally {
4912 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004914 }
4915
4916 /**
4917 * Return if the current radio is LTE on CDMA. This
4918 * is a tri-state return value as for a period of time
4919 * the mode may be unknown.
4920 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004921 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004922 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004923 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004924 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004925 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004926 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4927 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4928 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004929 }
4930
Sanket Padawe356d7632015-06-22 14:03:32 -07004931 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004932 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4933 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004934 try {
4935 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4936 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004937 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4938 }
4939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 final Phone phone = getPhone(subId);
4943 if (phone == null) {
4944 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4945 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004946 return TelephonyProperties.lte_on_cdma_device()
4947 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 }
4949 } finally {
4950 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004951 }
Wink Saville36469e72014-06-11 15:17:00 -07004952 }
4953
Wink Saville36469e72014-06-11 15:17:00 -07004954 /**
4955 * {@hide}
4956 * Returns Default subId, 0 in the case of single standby.
4957 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004958 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004959 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004960 }
4961
Shishir Agrawala9f32182016-04-12 12:00:16 -07004962 private int getSlotForDefaultSubscription() {
4963 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4964 }
4965
Wink Savilleb564aae2014-10-23 10:18:09 -07004966 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004967 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004968 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004969
Pengquan Menge92a50d2018-09-21 15:54:48 -07004970 private boolean isActiveSubscription(int subId) {
4971 return mSubscriptionController.isActiveSubId(subId);
4972 }
4973
Ihab Awadf2177b72013-11-25 13:33:23 -08004974 /**
4975 * @see android.telephony.TelephonyManager.WifiCallingChoices
4976 */
4977 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 final long identity = Binder.clearCallingIdentity();
4979 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004980 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4982 getWhenToMakeWifiCallsDefaultPreference());
4983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004986 }
4987
4988 /**
4989 * @see android.telephony.TelephonyManager.WifiCallingChoices
4990 */
4991 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004995 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
4999 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005000 }
5001
Sailesh Nepald1e68152013-12-12 19:08:02 -08005002 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005003 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005004 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005005 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005006
Jordan Liu4c733742019-02-28 12:03:40 -08005007 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5008 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5009 if (phoneId == -1) {
5010 throw new IllegalArgumentException("Given slot index: " + slotIndex
5011 + " does not correspond to an active phone");
5012 }
5013 return PhoneFactory.getPhone(phoneId);
5014 }
5015
Shishir Agrawal566b7612013-10-28 14:41:00 -07005016 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005017 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5018 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5020 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005022 if (DBG) {
5023 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5024 }
5025 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5026 p2);
5027 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005028
Jordan Liu4c733742019-02-28 12:03:40 -08005029
5030 @Override
5031 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5032 int slotIndex, String callingPackage, String aid, int p2) {
5033 enforceModifyPermission();
5034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5035 if (DBG) {
5036 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5037 }
5038 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5039 callingPackage, aid, p2);
5040 }
5041
5042 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5043 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 if (TextUtils.equals(ISDR_AID, aid)) {
5047 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005048 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5049 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050 if (bestComponent == null
5051 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5052 loge("The calling package is not allowed to access ISD-R.");
5053 throw new SecurityException(
5054 "The calling package is not allowed to access ISD-R.");
5055 }
Derek Tan740e1672017-06-27 14:56:27 -07005056 }
Derek Tan740e1672017-06-27 14:56:27 -07005057
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005059 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5060 null /* workSource */);
5061 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062 return response;
5063 } finally {
5064 Binder.restoreCallingIdentity(identity);
5065 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005066 }
5067
5068 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005069 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5071 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005072 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5073 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5074 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005075
Jordan Liu4c733742019-02-28 12:03:40 -08005076 @Override
5077 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5078 enforceModifyPermission();
5079 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5080 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5081 channel);
5082 }
5083
5084 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 final long identity = Binder.clearCallingIdentity();
5086 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 if (channel < 0) {
5088 return false;
5089 }
Jordan Liu4c733742019-02-28 12:03:40 -08005090 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5091 null /* workSource */);
5092 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005093 return success;
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005096 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005097 }
5098
5099 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005100 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005101 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5103 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005104 if (DBG) {
5105 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5106 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5107 + p3 + " data=" + data);
5108 }
5109 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5110 command, p1, p2, p3, data);
5111 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005112
Jordan Liu4c733742019-02-28 12:03:40 -08005113 @Override
5114 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5115 int command, int p1, int p2, int p3, String data) {
5116 enforceModifyPermission();
5117 if (DBG) {
5118 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5119 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5120 + p3 + " data=" + data);
5121 }
5122 return iccTransmitApduLogicalChannelWithPermission(
5123 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5124 data);
5125 }
5126
5127 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5128 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 final long identity = Binder.clearCallingIdentity();
5130 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005131 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 return "";
5133 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005136 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5137 null /* workSource */);
5138 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005140 // Append the returned status code to the end of the response payload.
5141 String s = Integer.toHexString(
5142 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5143 if (response.payload != null) {
5144 s = IccUtils.bytesToHexString(response.payload) + s;
5145 }
5146 return s;
5147 } finally {
5148 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005149 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005150 }
Jake Hambye994d462014-02-03 13:10:13 -08005151
Evan Charltonc66da362014-05-16 14:06:40 -07005152 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005153 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5154 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5156 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005157 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005158 if (DBG) {
5159 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5160 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5161 }
5162 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5163 cla, command, p1, p2, p3, data);
5164 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005165
Jordan Liu4c733742019-02-28 12:03:40 -08005166 @Override
5167 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5168 int command, int p1, int p2, int p3, String data) {
5169 enforceModifyPermission();
5170 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5171 if (DBG) {
5172 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5173 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5174 + " data=" + data);
5175 }
5176
5177 return iccTransmitApduBasicChannelWithPermission(
5178 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5179 p2, p3, data);
5180 }
5181
5182 // open APDU basic channel assuming the caller has sufficient permissions
5183 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5184 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
5187 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5188 && TextUtils.equals(ISDR_AID, data)) {
5189 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005190 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5191 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 if (bestComponent == null
5193 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5194 loge("The calling package is not allowed to select ISD-R.");
5195 throw new SecurityException(
5196 "The calling package is not allowed to select ISD-R.");
5197 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005198 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005199
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005200 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005201 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5202 null /* workSource */);
5203 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 // Append the returned status code to the end of the response payload.
5206 String s = Integer.toHexString(
5207 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5208 if (response.payload != null) {
5209 s = IccUtils.bytesToHexString(response.payload) + s;
5210 }
5211 return s;
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005214 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005215 }
5216
5217 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005218 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005219 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5221 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 if (DBG) {
5226 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5227 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5228 }
5229
5230 IccIoResult response =
5231 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5232 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5233 subId);
5234
5235 if (DBG) {
5236 log("Exchange SIM_IO [R]" + response);
5237 }
5238
5239 byte[] result = null;
5240 int length = 2;
5241 if (response.payload != null) {
5242 length = 2 + response.payload.length;
5243 result = new byte[length];
5244 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5245 } else {
5246 result = new byte[length];
5247 }
5248
5249 result[length - 1] = (byte) response.sw2;
5250 result[length - 2] = (byte) response.sw1;
5251 return result;
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005254 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005255 }
5256
Nathan Haroldb3014052017-01-25 15:57:32 -08005257 /**
5258 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5259 * on a particular subscription
5260 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005261 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5262 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005263 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005264 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005265 return null;
5266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267
5268 final long identity = Binder.clearCallingIdentity();
5269 try {
5270 if (appType != TelephonyManager.APPTYPE_USIM
5271 && appType != TelephonyManager.APPTYPE_SIM) {
5272 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5273 return null;
5274 }
5275 Object response = sendRequest(
5276 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5277 if (response instanceof String[]) {
5278 return (String[]) response;
5279 }
yincheng zhao2737e882019-09-06 17:06:54 -07005280 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005282 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 } finally {
5284 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005285 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005286 }
5287
yincheng zhao2737e882019-09-06 17:06:54 -07005288 /**
5289 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5290 * subscription.
5291 *
5292 * @param subId the id of the subscription.
5293 * @param appType the uicc app type, must be USIM or SIM.
5294 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5295 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005296 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005297 * @return number of fplmns that is successfully written to the SIM.
5298 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005299 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5300 String callingFeatureId) {
5301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5302 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005303 if (DBG) logv("no permissions for setForbiddenplmns");
5304 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5305 }
5306 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5307 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5308 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5309 }
5310 if (fplmns == null) {
5311 throw new IllegalArgumentException("Fplmn List provided is null");
5312 }
5313 for (String fplmn : fplmns) {
5314 if (!CellIdentity.isValidPlmn(fplmn)) {
5315 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5316 }
5317 }
5318 final long identity = Binder.clearCallingIdentity();
5319 try {
5320 Object response = sendRequest(
5321 CMD_SET_FORBIDDEN_PLMNS,
5322 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5323 subId);
5324 return (int) response;
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
5328 }
5329
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005330 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005331 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5333 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 final long identity = Binder.clearCallingIdentity();
5336 try {
5337 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5338 if (response.payload == null) {
5339 return "";
5340 }
Evan Charltonc66da362014-05-16 14:06:40 -07005341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 // Append the returned status code to the end of the response payload.
5343 String s = Integer.toHexString(
5344 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5345 s = IccUtils.bytesToHexString(response.payload) + s;
5346 return s;
5347 } finally {
5348 Binder.restoreCallingIdentity(identity);
5349 }
Evan Charltonc66da362014-05-16 14:06:40 -07005350 }
5351
Jake Hambye994d462014-02-03 13:10:13 -08005352 /**
5353 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5354 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5355 *
5356 * @param itemID the ID of the item to read
5357 * @return the NV item as a String, or null on error.
5358 */
5359 @Override
5360 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005361 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5363 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364
5365 final long identity = Binder.clearCallingIdentity();
5366 try {
5367 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005368 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5370 return value;
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
Jake Hambye994d462014-02-03 13:10:13 -08005374 }
5375
5376 /**
5377 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5378 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5379 *
5380 * @param itemID the ID of the item to read
5381 * @param itemValue the value to write, as a String
5382 * @return true on success; false on any failure
5383 */
5384 @Override
5385 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005386 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5388 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389
5390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5393 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005394 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5396 return success;
5397 } finally {
5398 Binder.restoreCallingIdentity(identity);
5399 }
Jake Hambye994d462014-02-03 13:10:13 -08005400 }
5401
5402 /**
5403 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5404 * Used for device configuration by some CDMA operators.
5405 *
5406 * @param preferredRoamingList byte array containing the new PRL
5407 * @return true on success; false on any failure
5408 */
5409 @Override
5410 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5412 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413
5414 final long identity = Binder.clearCallingIdentity();
5415 try {
5416 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5417 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5418 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5419 return success;
5420 } finally {
5421 Binder.restoreCallingIdentity(identity);
5422 }
Jake Hambye994d462014-02-03 13:10:13 -08005423 }
5424
5425 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005426 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005427 * Used for device configuration by some CDMA operators.
5428 *
chen xu6dac5ab2018-10-26 17:39:23 -07005429 * @param slotIndex - device slot.
5430 *
Jake Hambye994d462014-02-03 13:10:13 -08005431 * @return true on success; false on any failure
5432 */
5433 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005434 public boolean resetModemConfig(int slotIndex) {
5435 Phone phone = PhoneFactory.getPhone(slotIndex);
5436 if (phone != null) {
5437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5438 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439
chen xu6dac5ab2018-10-26 17:39:23 -07005440 final long identity = Binder.clearCallingIdentity();
5441 try {
5442 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5443 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5444 return success;
5445 } finally {
5446 Binder.restoreCallingIdentity(identity);
5447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 }
chen xu6dac5ab2018-10-26 17:39:23 -07005449 return false;
5450 }
5451
5452 /**
5453 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5454 *
5455 * @param slotIndex - device slot.
5456 *
5457 * @return true on success; false on any failure
5458 */
5459 @Override
5460 public boolean rebootModem(int slotIndex) {
5461 Phone phone = PhoneFactory.getPhone(slotIndex);
5462 if (phone != null) {
5463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5464 mApp, phone.getSubId(), "rebootModem");
5465
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5469 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5470 return success;
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
5474 }
5475 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005476 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005477
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005478 public String[] getPcscfAddress(String apnType, String callingPackage,
5479 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005480 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5482 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005483 return new String[0];
5484 }
5485
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 final long identity = Binder.clearCallingIdentity();
5487 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005488 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
Wink Saville36469e72014-06-11 15:17:00 -07005492 }
5493
Brad Ebinger51f743a2017-01-23 13:50:20 -08005494 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005495 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5496 * {@link #disableIms(int)}.
5497 * @param slotIndex device slot.
5498 */
5499 public void resetIms(int slotIndex) {
5500 enforceModifyPermission();
5501
5502 final long identity = Binder.clearCallingIdentity();
5503 try {
5504 if (mImsResolver == null) {
5505 // may happen if the does not support IMS.
5506 return;
5507 }
5508 mImsResolver.disableIms(slotIndex);
5509 mImsResolver.enableIms(slotIndex);
5510 } finally {
5511 Binder.restoreCallingIdentity(identity);
5512 }
5513 }
5514
5515 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005516 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5517 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005518 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005519 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005520 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521
5522 final long identity = Binder.clearCallingIdentity();
5523 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005524 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005525 // may happen if the device does not support IMS.
5526 return;
5527 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005528 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 } finally {
5530 Binder.restoreCallingIdentity(identity);
5531 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005532 }
5533
5534 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005535 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5536 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005537 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005538 public void disableIms(int slotId) {
5539 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540
5541 final long identity = Binder.clearCallingIdentity();
5542 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005543 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005544 // may happen if the device does not support IMS.
5545 return;
5546 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005547 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548 } finally {
5549 Binder.restoreCallingIdentity(identity);
5550 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005551 }
5552
5553 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005554 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5555 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005556 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005557 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005558 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005563 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005564 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5565 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005566 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005567 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005571 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005572 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005573 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5574 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005575 @Override
5576 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005577 enforceModifyPermission();
5578
5579 final long identity = Binder.clearCallingIdentity();
5580 try {
5581 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005582 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005583 } finally {
5584 Binder.restoreCallingIdentity(identity);
5585 }
5586 }
5587
5588 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005589 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005590 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005591 */
5592 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5593 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594
5595 final long identity = Binder.clearCallingIdentity();
5596 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005597 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005598 // may happen if the device does not support IMS.
5599 return null;
5600 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005601 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 } finally {
5603 Binder.restoreCallingIdentity(identity);
5604 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005605 }
5606
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005607 /**
5608 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005609 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005610 */
5611 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5612 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613
5614 final long identity = Binder.clearCallingIdentity();
5615 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005616 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005617 // may happen if the device does not support IMS.
5618 return null;
5619 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005620 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005624 }
5625
Brad Ebinger884c07b2018-02-15 16:17:40 -08005626 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005627 * Sets the ImsService Package Name that Telephony will bind to.
5628 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005629 * @param slotIndex the slot ID that the ImsService should bind for.
5630 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005631 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005632 * @param featureTypes An integer array of feature types associated with a packageName.
5633 * @param packageName The name of the package that the current configuration will be replaced
5634 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005635 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005636 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005637 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5638 int[] featureTypes, String packageName) {
5639 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5640 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5642 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005643 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 final long identity = Binder.clearCallingIdentity();
5646 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005647 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005648 // may happen if the device does not support IMS.
5649 return false;
5650 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005651 Map<Integer, String> featureConfig = new HashMap<>();
5652 for (int featureType : featureTypes) {
5653 featureConfig.put(featureType, packageName);
5654 }
5655 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5656 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005660 }
5661
5662 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005663 * Clears any carrier ImsService overrides for the slot index specified that were previously
5664 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5665 *
5666 * This should only be used for testing.
5667 *
5668 * @param slotIndex the slot ID that the ImsService should bind for.
5669 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5670 */
5671 @Override
5672 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5673 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5674 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5675 "clearCarrierImsServiceOverride");
5676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5677 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5678 "clearCarrierImsServiceOverride");
5679
5680 final long identity = Binder.clearCallingIdentity();
5681 try {
5682 if (mImsResolver == null) {
5683 // may happen if the device does not support IMS.
5684 return false;
5685 }
5686 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5687 } finally {
5688 Binder.restoreCallingIdentity(identity);
5689 }
5690 }
5691
5692 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005693 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005694 *
5695 * @param slotId The slot that the ImsService is associated with.
5696 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5697 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005698 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005699 * @return the package name of the ImsService configuration.
5700 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005701 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5702 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005703 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005704 TelephonyPermissions
5705 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5706 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5707 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005708
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 final long identity = Binder.clearCallingIdentity();
5710 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005711 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005712 // may happen if the device does not support IMS.
5713 return "";
5714 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005715 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005716 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5717 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 } finally {
5719 Binder.restoreCallingIdentity(identity);
5720 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005721 }
5722
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005723 /**
5724 * Get the MmTelFeature state associated with the requested subscription id.
5725 * @param subId The subscription that the MmTelFeature is associated with.
5726 * @param callback A callback with an integer containing the
5727 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5728 */
5729 @Override
5730 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5731 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5732 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5733 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5734 "IMS not available on device.");
5735 }
5736 final long token = Binder.clearCallingIdentity();
5737 try {
5738 int slotId = getSlotIndex(subId);
5739 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5740 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5741 + subId + "'");
5742 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5743 }
5744 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5745 try {
5746 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5747 } catch (RemoteException e) {
5748 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5749 + "Ignore");
5750 }
5751 });
5752 } finally {
5753 Binder.restoreCallingIdentity(token);
5754 }
5755 }
5756
Daniel Brightbb5840b2021-01-12 15:48:18 -08005757 /**
5758 * Sets the ims registration state on all valid {@link Phone}s.
5759 */
5760 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005761 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762
5763 final long identity = Binder.clearCallingIdentity();
5764 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005765 // NOTE: Before S, this method only set the default phone.
5766 for (final Phone phone : PhoneFactory.getPhones()) {
5767 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5768 phone.setImsRegistrationState(registered);
5769 }
5770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
5773 }
Wink Saville36469e72014-06-11 15:17:00 -07005774 }
5775
5776 /**
Stuart Scott54788802015-03-30 13:18:01 -07005777 * Set the network selection mode to automatic.
5778 *
5779 */
5780 @Override
5781 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5783 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784
5785 final long identity = Binder.clearCallingIdentity();
5786 try {
shilufc958392020-01-20 11:36:01 -08005787 if (!isActiveSubscription(subId)) {
5788 return;
5789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005791 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5792 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
Stuart Scott54788802015-03-30 13:18:01 -07005796 }
5797
Jack Yud10cdd42020-09-28 20:28:01 -07005798 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005799 * Ask the radio to connect to the input network and change selection mode to manual.
5800 *
5801 * @param subId the id of the subscription.
5802 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5803 * the operator to attach to.
5804 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5805 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5806 * normal network selection next time.
5807 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005808 */
5809 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005810 public boolean setNetworkSelectionModeManual(
5811 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005812 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5813 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005814
5815 if (!isActiveSubscription(subId)) {
5816 return false;
5817 }
5818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 final long identity = Binder.clearCallingIdentity();
5820 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005821 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005822 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005823 if (DBG) {
5824 log("setNetworkSelectionModeManual: subId: " + subId
5825 + " operator: " + operatorInfo);
5826 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005827 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
5830 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005831 }
shilu84f6e8b2019-12-19 13:58:01 -08005832 /**
5833 * Get the manual network selection
5834 *
5835 * @param subId the id of the subscription.
5836 *
5837 * @return the previously saved user selected PLMN
5838 */
5839 @Override
5840 public String getManualNetworkSelectionPlmn(int subId) {
5841 TelephonyPermissions
5842 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5843 mApp, subId, "getManualNetworkSelectionPlmn");
5844
5845 final long identity = Binder.clearCallingIdentity();
5846 try {
5847 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005848 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005849 }
5850
5851 final Phone phone = getPhone(subId);
5852 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005853 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005854 }
5855 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5856 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5857 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
5861 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005862
5863 /**
5864 * Scans for available networks.
5865 */
5866 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005867 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5868 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5870 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005871 LocationAccessPolicy.LocationPermissionResult locationResult =
5872 LocationAccessPolicy.checkLocationPermission(mApp,
5873 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5874 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005875 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005876 .setCallingPid(Binder.getCallingPid())
5877 .setCallingUid(Binder.getCallingUid())
5878 .setMethod("getCellNetworkScanResults")
5879 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005880 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5881 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005882 .build());
5883 switch (locationResult) {
5884 case DENIED_HARD:
5885 throw new SecurityException("Not allowed to access scan results -- location");
5886 case DENIED_SOFT:
5887 return null;
5888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889
Pengquan Menga1bb6272018-09-06 09:59:22 -07005890 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 try {
5892 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005893 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005898 }
5899
5900 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005901 * Get the call forwarding info, given the call forwarding reason.
5902 */
5903 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005904 public void getCallForwarding(int subId, int callForwardingReason,
5905 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005906 enforceReadPrivilegedPermission("getCallForwarding");
5907 long identity = Binder.clearCallingIdentity();
5908 try {
5909 if (DBG) {
5910 log("getCallForwarding: subId " + subId
5911 + " callForwardingReason" + callForwardingReason);
5912 }
Hall Liu27d24262020-09-18 19:04:59 -07005913
5914 Phone phone = getPhone(subId);
5915 if (phone == null) {
5916 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005917 callback.onError(
5918 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005919 } catch (RemoteException e) {
5920 // ignore
5921 }
5922 return;
5923 }
5924
5925 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5926 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5927 @Override
5928 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5929 try {
5930 callback.onCallForwardingInfoAvailable(info);
5931 } catch (RemoteException e) {
5932 // ignore
5933 }
5934 }
5935
5936 @Override
5937 public void onError(int error) {
5938 try {
5939 callback.onError(error);
5940 } catch (RemoteException e) {
5941 // ignore
5942 }
5943 }
5944 });
5945 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005946 } finally {
5947 Binder.restoreCallingIdentity(identity);
5948 }
5949 }
5950
5951 /**
5952 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5953 * reason, the number to forward, and the timeout before the forwarding is attempted.
5954 */
5955 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005956 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5957 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005958 enforceModifyPermission();
5959 long identity = Binder.clearCallingIdentity();
5960 try {
5961 if (DBG) {
5962 log("setCallForwarding: subId " + subId
5963 + " callForwardingInfo" + callForwardingInfo);
5964 }
Hall Liu27d24262020-09-18 19:04:59 -07005965
5966 Phone phone = getPhone(subId);
5967 if (phone == null) {
5968 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005969 callback.accept(
5970 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005971 } catch (RemoteException e) {
5972 // ignore
5973 }
5974 return;
5975 }
5976
5977 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5978 FunctionalUtils.ignoreRemoteException(callback::accept));
5979
5980 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005981 } finally {
5982 Binder.restoreCallingIdentity(identity);
5983 }
5984 }
5985
5986 /**
Hall Liu27d24262020-09-18 19:04:59 -07005987 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005988 */
5989 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005990 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005991 enforceReadPrivilegedPermission("getCallForwarding");
5992 long identity = Binder.clearCallingIdentity();
5993 try {
Hall Liu27d24262020-09-18 19:04:59 -07005994
5995 Phone phone = getPhone(subId);
5996 if (phone == null) {
5997 try {
5998 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5999 } catch (RemoteException e) {
6000 // ignore
6001 }
6002 return;
6003 }
6004
6005 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
6006
Shuo Qian4a594052020-01-23 11:59:30 -08006007 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07006008 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006009 } finally {
6010 Binder.restoreCallingIdentity(identity);
6011 }
6012 }
6013
6014 /**
Hall Liu27d24262020-09-18 19:04:59 -07006015 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006016 */
6017 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006018 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006019 enforceModifyPermission();
6020 long identity = Binder.clearCallingIdentity();
6021 try {
Hall Liu27d24262020-09-18 19:04:59 -07006022 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6023
6024 Phone phone = getPhone(subId);
6025 if (phone == null) {
6026 try {
6027 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6028 } catch (RemoteException e) {
6029 // ignore
6030 }
6031 return;
6032 }
6033
6034 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6035 FunctionalUtils.ignoreRemoteException(callback::accept));
6036
6037 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006038 } finally {
6039 Binder.restoreCallingIdentity(identity);
6040 }
6041 }
6042
6043 /**
yinxub1bed742017-04-17 11:45:04 -07006044 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006045 *
yinxub1bed742017-04-17 11:45:04 -07006046 * @param subId id of the subscription
6047 * @param request contains the radio access networks with bands/channels to scan
6048 * @param messenger callback messenger for scan results or errors
6049 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006050 * @return the id of the requested scan which can be used to stop the scan.
6051 */
6052 @Override
6053 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006054 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6056 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006057 LocationAccessPolicy.LocationPermissionResult locationResult =
6058 LocationAccessPolicy.checkLocationPermission(mApp,
6059 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6060 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006061 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006062 .setCallingPid(Binder.getCallingPid())
6063 .setCallingUid(Binder.getCallingUid())
6064 .setMethod("requestNetworkScan")
6065 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006066 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6067 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006068 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006069 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006070 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6071 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006072 if (e != null) {
6073 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6074 throw e;
6075 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006076 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006077 return TelephonyScanManager.INVALID_SCAN_ID;
6078 }
6079 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006080 }
Hall Liu912dfd32019-04-25 14:02:26 -07006081 int callingUid = Binder.getCallingUid();
6082 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006083 final long identity = Binder.clearCallingIdentity();
6084 try {
6085 return mNetworkScanRequestTracker.startNetworkScan(
6086 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006087 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006088 } finally {
6089 Binder.restoreCallingIdentity(identity);
6090 }
yinxu504e1392017-04-12 16:03:22 -07006091 }
6092
Hall Liub2ac8ef2019-02-28 15:56:23 -08006093 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006094 NetworkScanRequest request, int subId, String callingPackage) {
6095 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006096 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6097 boolean hasNetworkScanPermission =
6098 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6099 == PERMISSION_GRANTED;
6100
6101 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6102 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6103 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006104 }
6105
6106 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6107 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006108 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6109 return new SecurityException("Specific channels must not be"
6110 + " scanned without location access.");
6111 }
6112 }
6113 }
6114
Hall Liub2ac8ef2019-02-28 15:56:23 -08006115 return null;
6116 }
6117
yinxu504e1392017-04-12 16:03:22 -07006118 /**
6119 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006120 *
6121 * @param subId id of the subscription
6122 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006123 */
6124 @Override
6125 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6127 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128
Hall Liu912dfd32019-04-25 14:02:26 -07006129 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 final long identity = Binder.clearCallingIdentity();
6131 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006132 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 } finally {
6134 Binder.restoreCallingIdentity(identity);
6135 }
yinxu504e1392017-04-12 16:03:22 -07006136 }
6137
6138 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006139 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006140 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006141 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006142 */
6143 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006144 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006145 TelephonyPermissions
6146 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006147 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148
6149 final long identity = Binder.clearCallingIdentity();
6150 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006151 if (DBG) log("getAllowedNetworkTypesBitmask");
6152 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6153 int networkTypesBitmask = (result != null ? result[0] : -1);
6154 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6155 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156 } finally {
6157 Binder.restoreCallingIdentity(identity);
6158 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006159 }
6160
6161 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006162 * Get the allowed network types for certain reason.
6163 *
6164 * @param subId the id of the subscription.
6165 * @param reason the reason the allowed network type change is taking place
6166 * @return the allowed network types.
6167 */
6168 @Override
6169 public long getAllowedNetworkTypesForReason(int subId,
6170 @TelephonyManager.AllowedNetworkTypesReason int reason) {
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006171 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
6172 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
6179 }
6180
6181 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006182 * Enable/Disable E-UTRA-NR Dual Connectivity
6183 * @param subId subscription id of the sim card
6184 * @param nrDualConnectivityState expected NR dual connectivity state
6185 * This can be passed following states
6186 * <ol>
6187 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6188 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6189 * <li>Disable NR dual connectivity and force secondary cell to be released
6190 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6191 * </ol>
6192 * @return operation result.
6193 */
6194 @Override
6195 public int setNrDualConnectivityState(int subId,
6196 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6198 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006199 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006200 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6201 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6202 }
6203
Sooraj Sasindran37444802020-08-11 10:40:43 -07006204 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6208 nrDualConnectivityState, subId,
6209 workSource);
6210 if (DBG) log("enableNRDualConnectivity result: " + result);
6211 return result;
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
6214 }
6215 }
6216
6217 /**
6218 * Is E-UTRA-NR Dual Connectivity enabled
6219 * @return true if dual connectivity is enabled else false
6220 */
6221 @Override
6222 public boolean isNrDualConnectivityEnabled(int subId) {
6223 TelephonyPermissions
6224 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6225 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006226 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006227 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6228 return false;
6229 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006230 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6231 final long identity = Binder.clearCallingIdentity();
6232 try {
6233 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6234 null, subId, workSource);
6235 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6236 return isEnabled;
6237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
6240 }
6241
6242 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006243 * Set the allowed network types of the device and
6244 * provide the reason triggering the allowed network change.
6245 *
6246 * @param subId the id of the subscription.
6247 * @param reason the reason the allowed network type change is taking place
6248 * @param allowedNetworkTypes the allowed network types.
6249 * @return true on success; false on any failure.
6250 */
6251 @Override
6252 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006253 @TelephonyManager.AllowedNetworkTypesReason int reason,
6254 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006255 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6256 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006257 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6258 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6259 return false;
6260 }
6261
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006262 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6263 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6264
6265
6266 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6267 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6268 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006269 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006270
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006271 final long identity = Binder.clearCallingIdentity();
6272 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006273 Boolean success = (Boolean) sendRequest(
6274 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6275 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6276
6277 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6278 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006279 } finally {
6280 Binder.restoreCallingIdentity(identity);
6281 }
6282 }
6283
6284 /**
Miaoa84611c2019-03-15 09:21:10 +08006285 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006286 *
Miaoa84611c2019-03-15 09:21:10 +08006287 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006288 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006289 * @hide
6290 */
6291 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006292 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006293 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006295 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 try {
Miaoa84611c2019-03-15 09:21:10 +08006297 if (phone != null) {
6298 return phone.hasMatchedTetherApnSetting();
6299 } else {
6300 return false;
6301 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006302 } finally {
6303 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006304 }
Junda Liu475951f2014-11-07 16:45:03 -08006305 }
6306
6307 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006308 * Enable or disable always reporting signal strength changes from radio.
6309 *
6310 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6311 */
6312 @Override
6313 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6314 enforceModifyPermission();
6315 enforceSystemCaller();
6316
6317 final long identity = Binder.clearCallingIdentity();
6318 final Phone phone = getPhone(subId);
6319 try {
6320 if (phone != null) {
6321 if (DBG) {
6322 log("setAlwaysReportSignalStrength: subId=" + subId
6323 + " isEnable=" + isEnable);
6324 }
6325 phone.setAlwaysReportSignalStrength(isEnable);
6326 } else {
6327 loge("setAlwaysReportSignalStrength: no phone found for subId="
6328 + subId);
6329 }
6330 } finally {
6331 Binder.restoreCallingIdentity(identity);
6332 }
6333 }
6334
6335 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006336 * Get the user enabled state of Mobile Data.
6337 *
6338 * TODO: remove and use isUserDataEnabled.
6339 * This can't be removed now because some vendor codes
6340 * calls through ITelephony directly while they should
6341 * use TelephonyManager.
6342 *
6343 * @return true on enabled
6344 */
6345 @Override
6346 public boolean getDataEnabled(int subId) {
6347 return isUserDataEnabled(subId);
6348 }
6349
6350 /**
6351 * Get whether mobile data is enabled per user setting.
6352 *
6353 * There are other factors deciding whether mobile data is actually enabled, but they are
6354 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006355 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006356 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006357 *
6358 * @return {@code true} if data is enabled else {@code false}
6359 */
6360 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006361 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006362 try {
6363 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6364 null);
6365 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6367 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006368 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369
6370 final long identity = Binder.clearCallingIdentity();
6371 try {
6372 int phoneId = mSubscriptionController.getPhoneId(subId);
6373 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6374 Phone phone = PhoneFactory.getPhone(phoneId);
6375 if (phone != null) {
6376 boolean retVal = phone.isUserDataEnabled();
6377 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6378 return retVal;
6379 } else {
6380 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6381 return false;
6382 }
6383 } finally {
6384 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006385 }
6386 }
6387
6388 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006389 * Checks if the device is capable of mobile data by considering whether whether the
6390 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6391 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006392 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006393 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006394 */
6395 @Override
6396 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006397 try {
6398 try {
6399 mApp.enforceCallingOrSelfPermission(
6400 android.Manifest.permission.ACCESS_NETWORK_STATE,
6401 null);
6402 } catch (Exception e) {
6403 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6404 "isDataEnabled");
6405 }
6406 } catch (Exception e) {
6407 enforceReadPrivilegedPermission("isDataEnabled");
6408 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 int phoneId = mSubscriptionController.getPhoneId(subId);
6413 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6414 Phone phone = PhoneFactory.getPhone(phoneId);
6415 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006416 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6418 return retVal;
6419 } else {
6420 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6421 return false;
6422 }
6423 } finally {
6424 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006425 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006426 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006427
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006428 /**
6429 * Check if data is enabled for a specific reason
6430 * @param subId Subscription index
6431 * @param reason the reason the data enable change is taking place
6432 * @return {@code true} if the overall data is enabled; {@code false} if not.
6433 */
6434 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006435 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006436 @TelephonyManager.DataEnabledReason int reason) {
6437 try {
6438 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6439 null);
6440 } catch (Exception e) {
6441 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006442 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006443 }
6444
6445
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 int phoneId = mSubscriptionController.getPhoneId(subId);
6449 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006450 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006451 + " reason=" + reason);
6452 }
6453 Phone phone = PhoneFactory.getPhone(phoneId);
6454 if (phone != null) {
6455 boolean retVal;
6456 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6457 retVal = phone.isUserDataEnabled();
6458 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006459 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006460 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006461 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006462 return retVal;
6463 } else {
6464 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006465 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006466 + subId + " retVal=false");
6467 }
6468 return false;
6469 }
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
6473 }
6474
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006475 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006476 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006477 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6478 // Skip the check if it's one of these special uids
6479 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6480 }
6481
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006482 //load access rules from carrier configs, and check those as well: b/139133814
6483 SubscriptionController subController = SubscriptionController.getInstance();
6484 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6485 || subController == null) return privilegeFromSim;
6486
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006487 PackageManager pkgMgr = phone.getContext().getPackageManager();
6488 String[] packages = pkgMgr.getPackagesForUid(uid);
6489
6490 final long identity = Binder.clearCallingIdentity();
6491 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006492 int subId = phone.getSubId();
6493 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6494 // A test override is in place for the privileges for this subId, so don't try to
6495 // read the subscription privileges.
6496 return privilegeFromSim;
6497 }
6498 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006499 SubscriptionManager subManager = (SubscriptionManager)
6500 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6501 for (String pkg : packages) {
6502 if (subManager.canManageSubscription(subInfo, pkg)) {
6503 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6504 }
6505 }
6506 return privilegeFromSim;
6507 } finally {
6508 Binder.restoreCallingIdentity(identity);
6509 }
6510 }
6511
6512 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6513 String pkgName) {
6514 //load access rules from carrier configs, and check those as well: b/139133814
6515 SubscriptionController subController = SubscriptionController.getInstance();
6516 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6517 || subController == null) return privilegeFromSim;
6518
6519 final long identity = Binder.clearCallingIdentity();
6520 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006521 int subId = phone.getSubId();
6522 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6523 // A test override is in place for the privileges for this subId, so don't try to
6524 // read the subscription privileges.
6525 return privilegeFromSim;
6526 }
6527 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006528 SubscriptionManager subManager = (SubscriptionManager)
6529 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6530 return subManager.canManageSubscription(subInfo, pkgName)
6531 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
6535 }
6536
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006537 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006538 public int getCarrierPrivilegeStatus(int subId) {
6539 final Phone phone = getPhone(subId);
6540 if (phone == null) {
6541 loge("getCarrierPrivilegeStatus: Invalid subId");
6542 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6543 }
6544 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006545 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006546 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006547 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6548 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006549
6550 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6551 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006552 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006553 }
Junda Liu29340342014-07-10 15:23:27 -07006554
6555 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006556 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006557 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006558 final Phone phone = getPhone(subId);
6559 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006560 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006561 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6562 }
6563 UiccProfile profile =
6564 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6565 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006566 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006567 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6568 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006569 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006570 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006571 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006572 }
6573
6574 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006575 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6576 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006577 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006578 }
6579
6580 int phoneId = SubscriptionManager.getPhoneId(subId);
6581 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006582 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006583 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006584 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6585 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006586 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6587 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6588 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006589 }
6590
6591 @Override
6592 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006593 if (TextUtils.isEmpty(pkgName))
6594 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006595 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6596 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6597 UiccCard card = UiccController.getInstance().getUiccCard(i);
6598 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006599 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006600 continue;
6601 }
6602
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006603 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6604 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6605 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006606 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6607 break;
6608 }
6609 }
6610
6611 return result;
Junda Liu29340342014-07-10 15:23:27 -07006612 }
Derek Tan89e89d42014-07-08 17:00:10 -07006613
6614 @Override
Junda Liue64de782015-04-16 17:19:16 -07006615 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6616 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6617 loge("phoneId " + phoneId + " is not valid.");
6618 return null;
6619 }
6620 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006621 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006622 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006623 return null ;
6624 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006625 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006626 }
6627
Amith Yamasani6e118872016-02-19 12:53:51 -08006628 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006629 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006630 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006631 List<String> privilegedPackages = new ArrayList<>();
6632 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006633 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6634 // has UICC in that slot.
6635 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006636 if (card.hasCarrierPrivilegeRules()) {
6637 if (packages == null) {
6638 // Only check packages in user 0 for now
6639 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006640 PackageManager.MATCH_DISABLED_COMPONENTS
6641 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006642 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006643 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006644 }
6645 for (int p = packages.size() - 1; p >= 0; p--) {
6646 PackageInfo pkgInfo = packages.get(p);
6647 if (pkgInfo != null && pkgInfo.packageName != null
6648 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006649 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006650 privilegedPackages.add(pkgInfo.packageName);
6651 }
6652 }
6653 }
6654 }
6655 return privilegedPackages;
6656 }
6657
chen xuf7e9fe82019-05-09 19:31:02 -07006658 @Override
6659 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006660 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6661
6662 final long identity = Binder.clearCallingIdentity();
6663
chen xuf7e9fe82019-05-09 19:31:02 -07006664 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006665 try {
6666 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6667 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6668 }
6669 } finally {
6670 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006671 }
6672 return privilegedPackages;
6673 }
6674
Wink Savilleb564aae2014-10-23 10:18:09 -07006675 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006676 final Phone phone = getPhone(subId);
6677 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006678 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006679 return null;
6680 }
6681 String iccId = card.getIccId();
6682 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006683 return null;
6684 }
6685 return iccId;
6686 }
6687
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006688 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006689 public void setCallComposerStatus(int subId, int status) {
6690 enforceModifyPermission();
6691
6692 final long identity = Binder.clearCallingIdentity();
6693 try {
6694 Phone phone = getPhone(subId);
6695 if (phone != null) {
6696 Phone defaultPhone = phone.getImsPhone();
6697 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6698 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6699 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006700 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6701 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006702 }
6703 }
Shuo Qian284ae752020-12-22 19:10:14 -08006704 } catch (ImsException e) {
6705 throw new ServiceSpecificException(e.getCode());
6706 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006707 Binder.restoreCallingIdentity(identity);
6708 }
6709 }
6710
6711 @Override
6712 public int getCallComposerStatus(int subId) {
6713 enforceReadPrivilegedPermission("getCallComposerStatus");
6714
6715 final long identity = Binder.clearCallingIdentity();
6716 try {
6717 Phone phone = getPhone(subId);
6718 if (phone != null) {
6719 Phone defaultPhone = phone.getImsPhone();
6720 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6721 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6722 return imsPhone.getCallComposerStatus();
6723 }
6724 }
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
6728 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6729 }
6730
6731 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006732 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6733 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006734 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006735 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737 final long identity = Binder.clearCallingIdentity();
6738 try {
6739 final String iccId = getIccId(subId);
6740 final Phone phone = getPhone(subId);
6741 if (phone == null) {
6742 return false;
6743 }
6744 final String subscriberId = phone.getSubscriberId();
6745
6746 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006747 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748 + subscriberId + " to " + number);
6749 }
6750
6751 if (TextUtils.isEmpty(iccId)) {
6752 return false;
6753 }
6754
6755 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6756
6757 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6758 if (alphaTag == null) {
6759 editor.remove(alphaTagPrefKey);
6760 } else {
6761 editor.putString(alphaTagPrefKey, alphaTag);
6762 }
6763
6764 // Record both the line number and IMSI for this ICCID, since we need to
6765 // track all merged IMSIs based on line number
6766 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6767 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6768 if (number == null) {
6769 editor.remove(numberPrefKey);
6770 editor.remove(subscriberPrefKey);
6771 } else {
6772 editor.putString(numberPrefKey, number);
6773 editor.putString(subscriberPrefKey, subscriberId);
6774 }
6775
6776 editor.commit();
6777 return true;
6778 } finally {
6779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006780 }
Derek Tan7226c842014-07-02 17:42:23 -07006781 }
6782
6783 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006784 public String getLine1NumberForDisplay(int subId, String callingPackage,
6785 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006786 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006788 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006789 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006790 return null;
6791 }
Derek Tan97ebb422014-09-05 16:55:38 -07006792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793 final long identity = Binder.clearCallingIdentity();
6794 try {
6795 String iccId = getIccId(subId);
6796 if (iccId != null) {
6797 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6798 if (DBG_MERGE) {
6799 log("getLine1NumberForDisplay returning "
6800 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6801 }
6802 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006803 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006804 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6805 return null;
6806 } finally {
6807 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006808 }
Derek Tan7226c842014-07-02 17:42:23 -07006809 }
6810
6811 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006812 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6813 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006815 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006816 return null;
6817 }
Derek Tan97ebb422014-09-05 16:55:38 -07006818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006819 final long identity = Binder.clearCallingIdentity();
6820 try {
6821 String iccId = getIccId(subId);
6822 if (iccId != null) {
6823 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6824 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6825 }
6826 return null;
6827 } finally {
6828 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006829 }
Derek Tan7226c842014-07-02 17:42:23 -07006830 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006831
6832 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006833 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6834 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006835 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6836 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006838 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006839 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006840 return null;
6841 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006842
Jordan Liub49b04b2019-05-06 14:45:15 -07006843 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6844 // the process, where TelephonyManager was instantiated.
6845 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006846 final long identity = Binder.clearCallingIdentity();
6847 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006848 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006849 final TelephonyManager tele = TelephonyManager.from(context);
6850 final SubscriptionManager sub = SubscriptionManager.from(context);
6851
6852 // Figure out what subscribers are currently active
6853 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854
Jordan Liub49b04b2019-05-06 14:45:15 -07006855 // Only consider subs which match the current subId
6856 // This logic can be simplified. See b/131189269 for progress.
6857 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006858 activeSubscriberIds.add(tele.getSubscriberId(subId));
6859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006860
6861 // First pass, find a number override for an active subscriber
6862 String mergeNumber = null;
6863 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6864 for (String key : prefs.keySet()) {
6865 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6866 final String subscriberId = (String) prefs.get(key);
6867 if (activeSubscriberIds.contains(subscriberId)) {
6868 final String iccId = key.substring(
6869 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6870 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6871 mergeNumber = (String) prefs.get(numberKey);
6872 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006873 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 + " for active subscriber " + subscriberId);
6875 }
6876 if (!TextUtils.isEmpty(mergeNumber)) {
6877 break;
6878 }
6879 }
6880 }
6881 }
6882
6883 // Shortcut when no active merged subscribers
6884 if (TextUtils.isEmpty(mergeNumber)) {
6885 return null;
6886 }
6887
6888 // Second pass, find all subscribers under that line override
6889 final ArraySet<String> result = new ArraySet<>();
6890 for (String key : prefs.keySet()) {
6891 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6892 final String number = (String) prefs.get(key);
6893 if (mergeNumber.equals(number)) {
6894 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6895 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6896 final String subscriberId = (String) prefs.get(subscriberKey);
6897 if (!TextUtils.isEmpty(subscriberId)) {
6898 result.add(subscriberId);
6899 }
6900 }
6901 }
6902 }
6903
6904 final String[] resultArray = result.toArray(new String[result.size()]);
6905 Arrays.sort(resultArray);
6906 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006907 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6909 }
6910 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006911 } finally {
6912 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006913 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006914 }
6915
6916 @Override
zoey chen38003472019-12-13 17:16:31 +08006917 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6918 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006919
6920 final long identity = Binder.clearCallingIdentity();
6921 try {
6922 final TelephonyManager telephonyManager = mApp.getSystemService(
6923 TelephonyManager.class);
6924 String subscriberId = telephonyManager.getSubscriberId(subId);
6925 if (subscriberId == null) {
6926 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006927 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006928 + subId);
6929 }
6930 return null;
6931 }
6932
6933 final SubscriptionInfo info = SubscriptionController.getInstance()
6934 .getSubscriptionInfo(subId);
6935 final ParcelUuid groupUuid = info.getGroupUuid();
6936 // If it doesn't belong to any group, return just subscriberId of itself.
6937 if (groupUuid == null) {
6938 return new String[]{subscriberId};
6939 }
6940
6941 // Get all subscriberIds from the group.
6942 final List<String> mergedSubscriberIds = new ArrayList<>();
6943 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006944 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006945 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006946 for (SubscriptionInfo subInfo : groupInfos) {
6947 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6948 if (subscriberId != null) {
6949 mergedSubscriberIds.add(subscriberId);
6950 }
6951 }
6952
6953 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6954 } finally {
6955 Binder.restoreCallingIdentity(identity);
6956
6957 }
6958 }
6959
6960 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006961 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006962 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006963 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964
6965 final long identity = Binder.clearCallingIdentity();
6966 try {
6967 final Phone phone = getPhone(subId);
6968 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6969 } finally {
6970 Binder.restoreCallingIdentity(identity);
6971 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006972 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006973
6974 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006975 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006976 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6977 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006978 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6979 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980
6981 final long identity = Binder.clearCallingIdentity();
6982 try {
6983 final Phone phone = getPhone(subId);
6984 if (phone == null) {
6985 return false;
6986 }
6987 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6988 cdmaNonRoamingList);
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006991 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006992 }
6993
6994 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006995 @Deprecated
6996 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6997 enforceModifyPermission();
6998
6999 int returnValue = 0;
7000 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007001 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007002 if(result.exception == null) {
7003 if (result.result != null) {
7004 byte[] responseData = (byte[])(result.result);
7005 if(responseData.length > oemResp.length) {
7006 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7007 responseData.length + "bytes. Buffer Size is " +
7008 oemResp.length + "bytes.");
7009 }
7010 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7011 returnValue = responseData.length;
7012 }
7013 } else {
7014 CommandException ex = (CommandException) result.exception;
7015 returnValue = ex.getCommandError().ordinal();
7016 if(returnValue > 0) returnValue *= -1;
7017 }
7018 } catch (RuntimeException e) {
7019 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7020 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7021 if(returnValue > 0) returnValue *= -1;
7022 }
7023
7024 return returnValue;
7025 }
7026
7027 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007028 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007029 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007030 try {
7031 TelephonyPermissions
7032 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7033 mApp, phone.getSubId(), "getRadioAccessFamily");
7034 } catch (SecurityException e) {
7035 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7036 throw e;
7037 }
chen xub97461a2018-10-26 14:17:57 -07007038 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007039 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007040 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007041 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 final long identity = Binder.clearCallingIdentity();
7043 try {
chen xub97461a2018-10-26 14:17:57 -07007044 TelephonyPermissions
7045 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7046 mApp, phone.getSubId(), "getRadioAccessFamily");
7047 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 } finally {
7049 Binder.restoreCallingIdentity(identity);
7050 }
chen xub97461a2018-10-26 14:17:57 -07007051 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007052 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007053
7054 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007055 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007056 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007057 try {
7058 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7059 Binder.getCallingUid())) {
7060 throw new SecurityException("Package uid and package name do not match: "
7061 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7062 }
7063 } catch (PackageManager.NameNotFoundException e) {
7064 throw new SecurityException("Package name invalid:" + callingPackage);
7065 }
7066 RoleManager rm = mApp.getSystemService(RoleManager.class);
7067 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7068 if (!dialerRoleHolders.contains(callingPackage)) {
7069 throw new SecurityException("App must be the dialer role holder to"
7070 + " upload a call composer pic");
7071 }
7072
7073 Executors.newSingleThreadExecutor().execute(() -> {
7074 ByteArrayOutputStream output = new ByteArrayOutputStream(
7075 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7076 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7077 boolean readUntilEnd = false;
7078 int totalBytesRead = 0;
7079 byte[] buffer = new byte[16 * 1024];
7080 while (true) {
7081 int numRead;
7082 try {
7083 numRead = input.read(buffer);
7084 } catch (IOException e) {
7085 try {
7086 fd.checkError();
7087 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7088 null);
7089 } catch (IOException e1) {
7090 // This means that the other side closed explicitly with an error. If this
7091 // happens, log and ignore.
7092 loge("Remote end of call composer picture pipe closed: " + e1);
7093 }
7094 break;
7095 }
7096 if (numRead == -1) {
7097 readUntilEnd = true;
7098 break;
7099 }
7100 totalBytesRead += numRead;
7101 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7102 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7103 try {
7104 input.close();
7105 } catch (IOException e) {
7106 // ignore
7107 }
7108 break;
7109 }
7110 output.write(buffer, 0, numRead);
7111 }
7112 // Generally, the remote end will close the file descriptors. The only case where we
7113 // close is above, where the picture size is too big.
7114
7115 try {
7116 fd.checkError();
7117 } catch (IOException e) {
7118 loge("Remote end for call composer closed with an error: " + e);
7119 return;
7120 }
7121
Hall Liuaa4211e2021-01-20 15:43:39 -08007122 if (!readUntilEnd) {
7123 loge("Did not finish reading entire image; aborting");
7124 return;
7125 }
Hall Liu82694d52020-12-11 18:22:04 -08007126
Hall Liuaa4211e2021-01-20 15:43:39 -08007127 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7128 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7129 new CallComposerPictureTransfer.Factory() {},
7130 imageData,
7131 (result) -> {
7132 if (result.first != null) {
7133 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7134 Bundle outputResult = new Bundle();
7135 outputResult.putParcelable(
7136 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7137 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7138 outputResult);
7139 } else {
7140 callback.send(result.second, null);
7141 }
7142 }
7143 );
Hall Liu82694d52020-12-11 18:22:04 -08007144 });
7145 }
7146
7147 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007148 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007149 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007150 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007154 ImsManager.getInstance(defaultPhone.getContext(),
7155 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156 } finally {
7157 Binder.restoreCallingIdentity(identity);
7158 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007159 }
7160
7161 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007162 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007163 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7165 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007166 return false;
7167 }
Svet Ganovb320e182015-04-16 12:30:10 -07007168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 // Check the user preference and the system-level IMS setting. Even if the user has
7172 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7173 // In the long run, we may instead need to check if there exists a connection service
7174 // which can support video calling.
7175 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007176 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177 return imsManager.isVtEnabledByPlatform()
7178 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7179 && imsManager.isVtEnabledByUser();
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007183 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007184
Andrew Leea1239f22015-03-02 17:44:07 -08007185 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007186 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7187 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007189 mApp, subId, callingPackage, callingFeatureId,
7190 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 return false;
7192 }
7193
7194 final long identity = Binder.clearCallingIdentity();
7195 try {
7196 CarrierConfigManager configManager =
7197 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007198 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7200 } finally {
7201 Binder.restoreCallingIdentity(identity);
7202 }
Andrew Leea1239f22015-03-02 17:44:07 -08007203 }
7204
7205 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007206 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007208 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 return false;
7210 }
7211
7212 final long identity = Binder.clearCallingIdentity();
7213 try {
7214 CarrierConfigManager configManager =
7215 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007216 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
Andrew Leea1239f22015-03-02 17:44:07 -08007221 }
7222
Andrew Lee9431b832015-03-09 18:46:45 -07007223 @Override
7224 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007225 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007226 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007227 }
7228
7229 @Override
7230 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007231 final long identity = Binder.clearCallingIdentity();
7232 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007233 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234 } finally {
7235 Binder.restoreCallingIdentity(identity);
7236 }
Andrew Lee9431b832015-03-09 18:46:45 -07007237 }
7238
Hall Liuf6668912018-10-31 17:05:23 -07007239 /**
7240 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7241 * support for the feature and device firmware support.
7242 *
7243 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7244 */
7245 @Override
7246 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007248 final Phone phone = getPhone(subscriptionId);
7249 if (phone == null) {
7250 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7251 return false;
7252 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007254 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007255 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7256 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007257 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007258 return isCarrierSupported && isDeviceSupported;
7259 } finally {
7260 Binder.restoreCallingIdentity(identity);
7261 }
Hall Liu98187582018-01-22 19:15:32 -08007262 }
7263
Hall Liuf6668912018-10-31 17:05:23 -07007264 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007265 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7266 * RTT setting, will return true if the device and carrier both support RTT.
7267 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007268 */
7269 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270 final long identity = Binder.clearCallingIdentity();
7271 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007272 boolean isRttSupported = isRttSupported(subscriptionId);
7273 boolean isUserRttSettingOn = Settings.Secure.getInt(
7274 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7275 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7276 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7277 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 } finally {
7279 Binder.restoreCallingIdentity(identity);
7280 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007281 }
7282
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007283 @Deprecated
7284 @Override
7285 public String getDeviceId(String callingPackage) {
7286 return getDeviceIdWithFeature(callingPackage, null);
7287 }
7288
Sanket Padawe7310cc72015-01-14 09:53:20 -08007289 /**
7290 * Returns the unique device ID of phone, for example, the IMEI for
7291 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7292 *
7293 * <p>Requires Permission:
7294 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7295 */
7296 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007297 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007298 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007299 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007300 return null;
7301 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007302 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007303 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007304 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007305 return null;
7306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307
7308 final long identity = Binder.clearCallingIdentity();
7309 try {
7310 return phone.getDeviceId();
7311 } finally {
7312 Binder.restoreCallingIdentity(identity);
7313 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007314 }
7315
Ping Sunc67b7c22016-03-02 19:16:45 +08007316 /**
7317 * {@hide}
7318 * Returns the IMS Registration Status on a particular subid
7319 *
7320 * @param subId
7321 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007322 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007323 Phone phone = getPhone(subId);
7324 if (phone != null) {
7325 return phone.isImsRegistered();
7326 } else {
7327 return false;
7328 }
7329 }
7330
Santos Cordon7a1885b2015-02-03 11:15:19 -08007331 @Override
7332 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007339 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007340
Tyler Gunnf70ed162019-04-03 15:28:53 -07007341 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007342 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007343 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007345 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007346 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7347 }
7348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7351 } finally {
7352 Binder.restoreCallingIdentity(identity);
7353 }
7354 }
7355
7356 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007357 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007358 TelephonyPermissions
7359 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7360 mApp,
7361 subscriptionId,
7362 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007363 final long identity = Binder.clearCallingIdentity();
7364 try {
7365 Phone phone = getPhone(subscriptionId);
7366 if (phone == null) {
7367 return null;
7368 }
7369 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7370 } finally {
7371 Binder.restoreCallingIdentity(identity);
7372 }
7373 }
7374
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007375 /**
7376 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007377 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007378 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 Phone phone = getPhone(subId);
7382 if (phone != null) {
7383 return phone.isWifiCallingEnabled();
7384 } else {
7385 return false;
7386 }
7387 } finally {
7388 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007389 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007390 }
7391
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007392 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007393 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007394 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007395 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007396 final long identity = Binder.clearCallingIdentity();
7397 try {
7398 Phone phone = getPhone(subId);
7399 if (phone != null) {
7400 return phone.isVideoEnabled();
7401 } else {
7402 return false;
7403 }
7404 } finally {
7405 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007406 }
7407 }
7408
7409 /**
7410 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7411 * defined in {@link ImsRegistrationImplBase}.
7412 */
7413 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414 final long identity = Binder.clearCallingIdentity();
7415 try {
7416 Phone phone = getPhone(subId);
7417 if (phone != null) {
7418 return phone.getImsRegistrationTech();
7419 } else {
7420 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7421 }
7422 } finally {
7423 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007424 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007425 }
7426
Stuart Scott8eef64f2015-04-08 15:13:54 -07007427 @Override
7428 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007429 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007430 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7431 return;
7432 }
7433
Svet Ganovcc087f82015-05-12 20:35:54 -07007434 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007435
Svet Ganovcc087f82015-05-12 20:35:54 -07007436 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007437 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7438 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007439 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007440 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007441 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007442 Phone phone = getPhone(subId);
7443 if (phone != null) {
7444 SubscriptionManager.setSubscriptionProperty(subId,
7445 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7446 "user=" + RadioAccessFamily.getRafFromNetworkType(
7447 RILConstants.PREFERRED_NETWORK_MODE));
7448 phone.loadAllowedNetworksFromSubscriptionDatabase();
7449 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007450 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7451 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007452 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007453 // There has been issues when Sms raw table somehow stores orphan
7454 // fragments. They lead to garbled message when new fragments come
7455 // in and combined with those stale ones. In case this happens again,
7456 // user can reset all network settings which will clean up this table.
7457 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007458 // Clean up IMS settings as well here.
7459 int slotId = getSlotIndex(subId);
7460 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7461 ImsManager.getInstance(mApp, slotId).factoryReset();
7462 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007463
7464 // Erase modem config if erase modem on network setting is enabled.
7465 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7466 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7467 if (configValue != null && Boolean.parseBoolean(configValue)) {
7468 sendEraseModemConfig(getDefaultPhone());
7469 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007470 } finally {
7471 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007472 }
7473 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007474
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007475 private void cleanUpSmsRawTable(Context context) {
7476 ContentResolver resolver = context.getContentResolver();
7477 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7478 resolver.delete(uri, null, null);
7479 }
7480
Narayan Kamath1c496c22015-04-16 14:40:19 +01007481 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007482 public String getSimLocaleForSubscriber(int subId) {
7483 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7484 final Phone phone = getPhone(subId);
7485 if (phone == null) {
7486 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007487 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489 final long identity = Binder.clearCallingIdentity();
7490 try {
chen xu5d3637b2019-01-21 23:31:38 -08007491 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007492 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007493 if (info == null) {
7494 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7495 return null;
7496 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 // Try and fetch the locale from the carrier properties or from the SIM language
7498 // preferences (EF-PL and EF-LI)...
7499 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007501 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7502 if (localeFromDefaultSim != null) {
7503 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7504 if (DBG) log("Using locale from subId: " + subId + " locale: "
7505 + localeFromDefaultSim);
7506 return localeFromDefaultSim.toLanguageTag();
7507 } else {
7508 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509 }
7510 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007512 // The SIM language preferences only store a language (e.g. fr = French), not an
7513 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7514 // the SIM and carrier preferences does not include a country we add the country
7515 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007516 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007518 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007519 return mccLocale.toLanguageTag();
7520 }
7521
7522 if (DBG) log("No locale found - returning null");
7523 return null;
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007527 }
7528
7529 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007531 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007532 }
7533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 /**
7535 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7536 */
7537 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007538 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007539 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007540 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007541
Chenjie Yu1ba97252018-01-11 18:16:20 -08007542 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007543 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007544
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007545 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007546 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7547 * representing the state of the modem.
7548 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007549 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7550 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007551 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007552 */
7553 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007554 public void requestModemActivityInfo(ResultReceiver result) {
7555 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557
7558 final long identity = Binder.clearCallingIdentity();
7559 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007560 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007561 } finally {
7562 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007563 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007564 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007565
Siddharth Rayb8114062018-06-17 15:02:38 -07007566 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7567 // less than total activity duration.
7568 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7569 if (info == null) {
7570 return false;
7571 }
7572 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007573 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7574 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7575
Siddharth Rayb8114062018-06-17 15:02:38 -07007576 return (info.isValid()
7577 && (info.getSleepTimeMillis() <= activityDurationMs)
7578 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007579 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007580 && (totalTxTimeMs <= activityDurationMs));
7581 }
7582
Jack Yu85bd38a2015-11-09 11:34:32 -08007583 /**
7584 * {@hide}
7585 * Returns the service state information on specified subscription.
7586 */
7587 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007588 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7589 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007591 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007592 return null;
7593 }
7594
Hall Liuf19c44f2018-11-27 14:38:17 -08007595 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7596 LocationAccessPolicy.checkLocationPermission(mApp,
7597 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7598 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007599 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007600 .setCallingPid(Binder.getCallingPid())
7601 .setCallingUid(Binder.getCallingUid())
7602 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007603 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007604 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007605 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7606 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007607 .build());
7608
7609 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7610 LocationAccessPolicy.checkLocationPermission(mApp,
7611 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7612 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007613 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007614 .setCallingPid(Binder.getCallingPid())
7615 .setCallingUid(Binder.getCallingUid())
7616 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007617 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007618 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007619 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7620 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007621 .build());
7622 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7623 boolean hasFinePermission =
7624 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7625 boolean hasCoarsePermission =
7626 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7627
Jack Yu479f40e2020-10-27 21:29:25 -07007628 final Phone phone = getPhone(subId);
7629 if (phone == null) {
7630 return null;
7631 }
7632
Jordan Liu0f2bc442020-11-18 16:47:37 -08007633 final long identity = Binder.clearCallingIdentity();
7634
Jack Yu479f40e2020-10-27 21:29:25 -07007635 boolean isCallingPackageDataService = phone.getDataServicePackages()
7636 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007638 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7639 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7640 Rlog.d(LOG_TAG,
7641 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7642 return null;
7643 }
7644
Hall Liuf19c44f2018-11-27 14:38:17 -08007645 ServiceState ss = phone.getServiceState();
7646
7647 // Scrub out the location info in ServiceState depending on what level of access
7648 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007649 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007650 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7651 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007655 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007656
7657 /**
7658 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7659 *
7660 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7661 * voicemail ringtone.
7662 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7663 * PhoneAccount.
7664 */
7665 @Override
7666 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 final long identity = Binder.clearCallingIdentity();
7668 try {
7669 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7670 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007671 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007672 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7675 } finally {
7676 Binder.restoreCallingIdentity(identity);
7677 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007678 }
7679
7680 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007681 * Sets the per-account voicemail ringtone.
7682 *
7683 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7684 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7685 *
7686 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7687 * voicemail ringtone.
7688 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7689 * PhoneAccount.
7690 */
7691 @Override
7692 public void setVoicemailRingtoneUri(String callingPackage,
7693 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007694 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007695 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007696 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7697 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7699 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7700 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007702
7703 final long identity = Binder.clearCallingIdentity();
7704 try {
7705 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7706 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007707 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 }
7709 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7710 } finally {
7711 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007712 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007713 }
7714
7715 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007716 * Returns whether vibration is set for voicemail notification in Phone settings.
7717 *
7718 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7719 * voicemail vibration setting.
7720 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7721 */
7722 @Override
7723 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007724 final long identity = Binder.clearCallingIdentity();
7725 try {
7726 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7727 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007728 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7732 } finally {
7733 Binder.restoreCallingIdentity(identity);
7734 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007735 }
7736
Youhan Wange64578a2016-05-02 15:32:42 -07007737 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007738 * Sets the per-account voicemail vibration.
7739 *
7740 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7741 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7742 *
7743 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7744 * voicemail vibration setting.
7745 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7746 * specific PhoneAccount.
7747 */
7748 @Override
7749 public void setVoicemailVibrationEnabled(String callingPackage,
7750 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007751 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007753 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7754 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7756 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7757 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007758 }
7759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 final long identity = Binder.clearCallingIdentity();
7761 try {
7762 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7763 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007764 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 }
7766 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7767 } finally {
7768 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007769 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007770 }
7771
7772 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007773 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7774 *
7775 * @throws SecurityException if the caller does not have the required permission
7776 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007777 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007778 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007779 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007780 }
7781
7782 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007783 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7784 * permission.
7785 *
7786 * @throws SecurityException if the caller does not have the required permission
7787 */
7788 private void enforceSendSmsPermission() {
7789 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7790 }
7791
7792 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007793 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007794 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007795 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007796 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007797 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007798 final long identity = Binder.clearCallingIdentity();
7799 try {
7800 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007801 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802 if (componentName == null) {
7803 throw new SecurityException(
7804 "Caller not current active visual voicemail package[null]");
7805 }
7806 String vvmPackage = componentName.getPackageName();
7807 if (!callingPackage.equals(vvmPackage)) {
7808 throw new SecurityException("Caller not current active visual voicemail package["
7809 + vvmPackage + "]");
7810 }
7811 } finally {
7812 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007813 }
7814 }
7815
7816 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007817 * Return the application ID for the app type.
7818 *
7819 * @param subId the subscription ID that this request applies to.
7820 * @param appType the uicc app type.
7821 * @return Application ID for specificied app type, or null if no uicc.
7822 */
7823 @Override
7824 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007825 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007826 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007827
7828 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007829 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007830 if (phone == null) {
7831 return null;
7832 }
7833 String aid = null;
7834 try {
7835 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7836 .getApplicationByType(appType).getAid();
7837 } catch (Exception e) {
7838 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7839 }
7840 return aid;
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007843 }
Youhan Wange64578a2016-05-02 15:32:42 -07007844 }
7845
Youhan Wang4001d252016-05-11 10:29:41 -07007846 /**
7847 * Return the Electronic Serial Number.
7848 *
7849 * @param subId the subscription ID that this request applies to.
7850 * @return ESN or null if error.
7851 */
7852 @Override
7853 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007854 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007855 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007856
7857 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007858 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007859 if (phone == null) {
7860 return null;
7861 }
7862 String esn = null;
7863 try {
7864 esn = phone.getEsn();
7865 } catch (Exception e) {
7866 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7867 }
7868 return esn;
7869 } finally {
7870 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007871 }
Youhan Wang4001d252016-05-11 10:29:41 -07007872 }
7873
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007874 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007875 * Return the Preferred Roaming List Version.
7876 *
7877 * @param subId the subscription ID that this request applies to.
7878 * @return PRLVersion or null if error.
7879 */
7880 @Override
7881 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007882 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007883 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007884
7885 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007886 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887 if (phone == null) {
7888 return null;
7889 }
7890 String cdmaPrlVersion = null;
7891 try {
7892 cdmaPrlVersion = phone.getCdmaPrlVersion();
7893 } catch (Exception e) {
7894 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7895 }
7896 return cdmaPrlVersion;
7897 } finally {
7898 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007899 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007900 }
7901
7902 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007903 * Get snapshot of Telephony histograms
7904 * @return List of Telephony histograms
7905 * @hide
7906 */
7907 @Override
7908 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7910 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007911
7912 final long identity = Binder.clearCallingIdentity();
7913 try {
7914 return RIL.getTelephonyRILTimingHistograms();
7915 } finally {
7916 Binder.restoreCallingIdentity(identity);
7917 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007918 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007919
7920 /**
7921 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007922 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7923 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007924 * Require system privileges. In the future we may add this to carrier APIs.
7925 *
Michele Berionne482f8202018-11-27 18:57:59 -08007926 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007927 */
7928 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007929 @TelephonyManager.SetCarrierRestrictionResult
7930 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007931 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007932 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007933
Michele Berionne482f8202018-11-27 18:57:59 -08007934 if (carrierRestrictionRules == null) {
7935 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007936 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007937
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007938 final long identity = Binder.clearCallingIdentity();
7939 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007940 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007941 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007942 } finally {
7943 Binder.restoreCallingIdentity(identity);
7944 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007945 }
7946
7947 /**
7948 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007949 * Get the allowed carrier list and the excluded carrier list, including the priority between
7950 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007951 * Require system privileges. In the future we may add this to carrier APIs.
7952 *
Michele Berionne482f8202018-11-27 18:57:59 -08007953 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007954 */
7955 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007956 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007957 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007958 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959
7960 final long identity = Binder.clearCallingIdentity();
7961 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007962 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7963 if (response instanceof CarrierRestrictionRules) {
7964 return (CarrierRestrictionRules) response;
7965 }
7966 // Response is an Exception of some kind,
7967 // which is signalled to the user as a NULL retval
7968 return null;
7969 } catch (Exception e) {
7970 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7971 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007972 } finally {
7973 Binder.restoreCallingIdentity(identity);
7974 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007975 }
7976
fionaxu59545b42016-05-25 15:53:37 -07007977 /**
fionaxu59545b42016-05-25 15:53:37 -07007978 * Action set from carrier signalling broadcast receivers to enable/disable radio
7979 * @param subId the subscription ID that this action applies to.
7980 * @param enabled control enable or disable radio.
7981 * {@hide}
7982 */
7983 @Override
7984 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7985 enforceModifyPermission();
7986 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987
7988 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007989 if (phone == null) {
7990 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7991 return;
7992 }
7993 try {
7994 phone.carrierActionSetRadioEnabled(enabled);
7995 } catch (Exception e) {
7996 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007997 } finally {
7998 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007999 }
8000 }
8001
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008002 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008003 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8004 * network status based on which carrier apps could apply actions accordingly,
8005 * enable/disable default url handler for example.
8006 *
8007 * @param subId the subscription ID that this action applies to.
8008 * @param report control start/stop reporting the default network status.
8009 * {@hide}
8010 */
8011 @Override
8012 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8013 enforceModifyPermission();
8014 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008015
8016 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008017 if (phone == null) {
8018 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8019 return;
8020 }
8021 try {
8022 phone.carrierActionReportDefaultNetworkStatus(report);
8023 } catch (Exception e) {
8024 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008025 } finally {
8026 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008027 }
8028 }
8029
8030 /**
fionaxud9622282017-07-17 17:51:30 -07008031 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8032 * @param subId the subscription ID that this action applies to.
8033 * {@hide}
8034 */
8035 @Override
8036 public void carrierActionResetAll(int subId) {
8037 enforceModifyPermission();
8038 final Phone phone = getPhone(subId);
8039 if (phone == null) {
8040 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8041 return;
8042 }
8043 try {
8044 phone.carrierActionResetAll();
8045 } catch (Exception e) {
8046 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8047 }
8048 }
8049
8050 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008051 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8052 * bug report is being generated.
8053 */
8054 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008055 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008056 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8057 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008058 writer.println("Permission Denial: can't dump Phone from pid="
8059 + Binder.getCallingPid()
8060 + ", uid=" + Binder.getCallingUid()
8061 + "without permission "
8062 + android.Manifest.permission.DUMP);
8063 return;
8064 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008065 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008066 }
Jack Yueb89b242016-06-22 13:27:47 -07008067
Brad Ebingerdac2f002018-04-03 15:17:52 -07008068 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008069 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8070 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8071 @NonNull String[] args) {
8072 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8073 this, in.getFileDescriptor(), out.getFileDescriptor(),
8074 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008075 }
8076
Jack Yueb89b242016-06-22 13:27:47 -07008077 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008078 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008079 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008080 * @param reason the reason the data enable change is taking place
8081 * @param enabled True if enabling the data, otherwise disabling.
8082 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008083 */
8084 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008085 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008086 boolean enabled) {
8087 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8088 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8089 try {
8090 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008091 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008092 } catch (SecurityException se) {
8093 enforceModifyPermission();
8094 }
8095 } else {
8096 enforceModifyPermission();
8097 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008098
8099 final long identity = Binder.clearCallingIdentity();
8100 try {
8101 Phone phone = getPhone(subId);
8102 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008103 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8104 phone.carrierActionSetMeteredApnsEnabled(enabled);
8105 } else {
8106 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008108 }
8109 } finally {
8110 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008111 }
8112 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008113
8114 /**
8115 * Get Client request stats
8116 * @return List of Client Request Stats
8117 * @hide
8118 */
8119 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008120 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8121 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008122 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008123 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008124 return null;
8125 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008126 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008128 final long identity = Binder.clearCallingIdentity();
8129 try {
8130 if (phone != null) {
8131 return phone.getClientRequestStats();
8132 }
8133
8134 return null;
8135 } finally {
8136 Binder.restoreCallingIdentity(identity);
8137 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008138 }
8139
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008140 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008141 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008142 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008143 }
Jack Yueb4124c2017-02-16 15:32:43 -08008144
8145 /**
Grace Chen70990072017-03-24 17:21:30 -07008146 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008147 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008148 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008149 * @param state State of SIM (power down, power up, pass through)
8150 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8151 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8152 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008153 *
8154 **/
8155 @Override
Grace Chen70990072017-03-24 17:21:30 -07008156 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008157 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008158 Phone phone = PhoneFactory.getPhone(slotIndex);
8159
vagdeviaf9a5b92018-08-15 16:01:53 -07008160 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008162 final long identity = Binder.clearCallingIdentity();
8163 try {
8164 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008165 phone.setSimPowerState(state, null, workSource);
8166 }
8167 } finally {
8168 Binder.restoreCallingIdentity(identity);
8169 }
8170 }
8171
8172 /**
8173 * Set SIM card power state.
8174 *
8175 * @param slotIndex SIM slot id.
8176 * @param state State of SIM (power down, power up, pass through)
8177 * @param callback callback to trigger after success or failure
8178 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8179 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8180 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8181 *
8182 **/
8183 @Override
8184 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8185 IIntegerConsumer callback) {
8186 enforceModifyPermission();
8187 Phone phone = PhoneFactory.getPhone(slotIndex);
8188
8189 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8190
8191 final long identity = Binder.clearCallingIdentity();
8192 try {
8193 if (phone != null) {
8194 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8195 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 }
8197 } finally {
8198 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008199 }
8200 }
Shuo Qiandd210312017-04-12 22:11:33 +00008201
Tyler Gunn65d45c22017-06-05 11:22:26 -07008202 private boolean isUssdApiAllowed(int subId) {
8203 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008204 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008205 if (configManager == null) {
8206 return false;
8207 }
8208 PersistableBundle pb = configManager.getConfigForSubId(subId);
8209 if (pb == null) {
8210 return false;
8211 }
8212 return pb.getBoolean(
8213 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8214 }
8215
Shuo Qiandd210312017-04-12 22:11:33 +00008216 /**
8217 * Check if phone is in emergency callback mode
8218 * @return true if phone is in emergency callback mode
8219 * @param subId sub id
8220 */
goneil9c5f4872017-12-05 14:07:56 -08008221 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008222 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008223 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008224 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008225
8226 final long identity = Binder.clearCallingIdentity();
8227 try {
8228 if (phone != null) {
8229 return phone.isInEcm();
8230 } else {
8231 return false;
8232 }
8233 } finally {
8234 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008235 }
8236 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008237
8238 /**
8239 * Get the current signal strength information for the given subscription.
8240 * Because this information is not updated when the device is in a low power state
8241 * it should not be relied-upon to be current.
8242 * @param subId Subscription index
8243 * @return the most recent cached signal strength info from the modem
8244 */
8245 @Override
8246 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008247 final long identity = Binder.clearCallingIdentity();
8248 try {
8249 Phone p = getPhone(subId);
8250 if (p == null) {
8251 return null;
8252 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008254 return p.getSignalStrength();
8255 } finally {
8256 Binder.restoreCallingIdentity(identity);
8257 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008258 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008259
Pengquan Meng77b7f132018-08-22 14:49:57 -07008260 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008261 * Get the current modem radio state for the given slot.
8262 * @param slotIndex slot index.
8263 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008264 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008265 * @return the current radio power state from the modem
8266 */
8267 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008268 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008269 Phone phone = PhoneFactory.getPhone(slotIndex);
8270 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8272 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008273 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8274 }
8275
8276 final long identity = Binder.clearCallingIdentity();
8277 try {
8278 return phone.getRadioPowerState();
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
8282 }
8283 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8284 }
8285
8286 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008287 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8288 *
8289 * <p>Requires one of the following permissions:
8290 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8291 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8292 * privileges.
8293 *
8294 * @param subId subscription id
8295 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8296 * {@code false}.
8297 */
8298 @Override
8299 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008300 try {
8301 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8302 null);
8303 } catch (Exception e) {
8304 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8305 mApp, subId, "isDataRoamingEnabled");
8306 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008307
Pengquan Menga1bb6272018-09-06 09:59:22 -07008308 boolean isEnabled = false;
8309 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008310 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008311 Phone phone = getPhone(subId);
8312 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008313 } finally {
8314 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008315 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008316 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008317 }
8318
8319
8320 /**
8321 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8322 *
8323 * <p> Requires permission:
8324 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8325 * privileges.
8326 *
8327 * @param subId subscription id
8328 * @param isEnabled {@code true} means enable, {@code false} means disable.
8329 */
8330 @Override
8331 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8333 mApp, subId, "setDataRoamingEnabled");
8334
Pengquan Menga1bb6272018-09-06 09:59:22 -07008335 final long identity = Binder.clearCallingIdentity();
8336 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008337 Phone phone = getPhone(subId);
8338 if (phone != null) {
8339 phone.setDataRoamingEnabled(isEnabled);
8340 }
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008343 }
8344 }
8345
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008346 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008347 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008348 TelephonyPermissions
8349 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008350 mApp, subId, "isManualNetworkSelectionAllowed");
8351
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008352 boolean isAllowed = true;
8353 final long identity = Binder.clearCallingIdentity();
8354 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008355 Phone phone = getPhone(subId);
8356 if (phone != null) {
8357 isAllowed = phone.isCspPlmnEnabled();
8358 }
8359 } finally {
8360 Binder.restoreCallingIdentity(identity);
8361 }
8362 return isAllowed;
8363 }
8364
8365 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008366 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008367 // Verify that tha callingPackage belongs to the calling UID
8368 mApp.getSystemService(AppOpsManager.class)
8369 .checkPackage(Binder.getCallingUid(), callingPackage);
8370
Jordan Liu1e142fc2019-04-22 15:10:43 -07008371 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008372 try {
8373 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008374 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008375 } catch (SecurityException e) {
8376 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8377 // has carrier privileges on an active UICC
8378 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8379 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008380 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008381 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008382 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008383
8384 final long identity = Binder.clearCallingIdentity();
8385 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008386 UiccController uiccController = UiccController.getInstance();
8387 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008388 if (hasReadPermission) {
8389 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008390 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008391
8392 // Remove private info if the caller doesn't have access
8393 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8394 for (UiccCardInfo cardInfo : cardInfos) {
8395 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8396 // is available
8397 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8398 if (card == null || card.getUiccProfile() == null) {
8399 // assume no access if the card or profile is unavailable
8400 filteredInfos.add(cardInfo.getUnprivileged());
8401 continue;
8402 }
8403 UiccProfile profile = card.getUiccProfile();
8404 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8405 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8406 filteredInfos.add(cardInfo);
8407 } else {
8408 filteredInfos.add(cardInfo.getUnprivileged());
8409 }
8410 }
8411 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008412 } finally {
8413 Binder.restoreCallingIdentity(identity);
8414 }
8415 }
8416
8417 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008418 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008419 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008421 final long identity = Binder.clearCallingIdentity();
8422 try {
8423 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8424 if (slots == null) {
8425 Rlog.i(LOG_TAG, "slots is null.");
8426 return null;
8427 }
8428
8429 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8430 for (int i = 0; i < slots.length; i++) {
8431 UiccSlot slot = slots[i];
8432 if (slot == null) {
8433 continue;
8434 }
8435
Jordan Liu7be7e652019-05-06 18:55:02 +00008436 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008437 UiccCard card = slot.getUiccCard();
8438 if (card != null) {
8439 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008440 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008441 cardId = slot.getEid();
8442 if (TextUtils.isEmpty(cardId)) {
8443 cardId = slot.getIccId();
8444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008445 }
8446
Jordan Liu857451f2019-05-09 16:35:35 -07008447 if (cardId != null) {
8448 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8449 // if cardId is an EID, it's all digits so this is fine
8450 cardId = IccUtils.stripTrailingFs(cardId);
8451 }
8452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008453 int cardState = 0;
8454 switch (slot.getCardState()) {
8455 case CARDSTATE_ABSENT:
8456 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8457 break;
8458 case CARDSTATE_PRESENT:
8459 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8460 break;
8461 case CARDSTATE_ERROR:
8462 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8463 break;
8464 case CARDSTATE_RESTRICTED:
8465 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8466 break;
8467 default:
8468 break;
8469
8470 }
8471
8472 infos[i] = new UiccSlotInfo(
8473 slot.isActive(),
8474 slot.isEuicc(),
8475 cardId,
8476 cardState,
8477 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008478 slot.isExtendedApduSupported(),
8479 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008480 }
8481 return infos;
8482 } finally {
8483 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008484 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008485 }
8486
8487 @Override
8488 public boolean switchSlots(int[] physicalSlots) {
8489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490
8491 final long identity = Binder.clearCallingIdentity();
8492 try {
8493 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8494 } finally {
8495 Binder.restoreCallingIdentity(identity);
8496 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008497 }
Jack Yu4c988042018-02-27 15:30:01 -08008498
8499 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008500 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008501 final long identity = Binder.clearCallingIdentity();
8502 try {
8503 return UiccController.getInstance().getCardIdForDefaultEuicc();
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
8506 }
8507 }
8508
Pengquan Meng85728fb2018-03-12 16:31:21 -07008509 /**
goneil47ffb6e2018-04-06 15:40:58 -07008510 * A test API to reload the UICC profile.
8511 *
8512 * <p>Requires that the calling app has permission
8513 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8514 * @hide
8515 */
8516 @Override
8517 public void refreshUiccProfile(int subId) {
8518 enforceModifyPermission();
8519
8520 final long identity = Binder.clearCallingIdentity();
8521 try {
8522 Phone phone = getPhone(subId);
8523 if (phone == null) {
8524 return;
8525 }
8526 UiccCard uiccCard = phone.getUiccCard();
8527 if (uiccCard == null) {
8528 return;
8529 }
8530 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8531 if (uiccProfile == null) {
8532 return;
8533 }
8534 uiccProfile.refresh();
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
8538 }
8539
8540 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008541 * Returns false if the mobile data is disabled by default, otherwise return true.
8542 */
8543 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008544 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008545 }
8546
8547 /**
8548 * Returns true if the data roaming is enabled by default, i.e the system property
8549 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8550 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8551 */
8552 private boolean getDefaultDataRoamingEnabled(int subId) {
8553 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008554 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008555 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008556 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8557 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8558 return isDataRoamingEnabled;
8559 }
8560
8561 /**
8562 * Returns the default network type for the given {@code subId}, if the default network type is
8563 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8564 */
8565 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008566 List<Integer> list = TelephonyProperties.default_network();
8567 int phoneId = mSubscriptionController.getPhoneId(subId);
8568 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8569 return list.get(phoneId);
8570 }
8571 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008572 }
fionaxua13278b2018-03-21 00:08:13 -07008573
8574 @Override
8575 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008576 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008577 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008578
8579 final long identity = Binder.clearCallingIdentity();
8580 try {
8581 final Phone phone = getPhone(subId);
8582 if (phone == null) {
8583 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8584 return;
8585 }
chen xueaba88a2019-03-15 13:15:10 -07008586 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8587 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008588 if (carrierPrivilegeRules == null) {
8589 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8590 } else {
8591 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008593 } finally {
8594 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008595 }
fionaxua13278b2018-03-21 00:08:13 -07008596 }
8597
8598 @Override
8599 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008600 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008601
8602 final long identity = Binder.clearCallingIdentity();
8603 try {
8604 final Phone phone = getPhone(subId);
8605 if (phone == null) {
8606 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8607 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8608 }
8609 return phone.getCarrierIdListVersion();
8610 } finally {
8611 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008612 }
fionaxua13278b2018-03-21 00:08:13 -07008613 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008614
8615 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008616 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8617 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008618 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008619 mApp, subId, callingPackage, callingFeatureId,
8620 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008621 return -1;
8622 }
8623
8624 final long identity = Binder.clearCallingIdentity();
8625 try {
8626 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8627 } finally {
8628 Binder.restoreCallingIdentity(identity);
8629 }
8630 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008631
8632 @Override
8633 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008634 TelephonyPermissions
8635 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008636 mApp, subId, "getCdmaRoamingMode");
8637
8638 final long identity = Binder.clearCallingIdentity();
8639 try {
8640 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8641 } finally {
8642 Binder.restoreCallingIdentity(identity);
8643 }
8644 }
8645
8646 @Override
8647 public boolean setCdmaRoamingMode(int subId, int mode) {
8648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8649 mApp, subId, "setCdmaRoamingMode");
8650
8651 final long identity = Binder.clearCallingIdentity();
8652 try {
8653 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8654 } finally {
8655 Binder.restoreCallingIdentity(identity);
8656 }
8657 }
8658
8659 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008660 public int getCdmaSubscriptionMode(int subId) {
8661 TelephonyPermissions
8662 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8663 mApp, subId, "getCdmaSubscriptionMode");
8664
8665 final long identity = Binder.clearCallingIdentity();
8666 try {
8667 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8668 } finally {
8669 Binder.restoreCallingIdentity(identity);
8670 }
8671 }
8672
8673 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008674 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8676 mApp, subId, "setCdmaSubscriptionMode");
8677
8678 final long identity = Binder.clearCallingIdentity();
8679 try {
8680 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8681 } finally {
8682 Binder.restoreCallingIdentity(identity);
8683 }
8684 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008685
sqianc5eccab2018-10-19 18:46:41 -07008686 @Override
sqian8c685422019-02-22 15:55:18 -08008687 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008688 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008690 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8691 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008692 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8693 }
8694 final long identity = Binder.clearCallingIdentity();
8695 try {
sqian854d44b2018-12-12 16:48:18 -08008696 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8697 for (Phone phone: PhoneFactory.getPhones()) {
8698 if (phone.getEmergencyNumberTracker() != null
8699 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8700 emergencyNumberListInternal.put(
8701 phone.getSubId(),
8702 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8703 }
sqian11b7a0e2018-12-05 18:48:28 -08008704 }
sqian854d44b2018-12-12 16:48:18 -08008705 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008706 } finally {
8707 Binder.restoreCallingIdentity(identity);
8708 }
sqianc5eccab2018-10-19 18:46:41 -07008709 }
8710
8711 @Override
sqian8c685422019-02-22 15:55:18 -08008712 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008713 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008714 if (!exactMatch) {
8715 TelephonyPermissions
8716 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008717 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008718 }
8719 final long identity = Binder.clearCallingIdentity();
8720 try {
sqian854d44b2018-12-12 16:48:18 -08008721 for (Phone phone: PhoneFactory.getPhones()) {
8722 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008723 && phone.getEmergencyNumberTracker()
8724 .isEmergencyNumber(number, exactMatch)) {
8725 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008726 }
sqian11b7a0e2018-12-05 18:48:28 -08008727 }
8728 return false;
8729 } finally {
8730 Binder.restoreCallingIdentity(identity);
8731 }
8732 }
8733
sqianf4ca7ed2019-01-15 18:32:07 -08008734 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008735 * Start emergency callback mode for GsmCdmaPhone for testing.
8736 */
8737 @Override
8738 public void startEmergencyCallbackMode() {
8739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8740 "startEmergencyCallbackMode");
8741 enforceModifyPermission();
8742 final long identity = Binder.clearCallingIdentity();
8743 try {
8744 for (Phone phone : PhoneFactory.getPhones()) {
8745 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8746 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8747 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8748 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8749 gsmCdmaPhone.obtainMessage(
8750 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8751 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8752 }
8753 }
8754 } finally {
8755 Binder.restoreCallingIdentity(identity);
8756 }
8757 }
8758
8759 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008760 * Update emergency number list for test mode.
8761 */
8762 @Override
8763 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8764 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8765 "updateEmergencyNumberListTestMode");
8766
8767 final long identity = Binder.clearCallingIdentity();
8768 try {
8769 for (Phone phone: PhoneFactory.getPhones()) {
8770 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8771 if (tracker != null) {
8772 tracker.executeEmergencyNumberTestModeCommand(action, num);
8773 }
8774 }
8775 } finally {
8776 Binder.restoreCallingIdentity(identity);
8777 }
8778 }
8779
8780 /**
8781 * Get the full emergency number list for test mode.
8782 */
8783 @Override
8784 public List<String> getEmergencyNumberListTestMode() {
8785 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8786 "getEmergencyNumberListTestMode");
8787
8788 final long identity = Binder.clearCallingIdentity();
8789 try {
8790 Set<String> emergencyNumbers = new HashSet<>();
8791 for (Phone phone: PhoneFactory.getPhones()) {
8792 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8793 if (tracker != null) {
8794 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8795 emergencyNumbers.add(num.getNumber());
8796 }
8797 }
8798 }
8799 return new ArrayList<>(emergencyNumbers);
8800 } finally {
8801 Binder.restoreCallingIdentity(identity);
8802 }
8803 }
8804
chen xud6b45bd2018-10-30 22:27:10 -07008805 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008806 public int getEmergencyNumberDbVersion(int subId) {
8807 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8808
8809 final long identity = Binder.clearCallingIdentity();
8810 try {
8811 final Phone phone = getPhone(subId);
8812 if (phone == null) {
8813 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8814 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8815 }
8816 return phone.getEmergencyNumberDbVersion();
8817 } finally {
8818 Binder.restoreCallingIdentity(identity);
8819 }
8820 }
8821
8822 @Override
8823 public void notifyOtaEmergencyNumberDbInstalled() {
8824 enforceModifyPermission();
8825
8826 final long identity = Binder.clearCallingIdentity();
8827 try {
8828 for (Phone phone: PhoneFactory.getPhones()) {
8829 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8830 if (tracker != null) {
8831 tracker.updateOtaEmergencyNumberDatabase();
8832 }
8833 }
8834 } finally {
8835 Binder.restoreCallingIdentity(identity);
8836 }
8837 }
8838
8839 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008840 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008841 enforceActiveEmergencySessionPermission();
8842
8843 final long identity = Binder.clearCallingIdentity();
8844 try {
8845 for (Phone phone: PhoneFactory.getPhones()) {
8846 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8847 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008848 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8849 }
8850 }
8851 } finally {
8852 Binder.restoreCallingIdentity(identity);
8853 }
8854 }
8855
8856 @Override
8857 public void resetOtaEmergencyNumberDbFilePath() {
8858 enforceActiveEmergencySessionPermission();
8859
8860 final long identity = Binder.clearCallingIdentity();
8861 try {
8862 for (Phone phone: PhoneFactory.getPhones()) {
8863 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8864 if (tracker != null) {
8865 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008866 }
8867 }
8868 } finally {
8869 Binder.restoreCallingIdentity(identity);
8870 }
8871 }
8872
8873 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008874 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8875 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8876 Phone phone = getPhone(subId);
8877 if (phone == null) {
8878 return null;
8879 }
8880 final long identity = Binder.clearCallingIdentity();
8881 try {
8882 UiccProfile profile = UiccController.getInstance()
8883 .getUiccProfileForPhone(phone.getPhoneId());
8884 if (profile != null) {
8885 return profile.getCertsFromCarrierPrivilegeAccessRules();
8886 }
8887 } finally {
8888 Binder.restoreCallingIdentity(identity);
8889 }
8890 return null;
8891 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008892
8893 /**
8894 * Enable or disable a modem stack.
8895 */
8896 @Override
8897 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8898 enforceModifyPermission();
8899
8900 final long identity = Binder.clearCallingIdentity();
8901 try {
8902 Phone phone = PhoneFactory.getPhone(slotIndex);
8903 if (phone == null) {
8904 return false;
8905 } else {
8906 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8907 }
8908 } finally {
8909 Binder.restoreCallingIdentity(identity);
8910 }
8911 }
Michelecea4cf22018-12-21 15:00:11 -08008912
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008913 /**
8914 * Whether a modem stack is enabled or not.
8915 */
8916 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008917 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8918 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008919 Phone phone = PhoneFactory.getPhone(slotIndex);
8920 if (phone == null) return false;
8921
8922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008923 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8924 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008925 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8926 }
8927
8928 final long identity = Binder.clearCallingIdentity();
8929 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008930 try {
8931 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8932 } catch (NoSuchElementException ex) {
8933 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8934 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008935 } finally {
8936 Binder.restoreCallingIdentity(identity);
8937 }
8938 }
8939
Michelecea4cf22018-12-21 15:00:11 -08008940 @Override
Michele0ea7d782019-03-19 14:58:42 -07008941 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008942 enforceModifyPermission();
8943
8944 final long identity = Binder.clearCallingIdentity();
8945 try {
8946 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008947 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008948 .commit();
8949 } finally {
8950 Binder.restoreCallingIdentity(identity);
8951 }
8952 }
8953
8954 @Override
Michele0ea7d782019-03-19 14:58:42 -07008955 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008956 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008958 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8959 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008960 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008961 }
Michelecea4cf22018-12-21 15:00:11 -08008962
8963 final long identity = Binder.clearCallingIdentity();
8964 try {
Michele0ea7d782019-03-19 14:58:42 -07008965 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008966 } finally {
8967 Binder.restoreCallingIdentity(identity);
8968 }
8969 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008970
Michele0ea7d782019-03-19 14:58:42 -07008971 @TelephonyManager.IsMultiSimSupportedResult
8972 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008973 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8974 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8975 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008976 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8977 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008978 }
8979 // Check if the hardware supports multisim functionality. If usage of multisim is not
8980 // supported by the modem, indicate that it is restricted.
8981 PhoneCapability staticCapability =
8982 mPhoneConfigurationManager.getStaticPhoneCapability();
8983 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008984 loge("isMultiSimSupportedInternal: no static configuration available");
8985 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008986 }
SongFerngWang8236caa2021-01-17 21:51:44 +08008987 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008988 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8989 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008990 }
8991 // Check if support of multiple SIMs is restricted by carrier
8992 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008993 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008994 }
8995
Michele0ea7d782019-03-19 14:58:42 -07008996 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008997 }
8998
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008999 /**
9000 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009001 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9002 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9003 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009004 * @param numOfSims number of active sims we want to switch to
9005 */
9006 @Override
9007 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009008 if (numOfSims == 1) {
9009 enforceModifyPermission();
9010 } else {
9011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9012 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9013 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009014 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009015
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009016 try {
Michele30b57b22019-03-01 12:01:14 -08009017 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009018 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009019 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9020 return;
9021 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009022 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
9027
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009028 @Override
9029 public boolean isApplicationOnUicc(int subId, int appType) {
9030 enforceReadPrivilegedPermission("isApplicationOnUicc");
9031 Phone phone = getPhone(subId);
9032 if (phone == null) {
9033 return false;
9034 }
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 UiccCard uiccCard = phone.getUiccCard();
9038 if (uiccCard == null) {
9039 return false;
9040 }
9041 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9042 if (uiccProfile == null) {
9043 return false;
9044 }
9045 if (TelephonyManager.APPTYPE_SIM <= appType
9046 && appType <= TelephonyManager.APPTYPE_ISIM) {
9047 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9048 }
9049 return false;
9050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
9053 }
9054
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009055 /**
chen xub4baa772019-04-03 10:23:41 -07009056 * Get whether making changes to modem configurations will trigger reboot.
9057 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009058 */
9059 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009060 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9061 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009063 mApp, subId, callingPackage, callingFeatureId,
9064 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009065 return false;
9066 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009067 final long identity = Binder.clearCallingIdentity();
9068 try {
9069 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9070 } finally {
9071 Binder.restoreCallingIdentity(identity);
9072 }
9073 }
9074
Nathan Harold29f5f052019-02-15 13:41:57 -08009075 private void updateModemStateMetrics() {
9076 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9077 // TODO: check the state for each modem if the api is ready.
9078 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9079 }
9080
Pengquan Meng3889a572019-01-23 11:16:29 -08009081 @Override
9082 public int[] getSlotsMapping() {
9083 enforceReadPrivilegedPermission("getSlotsMapping");
9084
9085 final long identity = Binder.clearCallingIdentity();
9086 try {
9087 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9088 // All logical slots should have a mapping to a physical slot.
9089 int[] logicalSlotsMapping = new int[phoneCount];
9090 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9091 for (int i = 0; i < slotInfos.length; i++) {
9092 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9093 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9094 }
9095 }
9096 return logicalSlotsMapping;
9097 } finally {
9098 Binder.restoreCallingIdentity(identity);
9099 }
9100 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009101
9102 /**
9103 * Get the IRadio HAL Version
9104 */
9105 @Override
9106 public int getRadioHalVersion() {
9107 Phone phone = getDefaultPhone();
9108 if (phone == null) return -1;
9109 HalVersion hv = phone.getHalVersion();
9110 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9111 return hv.major * 100 + hv.minor;
9112 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009113
9114 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009115 * Get the current calling package name.
9116 * @return the current calling package name
9117 */
9118 @Override
9119 public String getCurrentPackageName() {
9120 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9121 }
9122
9123 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009124 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9125 * corresponding network requests on a subId.
9126 *
9127 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009128 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009129 * 2) APN is un-metered for this subscription, or
9130 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009131 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009132 *
9133 * @return whether data is allowed for a apn type.
9134 *
9135 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009136 */
9137 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009138 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009139 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9140 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009141
9142 // Now that all security checks passes, perform the operation as ourselves.
9143 final long identity = Binder.clearCallingIdentity();
9144 try {
9145 Phone phone = getPhone(subId);
9146 if (phone == null) return false;
9147
Jack Yu41407ee2019-05-13 16:54:09 -07009148 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009149 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9150 } finally {
9151 Binder.restoreCallingIdentity(identity);
9152 }
9153 }
9154
9155 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009156 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009157 enforceReadPrivilegedPermission("isApnMetered");
9158
9159 // Now that all security checks passes, perform the operation as ourselves.
9160 final long identity = Binder.clearCallingIdentity();
9161 try {
9162 Phone phone = getPhone(subId);
9163 if (phone == null) return true; // By default return true.
9164
Jack Yu41407ee2019-05-13 16:54:09 -07009165 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009166 } finally {
9167 Binder.restoreCallingIdentity(identity);
9168 }
9169 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009170
9171 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009172 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9173 int subscriptionId, IBooleanConsumer resultCallback) {
9174 enforceModifyPermission();
9175 long token = Binder.clearCallingIdentity();
9176 try {
9177 Phone phone = getPhone(subscriptionId);
9178 if (phone == null) {
9179 try {
9180 if (resultCallback != null) {
9181 resultCallback.accept(false);
9182 }
9183 } catch (RemoteException e) {
9184 // ignore
9185 }
9186 return;
9187 }
9188 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9189 Pair.create(specifiers, (x) -> {
9190 try {
9191 if (resultCallback != null) {
9192 resultCallback.accept(x);
9193 }
9194 } catch (RemoteException e) {
9195 // ignore
9196 }
9197 });
9198 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9199 } finally {
9200 Binder.restoreCallingIdentity(token);
9201 }
9202 }
9203
9204 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009205 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9206 TelephonyPermissions
9207 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9208 mApp, subId, "getSystemSelectionChannels");
9209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9210 final long identity = Binder.clearCallingIdentity();
9211 try {
Sarah Chin428d1d62021-03-13 03:17:40 -08009212 Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource);
9213 if (result instanceof IllegalStateException) {
9214 throw (IllegalStateException) result;
9215 }
9216 List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result;
Sarah Chin679c08a2020-11-18 13:39:35 -08009217 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9218 return specifiers;
9219 } finally {
9220 Binder.restoreCallingIdentity(identity);
9221 }
9222 }
9223
9224 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009225 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009226 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009227 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9228 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9229 if (iccRecords == null) {
9230 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9231 return false;
9232 }
9233 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9234 }
9235
9236 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009237 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9238 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009239 if (callingPackage == null) {
9240 callingPackage = getCurrentPackageName();
9241 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009242 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9243 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009244 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9245 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009246 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9247 }
9248 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9249 Intent intent = new Intent();
9250 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9251 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9252 // Bring up choose default SMS subscription dialog right now
9253 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9254 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9255 mApp.startActivity(intent);
9256 }
chen xud5ca2d52019-05-28 15:20:57 -07009257
9258 @Override
9259 public String getMmsUAProfUrl(int subId) {
9260 //TODO investigate if this API should require proper permission check in R b/133791609
9261 final long identity = Binder.clearCallingIdentity();
9262 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009263 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9264 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9265 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9266 return carrierUAProfUrl;
9267 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009268 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9269 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009270 } finally {
9271 Binder.restoreCallingIdentity(identity);
9272 }
9273 }
9274
9275 @Override
9276 public String getMmsUserAgent(int subId) {
9277 //TODO investigate if this API should require proper permission check in R b/133791609
9278 final long identity = Binder.clearCallingIdentity();
9279 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009280 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9281 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9282 if (!TextUtils.isEmpty(carrierUserAgent)) {
9283 return carrierUserAgent;
9284 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009285 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9286 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009287 } finally {
9288 Binder.restoreCallingIdentity(identity);
9289 }
9290 }
Jack Yub07d4972019-05-28 16:12:25 -07009291
9292 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009293 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9294 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009295
Jack Yub07d4972019-05-28 16:12:25 -07009296 final long identity = Binder.clearCallingIdentity();
9297 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009298 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009299 if (phone == null) return false;
9300
Hall Liua62f5da2020-09-25 10:42:19 -07009301 switch (policy) {
9302 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9303 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9304 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9305 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9306 default:
9307 throw new IllegalArgumentException(policy + " is not a valid policy");
9308 }
Jack Yub07d4972019-05-28 16:12:25 -07009309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
9312 }
9313
9314 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009315 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009316 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009317 enforceModifyPermission();
9318
changbettyd5c246e2019-12-24 15:40:37 +08009319 final long identity = Binder.clearCallingIdentity();
9320 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009321 Phone phone = getPhone(subscriptionId);
9322 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009323
Hall Liua62f5da2020-09-25 10:42:19 -07009324 switch (policy) {
9325 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9326 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9327 break;
9328 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9329 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9330 break;
9331 default:
9332 throw new IllegalArgumentException(policy + " is not a valid policy");
9333 }
changbettyd5c246e2019-12-24 15:40:37 +08009334 } finally {
9335 Binder.restoreCallingIdentity(identity);
9336 }
9337 }
9338
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009339 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009340 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009341 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9342 * otherwise.
9343 */
9344 @Override
9345 public void setCepEnabled(boolean isCepEnabled) {
9346 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9347
9348 final long identity = Binder.clearCallingIdentity();
9349 try {
9350 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9351 for (Phone phone : PhoneFactory.getPhones()) {
9352 Phone defaultPhone = phone.getImsPhone();
9353 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9354 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9355 ImsPhoneCallTracker imsPhoneCallTracker =
9356 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9357 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9358 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9359 + imsPhone.getMsisdn());
9360 }
9361 }
9362 } finally {
9363 Binder.restoreCallingIdentity(identity);
9364 }
9365 }
allenwtsu46dcc572020-01-08 18:24:03 +08009366
9367 /**
9368 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9369 *
9370 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9371 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9372 * before being read.
9373 */
9374 @Override
9375 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9376 isCompressed) {
9377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9378 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9380 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9381 }
9382 if (!isImsAvailableOnDevice()) {
9383 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9384 "IMS not available on device.");
9385 }
9386
9387 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009388 try {
Hui Wang761a6682020-10-31 05:12:53 +00009389 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9390 } finally {
9391 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009392 }
9393 }
zoey chene02881a2019-12-30 16:11:23 +08009394
9395 @Override
9396 public boolean isIccLockEnabled(int subId) {
9397 enforceReadPrivilegedPermission("isIccLockEnabled");
9398
9399 // Now that all security checks passes, perform the operation as ourselves.
9400 final long identity = Binder.clearCallingIdentity();
9401 try {
9402 Phone phone = getPhone(subId);
9403 if (phone != null && phone.getIccCard() != null) {
9404 return phone.getIccCard().getIccLockEnabled();
9405 } else {
9406 return false;
9407 }
9408 } finally {
9409 Binder.restoreCallingIdentity(identity);
9410 }
9411 }
9412
9413 /**
9414 * Set the ICC pin lock enabled or disabled.
9415 *
9416 * @return an integer representing the status of IccLock enabled or disabled in the following
9417 * three cases:
9418 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9419 * successfully.
9420 * - Positive number and zero for remaining password attempts.
9421 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9422 *
9423 */
9424 @Override
9425 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9426 enforceModifyPermission();
9427
9428 Phone phone = getPhone(subId);
9429 if (phone == null) {
9430 return 0;
9431 }
9432 // Now that all security checks passes, perform the operation as ourselves.
9433 final long identity = Binder.clearCallingIdentity();
9434 try {
9435 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9436 new Pair<Boolean, String>(enabled, password), phone, null);
9437 return attemptsRemaining;
9438
9439 } catch (Exception e) {
9440 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9441 } finally {
9442 Binder.restoreCallingIdentity(identity);
9443 }
9444 return 0;
9445 }
9446
9447 /**
9448 * Change the ICC password used in ICC pin lock.
9449 *
9450 * @return an integer representing the status of IccLock changed in the following three cases:
9451 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9452 * - Positive number and zero for remaining password attempts.
9453 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9454 *
9455 */
9456 @Override
9457 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9458 enforceModifyPermission();
9459
9460 Phone phone = getPhone(subId);
9461 if (phone == null) {
9462 return 0;
9463 }
9464 // Now that all security checks passes, perform the operation as ourselves.
9465 final long identity = Binder.clearCallingIdentity();
9466 try {
9467 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9468 new Pair<String, String>(oldPassword, newPassword), phone, null);
9469 return attemptsRemaining;
9470
9471 } catch (Exception e) {
9472 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9473 } finally {
9474 Binder.restoreCallingIdentity(identity);
9475 }
9476 return 0;
9477 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009478
9479 /**
9480 * Request for receiving user activity notification
9481 */
9482 @Override
9483 public void requestUserActivityNotification() {
9484 if (!mNotifyUserActivity.get()
9485 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9486 mNotifyUserActivity.set(true);
9487 }
9488 }
9489
9490 /**
9491 * Called when userActivity is signalled in the power manager.
9492 * This is safe to call from any thread, with any window manager locks held or not.
9493 */
9494 @Override
9495 public void userActivity() {
9496 // ***************************************
9497 // * Inherited from PhoneWindowManager *
9498 // ***************************************
9499 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9500 // WITH ITS LOCKS HELD.
9501 //
9502 // This code must be VERY careful about the locks
9503 // it acquires.
9504 // In fact, the current code acquires way too many,
9505 // and probably has lurking deadlocks.
9506
9507 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9508 throw new SecurityException("Only the OS may call notifyUserActivity()");
9509 }
9510
9511 if (mNotifyUserActivity.getAndSet(false)) {
9512 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9513 USER_ACTIVITY_NOTIFICATION_DELAY);
9514 }
9515 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009516
9517 @Override
9518 public boolean canConnectTo5GInDsdsMode() {
9519 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9520 }
Jack Yud10cdd42020-09-28 20:28:01 -07009521
9522 @Override
9523 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9524 String callingFeatureId) {
9525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9526 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9527 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9528 }
9529
9530 Phone phone = getPhone(subId);
9531 if (phone == null) {
9532 throw new RuntimeException("phone is not available");
9533 }
9534 // Now that all security checks passes, perform the operation as ourselves.
9535 final long identity = Binder.clearCallingIdentity();
9536 try {
9537 return phone.getEquivalentHomePlmns();
9538 } finally {
9539 Binder.restoreCallingIdentity(identity);
9540 }
9541 }
Daniel Bright59e67312020-11-13 11:49:37 -08009542
9543 @Override
9544 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009545 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9546 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009547 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009548 if (radioInterfaceCapabilities == null) {
9549 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009550 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009551 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009552 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009553
Hui Wang641e81c2020-10-12 12:14:23 -07009554 @Override
9555 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9556 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009557 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9558 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9559 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9560 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9561 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009562 if (DBG) {
9563 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9564 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9565 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9566 }
9567
9568 if (!SubscriptionManager.isValidSubscriptionId(subId)
9569 || appType < TelephonyManager.APPTYPE_UNKNOWN
9570 || appType > TelephonyManager.APPTYPE_ISIM
9571 || nafUrl == null || securityProtocol == null || callback == null) {
9572 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9573 if (callback != null) {
9574 try {
9575 callback.onAuthenticationFailure(
9576 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9577 } catch (RemoteException exception) {
9578 log("Fail to notify onAuthenticationFailure due to " + exception);
9579 }
9580 return;
9581 }
9582 }
9583
9584 final long token = Binder.clearCallingIdentity();
9585 try {
9586 getGbaManager(subId).bootstrapAuthenticationRequest(
9587 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9588 forceBootStrapping, callback));
9589 } finally {
9590 Binder.restoreCallingIdentity(token);
9591 }
9592 }
9593
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009594 /**
9595 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9596 * requested radio power state will actually be set. See {@link
9597 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9598 *
9599 * @param subId the subscription ID of the phone requesting to set the radio power state.
9600 * @param enable {@code true} if trying to turn radio on.
9601 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9602 * false}.
9603 */
9604 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9605 Phone phone = getPhone(subId);
9606 if (phone != null) {
9607 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9608 return true;
9609 }
9610 return false;
9611 }
9612
9613 private int handleDataThrottlingRequest(int subId,
9614 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009615 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9616 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9617 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9618 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9619 throw new IllegalArgumentException("modem does not support data throttling");
9620 }
9621
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009622 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9623 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9624 if (!setRadioPowerForThermal(subId, true)) {
9625 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9626 }
9627
9628 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9629
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009630 if (isDataThrottlingSupported) {
9631 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009632 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009633 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9634 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9635 } else if (thermalMitigationResult
9636 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9637 throw new IllegalArgumentException("modem does not support data throttling");
9638 }
9639 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009640 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009641
9642 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009643 }
9644
Jack Nudelman644b91a2021-03-12 14:09:48 -08009645 private static List<String> getThermalMitigationAllowlist(Context context) {
9646 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9647 for (String pckg : context.getResources()
9648 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9649 sThermalMitigationAllowlistedPackages.add(pckg);
9650 }
9651 }
9652
9653 return sThermalMitigationAllowlistedPackages;
9654 }
9655
9656 /**
9657 * Used by shell commands to add an authorized package name for thermal mitigation.
9658 * @param packageName name of package to be allowlisted
9659 * @param context
9660 */
9661 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9662 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9663 sThermalMitigationAllowlistedPackages.add(packageName);
9664 }
9665
9666 /**
9667 * Used by shell commands to remove an authorized package name for thermal mitigation.
9668 * @param packageName name of package to remove from allowlist
9669 * @param context
9670 */
9671 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9672 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9673 sThermalMitigationAllowlistedPackages.remove(packageName);
9674 }
9675
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009676 /**
9677 * Thermal mitigation request to control functionalities at modem.
9678 *
9679 * @param subId the id of the subscription.
9680 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009681 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009682 *
9683 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9684 */
9685 @Override
9686 @ThermalMitigationResult
9687 public int sendThermalMitigationRequest(
9688 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009689 ThermalMitigationRequest thermalMitigationRequest,
9690 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009691 enforceModifyPermission();
9692
Jack Nudelman644b91a2021-03-12 14:09:48 -08009693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9694 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9695 .contains(callingPackage)) {
9696 throw new SecurityException("Calling package must be configured in the device config. "
9697 + "calling package: " + callingPackage);
9698 }
9699
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009700 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9701 final long identity = Binder.clearCallingIdentity();
9702
9703 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9704 try {
9705 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9706 switch (thermalMitigationAction) {
9707 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9708 thermalMitigationResult =
9709 handleDataThrottlingRequest(subId,
9710 thermalMitigationRequest.getDataThrottlingRequest());
9711 break;
9712 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9713 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9714 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9715 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9716 }
9717
9718 // Ensure that radio is on. If not able to power on due to phone being
9719 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9720 if (!setRadioPowerForThermal(subId, true)) {
9721 thermalMitigationResult =
9722 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9723 break;
9724 }
9725
9726 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9727 false);
9728 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9729 break;
9730 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9731 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9732 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9733 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9734 }
9735
9736 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9737 if (registry != null) {
9738 TelephonyConnectionService service =
9739 registry.getTelephonyConnectionService();
9740 Phone phone = getPhone(subId);
9741 if (phone == null) {
9742 thermalMitigationResult =
9743 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9744 break;
9745 }
9746
9747 if (PhoneConstantConversions.convertCallState(phone.getState())
9748 != TelephonyManager.CALL_STATE_IDLE
9749 || phone.isInEmergencySmsMode() || phone.isInEcm()
9750 || (service != null && service.isEmergencyCallPending())) {
9751 String errorMessage = "Phone state is not valid. call state = "
9752 + PhoneConstantConversions.convertCallState(phone.getState())
9753 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9754 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9755 errorMessage += service == null
9756 ? " TelephonyConnectionService is null"
9757 : " isEmergencyCallPending = "
9758 + service.isEmergencyCallPending();
9759 Log.e(LOG_TAG, errorMessage);
9760 thermalMitigationResult =
9761 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9762 break;
9763 }
9764 } else {
9765 thermalMitigationResult =
9766 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9767 break;
9768 }
9769
9770 // Turn radio off. If not able to power off due to phone being unavailable,
9771 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9772 if (!setRadioPowerForThermal(subId, false)) {
9773 thermalMitigationResult =
9774 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9775 break;
9776 }
9777 thermalMitigationResult =
9778 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9779 break;
9780 default:
9781 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9782 + "not exist. Requested action: " + thermalMitigationAction);
9783 }
9784 } catch (IllegalArgumentException e) {
9785 throw e;
9786 } catch (Exception e) {
9787 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9788 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9789 } finally {
9790 Binder.restoreCallingIdentity(identity);
9791 }
9792
9793 if (DBG) {
9794 log("thermalMitigationRequest returning with thermalMitigationResult: "
9795 + thermalMitigationResult);
9796 }
9797
9798 return thermalMitigationResult;
9799 }
Hui Wang641e81c2020-10-12 12:14:23 -07009800
9801 /**
9802 * Set the GbaService Package Name that Telephony will bind to.
9803 *
9804 * @param subId The sim that the GbaService is associated with.
9805 * @param packageName The name of the package to be replaced with.
9806 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9807 */
9808 @Override
9809 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9810 enforceModifyPermission();
9811
9812 final long identity = Binder.clearCallingIdentity();
9813 try {
9814 return getGbaManager(subId).overrideServicePackage(packageName);
9815 } finally {
9816 Binder.restoreCallingIdentity(identity);
9817 }
9818 }
9819
9820 /**
9821 * Return the package name of the currently bound GbaService.
9822 *
9823 * @param subId The sim that the GbaService is associated with.
9824 * @return the package name of the GbaService configuration, null if GBA is not supported.
9825 */
9826 @Override
9827 public String getBoundGbaService(int subId) {
9828 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9829
9830 final long identity = Binder.clearCallingIdentity();
9831 try {
9832 return getGbaManager(subId).getServicePackage();
9833 } finally {
9834 Binder.restoreCallingIdentity(identity);
9835 }
9836 }
9837
9838 /**
9839 * Set the release time for telephony to unbind GbaService.
9840 *
9841 * @param subId The sim that the GbaService is associated with.
9842 * @param interval The release time to unbind GbaService by millisecond.
9843 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9844 */
9845 @Override
9846 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9847 enforceModifyPermission();
9848
9849 final long identity = Binder.clearCallingIdentity();
9850 try {
9851 return getGbaManager(subId).overrideReleaseTime(interval);
9852 } finally {
9853 Binder.restoreCallingIdentity(identity);
9854 }
9855 }
9856
9857 /**
9858 * Return the release time for telephony to unbind GbaService.
9859 *
9860 * @param subId The sim that the GbaService is associated with.
9861 * @return The release time to unbind GbaService by millisecond.
9862 */
9863 @Override
9864 public int getGbaReleaseTime(int subId) {
9865 enforceReadPrivilegedPermission("getGbaReleaseTime");
9866
9867 final long identity = Binder.clearCallingIdentity();
9868 try {
9869 return getGbaManager(subId).getReleaseTime();
9870 } finally {
9871 Binder.restoreCallingIdentity(identity);
9872 }
9873 }
9874
9875 private GbaManager getGbaManager(int subId) {
9876 GbaManager instance = GbaManager.getInstance(subId);
9877 if (instance == null) {
9878 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9879 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9880 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9881 }
9882 return instance;
9883 }
Hui Wang761a6682020-10-31 05:12:53 +00009884
9885 /**
9886 * indicate whether the device and the carrier can support
9887 * RCS VoLTE single registration.
9888 */
9889 @Override
9890 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009891 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9892 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9893 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9894 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009895
9896 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9897 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9898 }
9899
9900 final long identity = Binder.clearCallingIdentity();
9901 try {
9902 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9903 if (rpm != null) {
9904 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9905 }
9906 return false;
9907 } finally {
9908 Binder.restoreCallingIdentity(identity);
9909 }
9910 }
9911
9912 /**
9913 * Register RCS provisioning callback.
9914 */
9915 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009916 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009917 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009918 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009919 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009920 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9921 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009922
9923 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9924 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9925 }
9926 if (!isImsAvailableOnDevice()) {
9927 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9928 "IMS not available on device.");
9929 }
9930
9931 final long identity = Binder.clearCallingIdentity();
9932 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009933 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009934 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -08009935 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9936 "Service not available for the subscription.");
9937 }
Hui Wang761a6682020-10-31 05:12:53 +00009938 } finally {
9939 Binder.restoreCallingIdentity(identity);
9940 }
9941 }
9942
9943 /**
9944 * Unregister RCS provisioning callback.
9945 */
9946 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009947 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009948 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009949 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009950 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009951 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9952 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009953
9954 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9955 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9956 }
9957 if (!isImsAvailableOnDevice()) {
9958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9959 "IMS not available on device.");
9960 }
9961
9962 final long identity = Binder.clearCallingIdentity();
9963 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009964 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009965 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +00009966 } finally {
9967 Binder.restoreCallingIdentity(identity);
9968 }
9969 }
9970
9971 /**
9972 * trigger RCS reconfiguration.
9973 */
9974 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009975 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9976 "triggerRcsReconfiguration",
9977 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +00009978
9979 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9980 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9981 }
9982 if (!isImsAvailableOnDevice()) {
9983 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9984 "IMS not available on device.");
9985 }
9986
9987 final long identity = Binder.clearCallingIdentity();
9988 try {
9989 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9990 } finally {
9991 Binder.restoreCallingIdentity(identity);
9992 }
9993 }
9994
9995 /**
9996 * Provide the client configuration parameters of the RCS application.
9997 */
9998 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009999 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10000 "setRcsClientConfiguration",
10001 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010002
10003 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10004 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10005 }
10006 if (!isImsAvailableOnDevice()) {
10007 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10008 "IMS not available on device.");
10009 }
10010
10011 final long identity = Binder.clearCallingIdentity();
10012
10013 try {
10014 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10015 if (configBinder == null) {
10016 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
10017 } else {
10018 configBinder.setRcsClientConfiguration(rcc);
10019 }
10020 } catch (RemoteException e) {
10021 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
10022 } finally {
10023 Binder.restoreCallingIdentity(identity);
10024 }
10025 }
10026
10027 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010028 * Enables or disables the test mode for RCS VoLTE single registration.
10029 */
10030 @Override
10031 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10032 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10033 "setRcsSingleRegistrationTestModeEnabled");
10034
10035 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10036 }
10037
10038 /**
10039 * Gets the test mode for RCS VoLTE single registration.
10040 */
10041 @Override
10042 public boolean getRcsSingleRegistrationTestModeEnabled() {
10043 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10044 "getRcsSingleRegistrationTestModeEnabled");
10045
10046 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10047 }
10048
10049 /**
Hui Wang761a6682020-10-31 05:12:53 +000010050 * Overrides the config of RCS VoLTE single registration enabled for the device.
10051 */
10052 @Override
10053 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10054 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10055 "setDeviceSingleRegistrationEnabledOverride");
10056 enforceModifyPermission();
10057
10058 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10059 : Boolean.parseBoolean(enabledStr);
10060 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010061 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010062 }
10063
10064 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010065 * Sends a device to device communication message. Only usable via shell.
10066 * @param message message to send.
10067 * @param value message value.
10068 */
10069 @Override
10070 public void sendDeviceToDeviceMessage(int message, int value) {
10071 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010072 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010073 enforceModifyPermission();
10074
10075 final long identity = Binder.clearCallingIdentity();
10076 try {
10077 TelephonyConnectionService service =
10078 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10079 if (service == null) {
10080 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10081 return;
10082 }
10083 service.sendTestDeviceToDeviceMessage(message, value);
10084 } finally {
10085 Binder.restoreCallingIdentity(identity);
10086 }
10087 }
10088
Tyler Gunnbabbda02021-02-10 11:05:02 -080010089 /**
10090 * Sets the specified device to device transport active.
10091 * @param transport The transport to set active.
10092 */
10093 @Override
10094 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10095 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10096 "setActiveDeviceToDeviceTransport");
10097 enforceModifyPermission();
10098
10099 final long identity = Binder.clearCallingIdentity();
10100 try {
10101 TelephonyConnectionService service =
10102 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10103 if (service == null) {
10104 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10105 return;
10106 }
10107 service.setActiveDeviceToDeviceTransport(transport);
10108 } finally {
10109 Binder.restoreCallingIdentity(identity);
10110 }
10111 }
Tyler Gunn92479152021-01-20 16:30:10 -080010112
10113 /**
Hui Wang761a6682020-10-31 05:12:53 +000010114 * Gets the config of RCS VoLTE single registration enabled for the device.
10115 */
10116 @Override
10117 public boolean getDeviceSingleRegistrationEnabled() {
10118 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10119 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10120 }
10121
10122 /**
10123 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10124 */
10125 @Override
10126 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10127 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10128 "setCarrierSingleRegistrationEnabledOverride");
10129 enforceModifyPermission();
10130
10131 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10132 : Boolean.parseBoolean(enabledStr);
10133 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10134 subId, enabled);
10135 }
10136
10137 /**
10138 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10139 */
10140 @Override
10141 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10142 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10143 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10144 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010145
10146 /**
10147 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10148 * their mobile plan.
10149 */
10150 @Override
10151 public String getMobileProvisioningUrl() {
10152 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10153 final long identity = Binder.clearCallingIdentity();
10154 try {
10155 return getDefaultPhone().getMobileProvisioningUrl();
10156 } finally {
10157 Binder.restoreCallingIdentity(identity);
10158 }
10159 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010160
James.cf Linbcdf8b32021-01-14 16:44:13 +080010161 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010162 * Get the EAB contact from the EAB database.
10163 */
10164 @Override
10165 public String getContactFromEab(String contact) {
10166 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10167 enforceModifyPermission();
10168 final long identity = Binder.clearCallingIdentity();
10169 try {
10170 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10171 } finally {
10172 Binder.restoreCallingIdentity(identity);
10173 }
10174 }
10175
10176 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010177 * Remove the EAB contacts from the EAB database.
10178 */
10179 @Override
10180 public int removeContactFromEab(int subId, String contacts) {
10181 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10182 enforceModifyPermission();
10183 final long identity = Binder.clearCallingIdentity();
10184 try {
10185 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10186 } finally {
10187 Binder.restoreCallingIdentity(identity);
10188 }
10189 }
10190
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010191 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010192 public boolean getDeviceUceEnabled() {
10193 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10194 final long identity = Binder.clearCallingIdentity();
10195 try {
10196 return mApp.getDeviceUceEnabled();
10197 } finally {
10198 Binder.restoreCallingIdentity(identity);
10199 }
10200 }
10201
10202 @Override
10203 public void setDeviceUceEnabled(boolean isEnabled) {
10204 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10205 final long identity = Binder.clearCallingIdentity();
10206 try {
10207 mApp.setDeviceUceEnabled(isEnabled);
10208 } finally {
10209 Binder.restoreCallingIdentity(identity);
10210 }
10211 }
10212
Brad Ebinger14d467f2021-02-12 06:18:28 +000010213 /**
10214 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10215 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10216 */
10217 // Used for SHELL command only right now.
10218 @Override
10219 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10220 List<String> featureTags) {
10221 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10222 "addUceRegistrationOverrideShell");
10223 final long identity = Binder.clearCallingIdentity();
10224 try {
10225 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10226 new ArraySet<>(featureTags));
10227 } catch (ImsException e) {
10228 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10229 } finally {
10230 Binder.restoreCallingIdentity(identity);
10231 }
10232 }
10233
10234 /**
10235 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10236 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10237 */
10238 // Used for SHELL command only right now.
10239 @Override
10240 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10241 List<String> featureTags) {
10242 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10243 "removeUceRegistrationOverrideShell");
10244 final long identity = Binder.clearCallingIdentity();
10245 try {
10246 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10247 new ArraySet<>(featureTags));
10248 } catch (ImsException e) {
10249 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10250 } finally {
10251 Binder.restoreCallingIdentity(identity);
10252 }
10253 }
10254
10255 /**
10256 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10257 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10258 */
10259 // Used for SHELL command only right now.
10260 @Override
10261 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10262 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10263 "clearUceRegistrationOverrideShell");
10264 final long identity = Binder.clearCallingIdentity();
10265 try {
10266 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10267 } catch (ImsException e) {
10268 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10269 } finally {
10270 Binder.restoreCallingIdentity(identity);
10271 }
10272 }
10273
10274 /**
10275 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10276 */
10277 // Used for SHELL command only right now.
10278 @Override
10279 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10280 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10281 "getLatestRcsContactUceCapabilityShell");
10282 final long identity = Binder.clearCallingIdentity();
10283 try {
10284 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10285 } catch (ImsException e) {
10286 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10287 } finally {
10288 Binder.restoreCallingIdentity(identity);
10289 }
10290 }
10291
10292 /**
10293 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10294 * device does not have an active PUBLISH.
10295 */
10296 // Used for SHELL command only right now.
10297 @Override
10298 public String getLastUcePidfXmlShell(int subId) {
10299 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10300 final long identity = Binder.clearCallingIdentity();
10301 try {
10302 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10303 } catch (ImsException e) {
10304 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10305 } finally {
10306 Binder.restoreCallingIdentity(identity);
10307 }
10308 }
10309
10310
James.cf Lin4b784aa2021-01-31 03:25:15 +080010311 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010312 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10313 String callingPackage) {
10314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10315 mApp, subId, "setSignalStrengthUpdateRequest");
10316
10317 final int callingUid = Binder.getCallingUid();
10318 // Verify that tha callingPackage belongs to the calling UID
10319 mApp.getSystemService(AppOpsManager.class)
10320 .checkPackage(callingUid, callingPackage);
10321
10322 validateSignalStrengthUpdateRequest(request, callingUid);
10323
10324 final long identity = Binder.clearCallingIdentity();
10325 try {
10326 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10327 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10328
10329 if (result instanceof IllegalStateException) {
10330 throw (IllegalStateException) result;
10331 }
10332 } finally {
10333 Binder.restoreCallingIdentity(identity);
10334 }
10335 }
10336
10337 @Override
10338 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10339 String callingPackage) {
10340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10341 mApp, subId, "clearSignalStrengthUpdateRequest");
10342
10343 final int callingUid = Binder.getCallingUid();
10344 // Verify that tha callingPackage belongs to the calling UID
10345 mApp.getSystemService(AppOpsManager.class)
10346 .checkPackage(callingUid, callingPackage);
10347
10348 final long identity = Binder.clearCallingIdentity();
10349 try {
10350 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10351 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10352
10353 if (result instanceof IllegalStateException) {
10354 throw (IllegalStateException) result;
10355 }
10356 } finally {
10357 Binder.restoreCallingIdentity(identity);
10358 }
10359 }
10360
10361 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10362 int callingUid) {
10363 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10364 // phone/system process do not have further restriction on request
10365 return;
10366 }
10367
10368 // Applications has restrictions on how to use the request:
10369 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10370 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10371 // This is not system caller which has been checked above
10372 throw new IllegalArgumentException(
10373 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10374 }
10375
10376 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10377 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10378 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10379 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10380 || info.isEnabled()) {
10381 throw new IllegalArgumentException(
10382 "Only system can set hide fields in SignalThresholdInfo");
10383 }
10384
10385 // Thresholds length for each RAN need in range. This has been validated in
10386 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10387 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10388 final int[] thresholds = info.getThresholds();
10389 Objects.requireNonNull(thresholds);
10390 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10391 || thresholds.length
10392 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10393 throw new IllegalArgumentException(
10394 "thresholds length is out of range: " + thresholds.length);
10395 }
10396 }
10397 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010398
10399 /**
10400 * Gets the current phone capability.
10401 *
10402 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10403 * @return the PhoneCapability which describes the data connection capability of modem.
10404 * It's used to evaluate possible phone config change, for example from single
10405 * SIM device to multi-SIM device.
10406 */
10407 @Override
10408 public PhoneCapability getPhoneCapability() {
10409 enforceReadPrivilegedPermission("getPhoneCapability");
10410 final long identity = Binder.clearCallingIdentity();
10411 try {
10412 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10413 } finally {
10414 Binder.restoreCallingIdentity(identity);
10415 }
10416 }
Michele Berionne5e411512020-11-13 02:36:59 +000010417
10418 /**
10419 * Prepare TelephonyManager for an unattended reboot. The reboot is
10420 * required to be done shortly after the API is invoked.
10421 */
10422 @Override
10423 @TelephonyManager.PrepareUnattendedRebootResult
10424 public int prepareForUnattendedReboot() {
10425 enforceRebootPermission();
10426
10427 final long identity = Binder.clearCallingIdentity();
10428 try {
10429 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10430 } finally {
10431 Binder.restoreCallingIdentity(identity);
10432 }
10433 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010434
10435 /**
10436 * Request to get the current slicing configuration including URSP rules and
10437 * NSSAIs (configured, allowed and rejected).
10438 *
10439 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10440 */
10441 @Override
10442 public void getSlicingConfig(ResultReceiver callback) {
10443 enforceReadPrivilegedPermission("getSlicingConfig");
10444
10445 final long identity = Binder.clearCallingIdentity();
10446 try {
10447 Phone phone = getDefaultPhone();
10448 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10449 } finally {
10450 Binder.restoreCallingIdentity(identity);
10451 }
10452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010453}