blob: 68b51f3e20dd46d864c1a933794bdcc60357d29f [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;
Brad Ebinger4f6208e2021-03-23 21:04:45 +000032import android.app.compat.CompatChanges;
Hall Liu82694d52020-12-11 18:22:04 -080033import android.app.role.RoleManager;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070034import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070035import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.content.Context;
37import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070038import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070039import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080040import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070041import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.net.Uri;
43import android.os.AsyncResult;
44import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080045import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Bundle;
47import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.Looper;
50import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070051import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080052import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070053import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070054import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080055import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080056import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070057import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070058import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080059import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070060import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070061import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070062import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070063import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070064import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080065import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070066import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090067import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080068import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080069import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070070import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070071import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080072import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080073import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070074import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080075import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070076import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080077import android.telephony.CellIdentityCdma;
78import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070080import android.telephony.CellInfoGsm;
81import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070082import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080083import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070084import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070085import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070086import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080087import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070088import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080089import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070090import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080091import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080092import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070093import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080096import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080097import android.telephony.SignalStrengthUpdateRequest;
98import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080099import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800100import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -0800101import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800104import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800105import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800106import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000107import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700108import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700109import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800110import android.telephony.data.ApnSetting;
Hongbo Zeng156aa4a2021-02-08 21:50:28 +0800111import android.telephony.data.SlicingConfig;
Jack Yub5d8f642018-11-26 11:20:48 -0800112import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700113import android.telephony.gba.GbaAuthRequest;
114import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700115import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger14d467f2021-02-12 06:18:28 +0000118import android.telephony.ims.RcsContactUceCapability;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700119import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700120import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800121import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700122import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800123import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700124import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000125import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700126import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800127import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800128import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800129import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800130import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700133import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800135import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800136
Andrew Lee312e8172014-10-23 17:01:36 -0700137import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800138import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800139import com.android.ims.rcs.uce.eab.EabUtil;
Shuo Qian4a594052020-01-23 11:59:30 -0800140import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700142import com.android.internal.telephony.CallStateException;
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;
Kai Shif70f46f2021-03-03 13:59:46 -0800341 private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800343 // Parameters of select command.
344 private static final int SELECT_COMMAND = 0xA4;
345 private static final int SELECT_P1 = 0x04;
346 private static final int SELECT_P2 = 0;
347 private static final int SELECT_P3 = 0x10;
348
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 /** The singleton instance. */
350 private static PhoneInterfaceManager sInstance;
Jack Nudelman644b91a2021-03-12 14:09:48 -0800351 private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352
Wink Saville3ab207e2014-11-20 13:07:20 -0800353 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800354 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800355 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700356 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800357 private AppOpsManager mAppOps;
358 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800359 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800360 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700361 private PhoneConfigurationManager mPhoneConfigurationManager;
Daniel Bright94f43662021-03-01 14:43:40 -0800362 private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363
Peter Wangdafb9ac2020-01-15 14:13:38 -0800364 /** User Activity */
365 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800366 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
367
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700368 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
369
Derek Tan97ebb422014-09-05 16:55:38 -0700370 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
371 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800372 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800373 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700374
Michelecea4cf22018-12-21 15:00:11 -0800375 // String to store multi SIM allowed
376 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
377
Derek Tan740e1672017-06-27 14:56:27 -0700378 // The AID of ISD-R.
379 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
380
yinxub1bed742017-04-17 11:45:04 -0700381 private NetworkScanRequestTracker mNetworkScanRequestTracker;
382
David Kelly5e06a7f2018-03-12 14:10:59 +0000383 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
384 private static final int MANUFACTURER_CODE_LENGTH = 8;
385
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800386 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -0800387 private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800388
Derek Tan89e89d42014-07-08 17:00:10 -0700389 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700390 * Experiment flag to enable erase modem config on reset network, default value is false
391 */
392 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
393 "reset_network_erase_modem_config_enabled";
394
Rambo Wang0f050d82021-02-12 11:43:36 -0800395 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
396
Naina Nallurid63128d2019-09-17 14:10:30 -0700397 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700398 * A request object to use for transmitting data to an ICC.
399 */
400 private static final class IccAPDUArgument {
401 public int channel, cla, command, p1, p2, p3;
402 public String data;
403
404 public IccAPDUArgument(int channel, int cla, int command,
405 int p1, int p2, int p3, String data) {
406 this.channel = channel;
407 this.cla = cla;
408 this.command = command;
409 this.p1 = p1;
410 this.p2 = p2;
411 this.p3 = p3;
412 this.data = data;
413 }
414 }
415
416 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700417 * A request object to use for transmitting data to an ICC.
418 */
419 private static final class ManualNetworkSelectionArgument {
420 public OperatorInfo operatorInfo;
421 public boolean persistSelection;
422
423 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
424 this.operatorInfo = operatorInfo;
425 this.persistSelection = persistSelection;
426 }
427 }
428
429 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
431 * request after sending. The main thread will notify the request when it is complete.
432 */
433 private static final class MainThreadRequest {
434 /** The argument to use for the request */
435 public Object argument;
436 /** The result of the request that is run on the main thread */
437 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800438 // The subscriber id that this request applies to. Defaults to
439 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
440 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441
Nathan Harold92bed182018-10-12 18:16:49 -0700442 // In cases where subId is unavailable, the caller needs to specify the phone.
443 public Phone phone;
444
vagdeviaf9a5b92018-08-15 16:01:53 -0700445 public WorkSource workSource;
446
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447 public MainThreadRequest(Object argument) {
448 this.argument = argument;
449 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800450
Nathan Harold92bed182018-10-12 18:16:49 -0700451 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
452 this.argument = argument;
453 if (phone != null) {
454 this.phone = phone;
455 }
456 this.workSource = workSource;
457 }
458
vagdeviaf9a5b92018-08-15 16:01:53 -0700459 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800460 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800461 if (subId != null) {
462 this.subId = subId;
463 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700464 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700466 }
467
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800468 private static final class IncomingThirdPartyCallArgs {
469 public final ComponentName component;
470 public final String callId;
471 public final String callerDisplayName;
472
473 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
474 String callerDisplayName) {
475 this.component = component;
476 this.callId = callId;
477 this.callerDisplayName = callerDisplayName;
478 }
479 }
480
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481 /**
482 * A handler that processes messages on the main thread in the phone process. Since many
483 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
484 * inbound binder threads to the main thread in the phone process. The Binder thread
485 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
486 * on, which will be notified when the operation completes and will contain the result of the
487 * request.
488 *
489 * <p>If a MainThreadRequest object is provided in the msg.obj field,
490 * note that request.result must be set to something non-null for the calling thread to
491 * unblock.
492 */
493 private final class MainThreadHandler extends Handler {
494 @Override
495 public void handleMessage(Message msg) {
496 MainThreadRequest request;
497 Message onCompleted;
498 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800501 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700502
503 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 case CMD_HANDLE_USSD_REQUEST: {
505 request = (MainThreadRequest) msg.obj;
506 final Phone phone = getPhoneFromRequest(request);
507 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
508 String ussdRequest = ussdObject.first;
509 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700510
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 if (!isUssdApiAllowed(request.subId)) {
512 // Carrier does not support use of this API, return failure.
513 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
514 UssdResponse response = new UssdResponse(ussdRequest, null);
515 Bundle returnData = new Bundle();
516 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
517 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700518
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 request.result = true;
520 notifyRequester(request);
521 return;
522 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700523
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 try {
525 request.result = phone != null
526 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
527 } catch (CallStateException cse) {
528 request.result = false;
529 }
530 // Wake up the requesting thread
531 notifyRequester(request);
532 break;
pkanwar32d516d2016-10-14 19:37:38 -0700533 }
534
Yorke Lee716f67e2015-06-17 15:39:16 -0700535 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700536 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700537 final Phone phone = getPhoneFromRequest(request);
538 request.result = phone != null ?
539 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
540 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700541 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700543 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700544 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700545
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700547 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("iccTransmitApduLogicalChannel: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
556 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 iccArgument.channel, iccArgument.cla, iccArgument.command,
559 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 break;
563
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 ar = (AsyncResult) msg.obj;
566 request = (MainThreadRequest) ar.userObj;
567 if (ar.exception == null && ar.result != null) {
568 request.result = ar.result;
569 } else {
570 request.result = new IccIoResult(0x6F, 0, (byte[])null);
571 if (ar.result == null) {
572 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800573 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700574 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800575 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 } else {
577 loge("iccTransmitApduLogicalChannel: Unknown exception");
578 }
579 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 break;
582
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
584 request = (MainThreadRequest) msg.obj;
585 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800586 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 if (uiccCard == null) {
588 loge("iccTransmitApduBasicChannel: No UICC");
589 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 } else {
592 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
593 request);
594 uiccCard.iccTransmitApduBasicChannel(
595 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
596 iccArgument.p3, iccArgument.data, onCompleted);
597 }
598 break;
599
600 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
601 ar = (AsyncResult) msg.obj;
602 request = (MainThreadRequest) ar.userObj;
603 if (ar.exception == null && ar.result != null) {
604 request.result = ar.result;
605 } else {
606 request.result = new IccIoResult(0x6F, 0, (byte[])null);
607 if (ar.result == null) {
608 loge("iccTransmitApduBasicChannel: Empty response");
609 } else if (ar.exception instanceof CommandException) {
610 loge("iccTransmitApduBasicChannel: CommandException: " +
611 ar.exception);
612 } else {
613 loge("iccTransmitApduBasicChannel: Unknown exception");
614 }
615 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 break;
618
619 case CMD_EXCHANGE_SIM_IO:
620 request = (MainThreadRequest) msg.obj;
621 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 if (uiccCard == null) {
624 loge("iccExchangeSimIO: No UICC");
625 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 } else {
628 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
629 request);
630 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
631 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
632 iccArgument.data, onCompleted);
633 }
634 break;
635
636 case EVENT_EXCHANGE_SIM_IO_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
639 if (ar.exception == null && ar.result != null) {
640 request.result = ar.result;
641 } else {
642 request.result = new IccIoResult(0x6f, 0, (byte[])null);
643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700645 break;
646
Derek Tan4d5e5c12014-02-04 11:54:58 -0800647 case CMD_SEND_ENVELOPE:
648 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800649 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 if (uiccCard == null) {
651 loge("sendEnvelopeWithStatus: No UICC");
652 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700653 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700654 } else {
655 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
656 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
657 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800658 break;
659
660 case EVENT_SEND_ENVELOPE_DONE:
661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800665 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700666 request.result = new IccIoResult(0x6F, 0, (byte[])null);
667 if (ar.result == null) {
668 loge("sendEnvelopeWithStatus: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("sendEnvelopeWithStatus: CommandException: " +
671 ar.exception);
672 } else {
673 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
674 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800677 break;
678
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 case CMD_OPEN_CHANNEL:
680 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800681 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800682 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 if (uiccCard == null) {
684 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800685 request.result = new IccOpenLogicalChannelResponse(-1,
686 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700687 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700688 } else {
689 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800690 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
691 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700692 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 break;
694
695 case EVENT_OPEN_CHANNEL_DONE:
696 ar = (AsyncResult) msg.obj;
697 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700698 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700700 int[] result = (int[]) ar.result;
701 int channelId = result[0];
702 byte[] selectResponse = null;
703 if (result.length > 1) {
704 selectResponse = new byte[result.length - 1];
705 for (int i = 1; i < result.length; ++i) {
706 selectResponse[i - 1] = (byte) result[i];
707 }
708 }
709 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700710 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 if (ar.result == null) {
713 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700715 if (ar.exception != null) {
716 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
717 }
718
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700719 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700720 if (ar.exception instanceof CommandException) {
721 CommandException.Error error =
722 ((CommandException) (ar.exception)).getCommandError();
723 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700724 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700725 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700726 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700727 }
728 }
729 openChannelResp = new IccOpenLogicalChannelResponse(
730 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700731 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700732 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 break;
735
736 case CMD_CLOSE_CHANNEL:
737 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800738 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700739 if (uiccCard == null) {
740 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900741 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700742 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700743 } else {
744 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
745 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
746 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700747 break;
748
749 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800750 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
751 break;
752
753 case CMD_NV_READ_ITEM:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800756 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
757 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800758 break;
759
760 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800763 if (ar.exception == null && ar.result != null) {
764 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700765 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800766 request.result = "";
767 if (ar.result == null) {
768 loge("nvReadItem: Empty response");
769 } else if (ar.exception instanceof CommandException) {
770 loge("nvReadItem: CommandException: " +
771 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700772 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800773 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700774 }
775 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700777 break;
778
Jake Hambye994d462014-02-03 13:10:13 -0800779 case CMD_NV_WRITE_ITEM:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
782 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800783 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700784 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
787 case EVENT_NV_WRITE_ITEM_DONE:
788 handleNullReturnEvent(msg, "nvWriteItem");
789 break;
790
791 case CMD_NV_WRITE_CDMA_PRL:
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800794 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800795 break;
796
797 case EVENT_NV_WRITE_CDMA_PRL_DONE:
798 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
799 break;
800
chen xu6dac5ab2018-10-26 17:39:23 -0700801 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800802 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700803 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800804 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800805 break;
806
chen xu6dac5ab2018-10-26 17:39:23 -0700807 case EVENT_RESET_MODEM_CONFIG_DONE:
808 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800809 break;
810
Sooraj Sasindran37444802020-08-11 10:40:43 -0700811 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
812 request = (MainThreadRequest) msg.obj;
813 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
814 request);
815 Phone phone = getPhoneFromRequest(request);
816 if (phone != null) {
817 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
818 } else {
819 loge("isNRDualConnectivityEnabled: No phone object");
820 request.result = false;
821 notifyRequester(request);
822 }
823 break;
824 }
825
826 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 if (ar.exception == null && ar.result != null) {
830 request.result = ar.result;
831 } else {
832 // request.result must be set to something non-null
833 // for the calling thread to unblock
834 if (request.result != null) {
835 request.result = ar.result;
836 } else {
837 request.result = false;
838 }
839 if (ar.result == null) {
840 loge("isNRDualConnectivityEnabled: Empty response");
841 } else if (ar.exception instanceof CommandException) {
842 loge("isNRDualConnectivityEnabled: CommandException: "
843 + ar.exception);
844 } else {
845 loge("isNRDualConnectivityEnabled: Unknown exception");
846 }
847 }
848 notifyRequester(request);
849 break;
850
851 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
852 request = (MainThreadRequest) msg.obj;
853 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
854 Phone phone = getPhoneFromRequest(request);
855 if (phone != null) {
856 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
857 request.workSource);
858 } else {
859 loge("enableNrDualConnectivity: No phone object");
860 request.result =
861 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
862 notifyRequester(request);
863 }
864 break;
865 }
866
867 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null) {
871 request.result =
872 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
873 } else {
874 request.result =
875 TelephonyManager
876 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
877 if (ar.exception instanceof CommandException) {
878 CommandException.Error error =
879 ((CommandException) (ar.exception)).getCommandError();
880 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
881 request.result =
882 TelephonyManager
883 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000884 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
885 request.result =
886 TelephonyManager
887 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700888 }
889 loge("enableNrDualConnectivity" + ": CommandException: "
890 + ar.exception);
891 } else {
892 loge("enableNrDualConnectivity" + ": Unknown exception");
893 }
894 }
895 notifyRequester(request);
896 break;
897 }
898
SongFerngWang3ef3e072020-12-21 16:41:52 +0800899 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800901 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
902 request);
903 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 break;
905
SongFerngWang3ef3e072020-12-21 16:41:52 +0800906 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 ar = (AsyncResult) msg.obj;
908 request = (MainThreadRequest) ar.userObj;
909 if (ar.exception == null && ar.result != null) {
910 request.result = ar.result; // Integer
911 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530912 // request.result must be set to something non-null
913 // for the calling thread to unblock
914 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800915 if (ar.result == null) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800916 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 } else if (ar.exception instanceof CommandException) {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800918 loge("getAllowedNetworkTypesBitmask: CommandException: "
919 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800920 } else {
SongFerngWang3ef3e072020-12-21 16:41:52 +0800921 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800922 }
923 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700924 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800925 break;
926
SongFerngWang3ef3e072020-12-21 16:41:52 +0800927 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800928 request = (MainThreadRequest) msg.obj;
SongFerngWang3ef3e072020-12-21 16:41:52 +0800929 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
930 request);
931 Pair<Integer, Long> reasonWithNetworkTypes =
932 (Pair<Integer, Long>) request.argument;
933 getPhoneFromRequest(request).setAllowedNetworkTypes(
934 reasonWithNetworkTypes.first,
935 reasonWithNetworkTypes.second,
936 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800937 break;
938
SongFerngWang3ef3e072020-12-21 16:41:52 +0800939 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
940 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800941 break;
942
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000943 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
944 request = (MainThreadRequest)msg.obj;
945 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800946 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000947 break;
948
949 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
950 ar = (AsyncResult)msg.obj;
951 request = (MainThreadRequest)ar.userObj;
952 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700953 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000954 break;
955
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800956 case CMD_SET_VOICEMAIL_NUMBER:
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
959 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800960 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
961 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800962 break;
963
964 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
965 handleNullReturnEvent(msg, "setVoicemailNumber");
966 break;
967
Stuart Scott54788802015-03-30 13:18:01 -0700968 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
969 request = (MainThreadRequest) msg.obj;
970 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
971 request);
972 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
973 break;
974
975 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
976 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
977 break;
978
Shishir Agrawal302c8692015-06-19 13:49:39 -0700979 case CMD_PERFORM_NETWORK_SCAN:
980 request = (MainThreadRequest) msg.obj;
981 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
982 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
983 break;
984
Hall Liu27d24262020-09-18 19:04:59 -0700985 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800986 request = (MainThreadRequest) msg.obj;
987 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700988 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
989 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
990 request.argument;
991 int callForwardingReason = args.first;
992 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800993 break;
Hall Liu27d24262020-09-18 19:04:59 -0700994 }
995 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700998 TelephonyManager.CallForwardingInfoCallback callback =
999 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
1000 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -08001001 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -07001002 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -08001003 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
1004 for (CallForwardInfo callForwardInfo : callForwardInfos) {
1005 // Service Class is a bit mask per 3gpp 27.007. Search for
1006 // any service for voice call.
1007 if ((callForwardInfo.serviceClass
1008 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -07001009 callForwardingInfo = new CallForwardingInfo(true,
1010 callForwardInfo.reason,
1011 callForwardInfo.number,
1012 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -08001013 break;
1014 }
1015 }
1016 // Didn't find a call forward info for voice call.
1017 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -07001018 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
1019 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -08001020 }
Hall Liu27d24262020-09-18 19:04:59 -07001021 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -08001022 } else {
1023 if (ar.result == null) {
1024 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1025 }
1026 if (ar.exception != null) {
1027 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1028 }
Hall Liu940c4ca2020-09-29 17:10:18 -07001029 int errorCode = TelephonyManager
1030 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -08001031 if (ar.exception instanceof CommandException) {
1032 CommandException.Error error =
1033 ((CommandException) (ar.exception)).getCommandError();
1034 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001035 errorCode = TelephonyManager
1036 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -08001037 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001038 errorCode = TelephonyManager
1039 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -08001040 }
1041 }
Hall Liu27d24262020-09-18 19:04:59 -07001042 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001043 }
Shuo Qian4a594052020-01-23 11:59:30 -08001044 break;
Hall Liu27d24262020-09-18 19:04:59 -07001045 }
Shuo Qian4a594052020-01-23 11:59:30 -08001046
Hall Liu27d24262020-09-18 19:04:59 -07001047 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001050 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001051 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001052 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1053 request.argument).first;
1054 request.phone.setCallForwardingOption(
1055 callForwardingInfoToSet.isEnabled()
1056 ? CommandsInterface.CF_ACTION_ENABLE
1057 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001058 callForwardingInfoToSet.getReason(),
1059 callForwardingInfoToSet.getNumber(),
1060 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1061 break;
Hall Liu27d24262020-09-18 19:04:59 -07001062 }
Shuo Qian4a594052020-01-23 11:59:30 -08001063
Hall Liu27d24262020-09-18 19:04:59 -07001064 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001067 Consumer<Integer> callback =
1068 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1069 request.argument).second;
1070 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001071 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001072 int errorCode = TelephonyManager.CallForwardingInfoCallback
1073 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001074 if (ar.exception instanceof CommandException) {
1075 CommandException.Error error =
1076 ((CommandException) (ar.exception)).getCommandError();
1077 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001078 errorCode = TelephonyManager.CallForwardingInfoCallback
1079 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001080 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001081 errorCode = TelephonyManager.CallForwardingInfoCallback
1082 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001083 }
1084 }
1085 callback.accept(errorCode);
1086 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001087 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001088 }
Shuo Qian4a594052020-01-23 11:59:30 -08001089 break;
Hall Liu27d24262020-09-18 19:04:59 -07001090 }
Shuo Qian4a594052020-01-23 11:59:30 -08001091
Hall Liu27d24262020-09-18 19:04:59 -07001092 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001093 request = (MainThreadRequest) msg.obj;
1094 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1095 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1096 break;
Hall Liu27d24262020-09-18 19:04:59 -07001097 }
Shuo Qian4a594052020-01-23 11:59:30 -08001098
Hall Liu27d24262020-09-18 19:04:59 -07001099 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001100 ar = (AsyncResult) msg.obj;
1101 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001102 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001103 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1104 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001105 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001106 // Service Class is a bit mask per 3gpp 27.007.
1107 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001108 if (callForwardResults.length > 1
1109 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001110 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001111 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001112 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1113 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001114 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001115 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001116 }
1117 } else {
1118 if (ar.result == null) {
1119 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1120 }
1121 if (ar.exception != null) {
1122 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1123 }
1124 if (ar.exception instanceof CommandException) {
1125 CommandException.Error error =
1126 ((CommandException) (ar.exception)).getCommandError();
1127 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1128 callForwardingStatus =
1129 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1130 }
1131 }
1132 }
Hall Liu27d24262020-09-18 19:04:59 -07001133 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001134 break;
Hall Liu27d24262020-09-18 19:04:59 -07001135 }
Shuo Qian4a594052020-01-23 11:59:30 -08001136
Hall Liu27d24262020-09-18 19:04:59 -07001137 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001138 request = (MainThreadRequest) msg.obj;
1139 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001140 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1141 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001142 break;
Hall Liu27d24262020-09-18 19:04:59 -07001143 }
Shuo Qian4a594052020-01-23 11:59:30 -08001144
Hall Liu27d24262020-09-18 19:04:59 -07001145 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001146 ar = (AsyncResult) msg.obj;
1147 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001148 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1149 Consumer<Integer> callback =
1150 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1151 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001152 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001153 if (ar.exception instanceof CommandException) {
1154 CommandException.Error error =
1155 ((CommandException) (ar.exception)).getCommandError();
1156 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1157 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1158 } else {
1159 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1160 }
1161 } else {
1162 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1163 }
1164 } else {
1165 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1166 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001167 }
Shuo Qian4a594052020-01-23 11:59:30 -08001168 break;
Hall Liu27d24262020-09-18 19:04:59 -07001169 }
Shuo Qian4a594052020-01-23 11:59:30 -08001170
Shishir Agrawal302c8692015-06-19 13:49:39 -07001171 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1172 ar = (AsyncResult) msg.obj;
1173 request = (MainThreadRequest) ar.userObj;
1174 CellNetworkScanResult cellScanResult;
1175 if (ar.exception == null && ar.result != null) {
1176 cellScanResult = new CellNetworkScanResult(
1177 CellNetworkScanResult.STATUS_SUCCESS,
1178 (List<OperatorInfo>) ar.result);
1179 } else {
1180 if (ar.result == null) {
1181 loge("getCellNetworkScanResults: Empty response");
1182 }
1183 if (ar.exception != null) {
1184 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1185 }
1186 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1187 if (ar.exception instanceof CommandException) {
1188 CommandException.Error error =
1189 ((CommandException) (ar.exception)).getCommandError();
1190 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1191 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1192 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1193 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1194 }
1195 }
1196 cellScanResult = new CellNetworkScanResult(errorCode, null);
1197 }
1198 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001199 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001200 break;
1201
1202 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1203 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001204 ManualNetworkSelectionArgument selArg =
1205 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001206 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1207 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001208 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1209 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001210 break;
1211
1212 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001213 ar = (AsyncResult) msg.obj;
1214 request = (MainThreadRequest) ar.userObj;
1215 if (ar.exception == null) {
1216 request.result = true;
1217 } else {
1218 request.result = false;
1219 loge("setNetworkSelectionModeManual " + ar.exception);
1220 }
1221 notifyRequester(request);
1222 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001223 break;
1224
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001225 case CMD_GET_MODEM_ACTIVITY_INFO:
1226 request = (MainThreadRequest) msg.obj;
1227 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001228 if (defaultPhone != null) {
1229 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001230 } else {
1231 ResultReceiver result = (ResultReceiver) request.argument;
1232 Bundle bundle = new Bundle();
1233 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001234 new ModemActivityInfo(0, 0, 0,
1235 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001236 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001237 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001238 break;
1239
Hall Liud0f208c2020-10-14 16:54:44 -07001240 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001241 ar = (AsyncResult) msg.obj;
1242 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001243 ResultReceiver result = (ResultReceiver) request.argument;
1244
Hall Liud0f208c2020-10-14 16:54:44 -07001245 ModemActivityInfo ret = null;
1246 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001247 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001248 // Update the last modem activity info and the result of the request.
1249 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1250 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001251 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001252 int[] txTimeMs = info.getTransmitTimeMillis();
1253 int[] lastModemTxTimeMs = mLastModemActivityInfo
1254 .getTransmitTimeMillis();
1255 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1256 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1257 }
Hall Liu49656c02020-10-09 19:00:11 -07001258 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001259 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1260 + mLastModemActivityInfo.getSleepTimeMillis());
1261 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1262 + mLastModemActivityInfo.getIdleTimeMillis());
1263 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1264 mLastModemActivityInfo.setReceiveTimeMillis(
1265 info.getReceiveTimeMillis()
1266 + mLastModemActivityInfo.getReceiveTimeMillis());
1267 }
Hall Liu49656c02020-10-09 19:00:11 -07001268 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001269 mLastModemActivityInfo.getSleepTimeMillis(),
1270 mLastModemActivityInfo.getIdleTimeMillis(),
1271 mLastModemActivityInfo.getTransmitTimeMillis(),
1272 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001273 } else {
1274 if (ar.result == null) {
1275 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001276 error = TelephonyManager.ModemActivityInfoException
1277 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001278 } else if (ar.exception instanceof CommandException) {
1279 loge("queryModemActivityInfo: CommandException: " +
1280 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001281 error = TelephonyManager.ModemActivityInfoException
1282 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001283 } else {
1284 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001285 error = TelephonyManager.ModemActivityInfoException
1286 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001287 }
1288 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001289 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001290 if (ret != null) {
1291 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1292 } else {
1293 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1294 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001295 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001296 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001297 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001298 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001299
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 case CMD_SET_ALLOWED_CARRIERS:
1301 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001302 CarrierRestrictionRules argument =
1303 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001304 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001305 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 break;
1307
1308 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1309 ar = (AsyncResult) msg.obj;
1310 request = (MainThreadRequest) ar.userObj;
1311 if (ar.exception == null && ar.result != null) {
1312 request.result = ar.result;
1313 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001314 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1315 if (ar.exception instanceof CommandException) {
1316 loge("setAllowedCarriers: CommandException: " + ar.exception);
1317 CommandException.Error error =
1318 ((CommandException) (ar.exception)).getCommandError();
1319 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1320 request.result =
1321 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1322 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001323 } else {
1324 loge("setAllowedCarriers: Unknown exception");
1325 }
1326 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001327 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001328 break;
1329
1330 case CMD_GET_ALLOWED_CARRIERS:
1331 request = (MainThreadRequest) msg.obj;
1332 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001333 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001334 break;
1335
1336 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
1339 if (ar.exception == null && ar.result != null) {
1340 request.result = ar.result;
1341 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001342 request.result = new IllegalStateException(
1343 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001344 if (ar.result == null) {
1345 loge("getAllowedCarriers: Empty response");
1346 } else if (ar.exception instanceof CommandException) {
1347 loge("getAllowedCarriers: CommandException: " +
1348 ar.exception);
1349 } else {
1350 loge("getAllowedCarriers: Unknown exception");
1351 }
1352 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001353 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001354 break;
1355
Nathan Haroldb3014052017-01-25 15:57:32 -08001356 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1357 ar = (AsyncResult) msg.obj;
1358 request = (MainThreadRequest) ar.userObj;
1359 if (ar.exception == null && ar.result != null) {
1360 request.result = ar.result;
1361 } else {
1362 request.result = new IllegalArgumentException(
1363 "Failed to retrieve Forbidden Plmns");
1364 if (ar.result == null) {
1365 loge("getForbiddenPlmns: Empty response");
1366 } else {
1367 loge("getForbiddenPlmns: Unknown exception");
1368 }
1369 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001370 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001371 break;
1372
1373 case CMD_GET_FORBIDDEN_PLMNS:
1374 request = (MainThreadRequest) msg.obj;
1375 uiccCard = getUiccCardFromRequest(request);
1376 if (uiccCard == null) {
1377 loge("getForbiddenPlmns() UiccCard is null");
1378 request.result = new IllegalArgumentException(
1379 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001380 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001381 break;
1382 }
1383 Integer appType = (Integer) request.argument;
1384 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1385 if (uiccApp == null) {
1386 loge("getForbiddenPlmns() no app with specified type -- "
1387 + appType);
1388 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001389 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001390 break;
1391 } else {
1392 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1393 + " specified type -- " + appType);
1394 }
1395 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1396 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1397 onCompleted);
1398 break;
1399
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001400 case CMD_SWITCH_SLOTS:
1401 request = (MainThreadRequest) msg.obj;
1402 int[] physicalSlots = (int[]) request.argument;
1403 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1404 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1405 break;
1406
1407 case EVENT_SWITCH_SLOTS_DONE:
1408 ar = (AsyncResult) msg.obj;
1409 request = (MainThreadRequest) ar.userObj;
1410 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001411 notifyRequester(request);
1412 break;
1413 case CMD_GET_NETWORK_SELECTION_MODE:
1414 request = (MainThreadRequest) msg.obj;
1415 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1416 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1417 break;
1418
1419 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1420 ar = (AsyncResult) msg.obj;
1421 request = (MainThreadRequest) ar.userObj;
1422 if (ar.exception != null) {
1423 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1424 } else {
1425 int mode = ((int[]) ar.result)[0];
1426 if (mode == 0) {
1427 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1428 } else {
1429 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1430 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001431 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001432 notifyRequester(request);
1433 break;
1434 case CMD_GET_CDMA_ROAMING_MODE:
1435 request = (MainThreadRequest) msg.obj;
1436 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1437 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1438 break;
1439 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1440 ar = (AsyncResult) msg.obj;
1441 request = (MainThreadRequest) ar.userObj;
1442 if (ar.exception != null) {
1443 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1444 } else {
1445 request.result = ((int[]) ar.result)[0];
1446 }
1447 notifyRequester(request);
1448 break;
1449 case CMD_SET_CDMA_ROAMING_MODE:
1450 request = (MainThreadRequest) msg.obj;
1451 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1452 int mode = (int) request.argument;
1453 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1454 break;
1455 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
1458 request.result = ar.exception == null;
1459 notifyRequester(request);
1460 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001461 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1462 request = (MainThreadRequest) msg.obj;
1463 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1464 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1465 break;
1466 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 if (ar.exception != null) {
1470 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1471 } else {
1472 request.result = ((int[]) ar.result)[0];
1473 }
1474 notifyRequester(request);
1475 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001476 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1477 request = (MainThreadRequest) msg.obj;
1478 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1479 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001480 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1481 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001482 break;
1483 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1484 ar = (AsyncResult) msg.obj;
1485 request = (MainThreadRequest) ar.userObj;
1486 request.result = ar.exception == null;
1487 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001488 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 case CMD_GET_ALL_CELL_INFO:
1490 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001492 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 case EVENT_GET_ALL_CELL_INFO_DONE:
1495 ar = (AsyncResult) msg.obj;
1496 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001497 // If a timeout occurs, the response will be null
1498 request.result = (ar.exception == null && ar.result != null)
1499 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001500 synchronized (request) {
1501 request.notifyAll();
1502 }
1503 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001504 case CMD_REQUEST_CELL_INFO_UPDATE:
1505 request = (MainThreadRequest) msg.obj;
1506 request.phone.requestCellInfoUpdate(request.workSource,
1507 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1508 break;
1509 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1510 ar = (AsyncResult) msg.obj;
1511 request = (MainThreadRequest) ar.userObj;
1512 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1513 try {
1514 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001515 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001516 cb.onError(
1517 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1518 ar.exception.getClass().getName(),
1519 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001520 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001521 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001522 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001523 } else {
1524 // use the result as returned
1525 cb.onCellInfo((List<CellInfo>) ar.result);
1526 }
1527 } catch (RemoteException re) {
1528 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1529 }
1530 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001531 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001532 request = (MainThreadRequest) msg.obj;
1533 WorkSource ws = (WorkSource) request.argument;
1534 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001535 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001536 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001537 }
1538 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001539 ar = (AsyncResult) msg.obj;
1540 request = (MainThreadRequest) ar.userObj;
1541 if (ar.exception == null) {
1542 request.result = ar.result;
1543 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001544 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001545 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001546 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001547 }
1548
1549 synchronized (request) {
1550 request.notifyAll();
1551 }
1552 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001553 }
chen xu6dac5ab2018-10-26 17:39:23 -07001554 case CMD_MODEM_REBOOT:
1555 request = (MainThreadRequest) msg.obj;
1556 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001557 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001558 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001559 case EVENT_CMD_MODEM_REBOOT_DONE:
1560 handleNullReturnEvent(msg, "rebootModem");
1561 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001562 case CMD_REQUEST_ENABLE_MODEM:
1563 request = (MainThreadRequest) msg.obj;
1564 boolean enable = (boolean) request.argument;
1565 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001566 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001567 PhoneConfigurationManager.getInstance()
1568 .enablePhone(request.phone, enable, onCompleted);
1569 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001570 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001571 ar = (AsyncResult) msg.obj;
1572 request = (MainThreadRequest) ar.userObj;
1573 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001574 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001575 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001576 if ((boolean) request.result) {
1577 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1578 updateModemStateMetrics();
1579 } else {
1580 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1581 + ar.exception);
1582 }
1583 notifyRequester(request);
1584 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001585 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001586 case CMD_GET_MODEM_STATUS:
1587 request = (MainThreadRequest) msg.obj;
1588 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1589 PhoneConfigurationManager.getInstance()
1590 .getPhoneStatusFromModem(request.phone, onCompleted);
1591 break;
1592 case EVENT_GET_MODEM_STATUS_DONE:
1593 ar = (AsyncResult) msg.obj;
1594 request = (MainThreadRequest) ar.userObj;
1595 int id = request.phone.getPhoneId();
1596 if (ar.exception == null && ar.result != null) {
1597 request.result = ar.result;
1598 //update the cache as modem status has changed
1599 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1600 (boolean) request.result);
1601 } else {
1602 // Return true if modem status cannot be retrieved. For most cases,
1603 // modem status is on. And for older version modems, GET_MODEM_STATUS
1604 // and disable modem are not supported. Modem is always on.
1605 // TODO: this should be fixed in R to support a third
1606 // status UNKNOWN b/131631629
1607 request.result = true;
1608 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1609 + ar.exception);
1610 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001611 notifyRequester(request);
1612 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001613 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1614 request = (MainThreadRequest) msg.obj;
1615 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1616 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1617 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1618 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1619 break;
1620 }
1621 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1625 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1626 args.second.accept(ar.exception == null);
1627 notifyRequester(request);
1628 break;
1629 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001630 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1631 request = (MainThreadRequest) msg.obj;
1632 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1633 Phone phone = getPhoneFromRequest(request);
1634 if (phone != null) {
1635 phone.getSystemSelectionChannels(onCompleted);
1636 } else {
1637 loge("getSystemSelectionChannels: No phone object");
1638 request.result = new ArrayList<RadioAccessSpecifier>();
1639 notifyRequester(request);
1640 }
1641 break;
1642 }
1643 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1644 ar = (AsyncResult) msg.obj;
1645 request = (MainThreadRequest) ar.userObj;
1646 if (ar.exception == null && ar.result != null) {
1647 request.result = ar.result;
1648 } else {
1649 request.result = new IllegalArgumentException(
1650 "Failed to retrieve system selection channels");
1651 if (ar.result == null) {
1652 loge("getSystemSelectionChannels: Empty response");
1653 } else {
1654 loge("getSystemSelectionChannels: Unknown exception");
1655 }
1656 }
1657 notifyRequester(request);
1658 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001659 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1660 ar = (AsyncResult) msg.obj;
1661 request = (MainThreadRequest) ar.userObj;
1662 if (ar.exception == null && ar.result != null) {
1663 request.result = ar.result;
1664 } else {
1665 request.result = -1;
1666 loge("Failed to set Forbidden Plmns");
1667 if (ar.result == null) {
1668 loge("setForbidenPlmns: Empty response");
1669 } else if (ar.exception != null) {
1670 loge("setForbiddenPlmns: Exception: " + ar.exception);
1671 request.result = -1;
1672 } else {
1673 loge("setForbiddenPlmns: Unknown exception");
1674 }
1675 }
1676 notifyRequester(request);
1677 break;
1678 case CMD_SET_FORBIDDEN_PLMNS:
1679 request = (MainThreadRequest) msg.obj;
1680 uiccCard = getUiccCardFromRequest(request);
1681 if (uiccCard == null) {
1682 loge("setForbiddenPlmns: UiccCard is null");
1683 request.result = -1;
1684 notifyRequester(request);
1685 break;
1686 }
1687 Pair<Integer, List<String>> setFplmnsArgs =
1688 (Pair<Integer, List<String>>) request.argument;
1689 appType = setFplmnsArgs.first;
1690 List<String> fplmns = setFplmnsArgs.second;
1691 uiccApp = uiccCard.getApplicationByType(appType);
1692 if (uiccApp == null) {
1693 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1694 request.result = -1;
1695 loge("Failed to get UICC App");
1696 notifyRequester(request);
1697 } else {
1698 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1699 ((SIMRecords) uiccApp.getIccRecords())
1700 .setForbiddenPlmns(onCompleted, fplmns);
1701 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001702 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001703 case CMD_ERASE_MODEM_CONFIG:
1704 request = (MainThreadRequest) msg.obj;
1705 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1706 defaultPhone.eraseModemConfig(onCompleted);
1707 break;
1708 case EVENT_ERASE_MODEM_CONFIG_DONE:
1709 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001710 break;
zoey chene02881a2019-12-30 16:11:23 +08001711
Kai Shif70f46f2021-03-03 13:59:46 -08001712 case CMD_ERASE_DATA_SHARED_PREFERENCES:
1713 request = (MainThreadRequest) msg.obj;
1714 request.result = defaultPhone.eraseDataInSharedPreferences();
1715 notifyRequester(request);
1716 break;
1717
zoey chene02881a2019-12-30 16:11:23 +08001718 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1719 request = (MainThreadRequest) msg.obj;
1720 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1721 Pair<String, String> changed = (Pair<String, String>) request.argument;
1722 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1723 changed.first, changed.second, onCompleted);
1724 break;
1725 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1726 ar = (AsyncResult) msg.obj;
1727 request = (MainThreadRequest) ar.userObj;
1728 if (ar.exception == null) {
1729 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001730 // If the operation is successful, update the PIN storage
1731 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1732 int phoneId = getPhoneFromRequest(request).getPhoneId();
1733 UiccController.getInstance().getPinStorage()
1734 .storePin(passwords.second, phoneId);
zoey chene02881a2019-12-30 16:11:23 +08001735 } else {
1736 request.result = msg.arg1;
1737 }
1738 notifyRequester(request);
1739 break;
1740
Michele Berionne5e411512020-11-13 02:36:59 +00001741 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chene02881a2019-12-30 16:11:23 +08001742 request = (MainThreadRequest) msg.obj;
1743 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1744 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1745 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1746 enabled.first, enabled.second, onCompleted);
1747 break;
Michele Berionne5e411512020-11-13 02:36:59 +00001748 }
zoey chene02881a2019-12-30 16:11:23 +08001749 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1750 ar = (AsyncResult) msg.obj;
1751 request = (MainThreadRequest) ar.userObj;
1752 if (ar.exception == null) {
1753 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionne5e411512020-11-13 02:36:59 +00001754 // If the operation is successful, update the PIN storage
1755 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1756 int phoneId = getPhoneFromRequest(request).getPhoneId();
1757 if (enabled.first) {
1758 UiccController.getInstance().getPinStorage()
1759 .storePin(enabled.second, phoneId);
1760 } else {
1761 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1762 }
zoey chene02881a2019-12-30 16:11:23 +08001763 } else {
1764 request.result = msg.arg1;
1765 }
Michele Berionne5e411512020-11-13 02:36:59 +00001766
1767
zoey chene02881a2019-12-30 16:11:23 +08001768 notifyRequester(request);
1769 break;
1770
Peter Wangdafb9ac2020-01-15 14:13:38 -08001771 case MSG_NOTIFY_USER_ACTIVITY:
1772 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001773 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001774 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1775 getDefaultPhone().getContext().sendBroadcastAsUser(
1776 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1777 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001778
1779 case CMD_SET_DATA_THROTTLING: {
1780 request = (MainThreadRequest) msg.obj;
1781 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1782 DataThrottlingRequest dataThrottlingRequest =
1783 (DataThrottlingRequest) request.argument;
1784 Phone phone = getPhoneFromRequest(request);
1785 if (phone != null) {
1786 phone.setDataThrottling(onCompleted,
1787 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1788 dataThrottlingRequest.getCompletionDurationMillis());
1789 } else {
1790 loge("setDataThrottling: No phone object");
1791 request.result =
1792 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1793 notifyRequester(request);
1794 }
1795
1796 break;
1797 }
1798 case EVENT_SET_DATA_THROTTLING_DONE:
1799 ar = (AsyncResult) msg.obj;
1800 request = (MainThreadRequest) ar.userObj;
1801
1802 if (ar.exception == null) {
1803 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1804 } else if (ar.exception instanceof CommandException) {
1805 loge("setDataThrottling: CommandException: " + ar.exception);
1806 CommandException.Error error =
1807 ((CommandException) (ar.exception)).getCommandError();
1808
1809 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1810 request.result = TelephonyManager
1811 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1812 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1813 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08001814 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1815 request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001816 } else {
1817 request.result =
1818 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1819 }
1820 } else {
1821 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1822 }
1823 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1824 notifyRequester(request);
1825 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001826
1827 case CMD_SET_SIM_POWER: {
1828 request = (MainThreadRequest) msg.obj;
1829 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1830 request = (MainThreadRequest) msg.obj;
1831 int stateToSet =
1832 ((Pair<Integer, IIntegerConsumer>)
1833 request.argument).first;
1834 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1835 break;
1836 }
1837 case EVENT_SET_SIM_POWER_DONE: {
1838 ar = (AsyncResult) msg.obj;
1839 request = (MainThreadRequest) ar.userObj;
1840 IIntegerConsumer callback =
1841 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1842 if (ar.exception != null) {
1843 loge("setSimPower exception: " + ar.exception);
1844 int errorCode = TelephonyManager.CallForwardingInfoCallback
1845 .RESULT_ERROR_UNKNOWN;
1846 if (ar.exception instanceof CommandException) {
1847 CommandException.Error error =
1848 ((CommandException) (ar.exception)).getCommandError();
1849 if (error == CommandException.Error.SIM_ERR) {
1850 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1851 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1852 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1853 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1854 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1855 } else {
1856 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1857 }
1858 }
1859 try {
1860 callback.accept(errorCode);
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 } else {
1866 try {
1867 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1868 } catch (RemoteException e) {
1869 // Ignore if the remote process is no longer available to call back.
1870 Log.w(LOG_TAG, "setSimPower: callback not available.");
1871 }
1872 }
1873 break;
1874 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001875 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1876 request = (MainThreadRequest) msg.obj;
1877
1878 final Phone phone = getPhoneFromRequest(request);
1879 if (phone == null || phone.getServiceStateTracker() == null) {
1880 request.result = new IllegalStateException("Phone or SST is null");
1881 notifyRequester(request);
1882 break;
1883 }
1884
1885 Pair<Integer, SignalStrengthUpdateRequest> pair =
1886 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1887 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1888 request);
1889 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1890 request.subId, pair.first /*callingUid*/,
1891 pair.second /*request*/, onCompleted);
1892 break;
1893 }
1894 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1895 ar = (AsyncResult) msg.obj;
1896 request = (MainThreadRequest) ar.userObj;
1897 // request.result will be the exception of ar if present, true otherwise.
1898 // Be cautious not to leave result null which will wait() forever
1899 request.result = ar.exception != null ? ar.exception : true;
1900 notifyRequester(request);
1901 break;
1902 }
1903 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1904 request = (MainThreadRequest) msg.obj;
1905
1906 Phone phone = getPhoneFromRequest(request);
1907 if (phone == null || phone.getServiceStateTracker() == null) {
1908 request.result = new IllegalStateException("Phone or SST is null");
1909 notifyRequester(request);
1910 break;
1911 }
1912
1913 Pair<Integer, SignalStrengthUpdateRequest> pair =
1914 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1915 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1916 request);
1917 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1918 request.subId, pair.first /*callingUid*/,
1919 pair.second /*request*/, onCompleted);
1920 break;
1921 }
1922 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1923 ar = (AsyncResult) msg.obj;
1924 request = (MainThreadRequest) ar.userObj;
1925 request.result = ar.exception != null ? ar.exception : true;
1926 notifyRequester(request);
1927 break;
1928 }
Jordan Liu109698e2020-11-24 14:50:34 -08001929
Hongbo Zeng156aa4a2021-02-08 21:50:28 +08001930 case CMD_GET_SLICING_CONFIG: {
1931 request = (MainThreadRequest) msg.obj;
1932 onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request);
1933 request.phone.getSlicingConfig(onCompleted);
1934 break;
1935 }
1936 case EVENT_GET_SLICING_CONFIG_DONE: {
1937 ar = (AsyncResult) msg.obj;
1938 request = (MainThreadRequest) ar.userObj;
1939 ResultReceiver result = (ResultReceiver) request.argument;
1940
1941 SlicingConfig slicingConfig = null;
1942 Bundle bundle = new Bundle();
1943 int resultCode = 0;
1944 if (ar.exception != null) {
1945 Log.e(LOG_TAG, "Exception retrieving slicing configuration="
1946 + ar.exception);
1947 resultCode = TelephonyManager.SlicingException.ERROR_MODEM_ERROR;
1948 } else if (ar.result == null) {
1949 Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!");
1950 resultCode = TelephonyManager.SlicingException.ERROR_TIMEOUT;
1951 } else {
1952 // use the result as returned
1953 resultCode = TelephonyManager.SlicingException.SUCCESS;
1954 slicingConfig = (SlicingConfig) ar.result;
1955 }
1956
1957 if (slicingConfig == null) {
1958 slicingConfig = new SlicingConfig();
1959 }
1960 bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig);
1961 result.send(resultCode, bundle);
1962 notifyRequester(request);
1963 break;
1964 }
1965
Michele Berionne5e411512020-11-13 02:36:59 +00001966 case CMD_PREPARE_UNATTENDED_REBOOT:
1967 request = (MainThreadRequest) msg.obj;
1968 request.result =
1969 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1970 notifyRequester(request);
1971 break;
1972
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001973 default:
1974 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1975 break;
1976 }
1977 }
Jake Hambye994d462014-02-03 13:10:13 -08001978
Pengquan Menga1bb6272018-09-06 09:59:22 -07001979 private void notifyRequester(MainThreadRequest request) {
1980 synchronized (request) {
1981 request.notifyAll();
1982 }
1983 }
1984
Jake Hambye994d462014-02-03 13:10:13 -08001985 private void handleNullReturnEvent(Message msg, String command) {
1986 AsyncResult ar = (AsyncResult) msg.obj;
1987 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1988 if (ar.exception == null) {
1989 request.result = true;
1990 } else {
1991 request.result = false;
1992 if (ar.exception instanceof CommandException) {
1993 loge(command + ": CommandException: " + ar.exception);
1994 } else {
1995 loge(command + ": Unknown exception");
1996 }
1997 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001998 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
2001
2002 /**
2003 * Posts the specified command to be executed on the main thread,
2004 * waits for the request to complete, and returns the result.
2005 * @see #sendRequestAsync
2006 */
2007 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002008 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
2009 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07002010 }
2011
2012 /**
2013 * Posts the specified command to be executed on the main thread,
2014 * waits for the request to complete, and returns the result.
2015 * @see #sendRequestAsync
2016 */
2017 private Object sendRequest(int command, Object argument, WorkSource workSource) {
2018 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08002019 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07002020 }
2021
2022 /**
2023 * Posts the specified command to be executed on the main thread,
2024 * waits for the request to complete, and returns the result.
2025 * @see #sendRequestAsync
2026 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002027 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002028 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
2029 }
2030
2031 /**
2032 * Posts the specified command to be executed on the main thread,
2033 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
2034 * if not timeout or null otherwise.
2035 * @see #sendRequestAsync
2036 */
2037 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
2038 long timeoutInMs) {
2039 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07002040 }
2041
2042 /**
2043 * Posts the specified command to be executed on the main thread,
2044 * waits for the request to complete, and returns the result.
2045 * @see #sendRequestAsync
2046 */
Nathan Harold92bed182018-10-12 18:16:49 -07002047 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002048 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002049 }
2050
2051 /**
2052 * Posts the specified command to be executed on the main thread,
2053 * waits for the request to complete, and returns the result.
2054 * @see #sendRequestAsync
2055 */
2056 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002057 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
2058 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07002059 }
2060
2061 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08002062 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
2063 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
2064 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07002065 * @see #sendRequestAsync
2066 */
Rambo Wang0f050d82021-02-12 11:43:36 -08002067 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
2068 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
2070 throw new RuntimeException("This method will deadlock if called from the main thread.");
2071 }
2072
Nathan Harold92bed182018-10-12 18:16:49 -07002073 MainThreadRequest request = null;
2074 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
2075 throw new IllegalArgumentException("subId and phone cannot both be specified!");
2076 } else if (phone != null) {
2077 request = new MainThreadRequest(argument, phone, workSource);
2078 } else {
2079 request = new MainThreadRequest(argument, subId, workSource);
2080 }
2081
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 Message msg = mMainThreadHandler.obtainMessage(command, request);
2083 msg.sendToTarget();
2084
Rambo Wang0f050d82021-02-12 11:43:36 -08002085
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002087 if (timeoutInMs >= 0) {
2088 // Wait for at least timeoutInMs before returning null request result
2089 long now = SystemClock.elapsedRealtime();
2090 long deadline = now + timeoutInMs;
2091 while (request == null && now < deadline) {
2092 try {
2093 request.wait(deadline - now);
2094 } catch (InterruptedException e) {
2095 // Do nothing, go back and check if request is completed or timeout
2096 } finally {
2097 now = SystemClock.elapsedRealtime();
2098 }
2099 }
2100 } else {
2101 // Wait for the request to complete
2102 while (request.result == null) {
2103 try {
2104 request.wait();
2105 } catch (InterruptedException e) {
2106 // Do nothing, go back and wait until the request is complete
2107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109 }
2110 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002111 if (request.result == null) {
2112 Log.wtf(LOG_TAG,
2113 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 return request.result;
2116 }
2117
2118 /**
2119 * Asynchronous ("fire and forget") version of sendRequest():
2120 * Posts the specified command to be executed on the main thread, and
2121 * returns immediately.
2122 * @see #sendRequest
2123 */
2124 private void sendRequestAsync(int command) {
2125 mMainThreadHandler.sendEmptyMessage(command);
2126 }
2127
2128 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002129 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002130 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002131 */
2132 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002133 sendRequestAsync(command, argument, null, null);
2134 }
2135
2136 /**
2137 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2138 * @see {@link #sendRequest(int,Object)}
2139 */
2140 private void sendRequestAsync(
2141 int command, Object argument, Phone phone, WorkSource workSource) {
2142 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002143 Message msg = mMainThreadHandler.obtainMessage(command, request);
2144 msg.sendToTarget();
2145 }
2146
2147 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 * Initialize the singleton PhoneInterfaceManager instance.
2149 * This is only done once, at startup, from PhoneApp.onCreate().
2150 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002151 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 synchronized (PhoneInterfaceManager.class) {
2153 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002154 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 } else {
2156 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2157 }
2158 return sInstance;
2159 }
2160 }
2161
2162 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002163 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08002166 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002167 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2169 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002170 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002171 mTelephonySharedPreferences =
2172 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002173 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002174 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Daniel Bright94f43662021-03-01 14:43:40 -08002175 mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002176 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002178 publish();
2179 }
2180
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002181 private Phone getDefaultPhone() {
2182 Phone thePhone = getPhone(getDefaultSubscription());
2183 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2184 }
2185
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 private void publish() {
2187 if (DBG) log("publish: " + this);
2188
Peter Wangc035ce42020-01-08 21:00:22 -08002189 TelephonyFrameworkInitializer
2190 .getTelephonyServiceManager()
2191 .getTelephonyServiceRegisterer()
2192 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 }
2194
Stuart Scott584921c2015-01-15 17:10:34 -08002195 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002196 if (request.phone != null) {
2197 return request.phone;
2198 } else {
2199 return getPhoneFromSubId(request.subId);
2200 }
2201 }
2202
2203 private Phone getPhoneFromSubId(int subId) {
2204 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2205 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002206 }
2207
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002208 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2209 Phone phone = getPhoneFromRequest(request);
2210 return phone == null ? null :
2211 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2212 }
2213
Wink Saville36469e72014-06-11 15:17:00 -07002214 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002215 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002216 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218
Kai Shif70f46f2021-03-03 13:59:46 -08002219 private void sendEraseModemConfig(@NonNull Phone phone) {
2220 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2221 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2222 }
2223
2224 private void sendEraseDataInSharedPreferences(@NonNull Phone phone) {
2225 Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null);
2226 if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail"));
Naina Nallurid63128d2019-09-17 14:10:30 -07002227 }
2228
Peter Wang44b186e2020-01-13 23:33:09 -08002229 private boolean isImsAvailableOnDevice() {
2230 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2231 if (pm == null) {
2232 // For some reason package manger is not available.. This will fail internally anyway,
2233 // so do not throw error and allow.
2234 return true;
2235 }
2236 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2237 }
2238
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002240 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002241 }
2242
Wink Savilleb564aae2014-10-23 10:18:09 -07002243 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 if (DBG) log("dial: " + number);
2245 // No permission check needed here: This is just a wrapper around the
2246 // ACTION_DIAL intent, which is available to any app since it puts up
2247 // the UI before it does anything.
2248
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249 final long identity = Binder.clearCallingIdentity();
2250 try {
2251 String url = createTelUrl(number);
2252 if (url == null) {
2253 return;
2254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002256 // PENDING: should we just silently fail if phone is offhook or ringing?
2257 PhoneConstants.State state = mCM.getState(subId);
2258 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2259 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2260 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2261 mApp.startActivity(intent);
2262 }
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 }
2266 }
2267
2268 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002269 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002270 }
2271
Wink Savilleb564aae2014-10-23 10:18:09 -07002272 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 if (DBG) log("call: " + number);
2274
2275 // This is just a wrapper around the ACTION_CALL intent, but we still
2276 // need to do a permission check since we're calling startActivity()
2277 // from the context of the phone app.
2278 enforceCallPermission();
2279
Jordan Liu1617b712019-07-10 15:06:26 -07002280 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 != AppOpsManager.MODE_ALLOWED) {
2282 return;
2283 }
2284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285 final long identity = Binder.clearCallingIdentity();
2286 try {
2287 String url = createTelUrl(number);
2288 if (url == null) {
2289 return;
2290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 boolean isValid = false;
2293 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2294 if (slist != null) {
2295 for (SubscriptionInfo subInfoRecord : slist) {
2296 if (subInfoRecord.getSubscriptionId() == subId) {
2297 isValid = true;
2298 break;
2299 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002300 }
Wink Saville08874612014-08-31 19:19:58 -07002301 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002302 if (!isValid) {
2303 return;
2304 }
Wink Saville08874612014-08-31 19:19:58 -07002305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2307 intent.putExtra(SUBSCRIPTION_KEY, subId);
2308 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2309 mApp.startActivity(intent);
2310 } finally {
2311 Binder.restoreCallingIdentity(identity);
2312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
Wink Savilleb564aae2014-10-23 10:18:09 -07002315 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002316 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002317 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2318 }
2319
Wink Savilleb564aae2014-10-23 10:18:09 -07002320 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002321 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002322 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2323 }
2324
Wink Savilleb564aae2014-10-23 10:18:09 -07002325 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002330 Phone phone = getPhone(subId);
2331 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002332 checkSimPin.start();
2333 return checkSimPin.unlockSim(null, pin);
2334 } finally {
2335 Binder.restoreCallingIdentity(identity);
2336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 }
2338
Wink Savilleb564aae2014-10-23 10:18:09 -07002339 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341
2342 final long identity = Binder.clearCallingIdentity();
2343 try {
Michele Berionne5e411512020-11-13 02:36:59 +00002344 Phone phone = getPhone(subId);
2345 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346 checkSimPuk.start();
2347 return checkSimPuk.unlockSim(puk, pin);
2348 } finally {
2349 Binder.restoreCallingIdentity(identity);
2350 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
2352
2353 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002354 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 * a synchronous one.
2356 */
2357 private static class UnlockSim extends Thread {
2358
2359 private final IccCard mSimCard;
Michele Berionne5e411512020-11-13 02:36:59 +00002360 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361
2362 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002363 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2364 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365
2366 // For replies from SimCard interface
2367 private Handler mHandler;
2368
2369 // For async handler to identify request type
2370 private static final int SUPPLY_PIN_COMPLETE = 100;
2371
Michele Berionne5e411512020-11-13 02:36:59 +00002372 UnlockSim(int phoneId, IccCard simCard) {
2373 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 mSimCard = simCard;
2375 }
2376
2377 @Override
2378 public void run() {
2379 Looper.prepare();
2380 synchronized (UnlockSim.this) {
2381 mHandler = new Handler() {
2382 @Override
2383 public void handleMessage(Message msg) {
2384 AsyncResult ar = (AsyncResult) msg.obj;
2385 switch (msg.what) {
2386 case SUPPLY_PIN_COMPLETE:
2387 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2388 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002389 mRetryCount = msg.arg1;
2390 if (ar.exception != null) {
2391 if (ar.exception instanceof CommandException &&
2392 ((CommandException)(ar.exception)).getCommandError()
2393 == CommandException.Error.PASSWORD_INCORRECT) {
2394 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002395 } //When UiccCardApp dispose,handle message and return exception
2396 else if (ar.exception instanceof CommandException &&
2397 ((CommandException) (ar.exception)).getCommandError()
2398 == CommandException.Error.ABORTED) {
2399 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002400 } else {
2401 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2402 }
2403 } else {
2404 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 mDone = true;
2407 UnlockSim.this.notifyAll();
2408 }
2409 break;
2410 }
2411 }
2412 };
2413 UnlockSim.this.notifyAll();
2414 }
2415 Looper.loop();
2416 }
2417
2418 /*
2419 * Use PIN or PUK to unlock SIM card
2420 *
2421 * If PUK is null, unlock SIM card with PIN
2422 *
2423 * If PUK is not null, unlock SIM card with PUK and set PIN code
2424 */
Wink Saville9de0f752013-10-22 19:04:03 -07002425 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426
2427 while (mHandler == null) {
2428 try {
2429 wait();
2430 } catch (InterruptedException e) {
2431 Thread.currentThread().interrupt();
2432 }
2433 }
2434 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2435
2436 if (puk == null) {
2437 mSimCard.supplyPin(pin, callback);
2438 } else {
2439 mSimCard.supplyPuk(puk, pin, callback);
2440 }
2441
2442 while (!mDone) {
2443 try {
2444 Log.d(LOG_TAG, "wait for done");
2445 wait();
2446 } catch (InterruptedException e) {
2447 // Restore the interrupted status
2448 Thread.currentThread().interrupt();
2449 }
2450 }
2451 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002452 int[] resultArray = new int[2];
2453 resultArray[0] = mResult;
2454 resultArray[1] = mRetryCount;
Michele Berionne5e411512020-11-13 02:36:59 +00002455
2456 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2457 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2458 }
2459
Wink Saville9de0f752013-10-22 19:04:03 -07002460 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 }
2462 }
2463
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002464 /**
2465 * This method has been removed due to privacy and stability concerns.
2466 */
2467 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002469 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2470 return;
Wink Saville36469e72014-06-11 15:17:00 -07002471 }
2472
Nathan Harold1f889d82020-06-04 17:05:26 -07002473 @Override
2474 public void updateServiceLocationWithPackageName(String callingPackage) {
2475 mApp.getSystemService(AppOpsManager.class)
2476 .checkPackage(Binder.getCallingUid(), callingPackage);
2477
Nathan Haroldf096d982020-11-18 17:18:06 -08002478 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002479 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2480 // Callers targeting S have no business invoking this method.
2481 return;
2482 }
2483
2484 LocationAccessPolicy.LocationPermissionResult locationResult =
2485 LocationAccessPolicy.checkLocationPermission(mApp,
2486 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2487 .setCallingPackage(callingPackage)
2488 .setCallingFeatureId(null)
2489 .setCallingPid(Binder.getCallingPid())
2490 .setCallingUid(Binder.getCallingUid())
2491 .setMethod("updateServiceLocation")
2492 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2493 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2494 .build());
2495 // Apps that lack location permission have no business calling this method;
2496 // however, because no permission was declared in the public API, denials must
2497 // all be "soft".
2498 switch (locationResult) {
2499 case DENIED_HARD: /* fall through */
2500 case DENIED_SOFT:
2501 return;
2502 }
2503
2504 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 final long identity = Binder.clearCallingIdentity();
2506 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002507 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002509 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 }
2511 } finally {
2512 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002514 }
2515
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002516 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002517 @Override
2518 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002519 return isRadioOnWithFeature(callingPackage, null);
2520 }
2521
2522
2523 @Override
2524 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2525 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2526 callingFeatureId);
2527 }
2528
2529 @Deprecated
2530 @Override
2531 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2532 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002533 }
2534
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002535 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002536 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2537 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002539 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002540 return false;
2541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002542
2543 final long identity = Binder.clearCallingIdentity();
2544 try {
2545 return isRadioOnForSubscriber(subId);
2546 } finally {
2547 Binder.restoreCallingIdentity(identity);
2548 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002549 }
2550
2551 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552 final long identity = Binder.clearCallingIdentity();
2553 try {
2554 final Phone phone = getPhone(subId);
2555 if (phone != null) {
2556 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2557 } else {
2558 return false;
2559 }
2560 } finally {
2561 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002563 }
2564
2565 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002566 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 }
Wink Saville36469e72014-06-11 15:17:00 -07002568
Wink Savilleb564aae2014-10-23 10:18:09 -07002569 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002570 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 final Phone phone = getPhone(subId);
2575 if (phone != null) {
2576 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2577 }
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002580 }
Wink Saville36469e72014-06-11 15:17:00 -07002581 }
2582
2583 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002584 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002585 }
2586
Wink Savilleb564aae2014-10-23 10:18:09 -07002587 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002589
2590 final long identity = Binder.clearCallingIdentity();
2591 try {
2592 final Phone phone = getPhone(subId);
2593 if (phone == null) {
2594 return false;
2595 }
2596 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2597 toggleRadioOnOffForSubscriber(subId);
2598 }
2599 return true;
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
Wink Saville36469e72014-06-11 15:17:00 -07002604
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002605 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002606 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002607 /*
2608 * If any of the Radios are available, it will need to be
2609 * shutdown. So return true if any Radio is available.
2610 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611 final long identity = Binder.clearCallingIdentity();
2612 try {
2613 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2614 Phone phone = PhoneFactory.getPhone(i);
2615 if (phone != null && phone.isRadioAvailable()) return true;
2616 }
2617 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2618 return false;
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002621 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002622 }
2623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002625 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626 enforceModifyPermission();
2627
2628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2631 logv("Shutting down Phone " + i);
2632 shutdownRadioUsingPhoneId(i);
2633 }
2634 } finally {
2635 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002636 }
2637 }
2638
2639 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002640 Phone phone = PhoneFactory.getPhone(phoneId);
2641 if (phone != null && phone.isRadioAvailable()) {
2642 phone.shutdownRadio();
2643 }
2644 }
2645
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002647 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648
2649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2652 if (defaultPhone != null) {
2653 defaultPhone.setRadioPower(turnOn);
2654 return true;
2655 } else {
2656 loge("There's no default phone.");
2657 return false;
2658 }
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002661 }
Wink Saville36469e72014-06-11 15:17:00 -07002662 }
2663
Wink Savilleb564aae2014-10-23 10:18:09 -07002664 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 final Phone phone = getPhone(subId);
2670 if (phone != null) {
2671 phone.setRadioPower(turnOn);
2672 return true;
2673 } else {
2674 return false;
2675 }
2676 } finally {
2677 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002678 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 }
2680
Wink Saville36469e72014-06-11 15:17:00 -07002681 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002682 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 public boolean enableDataConnectivity() {
2684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
2686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 int subId = mSubscriptionController.getDefaultDataSubId();
2689 final Phone phone = getPhone(subId);
2690 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002691 phone.getDataEnabledSettings().setDataEnabled(
2692 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002693 return true;
2694 } else {
2695 return false;
2696 }
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002700 }
2701
Wink Saville36469e72014-06-11 15:17:00 -07002702 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002703 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002704 public boolean disableDataConnectivity() {
2705 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002706
2707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 int subId = mSubscriptionController.getDefaultDataSubId();
2710 final Phone phone = getPhone(subId);
2711 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002712 phone.getDataEnabledSettings().setDataEnabled(
2713 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 return true;
2715 } else {
2716 return false;
2717 }
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002720 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002721 }
2722
Sanket Padawe356d7632015-06-22 14:03:32 -07002723 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002724 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 final Phone phone = getPhone(subId);
2728 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002729 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 } else {
2731 return false;
2732 }
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736 }
2737
2738 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002739 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002740 }
2741
pkanwarae03a6b2016-11-06 20:37:09 -08002742 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743 enforceCallPermission();
2744
2745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2748 return;
2749 }
2750 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2751 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
2754 }
pkanwar32d516d2016-10-14 19:37:38 -07002755 };
2756
Wink Savilleb564aae2014-10-23 10:18:09 -07002757 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759
2760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2763 return false;
2764 }
2765 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002769 }
2770
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002771 /**
2772 * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage
2773 * tag on getCallState Binder call.
2774 */
2775 @Deprecated
2776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 public int getCallState() {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002778 if (CompatChanges.isChangeEnabled(
2779 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2780 Binder.getCallingUid())) {
2781 // Do not allow this API to be called on API version 31+, it should only be
2782 // called on old apps using this Binder call directly.
2783 throw new SecurityException("This method can only be used for applications "
2784 + "targeting API version 30 or less.");
2785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
Brad Ebinger4f6208e2021-03-23 21:04:45 +00002788 Phone phone = getPhone(getDefaultSubscription());
2789 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2790 PhoneConstantConversions.convertCallState(phone.getState());
2791 } finally {
2792 Binder.restoreCallingIdentity(identity);
2793 }
2794 }
2795
2796 @Override
2797 public int getCallStateForSubscription(int subId, String callingPackage, String featureId) {
2798 if (CompatChanges.isChangeEnabled(
2799 TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION,
2800 Binder.getCallingUid())) {
2801 // Check READ_PHONE_STATE for API version 31+
2802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2803 featureId, "getCallStateForSubscription")) {
2804 throw new SecurityException("getCallState requires READ_PHONE_STATE for apps "
2805 + "targeting API level 31+.");
2806 }
2807 }
2808 final long identity = Binder.clearCallingIdentity();
2809 try {
2810 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002811 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2812 PhoneConstantConversions.convertCallState(phone.getState());
2813 } finally {
2814 Binder.restoreCallingIdentity(identity);
2815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 }
2817
Sanket Padawe356d7632015-06-22 14:03:32 -07002818 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002819 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002820 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2821 }
2822
2823 @Override
2824 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 final long identity = Binder.clearCallingIdentity();
2826 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002827 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002828 if (phone != null) {
2829 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2830 } else {
2831 return PhoneConstantConversions.convertDataState(
2832 PhoneConstants.DataState.DISCONNECTED);
2833 }
2834 } finally {
2835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 }
2838
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002840 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002841 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2842 }
2843
2844 @Override
2845 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002846 final long identity = Binder.clearCallingIdentity();
2847 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002848 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849 if (phone != null) {
2850 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2851 } else {
2852 return TelephonyManager.DATA_ACTIVITY_NONE;
2853 }
2854 } finally {
2855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002857 }
2858
2859 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002860 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002861 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002862 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002863
2864 LocationAccessPolicy.LocationPermissionResult locationResult =
2865 LocationAccessPolicy.checkLocationPermission(mApp,
2866 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2867 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002868 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002869 .setCallingPid(Binder.getCallingPid())
2870 .setCallingUid(Binder.getCallingUid())
2871 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002872 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002873 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2874 .build());
2875 switch (locationResult) {
2876 case DENIED_HARD:
2877 throw new SecurityException("Not allowed to access cell location");
2878 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002879 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2880 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002881 }
2882
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002883 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002887 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002888 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 } finally {
2890 Binder.restoreCallingIdentity(identity);
2891 }
Svetoslav64fad262015-04-14 14:35:21 -07002892 }
2893
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002894 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002895 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002896 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2897 // registered cell info, so return a NULL country instead.
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002900 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2901 // Get default phone in this case.
2902 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2903 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002904 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002906 if (phone == null) return "";
2907 ServiceStateTracker sst = phone.getServiceStateTracker();
2908 if (sst == null) return "";
2909 LocaleTracker lt = sst.getLocaleTracker();
2910 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002911 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002912 } finally {
2913 Binder.restoreCallingIdentity(identity);
2914 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002915 }
2916
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002917 /**
2918 * This method was removed due to potential issues caused by performing partial
2919 * updates of service state, and lack of a credible use case.
2920 *
2921 * This has the ability to break the telephony implementation by disabling notification of
2922 * changes in device connectivity. DO NOT USE THIS!
2923 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002924 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002925 public void enableLocationUpdates() {
2926 mApp.enforceCallingOrSelfPermission(
2927 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002928 }
2929
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002930 /**
2931 * This method was removed due to potential issues caused by performing partial
2932 * updates of service state, and lack of a credible use case.
2933 *
2934 * This has the ability to break the telephony implementation by disabling notification of
2935 * changes in device connectivity. DO NOT USE THIS!
2936 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002937 @Override
2938 public void disableLocationUpdates() {
2939 mApp.enforceCallingOrSelfPermission(
2940 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002941 }
2942
2943 @Override
2944 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002945 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2946 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002947 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002948 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2949 throw new SecurityException(
2950 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2951 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002952
Jordan Liu1617b712019-07-10 15:06:26 -07002953 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002954 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2955 return null;
2956 }
Svetoslav64fad262015-04-14 14:35:21 -07002957
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002958 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002959
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002960 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002961 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002962
Nathan Haroldf180aac2018-06-01 18:43:55 -07002963 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2964 for (CellInfo ci : info) {
2965 if (ci instanceof CellInfoGsm) {
2966 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2967 } else if (ci instanceof CellInfoWcdma) {
2968 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002970 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002971 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002972 }
2973
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002974 private List<CellInfo> getCachedCellInfo() {
2975 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2976 for (Phone phone : PhoneFactory.getPhones()) {
2977 List<CellInfo> info = phone.getAllCellInfo();
2978 if (info != null) cellInfos.addAll(info);
2979 }
2980 return cellInfos;
2981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002982
2983 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002984 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002985 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002986 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002987
2988 LocationAccessPolicy.LocationPermissionResult locationResult =
2989 LocationAccessPolicy.checkLocationPermission(mApp,
2990 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2991 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002992 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002993 .setCallingPid(Binder.getCallingPid())
2994 .setCallingUid(Binder.getCallingUid())
2995 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002996 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002997 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2998 .build());
2999 switch (locationResult) {
3000 case DENIED_HARD:
3001 throw new SecurityException("Not allowed to access cell info");
3002 case DENIED_SOFT:
3003 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003004 }
3005
Nathan Haroldf096d982020-11-18 17:18:06 -08003006 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003007 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
3008 return getCachedCellInfo();
3009 }
3010
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07003011 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003012 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
3016 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07003017 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07003018 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 if (info != null) cellInfos.addAll(info);
3020 }
3021 return cellInfos;
3022 } finally {
3023 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003024 }
3025 }
3026
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07003027 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003028 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
3029 String callingFeatureId) {
3030 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
3031 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003032 }
3033
3034 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003035 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
3036 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003037 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003038 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003039 }
3040
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003041 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
3042 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003043 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003044 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08003045
3046 LocationAccessPolicy.LocationPermissionResult locationResult =
3047 LocationAccessPolicy.checkLocationPermission(mApp,
3048 new LocationAccessPolicy.LocationPermissionQuery.Builder()
3049 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07003050 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08003051 .setCallingPid(Binder.getCallingPid())
3052 .setCallingUid(Binder.getCallingUid())
3053 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07003054 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
3055 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08003056 .build());
3057 switch (locationResult) {
3058 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08003059 if (TelephonyPermissions
3060 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003061 // Safetynet logging for b/154934934
3062 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3063 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003064 throw new SecurityException("Not allowed to access cell info");
3065 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08003066 if (TelephonyPermissions
3067 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07003068 // Safetynet logging for b/154934934
3069 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
3070 }
Nathan Harold5320c422019-05-09 10:26:08 -07003071 try {
3072 cb.onCellInfo(new ArrayList<CellInfo>());
3073 } catch (RemoteException re) {
3074 // Drop without consequences
3075 }
Hall Liuf19c44f2018-11-27 14:38:17 -08003076 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003077 }
3078
Nathan Harolda939a962019-05-09 10:13:47 -07003079
3080 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07003081 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
3082
3083 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
3084 }
3085
3086 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003087 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08003088 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003089 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003090
3091 final long identity = Binder.clearCallingIdentity();
3092 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003093 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003097 }
3098
Shishir Agrawala9f32182016-04-12 12:00:16 -07003099 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003100 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003101 Phone phone = PhoneFactory.getPhone(slotIndex);
3102 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003103 return null;
3104 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003105 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003106 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003107 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003108 return null;
3109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 return phone.getImei();
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003117 }
3118
3119 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003120 public String getTypeAllocationCodeForSlot(int slotIndex) {
3121 Phone phone = PhoneFactory.getPhone(slotIndex);
3122 String tac = null;
3123 if (phone != null) {
3124 String imei = phone.getImei();
3125 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3126 }
3127 return tac;
3128 }
3129
3130 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003131 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003132 Phone phone = PhoneFactory.getPhone(slotIndex);
3133 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003134 return null;
3135 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003136
Jeff Davidson913390f2018-02-23 17:11:49 -08003137 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003138 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003139 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003140 return null;
3141 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142
3143 final long identity = Binder.clearCallingIdentity();
3144 try {
3145 return phone.getMeid();
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
3148 }
Jack Yu2af8d712017-03-15 17:14:14 -07003149 }
3150
3151 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003152 public String getManufacturerCodeForSlot(int slotIndex) {
3153 Phone phone = PhoneFactory.getPhone(slotIndex);
3154 String manufacturerCode = null;
3155 if (phone != null) {
3156 String meid = phone.getMeid();
3157 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3158 }
3159 return manufacturerCode;
3160 }
3161
3162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003163 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3164 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003165 Phone phone = PhoneFactory.getPhone(slotIndex);
3166 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003167 return null;
3168 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003169 int subId = phone.getSubId();
3170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003171 mApp, subId, callingPackage, callingFeatureId,
3172 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003173 return null;
3174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175
3176 final long identity = Binder.clearCallingIdentity();
3177 try {
3178 return phone.getDeviceSvn();
3179 } finally {
3180 Binder.restoreCallingIdentity(identity);
3181 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003182 }
3183
fionaxu43304da2017-11-27 22:51:16 -08003184 @Override
3185 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 final Phone phone = getPhone(subId);
3189 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3190 } finally {
3191 Binder.restoreCallingIdentity(identity);
3192 }
fionaxu43304da2017-11-27 22:51:16 -08003193 }
3194
3195 @Override
3196 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 final Phone phone = getPhone(subId);
3200 return phone == null ? null : phone.getCarrierName();
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
3203 }
fionaxu43304da2017-11-27 22:51:16 -08003204 }
3205
calvinpanffe225e2018-11-01 19:43:06 +08003206 @Override
chen xu0026ca62019-03-06 15:28:50 -08003207 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 final Phone phone = getPhone(subId);
3211 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003212 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
3216 }
3217
3218 @Override
chen xu0026ca62019-03-06 15:28:50 -08003219 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003223 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003224 } finally {
3225 Binder.restoreCallingIdentity(identity);
3226 }
3227 }
3228
chen xu651eec72018-11-11 19:03:44 -08003229 @Override
chen xu864e11c2018-12-06 22:10:03 -08003230 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3231 if (!isSubscriptionMccMnc) {
3232 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3233 }
chen xu651eec72018-11-11 19:03:44 -08003234 final Phone phone = PhoneFactory.getPhone(slotIndex);
3235 if (phone == null) {
3236 return TelephonyManager.UNKNOWN_CARRIER_ID;
3237 }
3238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 }
3245
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003246 //
3247 // Internal helper methods.
3248 //
3249
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003250 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3252 *
3253 * @throws SecurityException if the caller does not have the required permission
3254 */
3255 private void enforceModifyPermission() {
3256 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3257 }
3258
Shuo Qiancd19c462020-01-16 20:51:11 -08003259 /**
3260 * Make sure the caller is system.
3261 *
3262 * @throws SecurityException if the caller is not system.
3263 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003264 private static void enforceSystemCaller() {
Shuo Qiancd19c462020-01-16 20:51:11 -08003265 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3266 throw new SecurityException("Caller must be system");
3267 }
3268 }
3269
Shuo Qian3b6ee772019-11-13 17:43:31 -08003270 private void enforceActiveEmergencySessionPermission() {
3271 mApp.enforceCallingOrSelfPermission(
3272 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3273 }
3274
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003275 /**
3276 * Make sure the caller has the CALL_PHONE permission.
3277 *
3278 * @throws SecurityException if the caller does not have the required permission
3279 */
3280 private void enforceCallPermission() {
3281 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3282 }
3283
paulhu5a773602019-08-23 19:17:33 +08003284 private void enforceSettingsPermission() {
3285 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003286 }
3287
Michele Berionne5e411512020-11-13 02:36:59 +00003288 private void enforceRebootPermission() {
3289 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3290 }
3291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003292 private String createTelUrl(String number) {
3293 if (TextUtils.isEmpty(number)) {
3294 return null;
3295 }
3296
Jake Hambye994d462014-02-03 13:10:13 -08003297 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003298 }
3299
Ihab Awadf9e92732013-12-05 18:02:52 -08003300 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003301 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3302 }
3303
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003304 private static void logv(String msg) {
3305 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3306 }
3307
Ihab Awadf9e92732013-12-05 18:02:52 -08003308 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003309 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3310 }
3311
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003312 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003313 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003314 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003315 }
3316
Sanket Padawe356d7632015-06-22 14:03:32 -07003317 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003318 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003319 final long identity = Binder.clearCallingIdentity();
3320 try {
3321 final Phone phone = PhoneFactory.getPhone(slotIndex);
3322 if (phone == null) {
3323 return PhoneConstants.PHONE_TYPE_NONE;
3324 } else {
3325 return phone.getPhoneType();
3326 }
3327 } finally {
3328 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003330 }
3331
3332 /**
3333 * Returns the CDMA ERI icon index to display
3334 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003335 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003336 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3337 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3338 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003339 }
3340
Sanket Padawe356d7632015-06-22 14:03:32 -07003341 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003342 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3343 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003345 mApp, subId, callingPackage, callingFeatureId,
3346 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003347 return -1;
3348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349
3350 final long identity = Binder.clearCallingIdentity();
3351 try {
3352 final Phone phone = getPhone(subId);
3353 if (phone != null) {
3354 return phone.getCdmaEriIconIndex();
3355 } else {
3356 return -1;
3357 }
3358 } finally {
3359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003361 }
3362
3363 /**
3364 * Returns the CDMA ERI icon mode,
3365 * 0 - ON
3366 * 1 - FLASHING
3367 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003368 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003369 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3370 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3371 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003372 }
3373
Sanket Padawe356d7632015-06-22 14:03:32 -07003374 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003375 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3376 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003378 mApp, subId, callingPackage, callingFeatureId,
3379 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003380 return -1;
3381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 final Phone phone = getPhone(subId);
3386 if (phone != null) {
3387 return phone.getCdmaEriIconMode();
3388 } else {
3389 return -1;
3390 }
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003394 }
3395
3396 /**
3397 * Returns the CDMA ERI text,
3398 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003399 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003400 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3401 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3402 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003403 }
3404
Sanket Padawe356d7632015-06-22 14:03:32 -07003405 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003406 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3407 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003408 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003409 mApp, subId, callingPackage, callingFeatureId,
3410 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003411 return null;
3412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003413
3414 final long identity = Binder.clearCallingIdentity();
3415 try {
3416 final Phone phone = getPhone(subId);
3417 if (phone != null) {
3418 return phone.getCdmaEriText();
3419 } else {
3420 return null;
3421 }
3422 } finally {
3423 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003425 }
3426
3427 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003428 * Returns the CDMA MDN.
3429 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003430 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003431 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3433 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003439 return phone.getLine1Number();
3440 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003441 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003442 return null;
3443 }
3444 } finally {
3445 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003446 }
3447 }
3448
3449 /**
3450 * Returns the CDMA MIN.
3451 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003452 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003453 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3455 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003456
3457 final long identity = Binder.clearCallingIdentity();
3458 try {
3459 final Phone phone = getPhone(subId);
3460 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3461 return phone.getCdmaMin();
3462 } else {
3463 return null;
3464 }
3465 } finally {
3466 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003467 }
3468 }
3469
Hall Liud892bec2018-11-30 14:51:45 -08003470 @Override
3471 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3472 INumberVerificationCallback callback, String callingPackage) {
3473 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3474 != PERMISSION_GRANTED) {
3475 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3476 }
3477 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3478
3479 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3480 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003481 throw new SecurityException("Calling package must be configured in the device config: "
3482 + "calling package: " + callingPackage
3483 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003484 }
3485
3486 if (range == null) {
3487 throw new NullPointerException("Range must be non-null");
3488 }
3489
3490 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003491 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003492
3493 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3494 }
3495
Junda Liuca05d5d2014-08-14 22:36:34 -07003496 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 * Returns true if CDMA provisioning needs to run.
3498 */
3499 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003500 final long identity = Binder.clearCallingIdentity();
3501 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003503 } finally {
3504 Binder.restoreCallingIdentity(identity);
3505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003506 }
3507
3508 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003509 * Sets the voice mail number of a given subId.
3510 */
3511 @Override
3512 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003513 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3514 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
3518 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3519 new Pair<String, String>(alphaTag, number), new Integer(subId));
3520 return success;
3521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003524 }
3525
Ta-wei Yen87c49842016-05-13 21:19:52 -07003526 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003527 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3528 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003529 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3530 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003531 if (!TextUtils.equals(callingPackage, systemDialer)) {
3532 throw new SecurityException("caller must be system dialer");
3533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3538 if (phoneAccountHandle == null) {
3539 return null;
3540 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003541 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003542 } finally {
3543 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003544 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003545 }
3546
3547 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003548 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3549 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003552 mApp, subId, callingPackage, callingFeatureId,
3553 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003554 return null;
3555 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003556
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003557 final long identity = Binder.clearCallingIdentity();
3558 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003559 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003563 }
3564
3565 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003566 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3567 VisualVoicemailSmsFilterSettings settings) {
3568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569
3570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003573 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003577 }
3578
3579 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003580 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003582
3583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003586 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003590 }
3591
3592 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003593 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3594 String callingPackage, int subId) {
3595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003596
3597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003600 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003601 } finally {
3602 Binder.restoreCallingIdentity(identity);
3603 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003604 }
3605
3606 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003607 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003609
3610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003613 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614 } finally {
3615 Binder.restoreCallingIdentity(identity);
3616 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003617 }
3618
3619 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003620 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3621 String callingAttributionTag, int subId, String number, int port, String text,
3622 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003623 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003624 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003625 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003626 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003627 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3628 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003629 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003630
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003631 /**
fionaxu0152e512016-11-14 13:36:14 -08003632 * Sets the voice activation state of a given subId.
3633 */
3634 @Override
3635 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3637 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003638
3639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 final Phone phone = getPhone(subId);
3642 if (phone != null) {
3643 phone.setVoiceActivationState(activationState);
3644 } else {
3645 loge("setVoiceActivationState fails with invalid subId: " + subId);
3646 }
3647 } finally {
3648 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003649 }
3650 }
3651
3652 /**
3653 * Sets the data activation state of a given subId.
3654 */
3655 @Override
3656 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3658 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659
3660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 final Phone phone = getPhone(subId);
3663 if (phone != null) {
3664 phone.setDataActivationState(activationState);
3665 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003666 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667 }
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003670 }
3671 }
3672
3673 /**
3674 * Returns the voice activation state of a given subId.
3675 */
3676 @Override
3677 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003679
fionaxu0152e512016-11-14 13:36:14 -08003680 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003681 final long identity = Binder.clearCallingIdentity();
3682 try {
3683 if (phone != null) {
3684 return phone.getVoiceActivationState();
3685 } else {
3686 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3687 }
3688 } finally {
3689 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003690 }
3691 }
3692
3693 /**
3694 * Returns the data activation state of a given subId.
3695 */
3696 @Override
3697 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699
fionaxu0152e512016-11-14 13:36:14 -08003700 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003701 final long identity = Binder.clearCallingIdentity();
3702 try {
3703 if (phone != null) {
3704 return phone.getDataActivationState();
3705 } else {
3706 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3707 }
3708 } finally {
3709 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003710 }
3711 }
3712
3713 /**
Wink Saville36469e72014-06-11 15:17:00 -07003714 * Returns the unread count of voicemails for a subId
3715 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003716 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003717 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3718 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003720 mApp, subId, callingPackage, callingFeatureId,
3721 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003722 return 0;
3723 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003724 final long identity = Binder.clearCallingIdentity();
3725 try {
3726 final Phone phone = getPhone(subId);
3727 if (phone != null) {
3728 return phone.getVoiceMessageCount();
3729 } else {
3730 return 0;
3731 }
3732 } finally {
3733 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003735 }
3736
3737 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003738 * returns true, if the device is in a state where both voice and data
3739 * are supported simultaneously. This can change based on location or network condition.
3740 */
3741 @Override
3742 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743 final long identity = Binder.clearCallingIdentity();
3744 try {
3745 final Phone phone = getPhone(subId);
3746 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3747 } finally {
3748 Binder.restoreCallingIdentity(identity);
3749 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003750 }
3751
3752 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003753 * Send the dialer code if called from the current default dialer or the caller has
3754 * carrier privilege.
3755 * @param inputCode The dialer code to send
3756 */
3757 @Override
3758 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003759 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003760 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003761 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3762 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003763 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003764 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767
3768 final long identity = Binder.clearCallingIdentity();
3769 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003770 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
fionaxu235cc5e2017-03-06 22:25:57 -08003774 }
3775
Pengquan Menga1bb6272018-09-06 09:59:22 -07003776 @Override
3777 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003778 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07003779 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilufc958392020-01-20 11:36:01 -08003780 mApp, subId, "getNetworkSelectionMode");
3781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 if (!isActiveSubscription(subId)) {
3784 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3785 }
3786 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3787 } finally {
3788 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003789 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003790 }
3791
Brad Ebinger35c841c2018-10-01 10:40:55 -07003792 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003793 public boolean isInEmergencySmsMode() {
3794 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 for (Phone phone : PhoneFactory.getPhones()) {
3798 if (phone.isInEmergencySmsMode()) {
3799 return true;
3800 }
3801 }
3802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
3805 return false;
3806 }
3807
shilu366312e2019-12-17 09:28:10 -08003808 /**
3809 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3810 * @param subId The subscription to use to check the configuration.
3811 * @param c The callback that will be used to send the result.
3812 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003813 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003814 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3815 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003816 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003817 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003818
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003819 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3820 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3821 "IMS not available on device.");
3822 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003823 final long token = Binder.clearCallingIdentity();
3824 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003825 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003826 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003828 } catch (ImsException e) {
3829 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003830 } finally {
3831 Binder.restoreCallingIdentity(token);
3832 }
3833 }
3834
shilu366312e2019-12-17 09:28:10 -08003835 /**
3836 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3837 * @param subId The subscription to use to check the configuration.
3838 * @param c The callback that will be used to send the result.
3839 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003841 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003842 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003843 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003844 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3845 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3846 }
Meng Wangafbc5852019-09-19 17:37:13 -07003847 final long token = Binder.clearCallingIdentity();
3848 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003849 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003850 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3851 .removeRegistrationCallbackForSubscription(c, subId);
3852 } catch (ImsException e) {
3853 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3854 + "is inactive, ignoring unregister.");
3855 // If the subscription is no longer active, just return, since the callback
3856 // will already have been removed internally.
3857 } finally {
3858 Binder.restoreCallingIdentity(token);
3859 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003860 }
3861
Brad Ebingera34a6c22019-10-22 17:36:18 -07003862 /**
3863 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3864 */
3865 @Override
3866 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3867 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3868 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3869 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3870 "IMS not available on device.");
3871 }
3872 final long token = Binder.clearCallingIdentity();
3873 try {
3874 Phone phone = getPhone(subId);
3875 if (phone == null) {
3876 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3877 + subId + "'");
3878 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3879 }
3880 phone.getImsRegistrationState(regState -> {
3881 try {
3882 consumer.accept((regState == null)
3883 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3884 } catch (RemoteException e) {
3885 // Ignore if the remote process is no longer available to call back.
3886 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3887 }
3888 });
3889 } finally {
3890 Binder.restoreCallingIdentity(token);
3891 }
3892 }
3893
3894 /**
3895 * Get the transport type for the IMS service registration state.
3896 */
3897 @Override
3898 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Nathan Harold62c68512021-04-06 11:26:02 -07003899 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003900 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003901 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3902 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3903 "IMS not available on device.");
3904 }
3905 final long token = Binder.clearCallingIdentity();
3906 try {
3907 Phone phone = getPhone(subId);
3908 if (phone == null) {
3909 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3910 + subId + "'");
3911 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3912 }
3913 phone.getImsRegistrationTech(regTech -> {
3914 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3915 int regTechConverted = (regTech == null)
3916 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3917 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3918 regTechConverted);
3919 try {
3920 consumer.accept(regTechConverted);
3921 } catch (RemoteException e) {
3922 // Ignore if the remote process is no longer available to call back.
3923 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3924 }
3925 });
3926 } finally {
3927 Binder.restoreCallingIdentity(token);
3928 }
3929 }
3930
shilu366312e2019-12-17 09:28:10 -08003931 /**
3932 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3933 * @param subId The subscription to use to check the configuration.
3934 * @param c The callback that will be used to send the result.
3935 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003937 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3938 throws RemoteException {
Nathan Harold62c68512021-04-06 11:26:02 -07003939 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003940 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003941 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3942 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3943 "IMS not available on device.");
3944 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3946 final long token = Binder.clearCallingIdentity();
3947 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003948 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003949 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003950 } catch (ImsException e) {
3951 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 } finally {
3953 Binder.restoreCallingIdentity(token);
3954 }
3955 }
3956
shilu366312e2019-12-17 09:28:10 -08003957 /**
3958 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3959 * @param subId The subscription to use to check the configuration.
3960 * @param c The callback that will be used to send the result.
3961 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003963 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Nathan Harold62c68512021-04-06 11:26:02 -07003964 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08003965 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003966 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3967 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3968 }
Meng Wangafbc5852019-09-19 17:37:13 -07003969
3970 final long token = Binder.clearCallingIdentity();
3971 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003972 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003973 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003974 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003975 } catch (ImsException e) {
3976 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3977 + "is inactive, ignoring unregister.");
3978 // If the subscription is no longer active, just return, since the callback
3979 // will already have been removed internally.
3980 } finally {
3981 Binder.restoreCallingIdentity(token);
3982 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 }
3984
3985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003986 public boolean isCapable(int subId, int capability, int regTech) {
3987 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3989 final long token = Binder.clearCallingIdentity();
3990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003991 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3995 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003997 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3998 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 } finally {
4000 Binder.restoreCallingIdentity(token);
4001 }
4002 }
4003
4004 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004005 public boolean isAvailable(int subId, int capability, int regTech) {
4006 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 final long token = Binder.clearCallingIdentity();
4008 try {
4009 Phone phone = getPhone(subId);
4010 if (phone == null) return false;
4011 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07004012 } catch (com.android.ims.ImsException e) {
4013 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
4014 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 } finally {
4016 Binder.restoreCallingIdentity(token);
4017 }
4018 }
4019
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004020 /**
4021 * Determines if the MmTel feature capability is supported by the carrier configuration for this
4022 * subscription.
4023 * @param subId The subscription to use to check the configuration.
4024 * @param callback The callback that will be used to send the result.
4025 * @param capability The MmTelFeature capability that will be used to send the result.
4026 * @param transportType The transport type of the MmTelFeature capability.
4027 */
4028 @Override
4029 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
4030 int transportType) {
4031 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
4032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4034 "IMS not available on device.");
4035 }
4036 final long token = Binder.clearCallingIdentity();
4037 try {
4038 int slotId = getSlotIndex(subId);
4039 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4040 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
4041 + subId + "'");
4042 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4043 }
4044 ImsManager.getInstance(mApp, slotId).isSupported(capability,
4045 transportType, aBoolean -> {
4046 try {
4047 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
4048 } catch (RemoteException e) {
4049 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
4050 + "running. Ignore");
4051 }
4052 });
4053 } finally {
4054 Binder.restoreCallingIdentity(token);
4055 }
4056 }
4057
shilu366312e2019-12-17 09:28:10 -08004058 /**
4059 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4060 * @param subId The subscription to use to check the configuration.
4061 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 @Override
4063 public boolean isAdvancedCallingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004064 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004065 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08004066
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4068 final long token = Binder.clearCallingIdentity();
4069 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004070 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004072 } catch (ImsException e) {
4073 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004074 } finally {
4075 Binder.restoreCallingIdentity(token);
4076 }
4077 }
4078
4079 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004080 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004082 "setAdvancedCallingSettingEnabled");
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,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004088 } catch (ImsException e) {
4089 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004090 } finally {
4091 Binder.restoreCallingIdentity(identity);
4092 }
4093 }
4094
shilu366312e2019-12-17 09:28:10 -08004095 /**
4096 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4097 * @param subId The subscription to use to check the configuration.
4098 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08004100 public boolean isVtSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004101 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004102 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004106 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4107 } 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 setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004117 "setVtSettingEnabled");
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)).setVtSetting(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 /**
4130 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4131 * @param subId The subscription to use to check the configuration.
4132 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004133 @Override
4134 public boolean isVoWiFiSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004135 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004136 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004137 final long identity = Binder.clearCallingIdentity();
4138 try {
4139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004140 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004142 } catch (ImsException e) {
4143 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
4149 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004150 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004152 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004157 } catch (ImsException e) {
4158 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
4162 }
4163
shilu366312e2019-12-17 09:28:10 -08004164 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004165 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
4166 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4167 * @param subId The subscription to use to check the configuration.
4168 */
4169 @Override
4170 public boolean isCrossSimCallingEnabledByUser(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004171 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindrane655add2020-11-23 19:40:38 -08004172 mApp, subId, "isCrossSimCallingEnabledByUser");
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4176 return ImsManager.getInstance(mApp,
4177 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
4178 } catch (ImsException e) {
4179 throw new ServiceSpecificException(e.getCode());
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
4182 }
4183 }
4184
4185 /**
4186 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
4187 * Requires MODIFY_PHONE_STATE permission.
4188 * @param subId The subscription to use to check the configuration.
4189 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
4190 * false otherwise
4191 */
4192 @Override
4193 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
4194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4195 "setCrossSimCallingEnabled");
4196 final long identity = Binder.clearCallingIdentity();
4197 try {
4198 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4199 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
4200 .setCrossSimCallingEnabled(isEnabled);
4201 } catch (ImsException e) {
4202 throw new ServiceSpecificException(e.getCode());
4203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
4206 }
4207
4208 /**
shilu366312e2019-12-17 09:28:10 -08004209 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4210 * @param subId The subscription to use to check the configuration.
4211 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004212 @Override
Nathan Harold62c68512021-04-06 11:26:02 -07004213
Brad Ebinger35c841c2018-10-01 10:40:55 -07004214 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004215 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004216 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004220 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004222 } catch (ImsException e) {
4223 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004224 } finally {
4225 Binder.restoreCallingIdentity(identity);
4226 }
4227 }
4228
4229 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004230 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004232 "setVoWiFiRoamingSettingEnabled");
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 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004237 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
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 setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4247 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4248 "setVoWiFiNonPersistent");
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 Ebinger2d29c012019-05-07 18:33:46 -07004253 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
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
shilu366312e2019-12-17 09:28:10 -08004261 /**
4262 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4263 * @param subId The subscription to use to check the configuration.
4264 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004265 @Override
4266 public int getVoWiFiModeSetting(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004267 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004268 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004269 final long identity = Binder.clearCallingIdentity();
4270 try {
4271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004272 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004273 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004274 } catch (ImsException e) {
4275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
4279 }
4280
4281 @Override
4282 public void setVoWiFiModeSetting(int subId, int mode) {
4283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4284 "setVoWiFiModeSetting");
4285 final long identity = Binder.clearCallingIdentity();
4286 try {
4287 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004288 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004289 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004290 } catch (ImsException e) {
4291 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
4294 }
4295 }
4296
4297 @Override
4298 public int getVoWiFiRoamingModeSetting(int subId) {
4299 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4300 final long identity = Binder.clearCallingIdentity();
4301 try {
4302 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004303 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004304 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004305 } catch (ImsException e) {
4306 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
4310 }
4311
4312 @Override
4313 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4315 "setVoWiFiRoamingModeSetting");
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004319 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004320 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004321 } catch (ImsException e) {
4322 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
4326 }
4327
4328 @Override
4329 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4331 "setRttCapabilityEnabled");
4332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004335 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4336 } catch (ImsException e) {
4337 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
4341 }
4342
shilu366312e2019-12-17 09:28:10 -08004343 /**
4344 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4345 * @param subId The subscription to use to check the configuration.
4346 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004347 @Override
4348 public boolean isTtyOverVolteEnabled(int subId) {
Nathan Harold62c68512021-04-06 11:26:02 -07004349 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
Rambo Wang37f9c242020-02-10 14:45:28 -08004350 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004354 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004355 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004356 } catch (ImsException e) {
4357 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
4361 }
4362
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004363 @Override
4364 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4365 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4366 final long identity = Binder.clearCallingIdentity();
4367 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004368 if (!isImsAvailableOnDevice()) {
4369 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4370 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004371 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004372 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004373 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004374 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004375 } catch (ImsException e) {
4376 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
4380 }
4381
4382 @Override
4383 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4384 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4385 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004386 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4387 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4388 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004389 try {
4390 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004391 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004392 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004393 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004394 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4395 + "is inactive, ignoring unregister.");
4396 // If the subscription is no longer active, just return, since the callback will already
4397 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
4401 }
4402
allenwtsu99c623b2020-01-03 18:24:23 +08004403
4404 private void checkModifyPhoneStatePermission(int subId, String message) {
4405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4406 message);
4407 }
4408
4409 private boolean isImsProvisioningRequired(int subId, int capability,
4410 boolean isMmtelCapability) {
4411 Phone phone = getPhone(subId);
4412 if (phone == null) {
4413 loge("phone instance null for subid " + subId);
4414 return false;
4415 }
4416 if (isMmtelCapability) {
4417 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4418 return false;
4419 }
4420 } else {
4421 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4422 return false;
4423 }
4424 }
4425 return true;
4426 }
4427
4428 @Override
4429 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4430 boolean isProvisioned) {
4431 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4432
4433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4436 if (!isImsProvisioningRequired(subId, capability, false)) {
4437 return;
4438 }
4439
4440 // this capability requires provisioning, route to the correct API.
4441 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4442 switch (capability) {
4443 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4444 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4445 ims.setEabProvisioned(isProvisioned);
4446 break;
4447 default: {
4448 throw new IllegalArgumentException("Tried to set provisioning for "
4449 + "rcs capability '" + capability + "', which does not require "
4450 + "provisioning.");
4451 }
4452 }
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
4455 }
4456
4457 }
4458
4459
4460 @Override
4461 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4462 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4463 final long identity = Binder.clearCallingIdentity();
4464 try {
4465 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4466 if (!isImsProvisioningRequired(subId, capability, false)) {
4467 return true;
4468 }
4469
4470 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4471 switch (capability) {
4472 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4473 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4474 return ims.isEabProvisionedOnDevice();
4475
4476 default: {
4477 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4478 + "capability '" + capability + "', which does not require "
4479 + "provisioning.");
4480 }
4481 }
4482
4483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
4486 }
4487
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004488 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004489 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4490 boolean isProvisioned) {
4491 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4492 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4493 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4494 }
allenwtsu99c623b2020-01-03 18:24:23 +08004495 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004499 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004500 return;
4501 }
4502
4503 // this capability requires provisioning, route to the correct API.
4504 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4505 switch (capability) {
4506 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4507 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4508 ims.setVolteProvisioned(isProvisioned);
4509 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4510 ims.setWfcProvisioned(isProvisioned);
4511 }
4512 break;
4513 }
4514 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4515 // There is currently no difference in VT provisioning type.
4516 ims.setVtProvisioned(isProvisioned);
4517 break;
4518 }
4519 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4520 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4521 // change the capability of the feature instead if needed.
4522 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4523 == isProvisioned) {
4524 // No change in provisioning.
4525 return;
4526 }
4527 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4528 try {
4529 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004530 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004531 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4532 + ", Exception" + e.getMessage());
4533 }
4534 break;
4535 }
4536 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004537 throw new IllegalArgumentException("Tried to set provisioning for "
4538 + "MmTel capability '" + capability + "', which does not require "
4539 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004540 }
4541 }
4542
4543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
4546 }
4547
4548 @Override
4549 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4550 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4551 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4552 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4553 }
4554 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4555 final long identity = Binder.clearCallingIdentity();
4556 try {
4557 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004558 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004559 return true;
4560 }
4561
4562 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4563 switch (capability) {
4564 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4565 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4566 return ims.isVolteProvisionedOnDevice();
4567 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4568 return ims.isWfcProvisionedOnDevice();
4569 }
4570 // This should never happen, since we are checking tech above to make sure it
4571 // is either LTE or IWLAN.
4572 throw new IllegalArgumentException("Invalid radio technology for voice "
4573 + "capability.");
4574 }
4575 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4576 // There is currently no difference in VT provisioning type.
4577 return ims.isVtProvisionedOnDevice();
4578 }
4579 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4580 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4581 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4582 }
4583 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004584 throw new IllegalArgumentException(
4585 "Tried to get provisioning for MmTel capability '" + capability
4586 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004587 }
4588 }
4589
4590 } finally {
4591 Binder.restoreCallingIdentity(identity);
4592 }
4593 }
4594
4595 @Override
4596 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4597 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4598 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4599 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4600 }
4601 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4602 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4603 return (provisionedBits & capability) > 0;
4604 }
4605
4606 @Override
4607 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4608 boolean isProvisioned) {
4609 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4610 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4611 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4612 }
4613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4614 "setProvisioningStatusForCapability");
4615 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4616 // If the current provisioning status for capability already matches isProvisioned,
4617 // do nothing.
4618 if (((provisionedBits & capability) > 0) == isProvisioned) {
4619 return;
4620 }
4621 if (isProvisioned) {
4622 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4623 } else {
4624 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4625 }
4626 }
4627
4628 /**
4629 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4630 * technology. The bitfield should mirror the bitfield defined by
4631 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4632 */
4633 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4634 String key = getMmTelProvisioningKey(subId, tech);
4635 // Default is no capabilities are provisioned.
4636 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4637 }
4638
4639 /**
4640 * Sets the MmTel capability provisioning bitfield (defined by
4641 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4642 * technology specified.
4643 *
4644 * Note: This is a synchronous command and should not be called on UI thread.
4645 */
4646 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4647 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4648 String key = getMmTelProvisioningKey(subId, tech);
4649 editor.putInt(key, newField);
4650 editor.commit();
4651 }
4652
4653 private static String getMmTelProvisioningKey(int subId, int tech) {
4654 // resulting key is provision_ims_mmtel_{subId}_{tech}
4655 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4656 }
4657
4658 /**
4659 * Query CarrierConfig to see if the specified capability requires provisioning for the
4660 * carrier associated with the subscription id.
4661 */
4662 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4663 int capability) {
4664 CarrierConfigManager configManager = new CarrierConfigManager(context);
4665 PersistableBundle c = configManager.getConfigForSubId(subId);
4666 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004667 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004668 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4669 false);
4670 boolean requireVoiceVtProvisioning = c.getBoolean(
4671 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4672
4673 // First check to make sure that the capability requires provisioning.
4674 switch (capability) {
4675 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4676 // intentional fallthrough
4677 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4678 if (requireVoiceVtProvisioning) {
4679 // Voice and Video requires provisioning
4680 return true;
4681 }
4682 break;
4683 }
4684 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4685 if (requireUtProvisioning) {
4686 // UT requires provisioning
4687 return true;
4688 }
4689 break;
4690 }
4691 }
4692 return false;
4693 }
4694
allenwtsu99c623b2020-01-03 18:24:23 +08004695 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4696 int capability) {
4697 CarrierConfigManager configManager = new CarrierConfigManager(context);
4698 PersistableBundle c = configManager.getConfigForSubId(subId);
4699
4700 boolean requireRcsProvisioning = c.getBoolean(
4701 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4702
4703 // First check to make sure that the capability requires provisioning.
4704 switch (capability) {
4705 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4706 // intentional fallthrough
4707 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4708 if (requireRcsProvisioning) {
4709 // OPTION or PRESENCE requires provisioning
4710 return true;
4711 }
4712 break;
4713 }
4714 }
4715 return false;
4716 }
4717
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004718 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004719 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004720 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4721 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4722 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004723 enforceReadPrivilegedPermission("getImsProvisioningInt");
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
4726 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004727 int slotId = getSlotIndex(subId);
4728 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4729 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4730 + subId + "' for key:" + key);
4731 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4732 }
calvinpanb5a34062021-02-08 19:59:36 +08004733 return ImsManager.getInstance(mApp, slotId).getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004734 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004735 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4736 + subId + "' for key:" + key);
4737 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004738 } finally {
4739 Binder.restoreCallingIdentity(identity);
4740 }
4741 }
4742
4743 @Override
4744 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004745 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4746 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4747 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004748 enforceReadPrivilegedPermission("getImsProvisioningString");
4749 final long identity = Binder.clearCallingIdentity();
4750 try {
4751 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004752 int slotId = getSlotIndex(subId);
4753 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4754 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4755 + subId + "' for key:" + key);
4756 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4757 }
calvinpanb5a34062021-02-08 19:59:36 +08004758 return ImsManager.getInstance(mApp, slotId).getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004759 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004760 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4761 + subId + "' for key:" + key);
4762 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004763 } finally {
4764 Binder.restoreCallingIdentity(identity);
4765 }
4766 }
4767
4768 @Override
4769 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004770 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4771 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4772 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4774 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004775 final long identity = Binder.clearCallingIdentity();
4776 try {
4777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004778 int slotId = getSlotIndex(subId);
4779 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4780 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4781 + subId + "' for key:" + key);
4782 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4783 }
calvinpanb5a34062021-02-08 19:59:36 +08004784 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4785 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004786 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004787 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004788 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004789 } finally {
4790 Binder.restoreCallingIdentity(identity);
4791 }
4792 }
4793
4794 @Override
4795 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004796 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4797 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4798 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4800 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004801 final long identity = Binder.clearCallingIdentity();
4802 try {
4803 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004804 int slotId = getSlotIndex(subId);
4805 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4806 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4807 + subId + "' for key:" + key);
4808 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4809 }
calvinpanb5a34062021-02-08 19:59:36 +08004810 return ImsManager.getInstance(mApp, slotId).setConfig(key, value);
4811 } catch (com.android.ims.ImsException | RemoteException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004812 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
calvinpanb5a34062021-02-08 19:59:36 +08004813 + "' for key:" + key, e);
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004814 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004815 } finally {
4816 Binder.restoreCallingIdentity(identity);
4817 }
4818 }
4819
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004820 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004821 int slotId = SubscriptionManager.getSlotIndex(subId);
4822 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004823 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4824 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004825 }
4826 return slotId;
4827 }
4828
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004829 private int getSlotIndex(int subId) {
4830 int slotId = SubscriptionManager.getSlotIndex(subId);
4831 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4832 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4833 }
4834 return slotId;
4835 }
4836
Wink Saville36469e72014-06-11 15:17:00 -07004837 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004838 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004839 */
4840 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004841 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4842 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004843 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004844 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004845 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004846 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004847 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004848 mApp, subId, callingPackage, callingFeatureId,
4849 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004850 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4851 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853 final long identity = Binder.clearCallingIdentity();
4854 try {
4855 final Phone phone = getPhone(subId);
4856 if (phone != null) {
4857 return phone.getServiceState().getDataNetworkType();
4858 } else {
4859 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4860 }
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004863 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004864 }
4865
4866 /**
4867 * Returns the data network type
4868 */
4869 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004870 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4871 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4872 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004873 }
4874
4875 /**
4876 * Returns the data network type for a subId
4877 */
4878 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004879 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4880 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004882 mApp, subId, callingPackage, callingFeatureId,
4883 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004884 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4885 }
4886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 final long identity = Binder.clearCallingIdentity();
4888 try {
4889 final Phone phone = getPhone(subId);
4890 if (phone != null) {
4891 return phone.getServiceState().getDataNetworkType();
4892 } else {
4893 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4894 }
4895 } finally {
4896 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004897 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004898 }
4899
4900 /**
Wink Saville36469e72014-06-11 15:17:00 -07004901 * Returns the Voice network type for a subId
4902 */
4903 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004904 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4905 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004906 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004907 mApp, subId, callingPackage, callingFeatureId,
4908 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004909 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4910 }
4911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 final long identity = Binder.clearCallingIdentity();
4913 try {
4914 final Phone phone = getPhone(subId);
4915 if (phone != null) {
4916 return phone.getServiceState().getVoiceNetworkType();
4917 } else {
4918 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4919 }
4920 } finally {
4921 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004923 }
4924
4925 /**
4926 * @return true if a ICC card is present
4927 */
4928 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004929 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004930 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4931 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004932 }
4933
4934 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004935 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004936 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004937 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004938 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 final long identity = Binder.clearCallingIdentity();
4940 try {
4941 final Phone phone = PhoneFactory.getPhone(slotIndex);
4942 if (phone != null) {
4943 return phone.getIccCard().hasIccCard();
4944 } else {
4945 return false;
4946 }
4947 } finally {
4948 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004949 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004950 }
4951
4952 /**
4953 * Return if the current radio is LTE on CDMA. This
4954 * is a tri-state return value as for a period of time
4955 * the mode may be unknown.
4956 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004957 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004958 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004959 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004960 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004961 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004962 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4963 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4964 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004965 }
4966
Sanket Padawe356d7632015-06-22 14:03:32 -07004967 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004968 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4969 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004970 try {
4971 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4972 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004973 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4974 }
4975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 final long identity = Binder.clearCallingIdentity();
4977 try {
4978 final Phone phone = getPhone(subId);
4979 if (phone == null) {
4980 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4981 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004982 return TelephonyProperties.lte_on_cdma_device()
4983 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 }
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004987 }
Wink Saville36469e72014-06-11 15:17:00 -07004988 }
4989
Wink Saville36469e72014-06-11 15:17:00 -07004990 /**
4991 * {@hide}
4992 * Returns Default subId, 0 in the case of single standby.
4993 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004994 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004995 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004996 }
4997
Shishir Agrawala9f32182016-04-12 12:00:16 -07004998 private int getSlotForDefaultSubscription() {
4999 return mSubscriptionController.getPhoneId(getDefaultSubscription());
5000 }
5001
Wink Savilleb564aae2014-10-23 10:18:09 -07005002 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08005003 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07005004 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005005
Pengquan Menge92a50d2018-09-21 15:54:48 -07005006 private boolean isActiveSubscription(int subId) {
5007 return mSubscriptionController.isActiveSubId(subId);
5008 }
5009
Ihab Awadf2177b72013-11-25 13:33:23 -08005010 /**
5011 * @see android.telephony.TelephonyManager.WifiCallingChoices
5012 */
5013 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 final long identity = Binder.clearCallingIdentity();
5015 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005016 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
5018 getWhenToMakeWifiCallsDefaultPreference());
5019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
Ihab Awadf2177b72013-11-25 13:33:23 -08005022 }
5023
5024 /**
5025 * @see android.telephony.TelephonyManager.WifiCallingChoices
5026 */
5027 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 final long identity = Binder.clearCallingIdentity();
5029 try {
5030 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005031 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
5033 } finally {
5034 Binder.restoreCallingIdentity(identity);
5035 }
Ihab Awadf9e92732013-12-05 18:02:52 -08005036 }
5037
Sailesh Nepald1e68152013-12-12 19:08:02 -08005038 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07005039 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08005040 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08005041 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08005042
Jordan Liu4c733742019-02-28 12:03:40 -08005043 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
5044 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
5045 if (phoneId == -1) {
5046 throw new IllegalArgumentException("Given slot index: " + slotIndex
5047 + " does not correspond to an active phone");
5048 }
5049 return PhoneFactory.getPhone(phoneId);
5050 }
5051
Shishir Agrawal566b7612013-10-28 14:41:00 -07005052 @Override
Derek Tan740e1672017-06-27 14:56:27 -07005053 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
5054 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5056 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005058 if (DBG) {
5059 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
5060 }
5061 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
5062 p2);
5063 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005064
Jordan Liu4c733742019-02-28 12:03:40 -08005065
5066 @Override
5067 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
5068 int slotIndex, String callingPackage, String aid, int p2) {
5069 enforceModifyPermission();
5070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5071 if (DBG) {
5072 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
5073 }
5074 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5075 callingPackage, aid, p2);
5076 }
5077
5078 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
5079 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 if (TextUtils.equals(ISDR_AID, aid)) {
5083 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005084 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5085 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 if (bestComponent == null
5087 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5088 loge("The calling package is not allowed to access ISD-R.");
5089 throw new SecurityException(
5090 "The calling package is not allowed to access ISD-R.");
5091 }
Derek Tan740e1672017-06-27 14:56:27 -07005092 }
Derek Tan740e1672017-06-27 14:56:27 -07005093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005094 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08005095 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
5096 null /* workSource */);
5097 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 return response;
5099 } finally {
5100 Binder.restoreCallingIdentity(identity);
5101 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005102 }
5103
5104 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005105 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5107 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005108 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
5109 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
5110 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005111
Jordan Liu4c733742019-02-28 12:03:40 -08005112 @Override
5113 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
5114 enforceModifyPermission();
5115 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
5116 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
5117 channel);
5118 }
5119
5120 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 final long identity = Binder.clearCallingIdentity();
5122 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005123 if (channel < 0) {
5124 return false;
5125 }
Jordan Liu4c733742019-02-28 12:03:40 -08005126 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
5127 null /* workSource */);
5128 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005129 return success;
5130 } finally {
5131 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005132 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005133 }
5134
5135 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005136 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07005137 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5139 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08005140 if (DBG) {
5141 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
5142 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5143 + p3 + " data=" + data);
5144 }
5145 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
5146 command, p1, p2, p3, data);
5147 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005148
Jordan Liu4c733742019-02-28 12:03:40 -08005149 @Override
5150 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5151 int command, int p1, int p2, int p3, String data) {
5152 enforceModifyPermission();
5153 if (DBG) {
5154 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5155 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5156 + p3 + " data=" + data);
5157 }
5158 return iccTransmitApduLogicalChannelWithPermission(
5159 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5160 data);
5161 }
5162
5163 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5164 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 final long identity = Binder.clearCallingIdentity();
5166 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005167 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 return "";
5169 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005172 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5173 null /* workSource */);
5174 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005176 // Append the returned status code to the end of the response payload.
5177 String s = Integer.toHexString(
5178 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5179 if (response.payload != null) {
5180 s = IccUtils.bytesToHexString(response.payload) + s;
5181 }
5182 return s;
5183 } finally {
5184 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005185 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005186 }
Jake Hambye994d462014-02-03 13:10:13 -08005187
Evan Charltonc66da362014-05-16 14:06:40 -07005188 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005189 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5190 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5192 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005194 if (DBG) {
5195 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5196 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5197 }
5198 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5199 cla, command, p1, p2, p3, data);
5200 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005201
Jordan Liu4c733742019-02-28 12:03:40 -08005202 @Override
5203 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5204 int command, int p1, int p2, int p3, String data) {
5205 enforceModifyPermission();
5206 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5207 if (DBG) {
5208 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5209 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5210 + " data=" + data);
5211 }
5212
5213 return iccTransmitApduBasicChannelWithPermission(
5214 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5215 p2, p3, data);
5216 }
5217
5218 // open APDU basic channel assuming the caller has sufficient permissions
5219 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5220 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5224 && TextUtils.equals(ISDR_AID, data)) {
5225 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005226 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5227 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 if (bestComponent == null
5229 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5230 loge("The calling package is not allowed to select ISD-R.");
5231 throw new SecurityException(
5232 "The calling package is not allowed to select ISD-R.");
5233 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005234 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005237 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5238 null /* workSource */);
5239 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005240
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 // Append the returned status code to the end of the response payload.
5242 String s = Integer.toHexString(
5243 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5244 if (response.payload != null) {
5245 s = IccUtils.bytesToHexString(response.payload) + s;
5246 }
5247 return s;
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005250 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005251 }
5252
5253 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005254 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005255 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5257 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 final long identity = Binder.clearCallingIdentity();
5260 try {
5261 if (DBG) {
5262 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5263 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5264 }
5265
5266 IccIoResult response =
5267 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5268 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5269 subId);
5270
5271 if (DBG) {
5272 log("Exchange SIM_IO [R]" + response);
5273 }
5274
5275 byte[] result = null;
5276 int length = 2;
5277 if (response.payload != null) {
5278 length = 2 + response.payload.length;
5279 result = new byte[length];
5280 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5281 } else {
5282 result = new byte[length];
5283 }
5284
5285 result[length - 1] = (byte) response.sw2;
5286 result[length - 2] = (byte) response.sw1;
5287 return result;
5288 } finally {
5289 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005290 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005291 }
5292
Nathan Haroldb3014052017-01-25 15:57:32 -08005293 /**
5294 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5295 * on a particular subscription
5296 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005297 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5298 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005300 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005301 return null;
5302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005303
5304 final long identity = Binder.clearCallingIdentity();
5305 try {
5306 if (appType != TelephonyManager.APPTYPE_USIM
5307 && appType != TelephonyManager.APPTYPE_SIM) {
5308 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5309 return null;
5310 }
5311 Object response = sendRequest(
5312 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5313 if (response instanceof String[]) {
5314 return (String[]) response;
5315 }
yincheng zhao2737e882019-09-06 17:06:54 -07005316 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005318 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 } finally {
5320 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005321 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005322 }
5323
yincheng zhao2737e882019-09-06 17:06:54 -07005324 /**
5325 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5326 * subscription.
5327 *
5328 * @param subId the id of the subscription.
5329 * @param appType the uicc app type, must be USIM or SIM.
5330 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5331 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005332 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005333 * @return number of fplmns that is successfully written to the SIM.
5334 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005335 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5336 String callingFeatureId) {
5337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5338 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005339 if (DBG) logv("no permissions for setForbiddenplmns");
5340 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5341 }
5342 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5343 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5344 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5345 }
5346 if (fplmns == null) {
5347 throw new IllegalArgumentException("Fplmn List provided is null");
5348 }
5349 for (String fplmn : fplmns) {
5350 if (!CellIdentity.isValidPlmn(fplmn)) {
5351 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5352 }
5353 }
5354 final long identity = Binder.clearCallingIdentity();
5355 try {
5356 Object response = sendRequest(
5357 CMD_SET_FORBIDDEN_PLMNS,
5358 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5359 subId);
5360 return (int) response;
5361 } finally {
5362 Binder.restoreCallingIdentity(identity);
5363 }
5364 }
5365
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005366 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005367 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5369 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 final long identity = Binder.clearCallingIdentity();
5372 try {
5373 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5374 if (response.payload == null) {
5375 return "";
5376 }
Evan Charltonc66da362014-05-16 14:06:40 -07005377
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 // Append the returned status code to the end of the response payload.
5379 String s = Integer.toHexString(
5380 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5381 s = IccUtils.bytesToHexString(response.payload) + s;
5382 return s;
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
5385 }
Evan Charltonc66da362014-05-16 14:06:40 -07005386 }
5387
Jake Hambye994d462014-02-03 13:10:13 -08005388 /**
5389 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5390 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5391 *
5392 * @param itemID the ID of the item to read
5393 * @return the NV item as a String, or null on error.
5394 */
5395 @Override
5396 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005397 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5399 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400
5401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005404 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005405 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5406 return value;
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
Jake Hambye994d462014-02-03 13:10:13 -08005410 }
5411
5412 /**
5413 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5414 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5415 *
5416 * @param itemID the ID of the item to read
5417 * @param itemValue the value to write, as a String
5418 * @return true on success; false on any failure
5419 */
5420 @Override
5421 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005422 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5424 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425
5426 final long identity = Binder.clearCallingIdentity();
5427 try {
5428 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5429 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005430 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5432 return success;
5433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
Jake Hambye994d462014-02-03 13:10:13 -08005436 }
5437
5438 /**
5439 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5440 * Used for device configuration by some CDMA operators.
5441 *
5442 * @param preferredRoamingList byte array containing the new PRL
5443 * @return true on success; false on any failure
5444 */
5445 @Override
5446 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5448 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449
5450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5453 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5454 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5455 return success;
5456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458 }
Jake Hambye994d462014-02-03 13:10:13 -08005459 }
5460
5461 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005462 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005463 * Used for device configuration by some CDMA operators.
5464 *
chen xu6dac5ab2018-10-26 17:39:23 -07005465 * @param slotIndex - device slot.
5466 *
Jake Hambye994d462014-02-03 13:10:13 -08005467 * @return true on success; false on any failure
5468 */
5469 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005470 public boolean resetModemConfig(int slotIndex) {
5471 Phone phone = PhoneFactory.getPhone(slotIndex);
5472 if (phone != null) {
5473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5474 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475
chen xu6dac5ab2018-10-26 17:39:23 -07005476 final long identity = Binder.clearCallingIdentity();
5477 try {
5478 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5479 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5480 return success;
5481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 }
chen xu6dac5ab2018-10-26 17:39:23 -07005485 return false;
5486 }
5487
5488 /**
5489 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5490 *
5491 * @param slotIndex - device slot.
5492 *
5493 * @return true on success; false on any failure
5494 */
5495 @Override
5496 public boolean rebootModem(int slotIndex) {
5497 Phone phone = PhoneFactory.getPhone(slotIndex);
5498 if (phone != null) {
5499 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5500 mApp, phone.getSubId(), "rebootModem");
5501
5502 final long identity = Binder.clearCallingIdentity();
5503 try {
5504 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5505 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5506 return success;
5507 } finally {
5508 Binder.restoreCallingIdentity(identity);
5509 }
5510 }
5511 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005512 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005513
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005514 public String[] getPcscfAddress(String apnType, String callingPackage,
5515 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005516 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005517 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5518 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005519 return new String[0];
5520 }
5521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 final long identity = Binder.clearCallingIdentity();
5523 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005524 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 } finally {
5526 Binder.restoreCallingIdentity(identity);
5527 }
Wink Saville36469e72014-06-11 15:17:00 -07005528 }
5529
Brad Ebinger51f743a2017-01-23 13:50:20 -08005530 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005531 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5532 * {@link #disableIms(int)}.
5533 * @param slotIndex device slot.
5534 */
5535 public void resetIms(int slotIndex) {
5536 enforceModifyPermission();
5537
5538 final long identity = Binder.clearCallingIdentity();
5539 try {
5540 if (mImsResolver == null) {
5541 // may happen if the does not support IMS.
5542 return;
5543 }
5544 mImsResolver.disableIms(slotIndex);
5545 mImsResolver.enableIms(slotIndex);
5546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
5549 }
5550
5551 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005552 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5553 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005554 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005555 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557
5558 final long identity = Binder.clearCallingIdentity();
5559 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005560 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005561 // may happen if the device does not support IMS.
5562 return;
5563 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005564 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005568 }
5569
5570 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005571 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5572 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005573 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005574 public void disableIms(int slotId) {
5575 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576
5577 final long identity = Binder.clearCallingIdentity();
5578 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005579 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005580 // may happen if the device does not support IMS.
5581 return;
5582 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005583 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005587 }
5588
5589 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005590 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5591 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005592 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005593 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005594 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005595 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596
5597 final long identity = Binder.clearCallingIdentity();
5598 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005599 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005600 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5601 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005602 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005603 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 } finally {
5605 Binder.restoreCallingIdentity(identity);
5606 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005607 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005608 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005609 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5610 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005611 @Override
5612 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005613 enforceModifyPermission();
5614
5615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005618 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005619 } finally {
5620 Binder.restoreCallingIdentity(identity);
5621 }
5622 }
5623
5624 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005625 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005626 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005627 */
5628 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5629 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630
5631 final long identity = Binder.clearCallingIdentity();
5632 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005633 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005634 // may happen if the device does not support IMS.
5635 return null;
5636 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005637 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005641 }
5642
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005643 /**
5644 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005645 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005646 */
5647 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649
5650 final long identity = Binder.clearCallingIdentity();
5651 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005652 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005653 // may happen if the device does not support IMS.
5654 return null;
5655 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005656 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005660 }
5661
Brad Ebinger884c07b2018-02-15 16:17:40 -08005662 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005663 * Sets the ImsService Package Name that Telephony will bind to.
5664 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005665 * @param slotIndex the slot ID that the ImsService should bind for.
5666 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005667 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005668 * @param featureTypes An integer array of feature types associated with a packageName.
5669 * @param packageName The name of the package that the current configuration will be replaced
5670 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005671 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005672 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005673 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5674 int[] featureTypes, String packageName) {
5675 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5676 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5678 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005679 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 final long identity = Binder.clearCallingIdentity();
5682 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005683 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005684 // may happen if the device does not support IMS.
5685 return false;
5686 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005687 Map<Integer, String> featureConfig = new HashMap<>();
5688 for (int featureType : featureTypes) {
5689 featureConfig.put(featureType, packageName);
5690 }
5691 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5692 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005696 }
5697
5698 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005699 * Clears any carrier ImsService overrides for the slot index specified that were previously
5700 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5701 *
5702 * This should only be used for testing.
5703 *
5704 * @param slotIndex the slot ID that the ImsService should bind for.
5705 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5706 */
5707 @Override
5708 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5709 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5710 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5711 "clearCarrierImsServiceOverride");
5712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5713 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5714 "clearCarrierImsServiceOverride");
5715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 if (mImsResolver == null) {
5719 // may happen if the device does not support IMS.
5720 return false;
5721 }
5722 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5723 } finally {
5724 Binder.restoreCallingIdentity(identity);
5725 }
5726 }
5727
5728 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005729 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005730 *
5731 * @param slotId The slot that the ImsService is associated with.
5732 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5733 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005734 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005735 * @return the package name of the ImsService configuration.
5736 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005737 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5738 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005739 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005740 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005741 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Brad Ebinger24c29992019-12-05 13:03:21 -08005742 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5743 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 final long identity = Binder.clearCallingIdentity();
5746 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005747 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005748 // may happen if the device does not support IMS.
5749 return "";
5750 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005751 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005752 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5753 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005757 }
5758
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005759 /**
5760 * Get the MmTelFeature state associated with the requested subscription id.
5761 * @param subId The subscription that the MmTelFeature is associated with.
5762 * @param callback A callback with an integer containing the
5763 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5764 */
5765 @Override
5766 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5767 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5768 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5769 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5770 "IMS not available on device.");
5771 }
5772 final long token = Binder.clearCallingIdentity();
5773 try {
5774 int slotId = getSlotIndex(subId);
5775 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5776 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5777 + subId + "'");
5778 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5779 }
5780 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5781 try {
5782 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5783 } catch (RemoteException e) {
5784 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5785 + "Ignore");
5786 }
5787 });
5788 } finally {
5789 Binder.restoreCallingIdentity(token);
5790 }
5791 }
5792
Daniel Brightbb5840b2021-01-12 15:48:18 -08005793 /**
5794 * Sets the ims registration state on all valid {@link Phone}s.
5795 */
5796 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005797 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798
5799 final long identity = Binder.clearCallingIdentity();
5800 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005801 // NOTE: Before S, this method only set the default phone.
5802 for (final Phone phone : PhoneFactory.getPhones()) {
5803 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5804 phone.setImsRegistrationState(registered);
5805 }
5806 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
Wink Saville36469e72014-06-11 15:17:00 -07005810 }
5811
5812 /**
Stuart Scott54788802015-03-30 13:18:01 -07005813 * Set the network selection mode to automatic.
5814 *
5815 */
5816 @Override
5817 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5819 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005820
5821 final long identity = Binder.clearCallingIdentity();
5822 try {
shilufc958392020-01-20 11:36:01 -08005823 if (!isActiveSubscription(subId)) {
5824 return;
5825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005827 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5828 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831 }
Stuart Scott54788802015-03-30 13:18:01 -07005832 }
5833
Jack Yud10cdd42020-09-28 20:28:01 -07005834 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005835 * Ask the radio to connect to the input network and change selection mode to manual.
5836 *
5837 * @param subId the id of the subscription.
5838 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5839 * the operator to attach to.
5840 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5841 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5842 * normal network selection next time.
5843 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005844 */
5845 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005846 public boolean setNetworkSelectionModeManual(
5847 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5849 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005850
5851 if (!isActiveSubscription(subId)) {
5852 return false;
5853 }
5854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 final long identity = Binder.clearCallingIdentity();
5856 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005857 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005859 if (DBG) {
5860 log("setNetworkSelectionModeManual: subId: " + subId
5861 + " operator: " + operatorInfo);
5862 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005867 }
shilu84f6e8b2019-12-19 13:58:01 -08005868 /**
5869 * Get the manual network selection
5870 *
5871 * @param subId the id of the subscription.
5872 *
5873 * @return the previously saved user selected PLMN
5874 */
5875 @Override
5876 public String getManualNetworkSelectionPlmn(int subId) {
5877 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07005878 .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
shilu84f6e8b2019-12-19 13:58:01 -08005879 mApp, subId, "getManualNetworkSelectionPlmn");
5880
5881 final long identity = Binder.clearCallingIdentity();
5882 try {
5883 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005884 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005885 }
5886
5887 final Phone phone = getPhone(subId);
5888 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005889 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005890 }
5891 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5892 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5893 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
5897 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005898
5899 /**
5900 * Scans for available networks.
5901 */
5902 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005903 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5904 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5906 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005907 LocationAccessPolicy.LocationPermissionResult locationResult =
5908 LocationAccessPolicy.checkLocationPermission(mApp,
5909 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5910 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005911 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005912 .setCallingPid(Binder.getCallingPid())
5913 .setCallingUid(Binder.getCallingUid())
5914 .setMethod("getCellNetworkScanResults")
5915 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005916 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5917 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005918 .build());
5919 switch (locationResult) {
5920 case DENIED_HARD:
5921 throw new SecurityException("Not allowed to access scan results -- location");
5922 case DENIED_SOFT:
5923 return null;
5924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925
Pengquan Menga1bb6272018-09-06 09:59:22 -07005926 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 try {
5928 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005929 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005934 }
5935
5936 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005937 * Get the call forwarding info, given the call forwarding reason.
5938 */
5939 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005940 public void getCallForwarding(int subId, int callForwardingReason,
5941 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005942 enforceReadPrivilegedPermission("getCallForwarding");
5943 long identity = Binder.clearCallingIdentity();
5944 try {
5945 if (DBG) {
5946 log("getCallForwarding: subId " + subId
5947 + " callForwardingReason" + callForwardingReason);
5948 }
Hall Liu27d24262020-09-18 19:04:59 -07005949
5950 Phone phone = getPhone(subId);
5951 if (phone == null) {
5952 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005953 callback.onError(
5954 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005955 } catch (RemoteException e) {
5956 // ignore
5957 }
5958 return;
5959 }
5960
5961 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5962 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5963 @Override
5964 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5965 try {
5966 callback.onCallForwardingInfoAvailable(info);
5967 } catch (RemoteException e) {
5968 // ignore
5969 }
5970 }
5971
5972 @Override
5973 public void onError(int error) {
5974 try {
5975 callback.onError(error);
5976 } catch (RemoteException e) {
5977 // ignore
5978 }
5979 }
5980 });
5981 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005982 } finally {
5983 Binder.restoreCallingIdentity(identity);
5984 }
5985 }
5986
5987 /**
5988 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5989 * reason, the number to forward, and the timeout before the forwarding is attempted.
5990 */
5991 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005992 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5993 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005994 enforceModifyPermission();
5995 long identity = Binder.clearCallingIdentity();
5996 try {
5997 if (DBG) {
5998 log("setCallForwarding: subId " + subId
5999 + " callForwardingInfo" + callForwardingInfo);
6000 }
Hall Liu27d24262020-09-18 19:04:59 -07006001
6002 Phone phone = getPhone(subId);
6003 if (phone == null) {
6004 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07006005 callback.accept(
6006 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07006007 } catch (RemoteException e) {
6008 // ignore
6009 }
6010 return;
6011 }
6012
6013 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
6014 FunctionalUtils.ignoreRemoteException(callback::accept));
6015
6016 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006017 } finally {
6018 Binder.restoreCallingIdentity(identity);
6019 }
6020 }
6021
6022 /**
Hall Liu27d24262020-09-18 19:04:59 -07006023 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006024 */
6025 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006026 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006027 enforceReadPrivilegedPermission("getCallForwarding");
6028 long identity = Binder.clearCallingIdentity();
6029 try {
Hall Liu27d24262020-09-18 19:04:59 -07006030
6031 Phone phone = getPhone(subId);
6032 if (phone == null) {
6033 try {
6034 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6035 } catch (RemoteException e) {
6036 // ignore
6037 }
6038 return;
6039 }
6040
6041 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
6042
Shuo Qian4a594052020-01-23 11:59:30 -08006043 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07006044 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006045 } finally {
6046 Binder.restoreCallingIdentity(identity);
6047 }
6048 }
6049
6050 /**
Hall Liu27d24262020-09-18 19:04:59 -07006051 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08006052 */
6053 @Override
Hall Liu27d24262020-09-18 19:04:59 -07006054 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08006055 enforceModifyPermission();
6056 long identity = Binder.clearCallingIdentity();
6057 try {
Hall Liu27d24262020-09-18 19:04:59 -07006058 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
6059
6060 Phone phone = getPhone(subId);
6061 if (phone == null) {
6062 try {
6063 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
6064 } catch (RemoteException e) {
6065 // ignore
6066 }
6067 return;
6068 }
6069
6070 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
6071 FunctionalUtils.ignoreRemoteException(callback::accept));
6072
6073 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08006074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
6077 }
6078
6079 /**
yinxub1bed742017-04-17 11:45:04 -07006080 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07006081 *
yinxub1bed742017-04-17 11:45:04 -07006082 * @param subId id of the subscription
6083 * @param request contains the radio access networks with bands/channels to scan
6084 * @param messenger callback messenger for scan results or errors
6085 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07006086 * @return the id of the requested scan which can be used to stop the scan.
6087 */
6088 @Override
6089 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006090 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6092 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08006093 LocationAccessPolicy.LocationPermissionResult locationResult =
6094 LocationAccessPolicy.checkLocationPermission(mApp,
6095 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6096 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006097 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006098 .setCallingPid(Binder.getCallingPid())
6099 .setCallingUid(Binder.getCallingUid())
6100 .setMethod("requestNetworkScan")
6101 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08006102 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6103 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006104 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006105 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07006106 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
6107 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08006108 if (e != null) {
6109 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
6110 throw e;
6111 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07006112 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08006113 return TelephonyScanManager.INVALID_SCAN_ID;
6114 }
6115 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 }
Hall Liu912dfd32019-04-25 14:02:26 -07006117 int callingUid = Binder.getCallingUid();
6118 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07006119 final long identity = Binder.clearCallingIdentity();
6120 try {
6121 return mNetworkScanRequestTracker.startNetworkScan(
6122 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07006123 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07006124 } finally {
6125 Binder.restoreCallingIdentity(identity);
6126 }
yinxu504e1392017-04-12 16:03:22 -07006127 }
6128
Hall Liub2ac8ef2019-02-28 15:56:23 -08006129 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07006130 NetworkScanRequest request, int subId, String callingPackage) {
6131 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07006132 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6133 boolean hasNetworkScanPermission =
6134 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
6135 == PERMISSION_GRANTED;
6136
6137 if (!hasCarrierPriv && !hasNetworkScanPermission) {
6138 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
6139 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08006140 }
6141
6142 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
6143 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08006144 if (ras.getChannels() != null && ras.getChannels().length > 0) {
6145 return new SecurityException("Specific channels must not be"
6146 + " scanned without location access.");
6147 }
6148 }
6149 }
6150
Hall Liub2ac8ef2019-02-28 15:56:23 -08006151 return null;
6152 }
6153
yinxu504e1392017-04-12 16:03:22 -07006154 /**
6155 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006156 *
6157 * @param subId id of the subscription
6158 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006159 */
6160 @Override
6161 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6163 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164
Hall Liu912dfd32019-04-25 14:02:26 -07006165 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 final long identity = Binder.clearCallingIdentity();
6167 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006168 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171 }
yinxu504e1392017-04-12 16:03:22 -07006172 }
6173
6174 /**
SongFerngWang3ef3e072020-12-21 16:41:52 +08006175 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006176 *
SongFerngWang3ef3e072020-12-21 16:41:52 +08006177 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006178 */
6179 @Override
SongFerngWang3ef3e072020-12-21 16:41:52 +08006180 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006181 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006182 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang3ef3e072020-12-21 16:41:52 +08006183 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184
6185 final long identity = Binder.clearCallingIdentity();
6186 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006187 if (DBG) log("getAllowedNetworkTypesBitmask");
6188 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6189 int networkTypesBitmask = (result != null ? result[0] : -1);
6190 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6191 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006195 }
6196
6197 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006198 * Get the allowed network types for certain reason.
6199 *
6200 * @param subId the id of the subscription.
6201 * @param reason the reason the allowed network type change is taking place
6202 * @return the allowed network types.
6203 */
6204 @Override
6205 public long getAllowedNetworkTypesForReason(int subId,
6206 @TelephonyManager.AllowedNetworkTypesReason int reason) {
Nathan Harold62c68512021-04-06 11:26:02 -07006207 TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006208 mApp, subId, "getAllowedNetworkTypesForReason");
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006209 final long identity = Binder.clearCallingIdentity();
6210 try {
6211 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
6214 }
6215 }
6216
6217 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006218 * Enable/Disable E-UTRA-NR Dual Connectivity
6219 * @param subId subscription id of the sim card
6220 * @param nrDualConnectivityState expected NR dual connectivity state
6221 * This can be passed following states
6222 * <ol>
6223 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6224 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6225 * <li>Disable NR dual connectivity and force secondary cell to be released
6226 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6227 * </ol>
6228 * @return operation result.
6229 */
6230 @Override
6231 public int setNrDualConnectivityState(int subId,
6232 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6234 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006235 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006236 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6237 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6238 }
6239
Sooraj Sasindran37444802020-08-11 10:40:43 -07006240 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6244 nrDualConnectivityState, subId,
6245 workSource);
6246 if (DBG) log("enableNRDualConnectivity result: " + result);
6247 return result;
6248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250 }
6251 }
6252
6253 /**
6254 * Is E-UTRA-NR Dual Connectivity enabled
6255 * @return true if dual connectivity is enabled else false
6256 */
6257 @Override
6258 public boolean isNrDualConnectivityEnabled(int subId) {
6259 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07006260 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sooraj Sasindran37444802020-08-11 10:40:43 -07006261 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindran0e4e00a2021-03-16 18:02:32 -07006262 if (!isRadioInterfaceCapabilitySupported(
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006263 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6264 return false;
6265 }
Sooraj Sasindran37444802020-08-11 10:40:43 -07006266 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6270 null, subId, workSource);
6271 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6272 return isEnabled;
6273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
6276 }
6277
6278 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006279 * Set the allowed network types of the device and
6280 * provide the reason triggering the allowed network change.
6281 *
6282 * @param subId the id of the subscription.
6283 * @param reason the reason the allowed network type change is taking place
6284 * @param allowedNetworkTypes the allowed network types.
6285 * @return true on success; false on any failure.
6286 */
6287 @Override
6288 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang3ef3e072020-12-21 16:41:52 +08006289 @TelephonyManager.AllowedNetworkTypesReason int reason,
6290 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6292 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang3ef3e072020-12-21 16:41:52 +08006293 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6294 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6295 return false;
6296 }
6297
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006298 log("setAllowedNetworkTypesForReason: " + reason + " value: "
6299 + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes));
6300
6301
6302 if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) {
6303 log("setAllowedNetworkTypesForReason: " + reason + "does not change value");
6304 return true;
SongFerngWang3ef3e072020-12-21 16:41:52 +08006305 }
SongFerngWang8c6e82e2021-03-02 22:09:29 +08006306
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006307 final long identity = Binder.clearCallingIdentity();
6308 try {
SongFerngWang3ef3e072020-12-21 16:41:52 +08006309 Boolean success = (Boolean) sendRequest(
6310 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6311 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6312
6313 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6314 return success;
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
6318 }
6319
6320 /**
Miaoa84611c2019-03-15 09:21:10 +08006321 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006322 *
Miaoa84611c2019-03-15 09:21:10 +08006323 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006324 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006325 * @hide
6326 */
6327 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006328 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006329 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006330 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006331 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 try {
Miaoa84611c2019-03-15 09:21:10 +08006333 if (phone != null) {
6334 return phone.hasMatchedTetherApnSetting();
6335 } else {
6336 return false;
6337 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 } finally {
6339 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006340 }
Junda Liu475951f2014-11-07 16:45:03 -08006341 }
6342
6343 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006344 * Enable or disable always reporting signal strength changes from radio.
6345 *
6346 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6347 */
6348 @Override
6349 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6350 enforceModifyPermission();
6351 enforceSystemCaller();
6352
6353 final long identity = Binder.clearCallingIdentity();
6354 final Phone phone = getPhone(subId);
6355 try {
6356 if (phone != null) {
6357 if (DBG) {
6358 log("setAlwaysReportSignalStrength: subId=" + subId
6359 + " isEnable=" + isEnable);
6360 }
6361 phone.setAlwaysReportSignalStrength(isEnable);
6362 } else {
6363 loge("setAlwaysReportSignalStrength: no phone found for subId="
6364 + subId);
6365 }
6366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
6369 }
6370
6371 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006372 * Get the user enabled state of Mobile Data.
6373 *
6374 * TODO: remove and use isUserDataEnabled.
6375 * This can't be removed now because some vendor codes
6376 * calls through ITelephony directly while they should
6377 * use TelephonyManager.
6378 *
6379 * @return true on enabled
6380 */
6381 @Override
6382 public boolean getDataEnabled(int subId) {
6383 return isUserDataEnabled(subId);
6384 }
6385
6386 /**
6387 * Get whether mobile data is enabled per user setting.
6388 *
6389 * There are other factors deciding whether mobile data is actually enabled, but they are
6390 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006391 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006392 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006393 *
6394 * @return {@code true} if data is enabled else {@code false}
6395 */
6396 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006397 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006398 try {
6399 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6400 null);
6401 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6403 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006404 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405
6406 final long identity = Binder.clearCallingIdentity();
6407 try {
6408 int phoneId = mSubscriptionController.getPhoneId(subId);
6409 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6410 Phone phone = PhoneFactory.getPhone(phoneId);
6411 if (phone != null) {
6412 boolean retVal = phone.isUserDataEnabled();
6413 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6414 return retVal;
6415 } else {
6416 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6417 return false;
6418 }
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006421 }
6422 }
6423
6424 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006425 * Checks if the device is capable of mobile data by considering whether whether the
6426 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6427 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006428 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006429 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006430 */
6431 @Override
6432 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006433 try {
6434 try {
6435 mApp.enforceCallingOrSelfPermission(
6436 android.Manifest.permission.ACCESS_NETWORK_STATE,
6437 null);
6438 } catch (Exception e) {
6439 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6440 "isDataEnabled");
6441 }
6442 } catch (Exception e) {
6443 enforceReadPrivilegedPermission("isDataEnabled");
6444 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445
6446 final long identity = Binder.clearCallingIdentity();
6447 try {
6448 int phoneId = mSubscriptionController.getPhoneId(subId);
6449 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6450 Phone phone = PhoneFactory.getPhone(phoneId);
6451 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006452 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6454 return retVal;
6455 } else {
6456 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6457 return false;
6458 }
6459 } finally {
6460 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006461 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006462 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006463
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006464 /**
6465 * Check if data is enabled for a specific reason
6466 * @param subId Subscription index
6467 * @param reason the reason the data enable change is taking place
6468 * @return {@code true} if the overall data is enabled; {@code false} if not.
6469 */
6470 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006471 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006472 @TelephonyManager.DataEnabledReason int reason) {
6473 try {
6474 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6475 null);
6476 } catch (Exception e) {
6477 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006478 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006479 }
6480
6481
6482 final long identity = Binder.clearCallingIdentity();
6483 try {
6484 int phoneId = mSubscriptionController.getPhoneId(subId);
6485 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006486 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006487 + " reason=" + reason);
6488 }
6489 Phone phone = PhoneFactory.getPhone(phoneId);
6490 if (phone != null) {
6491 boolean retVal;
6492 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6493 retVal = phone.isUserDataEnabled();
6494 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006495 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006496 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006497 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006498 return retVal;
6499 } else {
6500 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006501 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006502 + subId + " retVal=false");
6503 }
6504 return false;
6505 }
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
6509 }
6510
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006511 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006512 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006513 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6514 // Skip the check if it's one of these special uids
6515 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6516 }
6517
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006518 //load access rules from carrier configs, and check those as well: b/139133814
6519 SubscriptionController subController = SubscriptionController.getInstance();
6520 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6521 || subController == null) return privilegeFromSim;
6522
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006523 PackageManager pkgMgr = phone.getContext().getPackageManager();
6524 String[] packages = pkgMgr.getPackagesForUid(uid);
6525
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006528 int subId = phone.getSubId();
6529 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6530 // A test override is in place for the privileges for this subId, so don't try to
6531 // read the subscription privileges.
6532 return privilegeFromSim;
6533 }
6534 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006535 SubscriptionManager subManager = (SubscriptionManager)
6536 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6537 for (String pkg : packages) {
6538 if (subManager.canManageSubscription(subInfo, pkg)) {
6539 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6540 }
6541 }
6542 return privilegeFromSim;
6543 } finally {
6544 Binder.restoreCallingIdentity(identity);
6545 }
6546 }
6547
6548 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6549 String pkgName) {
6550 //load access rules from carrier configs, and check those as well: b/139133814
6551 SubscriptionController subController = SubscriptionController.getInstance();
6552 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6553 || subController == null) return privilegeFromSim;
6554
6555 final long identity = Binder.clearCallingIdentity();
6556 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006557 int subId = phone.getSubId();
6558 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6559 // A test override is in place for the privileges for this subId, so don't try to
6560 // read the subscription privileges.
6561 return privilegeFromSim;
6562 }
6563 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006564 SubscriptionManager subManager = (SubscriptionManager)
6565 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6566 return subManager.canManageSubscription(subInfo, pkgName)
6567 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
6571 }
6572
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006573 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006574 public int getCarrierPrivilegeStatus(int subId) {
6575 final Phone phone = getPhone(subId);
6576 if (phone == null) {
6577 loge("getCarrierPrivilegeStatus: Invalid subId");
6578 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6579 }
6580 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006581 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006582 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006583 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6584 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006585
6586 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6587 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006588 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006589 }
Junda Liu29340342014-07-10 15:23:27 -07006590
6591 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006592 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006593 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006594 final Phone phone = getPhone(subId);
6595 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006596 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006597 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6598 }
6599 UiccProfile profile =
6600 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6601 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006602 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006603 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6604 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006605 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006606 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006607 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006608 }
6609
6610 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006611 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6612 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006613 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006614 }
6615
6616 int phoneId = SubscriptionManager.getPhoneId(subId);
6617 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006618 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006619 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006620 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6621 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006622 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6623 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6624 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006625 }
6626
6627 @Override
6628 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006629 if (TextUtils.isEmpty(pkgName))
6630 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006631 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6632 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6633 UiccCard card = UiccController.getInstance().getUiccCard(i);
6634 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006635 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006636 continue;
6637 }
6638
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006639 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6640 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6641 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006642 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6643 break;
6644 }
6645 }
6646
6647 return result;
Junda Liu29340342014-07-10 15:23:27 -07006648 }
Derek Tan89e89d42014-07-08 17:00:10 -07006649
6650 @Override
Junda Liue64de782015-04-16 17:19:16 -07006651 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6652 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6653 loge("phoneId " + phoneId + " is not valid.");
6654 return null;
6655 }
6656 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006657 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006658 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006659 return null ;
6660 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006661 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006662 }
6663
Amith Yamasani6e118872016-02-19 12:53:51 -08006664 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006665 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006666 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006667 List<String> privilegedPackages = new ArrayList<>();
6668 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006669 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6670 // has UICC in that slot.
6671 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006672 if (card.hasCarrierPrivilegeRules()) {
6673 if (packages == null) {
6674 // Only check packages in user 0 for now
6675 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006676 PackageManager.MATCH_DISABLED_COMPONENTS
6677 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006678 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006679 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006680 }
6681 for (int p = packages.size() - 1; p >= 0; p--) {
6682 PackageInfo pkgInfo = packages.get(p);
6683 if (pkgInfo != null && pkgInfo.packageName != null
6684 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006685 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006686 privilegedPackages.add(pkgInfo.packageName);
6687 }
6688 }
6689 }
6690 }
6691 return privilegedPackages;
6692 }
6693
chen xuf7e9fe82019-05-09 19:31:02 -07006694 @Override
6695 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006696 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6697
6698 final long identity = Binder.clearCallingIdentity();
6699
chen xuf7e9fe82019-05-09 19:31:02 -07006700 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006701 try {
6702 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6703 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6704 }
6705 } finally {
6706 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006707 }
6708 return privilegedPackages;
6709 }
6710
Wink Savilleb564aae2014-10-23 10:18:09 -07006711 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006712 final Phone phone = getPhone(subId);
6713 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006714 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006715 return null;
6716 }
6717 String iccId = card.getIccId();
6718 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006719 return null;
6720 }
6721 return iccId;
6722 }
6723
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006724 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006725 public void setCallComposerStatus(int subId, int status) {
6726 enforceModifyPermission();
6727
6728 final long identity = Binder.clearCallingIdentity();
6729 try {
6730 Phone phone = getPhone(subId);
6731 if (phone != null) {
6732 Phone defaultPhone = phone.getImsPhone();
6733 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6734 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6735 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006736 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6737 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006738 }
6739 }
Shuo Qian284ae752020-12-22 19:10:14 -08006740 } catch (ImsException e) {
6741 throw new ServiceSpecificException(e.getCode());
6742 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006743 Binder.restoreCallingIdentity(identity);
6744 }
6745 }
6746
6747 @Override
6748 public int getCallComposerStatus(int subId) {
6749 enforceReadPrivilegedPermission("getCallComposerStatus");
6750
6751 final long identity = Binder.clearCallingIdentity();
6752 try {
6753 Phone phone = getPhone(subId);
6754 if (phone != null) {
6755 Phone defaultPhone = phone.getImsPhone();
6756 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6757 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6758 return imsPhone.getCallComposerStatus();
6759 }
6760 }
6761 } finally {
6762 Binder.restoreCallingIdentity(identity);
6763 }
6764 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6765 }
6766
6767 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006768 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6769 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006770 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006771 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006773 final long identity = Binder.clearCallingIdentity();
6774 try {
6775 final String iccId = getIccId(subId);
6776 final Phone phone = getPhone(subId);
6777 if (phone == null) {
6778 return false;
6779 }
6780 final String subscriberId = phone.getSubscriberId();
6781
6782 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006783 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006784 + subscriberId + " to " + number);
6785 }
6786
6787 if (TextUtils.isEmpty(iccId)) {
6788 return false;
6789 }
6790
6791 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6792
6793 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6794 if (alphaTag == null) {
6795 editor.remove(alphaTagPrefKey);
6796 } else {
6797 editor.putString(alphaTagPrefKey, alphaTag);
6798 }
6799
6800 // Record both the line number and IMSI for this ICCID, since we need to
6801 // track all merged IMSIs based on line number
6802 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6803 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6804 if (number == null) {
6805 editor.remove(numberPrefKey);
6806 editor.remove(subscriberPrefKey);
6807 } else {
6808 editor.putString(numberPrefKey, number);
6809 editor.putString(subscriberPrefKey, subscriberId);
6810 }
6811
6812 editor.commit();
6813 return true;
6814 } finally {
6815 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006816 }
Derek Tan7226c842014-07-02 17:42:23 -07006817 }
6818
6819 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006820 public String getLine1NumberForDisplay(int subId, String callingPackage,
6821 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006822 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006824 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006825 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006826 return null;
6827 }
Derek Tan97ebb422014-09-05 16:55:38 -07006828
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829 final long identity = Binder.clearCallingIdentity();
6830 try {
6831 String iccId = getIccId(subId);
6832 if (iccId != null) {
6833 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6834 if (DBG_MERGE) {
6835 log("getLine1NumberForDisplay returning "
6836 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6837 }
6838 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6841 return null;
6842 } finally {
6843 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006844 }
Derek Tan7226c842014-07-02 17:42:23 -07006845 }
6846
6847 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006848 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6849 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006850 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006851 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006852 return null;
6853 }
Derek Tan97ebb422014-09-05 16:55:38 -07006854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 final long identity = Binder.clearCallingIdentity();
6856 try {
6857 String iccId = getIccId(subId);
6858 if (iccId != null) {
6859 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6860 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6861 }
6862 return null;
6863 } finally {
6864 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006865 }
Derek Tan7226c842014-07-02 17:42:23 -07006866 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006867
6868 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006869 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6870 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006871 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6872 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006874 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006875 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006876 return null;
6877 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006878
Jordan Liub49b04b2019-05-06 14:45:15 -07006879 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6880 // the process, where TelephonyManager was instantiated.
6881 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006882 final long identity = Binder.clearCallingIdentity();
6883 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006884 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885 final TelephonyManager tele = TelephonyManager.from(context);
6886 final SubscriptionManager sub = SubscriptionManager.from(context);
6887
6888 // Figure out what subscribers are currently active
6889 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890
Jordan Liub49b04b2019-05-06 14:45:15 -07006891 // Only consider subs which match the current subId
6892 // This logic can be simplified. See b/131189269 for progress.
6893 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006894 activeSubscriberIds.add(tele.getSubscriberId(subId));
6895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006896
6897 // First pass, find a number override for an active subscriber
6898 String mergeNumber = null;
6899 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6900 for (String key : prefs.keySet()) {
6901 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6902 final String subscriberId = (String) prefs.get(key);
6903 if (activeSubscriberIds.contains(subscriberId)) {
6904 final String iccId = key.substring(
6905 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6906 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6907 mergeNumber = (String) prefs.get(numberKey);
6908 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006909 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006910 + " for active subscriber " + subscriberId);
6911 }
6912 if (!TextUtils.isEmpty(mergeNumber)) {
6913 break;
6914 }
6915 }
6916 }
6917 }
6918
6919 // Shortcut when no active merged subscribers
6920 if (TextUtils.isEmpty(mergeNumber)) {
6921 return null;
6922 }
6923
6924 // Second pass, find all subscribers under that line override
6925 final ArraySet<String> result = new ArraySet<>();
6926 for (String key : prefs.keySet()) {
6927 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6928 final String number = (String) prefs.get(key);
6929 if (mergeNumber.equals(number)) {
6930 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6931 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6932 final String subscriberId = (String) prefs.get(subscriberKey);
6933 if (!TextUtils.isEmpty(subscriberId)) {
6934 result.add(subscriberId);
6935 }
6936 }
6937 }
6938 }
6939
6940 final String[] resultArray = result.toArray(new String[result.size()]);
6941 Arrays.sort(resultArray);
6942 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006943 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6945 }
6946 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006947 } finally {
6948 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006949 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006950 }
6951
6952 @Override
zoey chen38003472019-12-13 17:16:31 +08006953 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6954 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006955
6956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 final TelephonyManager telephonyManager = mApp.getSystemService(
6959 TelephonyManager.class);
6960 String subscriberId = telephonyManager.getSubscriberId(subId);
6961 if (subscriberId == null) {
6962 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006963 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006964 + subId);
6965 }
6966 return null;
6967 }
6968
6969 final SubscriptionInfo info = SubscriptionController.getInstance()
6970 .getSubscriptionInfo(subId);
6971 final ParcelUuid groupUuid = info.getGroupUuid();
6972 // If it doesn't belong to any group, return just subscriberId of itself.
6973 if (groupUuid == null) {
6974 return new String[]{subscriberId};
6975 }
6976
6977 // Get all subscriberIds from the group.
6978 final List<String> mergedSubscriberIds = new ArrayList<>();
6979 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006980 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006981 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006982 for (SubscriptionInfo subInfo : groupInfos) {
6983 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6984 if (subscriberId != null) {
6985 mergedSubscriberIds.add(subscriberId);
6986 }
6987 }
6988
6989 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
6992
6993 }
6994 }
6995
6996 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006997 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006998 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006999 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000
7001 final long identity = Binder.clearCallingIdentity();
7002 try {
7003 final Phone phone = getPhone(subId);
7004 return phone == null ? false : phone.setOperatorBrandOverride(brand);
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07007008 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05007009
7010 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007011 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007012 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
7013 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08007014 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7015 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016
7017 final long identity = Binder.clearCallingIdentity();
7018 try {
7019 final Phone phone = getPhone(subId);
7020 if (phone == null) {
7021 return false;
7022 }
7023 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
7024 cdmaNonRoamingList);
7025 } finally {
7026 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08007027 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08007028 }
7029
7030 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007031 @Deprecated
7032 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
7033 enforceModifyPermission();
7034
7035 int returnValue = 0;
7036 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07007037 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00007038 if(result.exception == null) {
7039 if (result.result != null) {
7040 byte[] responseData = (byte[])(result.result);
7041 if(responseData.length > oemResp.length) {
7042 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
7043 responseData.length + "bytes. Buffer Size is " +
7044 oemResp.length + "bytes.");
7045 }
7046 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
7047 returnValue = responseData.length;
7048 }
7049 } else {
7050 CommandException ex = (CommandException) result.exception;
7051 returnValue = ex.getCommandError().ordinal();
7052 if(returnValue > 0) returnValue *= -1;
7053 }
7054 } catch (RuntimeException e) {
7055 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
7056 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
7057 if(returnValue > 0) returnValue *= -1;
7058 }
7059
7060 return returnValue;
7061 }
7062
7063 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07007064 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007065 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07007066 try {
7067 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007068 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Shuo Qiandee53402020-05-29 14:08:15 -07007069 mApp, phone.getSubId(), "getRadioAccessFamily");
7070 } catch (SecurityException e) {
7071 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
7072 throw e;
7073 }
chen xub97461a2018-10-26 14:17:57 -07007074 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08007075 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07007076 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08007077 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078 final long identity = Binder.clearCallingIdentity();
7079 try {
chen xub97461a2018-10-26 14:17:57 -07007080 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007081 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
chen xub97461a2018-10-26 14:17:57 -07007082 mApp, phone.getSubId(), "getRadioAccessFamily");
7083 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084 } finally {
7085 Binder.restoreCallingIdentity(identity);
7086 }
chen xub97461a2018-10-26 14:17:57 -07007087 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007088 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007089
7090 @Override
Hall Liu82694d52020-12-11 18:22:04 -08007091 public void uploadCallComposerPicture(int subscriptionId, String callingPackage,
Hall Liue31bac62020-12-23 19:16:10 -08007092 String contentType, ParcelFileDescriptor fd, ResultReceiver callback) {
Hall Liu82694d52020-12-11 18:22:04 -08007093 try {
7094 if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0),
7095 Binder.getCallingUid())) {
7096 throw new SecurityException("Package uid and package name do not match: "
7097 + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage);
7098 }
7099 } catch (PackageManager.NameNotFoundException e) {
7100 throw new SecurityException("Package name invalid:" + callingPackage);
7101 }
7102 RoleManager rm = mApp.getSystemService(RoleManager.class);
7103 List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER);
7104 if (!dialerRoleHolders.contains(callingPackage)) {
7105 throw new SecurityException("App must be the dialer role holder to"
7106 + " upload a call composer pic");
7107 }
7108
7109 Executors.newSingleThreadExecutor().execute(() -> {
7110 ByteArrayOutputStream output = new ByteArrayOutputStream(
7111 (int) TelephonyManager.getMaximumCallComposerPictureSize());
7112 InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd);
7113 boolean readUntilEnd = false;
7114 int totalBytesRead = 0;
7115 byte[] buffer = new byte[16 * 1024];
7116 while (true) {
7117 int numRead;
7118 try {
7119 numRead = input.read(buffer);
7120 } catch (IOException e) {
7121 try {
7122 fd.checkError();
7123 callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED,
7124 null);
7125 } catch (IOException e1) {
7126 // This means that the other side closed explicitly with an error. If this
7127 // happens, log and ignore.
7128 loge("Remote end of call composer picture pipe closed: " + e1);
7129 }
7130 break;
7131 }
7132 if (numRead == -1) {
7133 readUntilEnd = true;
7134 break;
7135 }
7136 totalBytesRead += numRead;
7137 if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) {
7138 loge("Too many bytes read for call composer picture: " + totalBytesRead);
7139 try {
7140 input.close();
7141 } catch (IOException e) {
7142 // ignore
7143 }
7144 break;
7145 }
7146 output.write(buffer, 0, numRead);
7147 }
7148 // Generally, the remote end will close the file descriptors. The only case where we
7149 // close is above, where the picture size is too big.
7150
7151 try {
7152 fd.checkError();
7153 } catch (IOException e) {
7154 loge("Remote end for call composer closed with an error: " + e);
7155 return;
7156 }
7157
Hall Liuaa4211e2021-01-20 15:43:39 -08007158 if (!readUntilEnd) {
7159 loge("Did not finish reading entire image; aborting");
7160 return;
7161 }
Hall Liu82694d52020-12-11 18:22:04 -08007162
Hall Liuaa4211e2021-01-20 15:43:39 -08007163 ImageData imageData = new ImageData(output.toByteArray(), contentType, null);
7164 CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer(
7165 new CallComposerPictureTransfer.Factory() {},
7166 imageData,
7167 (result) -> {
7168 if (result.first != null) {
7169 ParcelUuid parcelUuid = new ParcelUuid(result.first);
7170 Bundle outputResult = new Bundle();
7171 outputResult.putParcelable(
7172 TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid);
7173 callback.send(TelephonyManager.CallComposerException.SUCCESS,
7174 outputResult);
7175 } else {
7176 callback.send(result.second, null);
7177 }
7178 }
7179 );
Hall Liu82694d52020-12-11 18:22:04 -08007180 });
7181 }
7182
7183 @Override
Andrew Leedf14ead2014-10-17 14:22:52 -07007184 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007185 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007186 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187
7188 final long identity = Binder.clearCallingIdentity();
7189 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007190 ImsManager.getInstance(defaultPhone.getContext(),
7191 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 } finally {
7193 Binder.restoreCallingIdentity(identity);
7194 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007195 }
7196
7197 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007198 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007199 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7201 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007202 return false;
7203 }
Svet Ganovb320e182015-04-16 12:30:10 -07007204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 final long identity = Binder.clearCallingIdentity();
7206 try {
7207 // Check the user preference and the system-level IMS setting. Even if the user has
7208 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7209 // In the long run, we may instead need to check if there exists a connection service
7210 // which can support video calling.
7211 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007212 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213 return imsManager.isVtEnabledByPlatform()
7214 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7215 && imsManager.isVtEnabledByUser();
7216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007219 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007220
Andrew Leea1239f22015-03-02 17:44:07 -08007221 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007222 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7223 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007225 mApp, subId, callingPackage, callingFeatureId,
7226 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 return false;
7228 }
7229
7230 final long identity = Binder.clearCallingIdentity();
7231 try {
7232 CarrierConfigManager configManager =
7233 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007234 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
Andrew Leea1239f22015-03-02 17:44:07 -08007239 }
7240
7241 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007242 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007244 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245 return false;
7246 }
7247
7248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 CarrierConfigManager configManager =
7251 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007252 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007253 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
Andrew Leea1239f22015-03-02 17:44:07 -08007257 }
7258
Andrew Lee9431b832015-03-09 18:46:45 -07007259 @Override
7260 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007261 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007262 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007263 }
7264
7265 @Override
7266 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007267 final long identity = Binder.clearCallingIdentity();
7268 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007269 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270 } finally {
7271 Binder.restoreCallingIdentity(identity);
7272 }
Andrew Lee9431b832015-03-09 18:46:45 -07007273 }
7274
Hall Liuf6668912018-10-31 17:05:23 -07007275 /**
7276 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7277 * support for the feature and device firmware support.
7278 *
7279 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7280 */
7281 @Override
7282 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007283 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007284 final Phone phone = getPhone(subscriptionId);
7285 if (phone == null) {
7286 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7287 return false;
7288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007289 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007290 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7292 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007293 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294 return isCarrierSupported && isDeviceSupported;
7295 } finally {
7296 Binder.restoreCallingIdentity(identity);
7297 }
Hall Liu98187582018-01-22 19:15:32 -08007298 }
7299
Hall Liuf6668912018-10-31 17:05:23 -07007300 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007301 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7302 * RTT setting, will return true if the device and carrier both support RTT.
7303 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007304 */
7305 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306 final long identity = Binder.clearCallingIdentity();
7307 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007308 boolean isRttSupported = isRttSupported(subscriptionId);
7309 boolean isUserRttSettingOn = Settings.Secure.getInt(
7310 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7311 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7312 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7313 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007317 }
7318
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007319 @Deprecated
7320 @Override
7321 public String getDeviceId(String callingPackage) {
7322 return getDeviceIdWithFeature(callingPackage, null);
7323 }
7324
Sanket Padawe7310cc72015-01-14 09:53:20 -08007325 /**
7326 * Returns the unique device ID of phone, for example, the IMEI for
7327 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7328 *
7329 * <p>Requires Permission:
7330 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7331 */
7332 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007333 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007334 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007335 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007336 return null;
7337 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007338 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007339 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007340 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007341 return null;
7342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343
7344 final long identity = Binder.clearCallingIdentity();
7345 try {
7346 return phone.getDeviceId();
7347 } finally {
7348 Binder.restoreCallingIdentity(identity);
7349 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007350 }
7351
Ping Sunc67b7c22016-03-02 19:16:45 +08007352 /**
7353 * {@hide}
7354 * Returns the IMS Registration Status on a particular subid
7355 *
7356 * @param subId
7357 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007358 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007359 Phone phone = getPhone(subId);
7360 if (phone != null) {
7361 return phone.isImsRegistered();
7362 } else {
7363 return false;
7364 }
7365 }
7366
Santos Cordon7a1885b2015-02-03 11:15:19 -08007367 @Override
7368 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 final long identity = Binder.clearCallingIdentity();
7370 try {
7371 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7372 } finally {
7373 Binder.restoreCallingIdentity(identity);
7374 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007375 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007376
Tyler Gunnf70ed162019-04-03 15:28:53 -07007377 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007378 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007379 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007380 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007381 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007382 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7383 }
7384 final long identity = Binder.clearCallingIdentity();
7385 try {
7386 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7387 } finally {
7388 Binder.restoreCallingIdentity(identity);
7389 }
7390 }
7391
7392 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007393 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007394 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07007395 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Alireza Forouzan4ac4f982021-03-16 22:18:52 -07007396 mApp,
7397 subscriptionId,
7398 "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007399 final long identity = Binder.clearCallingIdentity();
7400 try {
7401 Phone phone = getPhone(subscriptionId);
7402 if (phone == null) {
7403 return null;
7404 }
7405 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7406 } finally {
7407 Binder.restoreCallingIdentity(identity);
7408 }
7409 }
7410
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007411 /**
7412 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007413 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007414 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 final long identity = Binder.clearCallingIdentity();
7416 try {
7417 Phone phone = getPhone(subId);
7418 if (phone != null) {
7419 return phone.isWifiCallingEnabled();
7420 } else {
7421 return false;
7422 }
7423 } finally {
7424 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007425 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007426 }
7427
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007428 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007429 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007430 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007431 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007432 final long identity = Binder.clearCallingIdentity();
7433 try {
7434 Phone phone = getPhone(subId);
7435 if (phone != null) {
7436 return phone.isVideoEnabled();
7437 } else {
7438 return false;
7439 }
7440 } finally {
7441 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007442 }
7443 }
7444
7445 /**
7446 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7447 * defined in {@link ImsRegistrationImplBase}.
7448 */
7449 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 final long identity = Binder.clearCallingIdentity();
7451 try {
7452 Phone phone = getPhone(subId);
7453 if (phone != null) {
7454 return phone.getImsRegistrationTech();
7455 } else {
7456 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7457 }
7458 } finally {
7459 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007460 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007461 }
7462
Stuart Scott8eef64f2015-04-08 15:13:54 -07007463 @Override
7464 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007465 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007466 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7467 return;
7468 }
Kai Shif70f46f2021-03-03 13:59:46 -08007469 Phone defaultPhone = getDefaultPhone();
7470 if (defaultPhone != null) {
7471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7472 mApp, getDefaultPhone().getSubId(), "factoryReset");
7473 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007474 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007475
Svet Ganovcc087f82015-05-12 20:35:54 -07007476 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007477 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7478 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007479 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007480 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007481 setNetworkSelectionModeAutomatic(subId);
SongFerngWang8c6e82e2021-03-02 22:09:29 +08007482 Phone phone = getPhone(subId);
7483 if (phone != null) {
7484 SubscriptionManager.setSubscriptionProperty(subId,
7485 SubscriptionManager.ALLOWED_NETWORK_TYPES,
7486 "user=" + RadioAccessFamily.getRafFromNetworkType(
7487 RILConstants.PREFERRED_NETWORK_MODE));
7488 phone.loadAllowedNetworksFromSubscriptionDatabase();
7489 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007490 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
Jordan Liu857e73a2021-03-05 16:24:04 -08007491 getPhone(subId).resetCarrierKeysForImsiEncryption();
Svet Ganovcc087f82015-05-12 20:35:54 -07007492 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007493 // There has been issues when Sms raw table somehow stores orphan
7494 // fragments. They lead to garbled message when new fragments come
7495 // in and combined with those stale ones. In case this happens again,
7496 // user can reset all network settings which will clean up this table.
7497 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007498 // Clean up IMS settings as well here.
7499 int slotId = getSlotIndex(subId);
7500 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7501 ImsManager.getInstance(mApp, slotId).factoryReset();
7502 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007503
Kai Shif70f46f2021-03-03 13:59:46 -08007504 if (defaultPhone == null) {
7505 return;
7506 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007507 // Erase modem config if erase modem on network setting is enabled.
7508 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7509 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7510 if (configValue != null && Boolean.parseBoolean(configValue)) {
Kai Shif70f46f2021-03-03 13:59:46 -08007511 sendEraseModemConfig(defaultPhone);
Naina Nallurid63128d2019-09-17 14:10:30 -07007512 }
Kai Shif70f46f2021-03-03 13:59:46 -08007513
7514 sendEraseDataInSharedPreferences(defaultPhone);
Svet Ganovcc087f82015-05-12 20:35:54 -07007515 } finally {
7516 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007517 }
7518 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007519
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007520 private void cleanUpSmsRawTable(Context context) {
7521 ContentResolver resolver = context.getContentResolver();
7522 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7523 resolver.delete(uri, null, null);
7524 }
7525
Narayan Kamath1c496c22015-04-16 14:40:19 +01007526 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007527 public String getSimLocaleForSubscriber(int subId) {
7528 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7529 final Phone phone = getPhone(subId);
7530 if (phone == null) {
7531 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007532 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007534 final long identity = Binder.clearCallingIdentity();
7535 try {
chen xu5d3637b2019-01-21 23:31:38 -08007536 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007537 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007538 if (info == null) {
7539 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7540 return null;
7541 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007542 // Try and fetch the locale from the carrier properties or from the SIM language
7543 // preferences (EF-PL and EF-LI)...
7544 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007545 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007546 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7547 if (localeFromDefaultSim != null) {
7548 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7549 if (DBG) log("Using locale from subId: " + subId + " locale: "
7550 + localeFromDefaultSim);
7551 return localeFromDefaultSim.toLanguageTag();
7552 } else {
7553 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 }
7555 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 // The SIM language preferences only store a language (e.g. fr = French), not an
7558 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7559 // the SIM and carrier preferences does not include a country we add the country
7560 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007561 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007563 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007564 return mccLocale.toLanguageTag();
7565 }
7566
7567 if (DBG) log("No locale found - returning null");
7568 return null;
7569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007572 }
7573
7574 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007575 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007576 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007577 }
7578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 /**
7580 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7581 */
7582 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007583 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007584 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007585 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007586
Chenjie Yu1ba97252018-01-11 18:16:20 -08007587 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007588 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007589
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007590 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007591 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7592 * representing the state of the modem.
7593 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007594 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7595 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007596 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007597 */
7598 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007599 public void requestModemActivityInfo(ResultReceiver result) {
7600 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007601 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007602
7603 final long identity = Binder.clearCallingIdentity();
7604 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007605 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606 } finally {
7607 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007608 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007609 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007610
Siddharth Rayb8114062018-06-17 15:02:38 -07007611 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7612 // less than total activity duration.
7613 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7614 if (info == null) {
7615 return false;
7616 }
7617 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007618 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7619 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7620
Siddharth Rayb8114062018-06-17 15:02:38 -07007621 return (info.isValid()
7622 && (info.getSleepTimeMillis() <= activityDurationMs)
7623 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007624 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007625 && (totalTxTimeMs <= activityDurationMs));
7626 }
7627
Jack Yu85bd38a2015-11-09 11:34:32 -08007628 /**
7629 * {@hide}
7630 * Returns the service state information on specified subscription.
7631 */
7632 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007633 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7634 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007635 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007636 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007637 return null;
7638 }
7639
Hall Liuf19c44f2018-11-27 14:38:17 -08007640 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7641 LocationAccessPolicy.checkLocationPermission(mApp,
7642 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7643 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007644 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007645 .setCallingPid(Binder.getCallingPid())
7646 .setCallingUid(Binder.getCallingUid())
7647 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007648 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007649 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007650 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7651 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007652 .build());
7653
7654 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7655 LocationAccessPolicy.checkLocationPermission(mApp,
7656 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7657 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007658 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007659 .setCallingPid(Binder.getCallingPid())
7660 .setCallingUid(Binder.getCallingUid())
7661 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007662 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007663 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007664 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7665 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007666 .build());
7667 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7668 boolean hasFinePermission =
7669 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7670 boolean hasCoarsePermission =
7671 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7672
Jack Yu479f40e2020-10-27 21:29:25 -07007673 final Phone phone = getPhone(subId);
7674 if (phone == null) {
7675 return null;
7676 }
7677
Jordan Liu0f2bc442020-11-18 16:47:37 -08007678 final long identity = Binder.clearCallingIdentity();
7679
Jack Yu479f40e2020-10-27 21:29:25 -07007680 boolean isCallingPackageDataService = phone.getDataServicePackages()
7681 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007683 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7684 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7685 Rlog.d(LOG_TAG,
7686 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7687 return null;
7688 }
7689
Hall Liuf19c44f2018-11-27 14:38:17 -08007690 ServiceState ss = phone.getServiceState();
7691
7692 // Scrub out the location info in ServiceState depending on what level of access
7693 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007694 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007695 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7696 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007700 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007701
7702 /**
7703 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7704 *
7705 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7706 * voicemail ringtone.
7707 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7708 * PhoneAccount.
7709 */
7710 @Override
7711 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007712 final long identity = Binder.clearCallingIdentity();
7713 try {
7714 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7715 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007716 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007717 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007718
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007719 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7720 } finally {
7721 Binder.restoreCallingIdentity(identity);
7722 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007723 }
7724
7725 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007726 * Sets the per-account voicemail ringtone.
7727 *
7728 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7729 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7730 *
7731 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7732 * voicemail ringtone.
7733 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7734 * PhoneAccount.
7735 */
7736 @Override
7737 public void setVoicemailRingtoneUri(String callingPackage,
7738 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007739 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007741 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7742 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7744 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7745 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747
7748 final long identity = Binder.clearCallingIdentity();
7749 try {
7750 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7751 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007752 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007753 }
7754 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7755 } finally {
7756 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007757 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007758 }
7759
7760 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007761 * Returns whether vibration is set for voicemail notification in Phone settings.
7762 *
7763 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7764 * voicemail vibration setting.
7765 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7766 */
7767 @Override
7768 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 final long identity = Binder.clearCallingIdentity();
7770 try {
7771 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7772 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007773 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7777 } finally {
7778 Binder.restoreCallingIdentity(identity);
7779 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007780 }
7781
Youhan Wange64578a2016-05-02 15:32:42 -07007782 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007783 * Sets the per-account voicemail vibration.
7784 *
7785 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7786 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7787 *
7788 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7789 * voicemail vibration setting.
7790 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7791 * specific PhoneAccount.
7792 */
7793 @Override
7794 public void setVoicemailVibrationEnabled(String callingPackage,
7795 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007796 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007798 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7799 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7801 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7802 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007803 }
7804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007805 final long identity = Binder.clearCallingIdentity();
7806 try {
7807 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7808 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007809 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007810 }
7811 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7812 } finally {
7813 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007814 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007815 }
7816
7817 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007818 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7819 *
7820 * @throws SecurityException if the caller does not have the required permission
7821 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007822 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007823 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007824 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007825 }
7826
7827 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007828 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7829 * permission.
7830 *
7831 * @throws SecurityException if the caller does not have the required permission
7832 */
7833 private void enforceSendSmsPermission() {
7834 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7835 }
7836
7837 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007838 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007839 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007840 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007841 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007842 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007843 final long identity = Binder.clearCallingIdentity();
7844 try {
7845 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007846 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847 if (componentName == null) {
7848 throw new SecurityException(
7849 "Caller not current active visual voicemail package[null]");
7850 }
7851 String vvmPackage = componentName.getPackageName();
7852 if (!callingPackage.equals(vvmPackage)) {
7853 throw new SecurityException("Caller not current active visual voicemail package["
7854 + vvmPackage + "]");
7855 }
7856 } finally {
7857 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007858 }
7859 }
7860
7861 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007862 * Return the application ID for the app type.
7863 *
7864 * @param subId the subscription ID that this request applies to.
7865 * @param appType the uicc app type.
7866 * @return Application ID for specificied app type, or null if no uicc.
7867 */
7868 @Override
7869 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007870 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007871 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007872
7873 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007874 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 if (phone == null) {
7876 return null;
7877 }
7878 String aid = null;
7879 try {
7880 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7881 .getApplicationByType(appType).getAid();
7882 } catch (Exception e) {
7883 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7884 }
7885 return aid;
7886 } finally {
7887 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007888 }
Youhan Wange64578a2016-05-02 15:32:42 -07007889 }
7890
Youhan Wang4001d252016-05-11 10:29:41 -07007891 /**
7892 * Return the Electronic Serial Number.
7893 *
7894 * @param subId the subscription ID that this request applies to.
7895 * @return ESN or null if error.
7896 */
7897 @Override
7898 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007899 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007900 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901
7902 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007903 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007904 if (phone == null) {
7905 return null;
7906 }
7907 String esn = null;
7908 try {
7909 esn = phone.getEsn();
7910 } catch (Exception e) {
7911 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7912 }
7913 return esn;
7914 } finally {
7915 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007916 }
Youhan Wang4001d252016-05-11 10:29:41 -07007917 }
7918
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007919 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007920 * Return the Preferred Roaming List Version.
7921 *
7922 * @param subId the subscription ID that this request applies to.
7923 * @return PRLVersion or null if error.
7924 */
7925 @Override
7926 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007927 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007928 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007929
7930 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007931 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007932 if (phone == null) {
7933 return null;
7934 }
7935 String cdmaPrlVersion = null;
7936 try {
7937 cdmaPrlVersion = phone.getCdmaPrlVersion();
7938 } catch (Exception e) {
7939 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7940 }
7941 return cdmaPrlVersion;
7942 } finally {
7943 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007944 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007945 }
7946
7947 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007948 * Get snapshot of Telephony histograms
7949 * @return List of Telephony histograms
7950 * @hide
7951 */
7952 @Override
7953 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7955 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007956
7957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 return RIL.getTelephonyRILTimingHistograms();
7960 } finally {
7961 Binder.restoreCallingIdentity(identity);
7962 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007963 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007964
7965 /**
7966 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007967 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7968 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007969 * Require system privileges. In the future we may add this to carrier APIs.
7970 *
Michele Berionne482f8202018-11-27 18:57:59 -08007971 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007972 */
7973 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007974 @TelephonyManager.SetCarrierRestrictionResult
7975 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007976 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007977 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007978
Michele Berionne482f8202018-11-27 18:57:59 -08007979 if (carrierRestrictionRules == null) {
7980 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007981 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007982
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983 final long identity = Binder.clearCallingIdentity();
7984 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007985 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007986 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007987 } finally {
7988 Binder.restoreCallingIdentity(identity);
7989 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007990 }
7991
7992 /**
7993 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007994 * Get the allowed carrier list and the excluded carrier list, including the priority between
7995 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007996 * Require system privileges. In the future we may add this to carrier APIs.
7997 *
Michele Berionne482f8202018-11-27 18:57:59 -08007998 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007999 */
8000 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08008001 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008002 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07008003 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008004
8005 final long identity = Binder.clearCallingIdentity();
8006 try {
Michele Berionne482f8202018-11-27 18:57:59 -08008007 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
8008 if (response instanceof CarrierRestrictionRules) {
8009 return (CarrierRestrictionRules) response;
8010 }
8011 // Response is an Exception of some kind,
8012 // which is signalled to the user as a NULL retval
8013 return null;
8014 } catch (Exception e) {
8015 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
8016 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07008020 }
8021
fionaxu59545b42016-05-25 15:53:37 -07008022 /**
fionaxu59545b42016-05-25 15:53:37 -07008023 * Action set from carrier signalling broadcast receivers to enable/disable radio
8024 * @param subId the subscription ID that this action applies to.
8025 * @param enabled control enable or disable radio.
8026 * {@hide}
8027 */
8028 @Override
8029 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
8030 enforceModifyPermission();
8031 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032
8033 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07008034 if (phone == null) {
8035 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
8036 return;
8037 }
8038 try {
8039 phone.carrierActionSetRadioEnabled(enabled);
8040 } catch (Exception e) {
8041 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008042 } finally {
8043 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07008044 }
8045 }
8046
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008047 /**
fionaxu8da9cb12017-05-23 15:02:46 -07008048 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
8049 * network status based on which carrier apps could apply actions accordingly,
8050 * enable/disable default url handler for example.
8051 *
8052 * @param subId the subscription ID that this action applies to.
8053 * @param report control start/stop reporting the default network status.
8054 * {@hide}
8055 */
8056 @Override
8057 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
8058 enforceModifyPermission();
8059 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008060
8061 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07008062 if (phone == null) {
8063 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
8064 return;
8065 }
8066 try {
8067 phone.carrierActionReportDefaultNetworkStatus(report);
8068 } catch (Exception e) {
8069 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008070 } finally {
8071 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07008072 }
8073 }
8074
8075 /**
fionaxud9622282017-07-17 17:51:30 -07008076 * Action set from carrier signalling broadcast receivers to reset all carrier actions
8077 * @param subId the subscription ID that this action applies to.
8078 * {@hide}
8079 */
8080 @Override
8081 public void carrierActionResetAll(int subId) {
8082 enforceModifyPermission();
8083 final Phone phone = getPhone(subId);
8084 if (phone == null) {
8085 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
8086 return;
8087 }
8088 try {
8089 phone.carrierActionResetAll();
8090 } catch (Exception e) {
8091 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
8092 }
8093 }
8094
8095 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008096 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
8097 * bug report is being generated.
8098 */
8099 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07008100 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008101 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
8102 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07008103 writer.println("Permission Denial: can't dump Phone from pid="
8104 + Binder.getCallingPid()
8105 + ", uid=" + Binder.getCallingUid()
8106 + "without permission "
8107 + android.Manifest.permission.DUMP);
8108 return;
8109 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008110 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07008111 }
Jack Yueb89b242016-06-22 13:27:47 -07008112
Brad Ebingerdac2f002018-04-03 15:17:52 -07008113 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08008114 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
8115 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
8116 @NonNull String[] args) {
8117 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
8118 this, in.getFileDescriptor(), out.getFileDescriptor(),
8119 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07008120 }
8121
Jack Yueb89b242016-06-22 13:27:47 -07008122 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008123 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00008124 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008125 * @param reason the reason the data enable change is taking place
8126 * @param enabled True if enabling the data, otherwise disabling.
8127 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07008128 */
8129 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008130 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008131 boolean enabled) {
8132 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
8133 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8134 try {
8135 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07008136 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008137 } catch (SecurityException se) {
8138 enforceModifyPermission();
8139 }
8140 } else {
8141 enforceModifyPermission();
8142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143
8144 final long identity = Binder.clearCallingIdentity();
8145 try {
8146 Phone phone = getPhone(subId);
8147 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00008148 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
8149 phone.carrierActionSetMeteredApnsEnabled(enabled);
8150 } else {
8151 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
8152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 }
8154 } finally {
8155 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07008156 }
8157 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008158
8159 /**
8160 * Get Client request stats
8161 * @return List of Client Request Stats
8162 * @hide
8163 */
8164 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008165 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
8166 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08008167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008168 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008169 return null;
8170 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008171 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008172
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008173 final long identity = Binder.clearCallingIdentity();
8174 try {
8175 if (phone != null) {
8176 return phone.getClientRequestStats();
8177 }
8178
8179 return null;
8180 } finally {
8181 Binder.restoreCallingIdentity(identity);
8182 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008183 }
8184
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008185 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008186 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00008187 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07008188 }
Jack Yueb4124c2017-02-16 15:32:43 -08008189
8190 /**
Grace Chen70990072017-03-24 17:21:30 -07008191 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08008192 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008193 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07008194 * @param state State of SIM (power down, power up, pass through)
8195 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8196 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8197 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008198 *
8199 **/
8200 @Override
Grace Chen70990072017-03-24 17:21:30 -07008201 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008202 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008203 Phone phone = PhoneFactory.getPhone(slotIndex);
8204
vagdeviaf9a5b92018-08-15 16:01:53 -07008205 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008207 final long identity = Binder.clearCallingIdentity();
8208 try {
8209 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08008210 phone.setSimPowerState(state, null, workSource);
8211 }
8212 } finally {
8213 Binder.restoreCallingIdentity(identity);
8214 }
8215 }
8216
8217 /**
8218 * Set SIM card power state.
8219 *
8220 * @param slotIndex SIM slot id.
8221 * @param state State of SIM (power down, power up, pass through)
8222 * @param callback callback to trigger after success or failure
8223 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8224 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8225 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8226 *
8227 **/
8228 @Override
8229 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8230 IIntegerConsumer callback) {
8231 enforceModifyPermission();
8232 Phone phone = PhoneFactory.getPhone(slotIndex);
8233
8234 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8235
8236 final long identity = Binder.clearCallingIdentity();
8237 try {
8238 if (phone != null) {
8239 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8240 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008241 }
8242 } finally {
8243 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008244 }
8245 }
Shuo Qiandd210312017-04-12 22:11:33 +00008246
Tyler Gunn65d45c22017-06-05 11:22:26 -07008247 private boolean isUssdApiAllowed(int subId) {
8248 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008249 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008250 if (configManager == null) {
8251 return false;
8252 }
8253 PersistableBundle pb = configManager.getConfigForSubId(subId);
8254 if (pb == null) {
8255 return false;
8256 }
8257 return pb.getBoolean(
8258 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8259 }
8260
Shuo Qiandd210312017-04-12 22:11:33 +00008261 /**
8262 * Check if phone is in emergency callback mode
8263 * @return true if phone is in emergency callback mode
8264 * @param subId sub id
8265 */
goneil9c5f4872017-12-05 14:07:56 -08008266 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008267 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008268 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008269 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008270
8271 final long identity = Binder.clearCallingIdentity();
8272 try {
8273 if (phone != null) {
8274 return phone.isInEcm();
8275 } else {
8276 return false;
8277 }
8278 } finally {
8279 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008280 }
8281 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008282
8283 /**
8284 * Get the current signal strength information for the given subscription.
8285 * Because this information is not updated when the device is in a low power state
8286 * it should not be relied-upon to be current.
8287 * @param subId Subscription index
8288 * @return the most recent cached signal strength info from the modem
8289 */
8290 @Override
8291 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008292 final long identity = Binder.clearCallingIdentity();
8293 try {
8294 Phone p = getPhone(subId);
8295 if (p == null) {
8296 return null;
8297 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299 return p.getSignalStrength();
8300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008303 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008304
Pengquan Meng77b7f132018-08-22 14:49:57 -07008305 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008306 * Get the current modem radio state for the given slot.
8307 * @param slotIndex slot index.
8308 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008309 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008310 * @return the current radio power state from the modem
8311 */
8312 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008313 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008314 Phone phone = PhoneFactory.getPhone(slotIndex);
8315 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8317 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008318 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8319 }
8320
8321 final long identity = Binder.clearCallingIdentity();
8322 try {
8323 return phone.getRadioPowerState();
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
8328 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8329 }
8330
8331 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008332 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8333 *
8334 * <p>Requires one of the following permissions:
8335 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8336 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8337 * privileges.
8338 *
8339 * @param subId subscription id
8340 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8341 * {@code false}.
8342 */
8343 @Override
8344 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008345 try {
8346 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8347 null);
8348 } catch (Exception e) {
Nathan Harold62c68512021-04-06 11:26:02 -07008349 TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
Shuo Qian093013d2020-08-13 15:42:55 -07008350 mApp, subId, "isDataRoamingEnabled");
8351 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008352
Pengquan Menga1bb6272018-09-06 09:59:22 -07008353 boolean isEnabled = false;
8354 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008355 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008356 Phone phone = getPhone(subId);
8357 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008358 } finally {
8359 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008360 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008361 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008362 }
8363
8364
8365 /**
8366 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8367 *
8368 * <p> Requires permission:
8369 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8370 * privileges.
8371 *
8372 * @param subId subscription id
8373 * @param isEnabled {@code true} means enable, {@code false} means disable.
8374 */
8375 @Override
8376 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008377 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8378 mApp, subId, "setDataRoamingEnabled");
8379
Pengquan Menga1bb6272018-09-06 09:59:22 -07008380 final long identity = Binder.clearCallingIdentity();
8381 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008382 Phone phone = getPhone(subId);
8383 if (phone != null) {
8384 phone.setDataRoamingEnabled(isEnabled);
8385 }
8386 } finally {
8387 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008388 }
8389 }
8390
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008391 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008392 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008393 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008394 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008395 mApp, subId, "isManualNetworkSelectionAllowed");
8396
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008397 boolean isAllowed = true;
8398 final long identity = Binder.clearCallingIdentity();
8399 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008400 Phone phone = getPhone(subId);
8401 if (phone != null) {
8402 isAllowed = phone.isCspPlmnEnabled();
8403 }
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
8407 return isAllowed;
8408 }
8409
8410 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008411 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008412 // Verify that tha callingPackage belongs to the calling UID
8413 mApp.getSystemService(AppOpsManager.class)
8414 .checkPackage(Binder.getCallingUid(), callingPackage);
8415
Jordan Liu1e142fc2019-04-22 15:10:43 -07008416 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008417 try {
8418 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008419 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008420 } catch (SecurityException e) {
8421 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8422 // has carrier privileges on an active UICC
8423 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8424 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008425 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008426 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008427 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008428
8429 final long identity = Binder.clearCallingIdentity();
8430 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008431 UiccController uiccController = UiccController.getInstance();
8432 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008433 if (hasReadPermission) {
8434 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008435 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008436
8437 // Remove private info if the caller doesn't have access
8438 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8439 for (UiccCardInfo cardInfo : cardInfos) {
8440 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8441 // is available
8442 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8443 if (card == null || card.getUiccProfile() == null) {
8444 // assume no access if the card or profile is unavailable
8445 filteredInfos.add(cardInfo.getUnprivileged());
8446 continue;
8447 }
8448 UiccProfile profile = card.getUiccProfile();
8449 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8450 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8451 filteredInfos.add(cardInfo);
8452 } else {
8453 filteredInfos.add(cardInfo.getUnprivileged());
8454 }
8455 }
8456 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008457 } finally {
8458 Binder.restoreCallingIdentity(identity);
8459 }
8460 }
8461
8462 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008463 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008464 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008466 final long identity = Binder.clearCallingIdentity();
8467 try {
8468 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8469 if (slots == null) {
8470 Rlog.i(LOG_TAG, "slots is null.");
8471 return null;
8472 }
8473
8474 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8475 for (int i = 0; i < slots.length; i++) {
8476 UiccSlot slot = slots[i];
8477 if (slot == null) {
8478 continue;
8479 }
8480
Jordan Liu7be7e652019-05-06 18:55:02 +00008481 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008482 UiccCard card = slot.getUiccCard();
8483 if (card != null) {
8484 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008485 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008486 cardId = slot.getEid();
8487 if (TextUtils.isEmpty(cardId)) {
8488 cardId = slot.getIccId();
8489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008490 }
8491
Jordan Liu857451f2019-05-09 16:35:35 -07008492 if (cardId != null) {
8493 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8494 // if cardId is an EID, it's all digits so this is fine
8495 cardId = IccUtils.stripTrailingFs(cardId);
8496 }
8497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008498 int cardState = 0;
8499 switch (slot.getCardState()) {
8500 case CARDSTATE_ABSENT:
8501 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8502 break;
8503 case CARDSTATE_PRESENT:
8504 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8505 break;
8506 case CARDSTATE_ERROR:
8507 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8508 break;
8509 case CARDSTATE_RESTRICTED:
8510 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8511 break;
8512 default:
8513 break;
8514
8515 }
8516
8517 infos[i] = new UiccSlotInfo(
8518 slot.isActive(),
8519 slot.isEuicc(),
8520 cardId,
8521 cardState,
8522 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008523 slot.isExtendedApduSupported(),
8524 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008525 }
8526 return infos;
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008529 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008530 }
8531
8532 @Override
8533 public boolean switchSlots(int[] physicalSlots) {
8534 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008535
8536 final long identity = Binder.clearCallingIdentity();
8537 try {
8538 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
8541 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008542 }
Jack Yu4c988042018-02-27 15:30:01 -08008543
8544 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008545 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008546 final long identity = Binder.clearCallingIdentity();
8547 try {
8548 return UiccController.getInstance().getCardIdForDefaultEuicc();
8549 } finally {
8550 Binder.restoreCallingIdentity(identity);
8551 }
8552 }
8553
Pengquan Meng85728fb2018-03-12 16:31:21 -07008554 /**
goneil47ffb6e2018-04-06 15:40:58 -07008555 * A test API to reload the UICC profile.
8556 *
8557 * <p>Requires that the calling app has permission
8558 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8559 * @hide
8560 */
8561 @Override
8562 public void refreshUiccProfile(int subId) {
8563 enforceModifyPermission();
8564
8565 final long identity = Binder.clearCallingIdentity();
8566 try {
8567 Phone phone = getPhone(subId);
8568 if (phone == null) {
8569 return;
8570 }
8571 UiccCard uiccCard = phone.getUiccCard();
8572 if (uiccCard == null) {
8573 return;
8574 }
8575 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8576 if (uiccProfile == null) {
8577 return;
8578 }
8579 uiccProfile.refresh();
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
8582 }
8583 }
8584
8585 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008586 * Returns false if the mobile data is disabled by default, otherwise return true.
8587 */
8588 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008589 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008590 }
8591
8592 /**
8593 * Returns true if the data roaming is enabled by default, i.e the system property
8594 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8595 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8596 */
8597 private boolean getDefaultDataRoamingEnabled(int subId) {
8598 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008599 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008600 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008601 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8602 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8603 return isDataRoamingEnabled;
8604 }
8605
8606 /**
8607 * Returns the default network type for the given {@code subId}, if the default network type is
8608 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8609 */
8610 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008611 List<Integer> list = TelephonyProperties.default_network();
8612 int phoneId = mSubscriptionController.getPhoneId(subId);
8613 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8614 return list.get(phoneId);
8615 }
8616 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008617 }
fionaxua13278b2018-03-21 00:08:13 -07008618
8619 @Override
8620 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008621 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008622 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008623
8624 final long identity = Binder.clearCallingIdentity();
8625 try {
8626 final Phone phone = getPhone(subId);
8627 if (phone == null) {
8628 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8629 return;
8630 }
chen xueaba88a2019-03-15 13:15:10 -07008631 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8632 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008633 if (carrierPrivilegeRules == null) {
8634 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8635 } else {
8636 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008638 } finally {
8639 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008640 }
fionaxua13278b2018-03-21 00:08:13 -07008641 }
8642
8643 @Override
8644 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008645 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008646
8647 final long identity = Binder.clearCallingIdentity();
8648 try {
8649 final Phone phone = getPhone(subId);
8650 if (phone == null) {
8651 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8652 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8653 }
8654 return phone.getCarrierIdListVersion();
8655 } finally {
8656 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008657 }
fionaxua13278b2018-03-21 00:08:13 -07008658 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008659
8660 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008661 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8662 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008664 mApp, subId, callingPackage, callingFeatureId,
8665 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008666 return -1;
8667 }
8668
8669 final long identity = Binder.clearCallingIdentity();
8670 try {
8671 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8672 } finally {
8673 Binder.restoreCallingIdentity(identity);
8674 }
8675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008676
8677 @Override
8678 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008679 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008680 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008681 mApp, subId, "getCdmaRoamingMode");
8682
8683 final long identity = Binder.clearCallingIdentity();
8684 try {
8685 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8686 } finally {
8687 Binder.restoreCallingIdentity(identity);
8688 }
8689 }
8690
8691 @Override
8692 public boolean setCdmaRoamingMode(int subId, int mode) {
8693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8694 mApp, subId, "setCdmaRoamingMode");
8695
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
8698 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
8702 }
8703
8704 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008705 public int getCdmaSubscriptionMode(int subId) {
8706 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008707 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chinbaab1432020-10-28 13:46:24 -07008708 mApp, subId, "getCdmaSubscriptionMode");
8709
8710 final long identity = Binder.clearCallingIdentity();
8711 try {
8712 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8713 } finally {
8714 Binder.restoreCallingIdentity(identity);
8715 }
8716 }
8717
8718 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008719 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8721 mApp, subId, "setCdmaSubscriptionMode");
8722
8723 final long identity = Binder.clearCallingIdentity();
8724 try {
8725 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8726 } finally {
8727 Binder.restoreCallingIdentity(identity);
8728 }
8729 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008730
sqianc5eccab2018-10-19 18:46:41 -07008731 @Override
sqian8c685422019-02-22 15:55:18 -08008732 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008733 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008735 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8736 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008737 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8738 }
8739 final long identity = Binder.clearCallingIdentity();
8740 try {
sqian854d44b2018-12-12 16:48:18 -08008741 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8742 for (Phone phone: PhoneFactory.getPhones()) {
8743 if (phone.getEmergencyNumberTracker() != null
8744 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8745 emergencyNumberListInternal.put(
8746 phone.getSubId(),
8747 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8748 }
sqian11b7a0e2018-12-05 18:48:28 -08008749 }
sqian854d44b2018-12-12 16:48:18 -08008750 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008751 } finally {
8752 Binder.restoreCallingIdentity(identity);
8753 }
sqianc5eccab2018-10-19 18:46:41 -07008754 }
8755
8756 @Override
sqian8c685422019-02-22 15:55:18 -08008757 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008758 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008759 if (!exactMatch) {
8760 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07008761 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008762 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008763 }
8764 final long identity = Binder.clearCallingIdentity();
8765 try {
sqian854d44b2018-12-12 16:48:18 -08008766 for (Phone phone: PhoneFactory.getPhones()) {
8767 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008768 && phone.getEmergencyNumberTracker()
8769 .isEmergencyNumber(number, exactMatch)) {
8770 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008771 }
sqian11b7a0e2018-12-05 18:48:28 -08008772 }
8773 return false;
8774 } finally {
8775 Binder.restoreCallingIdentity(identity);
8776 }
8777 }
8778
sqianf4ca7ed2019-01-15 18:32:07 -08008779 /**
Shuo Qianccbaf742021-02-22 18:32:21 -08008780 * Start emergency callback mode for GsmCdmaPhone for testing.
8781 */
8782 @Override
8783 public void startEmergencyCallbackMode() {
8784 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8785 "startEmergencyCallbackMode");
8786 enforceModifyPermission();
8787 final long identity = Binder.clearCallingIdentity();
8788 try {
8789 for (Phone phone : PhoneFactory.getPhones()) {
8790 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
8791 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
8792 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
8793 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
8794 gsmCdmaPhone.obtainMessage(
8795 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
8796 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
8797 }
8798 }
8799 } finally {
8800 Binder.restoreCallingIdentity(identity);
8801 }
8802 }
8803
8804 /**
sqianf4ca7ed2019-01-15 18:32:07 -08008805 * Update emergency number list for test mode.
8806 */
8807 @Override
8808 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8809 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8810 "updateEmergencyNumberListTestMode");
8811
8812 final long identity = Binder.clearCallingIdentity();
8813 try {
8814 for (Phone phone: PhoneFactory.getPhones()) {
8815 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8816 if (tracker != null) {
8817 tracker.executeEmergencyNumberTestModeCommand(action, num);
8818 }
8819 }
8820 } finally {
8821 Binder.restoreCallingIdentity(identity);
8822 }
8823 }
8824
8825 /**
8826 * Get the full emergency number list for test mode.
8827 */
8828 @Override
8829 public List<String> getEmergencyNumberListTestMode() {
8830 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8831 "getEmergencyNumberListTestMode");
8832
8833 final long identity = Binder.clearCallingIdentity();
8834 try {
8835 Set<String> emergencyNumbers = new HashSet<>();
8836 for (Phone phone: PhoneFactory.getPhones()) {
8837 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8838 if (tracker != null) {
8839 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8840 emergencyNumbers.add(num.getNumber());
8841 }
8842 }
8843 }
8844 return new ArrayList<>(emergencyNumbers);
8845 } finally {
8846 Binder.restoreCallingIdentity(identity);
8847 }
8848 }
8849
chen xud6b45bd2018-10-30 22:27:10 -07008850 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008851 public int getEmergencyNumberDbVersion(int subId) {
8852 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8853
8854 final long identity = Binder.clearCallingIdentity();
8855 try {
8856 final Phone phone = getPhone(subId);
8857 if (phone == null) {
8858 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8859 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8860 }
8861 return phone.getEmergencyNumberDbVersion();
8862 } finally {
8863 Binder.restoreCallingIdentity(identity);
8864 }
8865 }
8866
8867 @Override
8868 public void notifyOtaEmergencyNumberDbInstalled() {
8869 enforceModifyPermission();
8870
8871 final long identity = Binder.clearCallingIdentity();
8872 try {
8873 for (Phone phone: PhoneFactory.getPhones()) {
8874 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8875 if (tracker != null) {
8876 tracker.updateOtaEmergencyNumberDatabase();
8877 }
8878 }
8879 } finally {
8880 Binder.restoreCallingIdentity(identity);
8881 }
8882 }
8883
8884 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008885 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008886 enforceActiveEmergencySessionPermission();
8887
8888 final long identity = Binder.clearCallingIdentity();
8889 try {
8890 for (Phone phone: PhoneFactory.getPhones()) {
8891 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8892 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008893 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8894 }
8895 }
8896 } finally {
8897 Binder.restoreCallingIdentity(identity);
8898 }
8899 }
8900
8901 @Override
8902 public void resetOtaEmergencyNumberDbFilePath() {
8903 enforceActiveEmergencySessionPermission();
8904
8905 final long identity = Binder.clearCallingIdentity();
8906 try {
8907 for (Phone phone: PhoneFactory.getPhones()) {
8908 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8909 if (tracker != null) {
8910 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008911 }
8912 }
8913 } finally {
8914 Binder.restoreCallingIdentity(identity);
8915 }
8916 }
8917
8918 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008919 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8920 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8921 Phone phone = getPhone(subId);
8922 if (phone == null) {
8923 return null;
8924 }
8925 final long identity = Binder.clearCallingIdentity();
8926 try {
8927 UiccProfile profile = UiccController.getInstance()
8928 .getUiccProfileForPhone(phone.getPhoneId());
8929 if (profile != null) {
8930 return profile.getCertsFromCarrierPrivilegeAccessRules();
8931 }
8932 } finally {
8933 Binder.restoreCallingIdentity(identity);
8934 }
8935 return null;
8936 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008937
8938 /**
8939 * Enable or disable a modem stack.
8940 */
8941 @Override
8942 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8943 enforceModifyPermission();
8944
8945 final long identity = Binder.clearCallingIdentity();
8946 try {
8947 Phone phone = PhoneFactory.getPhone(slotIndex);
8948 if (phone == null) {
8949 return false;
8950 } else {
8951 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8952 }
8953 } finally {
8954 Binder.restoreCallingIdentity(identity);
8955 }
8956 }
Michelecea4cf22018-12-21 15:00:11 -08008957
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008958 /**
8959 * Whether a modem stack is enabled or not.
8960 */
8961 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008962 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8963 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008964 Phone phone = PhoneFactory.getPhone(slotIndex);
8965 if (phone == null) return false;
8966
8967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008968 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8969 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008970 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8971 }
8972
8973 final long identity = Binder.clearCallingIdentity();
8974 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008975 try {
8976 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8977 } catch (NoSuchElementException ex) {
8978 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8979 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
8984
Michelecea4cf22018-12-21 15:00:11 -08008985 @Override
Michele0ea7d782019-03-19 14:58:42 -07008986 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008987 enforceModifyPermission();
8988
8989 final long identity = Binder.clearCallingIdentity();
8990 try {
8991 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008992 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008993 .commit();
8994 } finally {
8995 Binder.restoreCallingIdentity(identity);
8996 }
8997 }
8998
8999 @Override
Michele0ea7d782019-03-19 14:58:42 -07009000 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009001 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08009002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009003 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
9004 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07009005 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08009006 }
Michelecea4cf22018-12-21 15:00:11 -08009007
9008 final long identity = Binder.clearCallingIdentity();
9009 try {
Michele0ea7d782019-03-19 14:58:42 -07009010 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08009011 } finally {
9012 Binder.restoreCallingIdentity(identity);
9013 }
9014 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009015
Michele0ea7d782019-03-19 14:58:42 -07009016 @TelephonyManager.IsMultiSimSupportedResult
9017 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08009018 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
9019 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
9020 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009021 loge("isMultiSimSupportedInternal: requires at least 2 cards");
9022 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009023 }
9024 // Check if the hardware supports multisim functionality. If usage of multisim is not
9025 // supported by the modem, indicate that it is restricted.
9026 PhoneCapability staticCapability =
9027 mPhoneConfigurationManager.getStaticPhoneCapability();
9028 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07009029 loge("isMultiSimSupportedInternal: no static configuration available");
9030 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009031 }
SongFerngWang8236caa2021-01-17 21:51:44 +08009032 if (staticCapability.getLogicalModemList().size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07009033 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
9034 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08009035 }
9036 // Check if support of multiple SIMs is restricted by carrier
9037 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07009038 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08009039 }
9040
Michele0ea7d782019-03-19 14:58:42 -07009041 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08009042 }
9043
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009044 /**
9045 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009046 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
9047 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
9048 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009049 * @param numOfSims number of active sims we want to switch to
9050 */
9051 @Override
9052 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08009053 if (numOfSims == 1) {
9054 enforceModifyPermission();
9055 } else {
9056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9057 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
9058 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009059 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08009060
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009061 try {
Michele30b57b22019-03-01 12:01:14 -08009062 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07009063 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08009064 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
9065 return;
9066 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009067 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
9068 } finally {
9069 Binder.restoreCallingIdentity(identity);
9070 }
9071 }
9072
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09009073 @Override
9074 public boolean isApplicationOnUicc(int subId, int appType) {
9075 enforceReadPrivilegedPermission("isApplicationOnUicc");
9076 Phone phone = getPhone(subId);
9077 if (phone == null) {
9078 return false;
9079 }
9080 final long identity = Binder.clearCallingIdentity();
9081 try {
9082 UiccCard uiccCard = phone.getUiccCard();
9083 if (uiccCard == null) {
9084 return false;
9085 }
9086 UiccProfile uiccProfile = uiccCard.getUiccProfile();
9087 if (uiccProfile == null) {
9088 return false;
9089 }
9090 if (TelephonyManager.APPTYPE_SIM <= appType
9091 && appType <= TelephonyManager.APPTYPE_ISIM) {
9092 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
9093 }
9094 return false;
9095 } finally {
9096 Binder.restoreCallingIdentity(identity);
9097 }
9098 }
9099
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08009100 /**
chen xub4baa772019-04-03 10:23:41 -07009101 * Get whether making changes to modem configurations will trigger reboot.
9102 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009103 */
9104 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009105 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
9106 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07009107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07009108 mApp, subId, callingPackage, callingFeatureId,
9109 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07009110 return false;
9111 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08009112 final long identity = Binder.clearCallingIdentity();
9113 try {
9114 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
9115 } finally {
9116 Binder.restoreCallingIdentity(identity);
9117 }
9118 }
9119
Nathan Harold29f5f052019-02-15 13:41:57 -08009120 private void updateModemStateMetrics() {
9121 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
9122 // TODO: check the state for each modem if the api is ready.
9123 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
9124 }
9125
Pengquan Meng3889a572019-01-23 11:16:29 -08009126 @Override
9127 public int[] getSlotsMapping() {
9128 enforceReadPrivilegedPermission("getSlotsMapping");
9129
9130 final long identity = Binder.clearCallingIdentity();
9131 try {
9132 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
9133 // All logical slots should have a mapping to a physical slot.
9134 int[] logicalSlotsMapping = new int[phoneCount];
9135 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
9136 for (int i = 0; i < slotInfos.length; i++) {
9137 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
9138 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
9139 }
9140 }
9141 return logicalSlotsMapping;
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
9144 }
9145 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08009146
9147 /**
9148 * Get the IRadio HAL Version
9149 */
9150 @Override
9151 public int getRadioHalVersion() {
9152 Phone phone = getDefaultPhone();
9153 if (phone == null) return -1;
9154 HalVersion hv = phone.getHalVersion();
9155 if (hv.equals(HalVersion.UNKNOWN)) return -1;
9156 return hv.major * 100 + hv.minor;
9157 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009158
9159 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009160 * Get the current calling package name.
9161 * @return the current calling package name
9162 */
9163 @Override
9164 public String getCurrentPackageName() {
9165 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
9166 }
9167
9168 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07009169 * Return whether data is enabled for certain APN type. This will tell if framework will accept
9170 * corresponding network requests on a subId.
9171 *
9172 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009173 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07009174 * 2) APN is un-metered for this subscription, or
9175 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07009176 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07009177 *
9178 * @return whether data is allowed for a apn type.
9179 *
9180 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009181 */
9182 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07009183 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07009184 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
9185 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009186
9187 // Now that all security checks passes, perform the operation as ourselves.
9188 final long identity = Binder.clearCallingIdentity();
9189 try {
9190 Phone phone = getPhone(subId);
9191 if (phone == null) return false;
9192
Jack Yu41407ee2019-05-13 16:54:09 -07009193 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07009194 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
9195 } finally {
9196 Binder.restoreCallingIdentity(identity);
9197 }
9198 }
9199
9200 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07009201 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07009202 enforceReadPrivilegedPermission("isApnMetered");
9203
9204 // Now that all security checks passes, perform the operation as ourselves.
9205 final long identity = Binder.clearCallingIdentity();
9206 try {
9207 Phone phone = getPhone(subId);
9208 if (phone == null) return true; // By default return true.
9209
Jack Yu41407ee2019-05-13 16:54:09 -07009210 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07009211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009215
9216 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08009217 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
9218 int subscriptionId, IBooleanConsumer resultCallback) {
9219 enforceModifyPermission();
9220 long token = Binder.clearCallingIdentity();
9221 try {
9222 Phone phone = getPhone(subscriptionId);
9223 if (phone == null) {
9224 try {
9225 if (resultCallback != null) {
9226 resultCallback.accept(false);
9227 }
9228 } catch (RemoteException e) {
9229 // ignore
9230 }
9231 return;
9232 }
9233 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9234 Pair.create(specifiers, (x) -> {
9235 try {
9236 if (resultCallback != null) {
9237 resultCallback.accept(x);
9238 }
9239 } catch (RemoteException e) {
9240 // ignore
9241 }
9242 });
9243 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9244 } finally {
9245 Binder.restoreCallingIdentity(token);
9246 }
9247 }
9248
9249 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08009250 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9251 TelephonyPermissions
Nathan Harold62c68512021-04-06 11:26:02 -07009252 .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Sarah Chin679c08a2020-11-18 13:39:35 -08009253 mApp, subId, "getSystemSelectionChannels");
9254 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9255 final long identity = Binder.clearCallingIdentity();
9256 try {
9257 List<RadioAccessSpecifier> specifiers =
9258 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9259 null, subId, workSource);
9260 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9261 return specifiers;
9262 } finally {
9263 Binder.restoreCallingIdentity(identity);
9264 }
9265 }
9266
9267 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009268 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009269 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009270 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9271 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9272 if (iccRecords == null) {
9273 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9274 return false;
9275 }
9276 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9277 }
9278
9279 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009280 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9281 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009282 if (callingPackage == null) {
9283 callingPackage = getCurrentPackageName();
9284 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009285 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9286 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009287 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9288 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009289 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9290 }
9291 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9292 Intent intent = new Intent();
9293 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9294 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9295 // Bring up choose default SMS subscription dialog right now
9296 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9297 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9298 mApp.startActivity(intent);
9299 }
chen xud5ca2d52019-05-28 15:20:57 -07009300
9301 @Override
9302 public String getMmsUAProfUrl(int subId) {
9303 //TODO investigate if this API should require proper permission check in R b/133791609
9304 final long identity = Binder.clearCallingIdentity();
9305 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009306 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9307 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9308 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9309 return carrierUAProfUrl;
9310 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009311 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9312 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009313 } finally {
9314 Binder.restoreCallingIdentity(identity);
9315 }
9316 }
9317
9318 @Override
9319 public String getMmsUserAgent(int subId) {
9320 //TODO investigate if this API should require proper permission check in R b/133791609
9321 final long identity = Binder.clearCallingIdentity();
9322 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009323 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9324 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9325 if (!TextUtils.isEmpty(carrierUserAgent)) {
9326 return carrierUserAgent;
9327 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009328 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9329 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009330 } finally {
9331 Binder.restoreCallingIdentity(identity);
9332 }
9333 }
Jack Yub07d4972019-05-28 16:12:25 -07009334
9335 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009336 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9337 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009338
Jack Yub07d4972019-05-28 16:12:25 -07009339 final long identity = Binder.clearCallingIdentity();
9340 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009341 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009342 if (phone == null) return false;
9343
Hall Liua62f5da2020-09-25 10:42:19 -07009344 switch (policy) {
9345 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9346 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9347 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9348 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9349 default:
9350 throw new IllegalArgumentException(policy + " is not a valid policy");
9351 }
Jack Yub07d4972019-05-28 16:12:25 -07009352 } finally {
9353 Binder.restoreCallingIdentity(identity);
9354 }
9355 }
9356
9357 @Override
Hall Liuc66bb112021-02-02 12:09:32 -08009358 public void setMobileDataPolicyEnabled(int subscriptionId, int policy,
Hall Liua62f5da2020-09-25 10:42:19 -07009359 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009360 enforceModifyPermission();
9361
changbettyd5c246e2019-12-24 15:40:37 +08009362 final long identity = Binder.clearCallingIdentity();
9363 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009364 Phone phone = getPhone(subscriptionId);
9365 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009366
Hall Liua62f5da2020-09-25 10:42:19 -07009367 switch (policy) {
9368 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9369 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9370 break;
9371 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9372 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9373 break;
9374 default:
9375 throw new IllegalArgumentException(policy + " is not a valid policy");
9376 }
changbettyd5c246e2019-12-24 15:40:37 +08009377 } finally {
9378 Binder.restoreCallingIdentity(identity);
9379 }
9380 }
9381
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009382 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009383 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009384 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9385 * otherwise.
9386 */
9387 @Override
9388 public void setCepEnabled(boolean isCepEnabled) {
9389 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9390
9391 final long identity = Binder.clearCallingIdentity();
9392 try {
9393 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9394 for (Phone phone : PhoneFactory.getPhones()) {
9395 Phone defaultPhone = phone.getImsPhone();
9396 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9397 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9398 ImsPhoneCallTracker imsPhoneCallTracker =
9399 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9400 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9401 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9402 + imsPhone.getMsisdn());
9403 }
9404 }
9405 } finally {
9406 Binder.restoreCallingIdentity(identity);
9407 }
9408 }
allenwtsu46dcc572020-01-08 18:24:03 +08009409
9410 /**
9411 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9412 *
9413 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9414 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9415 * before being read.
9416 */
9417 @Override
9418 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9419 isCompressed) {
9420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9421 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009422 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9423 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9424 }
9425 if (!isImsAvailableOnDevice()) {
9426 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9427 "IMS not available on device.");
9428 }
9429
9430 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009431 try {
Hui Wang761a6682020-10-31 05:12:53 +00009432 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9433 } finally {
9434 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009435 }
9436 }
zoey chene02881a2019-12-30 16:11:23 +08009437
9438 @Override
9439 public boolean isIccLockEnabled(int subId) {
9440 enforceReadPrivilegedPermission("isIccLockEnabled");
9441
9442 // Now that all security checks passes, perform the operation as ourselves.
9443 final long identity = Binder.clearCallingIdentity();
9444 try {
9445 Phone phone = getPhone(subId);
9446 if (phone != null && phone.getIccCard() != null) {
9447 return phone.getIccCard().getIccLockEnabled();
9448 } else {
9449 return false;
9450 }
9451 } finally {
9452 Binder.restoreCallingIdentity(identity);
9453 }
9454 }
9455
9456 /**
9457 * Set the ICC pin lock enabled or disabled.
9458 *
9459 * @return an integer representing the status of IccLock enabled or disabled in the following
9460 * three cases:
9461 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9462 * successfully.
9463 * - Positive number and zero for remaining password attempts.
9464 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9465 *
9466 */
9467 @Override
9468 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9469 enforceModifyPermission();
9470
9471 Phone phone = getPhone(subId);
9472 if (phone == null) {
9473 return 0;
9474 }
9475 // Now that all security checks passes, perform the operation as ourselves.
9476 final long identity = Binder.clearCallingIdentity();
9477 try {
9478 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9479 new Pair<Boolean, String>(enabled, password), phone, null);
9480 return attemptsRemaining;
9481
9482 } catch (Exception e) {
9483 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9484 } finally {
9485 Binder.restoreCallingIdentity(identity);
9486 }
9487 return 0;
9488 }
9489
9490 /**
9491 * Change the ICC password used in ICC pin lock.
9492 *
9493 * @return an integer representing the status of IccLock changed in the following three cases:
9494 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9495 * - Positive number and zero for remaining password attempts.
9496 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9497 *
9498 */
9499 @Override
9500 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9501 enforceModifyPermission();
9502
9503 Phone phone = getPhone(subId);
9504 if (phone == null) {
9505 return 0;
9506 }
9507 // Now that all security checks passes, perform the operation as ourselves.
9508 final long identity = Binder.clearCallingIdentity();
9509 try {
9510 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9511 new Pair<String, String>(oldPassword, newPassword), phone, null);
9512 return attemptsRemaining;
9513
9514 } catch (Exception e) {
9515 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9516 } finally {
9517 Binder.restoreCallingIdentity(identity);
9518 }
9519 return 0;
9520 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009521
9522 /**
9523 * Request for receiving user activity notification
9524 */
9525 @Override
9526 public void requestUserActivityNotification() {
9527 if (!mNotifyUserActivity.get()
9528 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9529 mNotifyUserActivity.set(true);
9530 }
9531 }
9532
9533 /**
9534 * Called when userActivity is signalled in the power manager.
9535 * This is safe to call from any thread, with any window manager locks held or not.
9536 */
9537 @Override
9538 public void userActivity() {
9539 // ***************************************
9540 // * Inherited from PhoneWindowManager *
9541 // ***************************************
9542 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9543 // WITH ITS LOCKS HELD.
9544 //
9545 // This code must be VERY careful about the locks
9546 // it acquires.
9547 // In fact, the current code acquires way too many,
9548 // and probably has lurking deadlocks.
9549
9550 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9551 throw new SecurityException("Only the OS may call notifyUserActivity()");
9552 }
9553
9554 if (mNotifyUserActivity.getAndSet(false)) {
9555 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9556 USER_ACTIVITY_NOTIFICATION_DELAY);
9557 }
9558 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009559
9560 @Override
9561 public boolean canConnectTo5GInDsdsMode() {
9562 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9563 }
Jack Yud10cdd42020-09-28 20:28:01 -07009564
9565 @Override
9566 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9567 String callingFeatureId) {
9568 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9569 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9570 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9571 }
9572
9573 Phone phone = getPhone(subId);
9574 if (phone == null) {
9575 throw new RuntimeException("phone is not available");
9576 }
9577 // Now that all security checks passes, perform the operation as ourselves.
9578 final long identity = Binder.clearCallingIdentity();
9579 try {
9580 return phone.getEquivalentHomePlmns();
9581 } finally {
9582 Binder.restoreCallingIdentity(identity);
9583 }
9584 }
Daniel Bright59e67312020-11-13 11:49:37 -08009585
9586 @Override
9587 public boolean isRadioInterfaceCapabilitySupported(
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009588 final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9589 Set<String> radioInterfaceCapabilities =
Daniel Bright94f43662021-03-01 14:43:40 -08009590 mRadioInterfaceCapabilities.getCapabilities();
Daniel Bright59e67312020-11-13 11:49:37 -08009591 if (radioInterfaceCapabilities == null) {
9592 throw new RuntimeException("radio interface capabilities are not available");
Daniel Bright59e67312020-11-13 11:49:37 -08009593 }
Daniel Bright95a4c1f2021-02-11 09:57:16 -08009594 return radioInterfaceCapabilities.contains(capability);
Daniel Bright59e67312020-11-13 11:49:37 -08009595 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009596
Hui Wang641e81c2020-10-12 12:14:23 -07009597 @Override
9598 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9599 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger34c09a52021-02-17 23:23:21 +00009600 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9601 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9602 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9603 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9604 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang641e81c2020-10-12 12:14:23 -07009605 if (DBG) {
9606 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9607 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9608 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9609 }
9610
9611 if (!SubscriptionManager.isValidSubscriptionId(subId)
9612 || appType < TelephonyManager.APPTYPE_UNKNOWN
9613 || appType > TelephonyManager.APPTYPE_ISIM
9614 || nafUrl == null || securityProtocol == null || callback == null) {
9615 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9616 if (callback != null) {
9617 try {
9618 callback.onAuthenticationFailure(
9619 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9620 } catch (RemoteException exception) {
9621 log("Fail to notify onAuthenticationFailure due to " + exception);
9622 }
9623 return;
9624 }
9625 }
9626
9627 final long token = Binder.clearCallingIdentity();
9628 try {
9629 getGbaManager(subId).bootstrapAuthenticationRequest(
9630 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9631 forceBootStrapping, callback));
9632 } finally {
9633 Binder.restoreCallingIdentity(token);
9634 }
9635 }
9636
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009637 /**
9638 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9639 * requested radio power state will actually be set. See {@link
9640 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9641 *
9642 * @param subId the subscription ID of the phone requesting to set the radio power state.
9643 * @param enable {@code true} if trying to turn radio on.
9644 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9645 * false}.
9646 */
9647 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9648 Phone phone = getPhone(subId);
9649 if (phone != null) {
9650 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9651 return true;
9652 }
9653 return false;
9654 }
9655
9656 private int handleDataThrottlingRequest(int subId,
9657 DataThrottlingRequest dataThrottlingRequest) {
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009658 boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported(
9659 TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING);
9660 if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction()
9661 != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) {
9662 throw new IllegalArgumentException("modem does not support data throttling");
9663 }
9664
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009665 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9666 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9667 if (!setRadioPowerForThermal(subId, true)) {
9668 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9669 }
9670
9671 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9672
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009673 if (isDataThrottlingSupported) {
9674 int thermalMitigationResult =
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009675 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009676 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9677 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9678 } else if (thermalMitigationResult
9679 == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) {
9680 throw new IllegalArgumentException("modem does not support data throttling");
9681 }
9682 return thermalMitigationResult;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009683 }
Jack Nudelman5d6a98b2021-03-04 14:26:25 -08009684
9685 return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009686 }
9687
Jack Nudelman644b91a2021-03-12 14:09:48 -08009688 private static List<String> getThermalMitigationAllowlist(Context context) {
9689 if (sThermalMitigationAllowlistedPackages.isEmpty()) {
9690 for (String pckg : context.getResources()
9691 .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) {
9692 sThermalMitigationAllowlistedPackages.add(pckg);
9693 }
9694 }
9695
9696 return sThermalMitigationAllowlistedPackages;
9697 }
9698
9699 /**
9700 * Used by shell commands to add an authorized package name for thermal mitigation.
9701 * @param packageName name of package to be allowlisted
9702 * @param context
9703 */
9704 static void addPackageToThermalMitigationAllowlist(String packageName, Context context) {
9705 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9706 sThermalMitigationAllowlistedPackages.add(packageName);
9707 }
9708
9709 /**
9710 * Used by shell commands to remove an authorized package name for thermal mitigation.
9711 * @param packageName name of package to remove from allowlist
9712 * @param context
9713 */
9714 static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) {
9715 sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context);
9716 sThermalMitigationAllowlistedPackages.remove(packageName);
9717 }
9718
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009719 /**
9720 * Thermal mitigation request to control functionalities at modem.
9721 *
9722 * @param subId the id of the subscription.
9723 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
Jack Nudelman644b91a2021-03-12 14:09:48 -08009724 * @param callingPackage the package name of the calling package.
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009725 *
9726 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9727 */
9728 @Override
9729 @ThermalMitigationResult
9730 public int sendThermalMitigationRequest(
9731 int subId,
Jack Nudelman644b91a2021-03-12 14:09:48 -08009732 ThermalMitigationRequest thermalMitigationRequest,
9733 String callingPackage) throws IllegalArgumentException {
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009734 enforceModifyPermission();
9735
Jack Nudelman644b91a2021-03-12 14:09:48 -08009736 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
9737 if (!getThermalMitigationAllowlist(getDefaultPhone().getContext())
9738 .contains(callingPackage)) {
9739 throw new SecurityException("Calling package must be configured in the device config. "
9740 + "calling package: " + callingPackage);
9741 }
9742
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009743 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9744 final long identity = Binder.clearCallingIdentity();
9745
9746 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9747 try {
9748 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9749 switch (thermalMitigationAction) {
9750 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9751 thermalMitigationResult =
9752 handleDataThrottlingRequest(subId,
9753 thermalMitigationRequest.getDataThrottlingRequest());
9754 break;
9755 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9756 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9757 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9758 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9759 }
9760
9761 // Ensure that radio is on. If not able to power on due to phone being
9762 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9763 if (!setRadioPowerForThermal(subId, true)) {
9764 thermalMitigationResult =
9765 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9766 break;
9767 }
9768
9769 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9770 false);
9771 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9772 break;
9773 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9774 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9775 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9776 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9777 }
9778
9779 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9780 if (registry != null) {
9781 TelephonyConnectionService service =
9782 registry.getTelephonyConnectionService();
9783 Phone phone = getPhone(subId);
9784 if (phone == null) {
9785 thermalMitigationResult =
9786 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9787 break;
9788 }
9789
9790 if (PhoneConstantConversions.convertCallState(phone.getState())
9791 != TelephonyManager.CALL_STATE_IDLE
9792 || phone.isInEmergencySmsMode() || phone.isInEcm()
9793 || (service != null && service.isEmergencyCallPending())) {
9794 String errorMessage = "Phone state is not valid. call state = "
9795 + PhoneConstantConversions.convertCallState(phone.getState())
9796 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9797 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9798 errorMessage += service == null
9799 ? " TelephonyConnectionService is null"
9800 : " isEmergencyCallPending = "
9801 + service.isEmergencyCallPending();
9802 Log.e(LOG_TAG, errorMessage);
9803 thermalMitigationResult =
9804 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9805 break;
9806 }
9807 } else {
9808 thermalMitigationResult =
9809 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9810 break;
9811 }
9812
9813 // Turn radio off. If not able to power off due to phone being unavailable,
9814 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9815 if (!setRadioPowerForThermal(subId, false)) {
9816 thermalMitigationResult =
9817 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9818 break;
9819 }
9820 thermalMitigationResult =
9821 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9822 break;
9823 default:
9824 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9825 + "not exist. Requested action: " + thermalMitigationAction);
9826 }
9827 } catch (IllegalArgumentException e) {
9828 throw e;
9829 } catch (Exception e) {
9830 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9831 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9832 } finally {
9833 Binder.restoreCallingIdentity(identity);
9834 }
9835
9836 if (DBG) {
9837 log("thermalMitigationRequest returning with thermalMitigationResult: "
9838 + thermalMitigationResult);
9839 }
9840
9841 return thermalMitigationResult;
9842 }
Hui Wang641e81c2020-10-12 12:14:23 -07009843
9844 /**
9845 * Set the GbaService Package Name that Telephony will bind to.
9846 *
9847 * @param subId The sim that the GbaService is associated with.
9848 * @param packageName The name of the package to be replaced with.
9849 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9850 */
9851 @Override
9852 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9853 enforceModifyPermission();
9854
9855 final long identity = Binder.clearCallingIdentity();
9856 try {
9857 return getGbaManager(subId).overrideServicePackage(packageName);
9858 } finally {
9859 Binder.restoreCallingIdentity(identity);
9860 }
9861 }
9862
9863 /**
9864 * Return the package name of the currently bound GbaService.
9865 *
9866 * @param subId The sim that the GbaService is associated with.
9867 * @return the package name of the GbaService configuration, null if GBA is not supported.
9868 */
9869 @Override
9870 public String getBoundGbaService(int subId) {
9871 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9872
9873 final long identity = Binder.clearCallingIdentity();
9874 try {
9875 return getGbaManager(subId).getServicePackage();
9876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
9880
9881 /**
9882 * Set the release time for telephony to unbind GbaService.
9883 *
9884 * @param subId The sim that the GbaService is associated with.
9885 * @param interval The release time to unbind GbaService by millisecond.
9886 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9887 */
9888 @Override
9889 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9890 enforceModifyPermission();
9891
9892 final long identity = Binder.clearCallingIdentity();
9893 try {
9894 return getGbaManager(subId).overrideReleaseTime(interval);
9895 } finally {
9896 Binder.restoreCallingIdentity(identity);
9897 }
9898 }
9899
9900 /**
9901 * Return the release time for telephony to unbind GbaService.
9902 *
9903 * @param subId The sim that the GbaService is associated with.
9904 * @return The release time to unbind GbaService by millisecond.
9905 */
9906 @Override
9907 public int getGbaReleaseTime(int subId) {
9908 enforceReadPrivilegedPermission("getGbaReleaseTime");
9909
9910 final long identity = Binder.clearCallingIdentity();
9911 try {
9912 return getGbaManager(subId).getReleaseTime();
9913 } finally {
9914 Binder.restoreCallingIdentity(identity);
9915 }
9916 }
9917
9918 private GbaManager getGbaManager(int subId) {
9919 GbaManager instance = GbaManager.getInstance(subId);
9920 if (instance == null) {
9921 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9922 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9923 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9924 }
9925 return instance;
9926 }
Hui Wang761a6682020-10-31 05:12:53 +00009927
9928 /**
9929 * indicate whether the device and the carrier can support
9930 * RCS VoLTE single registration.
9931 */
9932 @Override
9933 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009934 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9935 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9936 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9937 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009938
9939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9940 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9941 }
9942
9943 final long identity = Binder.clearCallingIdentity();
9944 try {
9945 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9946 if (rpm != null) {
9947 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9948 }
9949 return false;
9950 } finally {
9951 Binder.restoreCallingIdentity(identity);
9952 }
9953 }
9954
9955 /**
9956 * Register RCS provisioning callback.
9957 */
9958 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009959 public void registerRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009960 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009961 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009962 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009963 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9964 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009965
9966 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9967 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9968 }
9969 if (!isImsAvailableOnDevice()) {
9970 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9971 "IMS not available on device.");
9972 }
9973
9974 final long identity = Binder.clearCallingIdentity();
9975 try {
Hui Wang68cd3722021-01-11 20:04:53 -08009976 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009977 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang68cd3722021-01-11 20:04:53 -08009978 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9979 "Service not available for the subscription.");
9980 }
Hui Wang761a6682020-10-31 05:12:53 +00009981 } finally {
9982 Binder.restoreCallingIdentity(identity);
9983 }
9984 }
9985
9986 /**
9987 * Unregister RCS provisioning callback.
9988 */
9989 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009990 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang761a6682020-10-31 05:12:53 +00009991 IRcsConfigCallback callback) {
Brad Ebinger34c09a52021-02-17 23:23:21 +00009992 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009993 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger34c09a52021-02-17 23:23:21 +00009994 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9995 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang761a6682020-10-31 05:12:53 +00009996
9997 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9998 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9999 }
10000 if (!isImsAvailableOnDevice()) {
10001 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10002 "IMS not available on device.");
10003 }
10004
10005 final long identity = Binder.clearCallingIdentity();
10006 try {
Hui Wang68cd3722021-01-11 20:04:53 -080010007 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -080010008 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang761a6682020-10-31 05:12:53 +000010009 } finally {
10010 Binder.restoreCallingIdentity(identity);
10011 }
10012 }
10013
10014 /**
10015 * trigger RCS reconfiguration.
10016 */
10017 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010018 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10019 "triggerRcsReconfiguration",
10020 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010021
10022 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10023 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10024 }
10025 if (!isImsAvailableOnDevice()) {
10026 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10027 "IMS not available on device.");
10028 }
10029
10030 final long identity = Binder.clearCallingIdentity();
10031 try {
10032 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
10033 } finally {
10034 Binder.restoreCallingIdentity(identity);
10035 }
10036 }
10037
10038 /**
10039 * Provide the client configuration parameters of the RCS application.
10040 */
10041 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger34c09a52021-02-17 23:23:21 +000010042 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
10043 "setRcsClientConfiguration",
10044 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang761a6682020-10-31 05:12:53 +000010045
10046 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
10047 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
10048 }
10049 if (!isImsAvailableOnDevice()) {
10050 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
10051 "IMS not available on device.");
10052 }
10053
10054 final long identity = Binder.clearCallingIdentity();
10055
10056 try {
10057 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
10058 if (configBinder == null) {
10059 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
10060 } else {
10061 configBinder.setRcsClientConfiguration(rcc);
10062 }
10063 } catch (RemoteException e) {
10064 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
10065 } finally {
10066 Binder.restoreCallingIdentity(identity);
10067 }
10068 }
10069
10070 /**
Hui Wangbaaee6a2021-02-19 20:45:36 -080010071 * Enables or disables the test mode for RCS VoLTE single registration.
10072 */
10073 @Override
10074 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
10075 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10076 "setRcsSingleRegistrationTestModeEnabled");
10077
10078 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
10079 }
10080
10081 /**
10082 * Gets the test mode for RCS VoLTE single registration.
10083 */
10084 @Override
10085 public boolean getRcsSingleRegistrationTestModeEnabled() {
10086 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10087 "getRcsSingleRegistrationTestModeEnabled");
10088
10089 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
10090 }
10091
10092 /**
Hui Wang761a6682020-10-31 05:12:53 +000010093 * Overrides the config of RCS VoLTE single registration enabled for the device.
10094 */
10095 @Override
10096 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
10097 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10098 "setDeviceSingleRegistrationEnabledOverride");
10099 enforceModifyPermission();
10100
10101 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10102 : Boolean.parseBoolean(enabledStr);
10103 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +000010104 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang761a6682020-10-31 05:12:53 +000010105 }
10106
10107 /**
Tyler Gunn92479152021-01-20 16:30:10 -080010108 * Sends a device to device communication message. Only usable via shell.
10109 * @param message message to send.
10110 * @param value message value.
10111 */
10112 @Override
10113 public void sendDeviceToDeviceMessage(int message, int value) {
10114 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
Tyler Gunnbabbda02021-02-10 11:05:02 -080010115 "sendDeviceToDeviceMessage");
Tyler Gunn92479152021-01-20 16:30:10 -080010116 enforceModifyPermission();
10117
10118 final long identity = Binder.clearCallingIdentity();
10119 try {
10120 TelephonyConnectionService service =
10121 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10122 if (service == null) {
10123 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
10124 return;
10125 }
10126 service.sendTestDeviceToDeviceMessage(message, value);
10127 } finally {
10128 Binder.restoreCallingIdentity(identity);
10129 }
10130 }
10131
Tyler Gunnbabbda02021-02-10 11:05:02 -080010132 /**
10133 * Sets the specified device to device transport active.
10134 * @param transport The transport to set active.
10135 */
10136 @Override
10137 public void setActiveDeviceToDeviceTransport(@NonNull String transport) {
10138 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10139 "setActiveDeviceToDeviceTransport");
10140 enforceModifyPermission();
10141
10142 final long identity = Binder.clearCallingIdentity();
10143 try {
10144 TelephonyConnectionService service =
10145 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
10146 if (service == null) {
10147 Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call.");
10148 return;
10149 }
10150 service.setActiveDeviceToDeviceTransport(transport);
10151 } finally {
10152 Binder.restoreCallingIdentity(identity);
10153 }
10154 }
Tyler Gunn92479152021-01-20 16:30:10 -080010155
10156 /**
Hui Wang761a6682020-10-31 05:12:53 +000010157 * Gets the config of RCS VoLTE single registration enabled for the device.
10158 */
10159 @Override
10160 public boolean getDeviceSingleRegistrationEnabled() {
10161 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
10162 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
10163 }
10164
10165 /**
10166 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
10167 */
10168 @Override
10169 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
10170 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10171 "setCarrierSingleRegistrationEnabledOverride");
10172 enforceModifyPermission();
10173
10174 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10175 : Boolean.parseBoolean(enabledStr);
10176 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
10177 subId, enabled);
10178 }
10179
10180 /**
10181 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
10182 */
10183 @Override
10184 public boolean getCarrierSingleRegistrationEnabled(int subId) {
10185 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
10186 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
10187 }
Chiachang Wangd6d34772020-12-22 11:38:27 +080010188
10189 /**
Hui Wangb647abe2021-02-26 09:33:38 -080010190 * Overrides the ims feature validation result
10191 */
10192 @Override
10193 public boolean setImsFeatureValidationOverride(int subId, String enabledStr) {
10194 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10195 "setImsFeatureValidationOverride");
10196
10197 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
10198 : Boolean.parseBoolean(enabledStr);
10199 return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation(
10200 subId, enabled);
10201 }
10202
10203 /**
10204 * Gets the ims feature validation override value
10205 */
10206 @Override
10207 public boolean getImsFeatureValidationOverride(int subId) {
10208 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10209 "getImsFeatureValidationOverride");
10210 return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId);
10211 }
10212
10213 /**
Chiachang Wangd6d34772020-12-22 11:38:27 +080010214 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
10215 * their mobile plan.
10216 */
10217 @Override
10218 public String getMobileProvisioningUrl() {
10219 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
10220 final long identity = Binder.clearCallingIdentity();
10221 try {
10222 return getDefaultPhone().getMobileProvisioningUrl();
10223 } finally {
10224 Binder.restoreCallingIdentity(identity);
10225 }
10226 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010227
James.cf Linbcdf8b32021-01-14 16:44:13 +080010228 /**
calvinpane4a8a1d2021-01-25 13:51:18 +080010229 * Get the EAB contact from the EAB database.
10230 */
10231 @Override
10232 public String getContactFromEab(String contact) {
10233 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
10234 enforceModifyPermission();
10235 final long identity = Binder.clearCallingIdentity();
10236 try {
10237 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
10238 } finally {
10239 Binder.restoreCallingIdentity(identity);
10240 }
10241 }
10242
10243 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +080010244 * Remove the EAB contacts from the EAB database.
10245 */
10246 @Override
10247 public int removeContactFromEab(int subId, String contacts) {
10248 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
10249 enforceModifyPermission();
10250 final long identity = Binder.clearCallingIdentity();
10251 try {
10252 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
10253 } finally {
10254 Binder.restoreCallingIdentity(identity);
10255 }
10256 }
10257
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010258 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +080010259 public boolean getDeviceUceEnabled() {
10260 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
10261 final long identity = Binder.clearCallingIdentity();
10262 try {
10263 return mApp.getDeviceUceEnabled();
10264 } finally {
10265 Binder.restoreCallingIdentity(identity);
10266 }
10267 }
10268
10269 @Override
10270 public void setDeviceUceEnabled(boolean isEnabled) {
10271 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
10272 final long identity = Binder.clearCallingIdentity();
10273 try {
10274 mApp.setDeviceUceEnabled(isEnabled);
10275 } finally {
10276 Binder.restoreCallingIdentity(identity);
10277 }
10278 }
10279
Brad Ebinger14d467f2021-02-12 06:18:28 +000010280 /**
10281 * Add new feature tags to the Set used to calculate the capabilities in PUBLISH.
10282 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10283 */
10284 // Used for SHELL command only right now.
10285 @Override
10286 public RcsContactUceCapability addUceRegistrationOverrideShell(int subId,
10287 List<String> featureTags) {
10288 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10289 "addUceRegistrationOverrideShell");
10290 final long identity = Binder.clearCallingIdentity();
10291 try {
10292 return mApp.imsRcsController.addUceRegistrationOverrideShell(subId,
10293 new ArraySet<>(featureTags));
10294 } catch (ImsException e) {
10295 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10296 } finally {
10297 Binder.restoreCallingIdentity(identity);
10298 }
10299 }
10300
10301 /**
10302 * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH.
10303 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10304 */
10305 // Used for SHELL command only right now.
10306 @Override
10307 public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId,
10308 List<String> featureTags) {
10309 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10310 "removeUceRegistrationOverrideShell");
10311 final long identity = Binder.clearCallingIdentity();
10312 try {
10313 return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId,
10314 new ArraySet<>(featureTags));
10315 } catch (ImsException e) {
10316 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10317 } finally {
10318 Binder.restoreCallingIdentity(identity);
10319 }
10320 }
10321
10322 /**
10323 * Clear all overrides in the Set used to calculate the capabilities in PUBLISH.
10324 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10325 */
10326 // Used for SHELL command only right now.
10327 @Override
10328 public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) {
10329 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10330 "clearUceRegistrationOverrideShell");
10331 final long identity = Binder.clearCallingIdentity();
10332 try {
10333 return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId);
10334 } catch (ImsException e) {
10335 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10336 } finally {
10337 Binder.restoreCallingIdentity(identity);
10338 }
10339 }
10340
10341 /**
10342 * @return current RcsContactUceCapability instance that will be used for PUBLISH.
10343 */
10344 // Used for SHELL command only right now.
10345 @Override
10346 public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) {
10347 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
10348 "getLatestRcsContactUceCapabilityShell");
10349 final long identity = Binder.clearCallingIdentity();
10350 try {
10351 return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId);
10352 } catch (ImsException e) {
10353 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10354 } finally {
10355 Binder.restoreCallingIdentity(identity);
10356 }
10357 }
10358
10359 /**
10360 * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the
10361 * device does not have an active PUBLISH.
10362 */
10363 // Used for SHELL command only right now.
10364 @Override
10365 public String getLastUcePidfXmlShell(int subId) {
10366 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml");
10367 final long identity = Binder.clearCallingIdentity();
10368 try {
10369 return mApp.imsRcsController.getLastUcePidfXmlShell(subId);
10370 } catch (ImsException e) {
10371 throw new ServiceSpecificException(e.getCode(), e.getMessage());
10372 } finally {
10373 Binder.restoreCallingIdentity(identity);
10374 }
10375 }
10376
10377
James.cf Lin4b784aa2021-01-31 03:25:15 +080010378 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -080010379 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10380 String callingPackage) {
10381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10382 mApp, subId, "setSignalStrengthUpdateRequest");
10383
10384 final int callingUid = Binder.getCallingUid();
10385 // Verify that tha callingPackage belongs to the calling UID
10386 mApp.getSystemService(AppOpsManager.class)
10387 .checkPackage(callingUid, callingPackage);
10388
10389 validateSignalStrengthUpdateRequest(request, callingUid);
10390
10391 final long identity = Binder.clearCallingIdentity();
10392 try {
10393 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
10394 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10395
10396 if (result instanceof IllegalStateException) {
10397 throw (IllegalStateException) result;
10398 }
10399 } finally {
10400 Binder.restoreCallingIdentity(identity);
10401 }
10402 }
10403
10404 @Override
10405 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
10406 String callingPackage) {
10407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
10408 mApp, subId, "clearSignalStrengthUpdateRequest");
10409
10410 final int callingUid = Binder.getCallingUid();
10411 // Verify that tha callingPackage belongs to the calling UID
10412 mApp.getSystemService(AppOpsManager.class)
10413 .checkPackage(callingUid, callingPackage);
10414
10415 final long identity = Binder.clearCallingIdentity();
10416 try {
10417 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
10418 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
10419
10420 if (result instanceof IllegalStateException) {
10421 throw (IllegalStateException) result;
10422 }
10423 } finally {
10424 Binder.restoreCallingIdentity(identity);
10425 }
10426 }
10427
10428 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
10429 int callingUid) {
10430 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
10431 // phone/system process do not have further restriction on request
10432 return;
10433 }
10434
10435 // Applications has restrictions on how to use the request:
10436 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
10437 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
10438 // This is not system caller which has been checked above
10439 throw new IllegalArgumentException(
10440 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
10441 }
10442
10443 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
10444 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
10445 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
10446 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
10447 || info.isEnabled()) {
10448 throw new IllegalArgumentException(
10449 "Only system can set hide fields in SignalThresholdInfo");
10450 }
10451
10452 // Thresholds length for each RAN need in range. This has been validated in
10453 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10454 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10455 final int[] thresholds = info.getThresholds();
10456 Objects.requireNonNull(thresholds);
10457 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10458 || thresholds.length
10459 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10460 throw new IllegalArgumentException(
10461 "thresholds length is out of range: " + thresholds.length);
10462 }
10463 }
10464 }
SongFerngWang8236caa2021-01-17 21:51:44 +080010465
10466 /**
10467 * Gets the current phone capability.
10468 *
10469 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
10470 * @return the PhoneCapability which describes the data connection capability of modem.
10471 * It's used to evaluate possible phone config change, for example from single
10472 * SIM device to multi-SIM device.
10473 */
10474 @Override
10475 public PhoneCapability getPhoneCapability() {
10476 enforceReadPrivilegedPermission("getPhoneCapability");
10477 final long identity = Binder.clearCallingIdentity();
10478 try {
10479 return mPhoneConfigurationManager.getCurrentPhoneCapability();
10480 } finally {
10481 Binder.restoreCallingIdentity(identity);
10482 }
10483 }
Michele Berionne5e411512020-11-13 02:36:59 +000010484
10485 /**
10486 * Prepare TelephonyManager for an unattended reboot. The reboot is
10487 * required to be done shortly after the API is invoked.
10488 */
10489 @Override
10490 @TelephonyManager.PrepareUnattendedRebootResult
10491 public int prepareForUnattendedReboot() {
10492 enforceRebootPermission();
10493
10494 final long identity = Binder.clearCallingIdentity();
10495 try {
10496 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10497 } finally {
10498 Binder.restoreCallingIdentity(identity);
10499 }
10500 }
Hongbo Zeng156aa4a2021-02-08 21:50:28 +080010501
10502 /**
10503 * Request to get the current slicing configuration including URSP rules and
10504 * NSSAIs (configured, allowed and rejected).
10505 *
10506 * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission.
10507 */
10508 @Override
10509 public void getSlicingConfig(ResultReceiver callback) {
10510 enforceReadPrivilegedPermission("getSlicingConfig");
10511
10512 final long identity = Binder.clearCallingIdentity();
10513 try {
10514 Phone phone = getDefaultPhone();
10515 sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null);
10516 } finally {
10517 Binder.restoreCallingIdentity(identity);
10518 }
10519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010520}